Files
Fishing2/Assets/TFP/_Standard/0_Extra/Shaders/TFP_Particle.shader
2025-06-05 07:33:02 +08:00

568 lines
30 KiB
Plaintext

// Shader created with Shader Forge v1.38
// Shader Forge (c) Freya Holmer - http://www.acegikmo.com/shaderforge/
// Note: Manually altering this data may prevent you from opening it in Shader Forge
/*SF_DATA;ver:1.38;sub:START;pass:START;ps:flbk:Particles/Additive (Soft),iptp:0,cusa:False,bamd:0,cgin:,lico:1,lgpr:1,limd:3,spmd:0,trmd:0,grmd:0,uamb:True,mssp:True,bkdf:True,hqlp:False,rprd:True,enco:False,rmgx:True,imps:True,rpth:0,vtps:0,hqsc:True,nrmq:1,nrsp:0,vomd:0,spxs:False,tesm:0,olmd:1,culm:0,bsrc:0,bdst:1,dpts:2,wrdp:True,dith:3,atcv:False,rfrpo:True,rfrpn:Refraction,coma:15,ufog:True,aust:True,igpj:False,qofs:0,qpre:2,rntp:3,fgom:False,fgoc:False,fgod:False,fgor:False,fgmd:0,fgcr:0.5441177,fgcg:0.5202206,fgcb:0.476103,fgca:1,fgde:0.00075,fgrn:0,fgrf:600,stcl:False,atwp:False,stva:128,stmr:255,stmw:255,stcp:6,stps:0,stfa:0,stfz:0,ofsf:0,ofsu:0,f2p0:False,fnsp:False,fnfb:False,fsmp:False;n:type:ShaderForge.SFN_Final,id:2865,x:32719,y:32712,varname:node_2865,prsc:2|diff-6343-OUT,spec-6584-OUT,gloss-6052-OUT,transm-9869-OUT,clip-8244-OUT;n:type:ShaderForge.SFN_Multiply,id:6343,x:32114,y:32710,varname:node_6343,prsc:2|A-7736-RGB,B-6665-RGB,C-9046-RGB;n:type:ShaderForge.SFN_Color,id:6665,x:31921,y:32805,ptovrint:False,ptlb:Color,ptin:_Color,varname:_Color,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,c1:1,c2:1,c3:1,c4:1;n:type:ShaderForge.SFN_Tex2d,id:7736,x:31921,y:32620,ptovrint:True,ptlb:Base Color,ptin:_MainTex,varname:_MainTex,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,ntxv:0,isnm:False;n:type:ShaderForge.SFN_Vector1,id:6584,x:32318,y:32762,varname:node_6584,prsc:2,v1:0.04;n:type:ShaderForge.SFN_Slider,id:1631,x:31775,y:33091,ptovrint:False,ptlb:Alpha,ptin:_Alpha,varname:node_1631,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,min:0,cur:0.8,max:1;n:type:ShaderForge.SFN_Multiply,id:8244,x:32135,y:32946,varname:node_8244,prsc:2|A-7736-A,B-1631-OUT,C-9046-A,D-9401-OUT;n:type:ShaderForge.SFN_VertexColor,id:9046,x:31699,y:32911,varname:node_9046,prsc:2;n:type:ShaderForge.SFN_Vector1,id:9401,x:31782,y:33211,varname:node_9401,prsc:2,v1:2;n:type:ShaderForge.SFN_Vector1,id:6052,x:32318,y:32827,varname:node_6052,prsc:2,v1:0.3;n:type:ShaderForge.SFN_ValueProperty,id:9869,x:32318,y:32913,ptovrint:False,ptlb:Transmission,ptin:_Transmission,varname:node_9869,prsc:2,glob:False,taghide:False,taghdr:False,tagprd:False,tagnsco:False,tagnrm:False,v1:0.5;proporder:6665-7736-1631-9869;pass:END;sub:END;*/
Shader "TFP/TFP_Particle" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Base Color", 2D) = "white" {}
_Alpha ("Alpha", Range(0, 1)) = 0.8
_Transmission ("Transmission", Float ) = 0.5
[HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags {
"Queue"="AlphaTest"
"RenderType"="TransparentCutout"
}
LOD 2000
Pass {
Name "FORWARD"
Tags {
"LightMode"="ForwardBase"
}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
#define _GLOSSYENV 1
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
#include "UnityStandardBRDF.cginc"
#pragma multi_compile_fwdbase_fullshadows
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
#pragma multi_compile_fog
#pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
#pragma target 3.0
// Dithering function, to use with scene UVs (screen pixel coords)
// 4x4 Bayer matrix, based on https://en.wikipedia.org/wiki/Ordered_dithering
float BinaryDither4x4( float value, float2 sceneUVs ) {
float4x4 mtx = float4x4(
float4( 1, 9, 3, 11 )/17.0,
float4( 13, 5, 15, 7 )/17.0,
float4( 4, 12, 2, 10 )/17.0,
float4( 16, 8, 14, 6 )/17.0
);
float2 px = floor(_ScreenParams.xy * sceneUVs);
int xSmp = fmod(px.x,4);
int ySmp = fmod(px.y,4);
float4 xVec = 1-saturate(abs(float4(0,1,2,3) - xSmp));
float4 yVec = 1-saturate(abs(float4(0,1,2,3) - ySmp));
float4 pxMult = float4( dot(mtx[0],yVec), dot(mtx[1],yVec), dot(mtx[2],yVec), dot(mtx[3],yVec) );
return round(value + dot(pxMult, xVec));
}
uniform float4 _Color;
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
uniform float _Alpha;
uniform float _Transmission;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 vertexColor : COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
float3 normalDir : TEXCOORD4;
float3 tangentDir : TEXCOORD5;
float3 bitangentDir : TEXCOORD6;
float4 vertexColor : COLOR;
float4 projPos : TEXCOORD7;
LIGHTING_COORDS(8,9)
UNITY_FOG_COORDS(10)
#if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH)
float4 ambientOrLightmapUV : TEXCOORD11;
#endif
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
o.vertexColor = v.vertexColor;
#ifdef LIGHTMAP_ON
o.ambientOrLightmapUV.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
o.ambientOrLightmapUV.zw = 0;
#elif UNITY_SHOULD_SAMPLE_SH
#endif
#ifdef DYNAMICLIGHTMAP_ON
o.ambientOrLightmapUV.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
#endif
o.normalDir = UnityObjectToWorldNormal(v.normal);
o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
float3 lightColor = _LightColor0.rgb;
o.pos = UnityObjectToClipPos( v.vertex );
UNITY_TRANSFER_FOG(o,o.pos);
o.projPos = ComputeScreenPos (o.pos);
COMPUTE_EYEDEPTH(o.projPos.z);
TRANSFER_VERTEX_TO_FRAGMENT(o)
return o;
}
float4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
float3 normalDirection = i.normalDir;
float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
float2 sceneUVs = (i.projPos.xy / i.projPos.w);
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
clip( BinaryDither4x4((_MainTex_var.a*_Alpha*i.vertexColor.a*2.0) - 1.5, sceneUVs) );
float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
float3 lightColor = _LightColor0.rgb;
float3 halfDirection = normalize(viewDirection+lightDirection);
////// Lighting:
UNITY_LIGHT_ATTENUATION(attenuation,i, i.posWorld.xyz);
float3 attenColor = attenuation * _LightColor0.xyz;
float Pi = 3.141592654;
float InvPi = 0.31830988618;
///////// Gloss:
float gloss = 0.3;
float perceptualRoughness = 1.0 - 0.3;
float roughness = perceptualRoughness * perceptualRoughness;
float specPow = exp2( gloss * 10.0 + 1.0 );
/////// GI Data:
UnityLight light;
#ifdef LIGHTMAP_OFF
light.color = lightColor;
light.dir = lightDirection;
light.ndotl = LambertTerm (normalDirection, light.dir);
#else
light.color = half3(0.f, 0.f, 0.f);
light.ndotl = 0.0f;
light.dir = half3(0.f, 0.f, 0.f);
#endif
UnityGIInput d;
d.light = light;
d.worldPos = i.posWorld.xyz;
d.worldViewDir = viewDirection;
d.atten = attenuation;
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
d.ambient = 0;
d.lightmapUV = i.ambientOrLightmapUV;
#else
d.ambient = i.ambientOrLightmapUV;
#endif
#if UNITY_SPECCUBE_BLENDING || UNITY_SPECCUBE_BOX_PROJECTION
d.boxMin[0] = unity_SpecCube0_BoxMin;
d.boxMin[1] = unity_SpecCube1_BoxMin;
#endif
#if UNITY_SPECCUBE_BOX_PROJECTION
d.boxMax[0] = unity_SpecCube0_BoxMax;
d.boxMax[1] = unity_SpecCube1_BoxMax;
d.probePosition[0] = unity_SpecCube0_ProbePosition;
d.probePosition[1] = unity_SpecCube1_ProbePosition;
#endif
d.probeHDR[0] = unity_SpecCube0_HDR;
d.probeHDR[1] = unity_SpecCube1_HDR;
Unity_GlossyEnvironmentData ugls_en_data;
ugls_en_data.roughness = 1.0 - gloss;
ugls_en_data.reflUVW = viewReflectDirection;
UnityGI gi = UnityGlobalIllumination(d, 1, normalDirection, ugls_en_data );
lightDirection = gi.light.dir;
lightColor = gi.light.color;
////// Specular:
float NdotL = saturate(dot( normalDirection, lightDirection ));
float LdotH = saturate(dot(lightDirection, halfDirection));
float node_6584 = 0.04;
float3 specularColor = float3(node_6584,node_6584,node_6584);
float specularMonochrome;
float3 diffuseColor = (_MainTex_var.rgb*_Color.rgb*i.vertexColor.rgb); // Need this for specular when using metallic
diffuseColor = EnergyConservationBetweenDiffuseAndSpecular(diffuseColor, specularColor, specularMonochrome);
specularMonochrome = 1.0-specularMonochrome;
float NdotV = abs(dot( normalDirection, viewDirection ));
float NdotH = saturate(dot( normalDirection, halfDirection ));
float VdotH = saturate(dot( viewDirection, halfDirection ));
float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );
float normTerm = GGXTerm(NdotH, roughness);
float specularPBL = (visTerm*normTerm) * UNITY_PI;
#ifdef UNITY_COLORSPACE_GAMMA
specularPBL = sqrt(max(1e-4h, specularPBL));
#endif
specularPBL = max(0, specularPBL * NdotL);
#if defined(_SPECULARHIGHLIGHTS_OFF)
specularPBL = 0.0;
#endif
half surfaceReduction;
#ifdef UNITY_COLORSPACE_GAMMA
surfaceReduction = 1.0-0.28*roughness*perceptualRoughness;
#else
surfaceReduction = 1.0/(roughness*roughness + 1.0);
#endif
specularPBL *= any(specularColor) ? 1.0 : 0.0;
float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
half grazingTerm = saturate( gloss + specularMonochrome );
float3 indirectSpecular = (gi.indirect.specular);
indirectSpecular *= FresnelLerp (specularColor, grazingTerm, NdotV);
indirectSpecular *= surfaceReduction;
float3 specular = (directSpecular + indirectSpecular);
/////// Diffuse:
NdotL = dot( normalDirection, lightDirection );
float3 forwardLight = max(0.0, NdotL );
float3 backLight = max(0.0, -NdotL ) * float3(_Transmission,_Transmission,_Transmission);
NdotL = max(0.0,dot( normalDirection, lightDirection ));
half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
float3 NdotLWrap = max(0,NdotL);
float nlPow5 = Pow5(1-NdotLWrap);
float nvPow5 = Pow5(1-NdotV);
float3 directDiffuse = ((forwardLight+backLight) + ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL)) * attenColor;
float3 indirectDiffuse = float3(0,0,0);
indirectDiffuse += gi.indirect.diffuse;
diffuseColor *= 1-specularMonochrome;
float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
/// Final Color:
float3 finalColor = diffuse + specular;
fixed4 finalRGBA = fixed4(finalColor,1);
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
return finalRGBA;
}
ENDCG
}
Pass {
Name "FORWARD_DELTA"
Tags {
"LightMode"="ForwardAdd"
}
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
#define _GLOSSYENV 1
#include "UnityCG.cginc"
#include "AutoLight.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
#include "UnityStandardBRDF.cginc"
#pragma multi_compile_fwdadd_fullshadows
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
#pragma multi_compile_fog
#pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
#pragma target 3.0
// Dithering function, to use with scene UVs (screen pixel coords)
// 4x4 Bayer matrix, based on https://en.wikipedia.org/wiki/Ordered_dithering
float BinaryDither4x4( float value, float2 sceneUVs ) {
float4x4 mtx = float4x4(
float4( 1, 9, 3, 11 )/17.0,
float4( 13, 5, 15, 7 )/17.0,
float4( 4, 12, 2, 10 )/17.0,
float4( 16, 8, 14, 6 )/17.0
);
float2 px = floor(_ScreenParams.xy * sceneUVs);
int xSmp = fmod(px.x,4);
int ySmp = fmod(px.y,4);
float4 xVec = 1-saturate(abs(float4(0,1,2,3) - xSmp));
float4 yVec = 1-saturate(abs(float4(0,1,2,3) - ySmp));
float4 pxMult = float4( dot(mtx[0],yVec), dot(mtx[1],yVec), dot(mtx[2],yVec), dot(mtx[3],yVec) );
return round(value + dot(pxMult, xVec));
}
uniform float4 _Color;
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
uniform float _Alpha;
uniform float _Transmission;
struct VertexInput {
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 tangent : TANGENT;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 vertexColor : COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
float3 normalDir : TEXCOORD4;
float3 tangentDir : TEXCOORD5;
float3 bitangentDir : TEXCOORD6;
float4 vertexColor : COLOR;
float4 projPos : TEXCOORD7;
LIGHTING_COORDS(8,9)
UNITY_FOG_COORDS(10)
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
o.vertexColor = v.vertexColor;
o.normalDir = UnityObjectToWorldNormal(v.normal);
o.tangentDir = normalize( mul( unity_ObjectToWorld, float4( v.tangent.xyz, 0.0 ) ).xyz );
o.bitangentDir = normalize(cross(o.normalDir, o.tangentDir) * v.tangent.w);
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
float3 lightColor = _LightColor0.rgb;
o.pos = UnityObjectToClipPos( v.vertex );
UNITY_TRANSFER_FOG(o,o.pos);
o.projPos = ComputeScreenPos (o.pos);
COMPUTE_EYEDEPTH(o.projPos.z);
TRANSFER_VERTEX_TO_FRAGMENT(o)
return o;
}
float4 frag(VertexOutput i) : COLOR {
i.normalDir = normalize(i.normalDir);
float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
float3 normalDirection = i.normalDir;
float2 sceneUVs = (i.projPos.xy / i.projPos.w);
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
clip( BinaryDither4x4((_MainTex_var.a*_Alpha*i.vertexColor.a*2.0) - 1.5, sceneUVs) );
float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
float3 lightColor = _LightColor0.rgb;
float3 halfDirection = normalize(viewDirection+lightDirection);
////// Lighting:
UNITY_LIGHT_ATTENUATION(attenuation,i, i.posWorld.xyz);
float3 attenColor = attenuation * _LightColor0.xyz;
float Pi = 3.141592654;
float InvPi = 0.31830988618;
///////// Gloss:
float gloss = 0.3;
float perceptualRoughness = 1.0 - 0.3;
float roughness = perceptualRoughness * perceptualRoughness;
float specPow = exp2( gloss * 10.0 + 1.0 );
////// Specular:
float NdotL = saturate(dot( normalDirection, lightDirection ));
float LdotH = saturate(dot(lightDirection, halfDirection));
float node_6584 = 0.04;
float3 specularColor = float3(node_6584,node_6584,node_6584);
float specularMonochrome;
float3 diffuseColor = (_MainTex_var.rgb*_Color.rgb*i.vertexColor.rgb); // Need this for specular when using metallic
diffuseColor = EnergyConservationBetweenDiffuseAndSpecular(diffuseColor, specularColor, specularMonochrome);
specularMonochrome = 1.0-specularMonochrome;
float NdotV = abs(dot( normalDirection, viewDirection ));
float NdotH = saturate(dot( normalDirection, halfDirection ));
float VdotH = saturate(dot( viewDirection, halfDirection ));
float visTerm = SmithJointGGXVisibilityTerm( NdotL, NdotV, roughness );
float normTerm = GGXTerm(NdotH, roughness);
float specularPBL = (visTerm*normTerm) * UNITY_PI;
#ifdef UNITY_COLORSPACE_GAMMA
specularPBL = sqrt(max(1e-4h, specularPBL));
#endif
specularPBL = max(0, specularPBL * NdotL);
#if defined(_SPECULARHIGHLIGHTS_OFF)
specularPBL = 0.0;
#endif
specularPBL *= any(specularColor) ? 1.0 : 0.0;
float3 directSpecular = attenColor*specularPBL*FresnelTerm(specularColor, LdotH);
float3 specular = directSpecular;
/////// Diffuse:
NdotL = dot( normalDirection, lightDirection );
float3 forwardLight = max(0.0, NdotL );
float3 backLight = max(0.0, -NdotL ) * float3(_Transmission,_Transmission,_Transmission);
NdotL = max(0.0,dot( normalDirection, lightDirection ));
half fd90 = 0.5 + 2 * LdotH * LdotH * (1-gloss);
float3 NdotLWrap = max(0,NdotL);
float nlPow5 = Pow5(1-NdotLWrap);
float nvPow5 = Pow5(1-NdotV);
float3 directDiffuse = ((forwardLight+backLight) + ((1 +(fd90 - 1)*nlPow5) * (1 + (fd90 - 1)*nvPow5) * NdotL)) * attenColor;
diffuseColor *= 1-specularMonochrome;
float3 diffuse = directDiffuse * diffuseColor;
/// Final Color:
float3 finalColor = diffuse + specular;
fixed4 finalRGBA = fixed4(finalColor * 1,0);
UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
return finalRGBA;
}
ENDCG
}
Pass {
Name "ShadowCaster"
Tags {
"LightMode"="ShadowCaster"
}
Offset 1, 1
Cull Back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
#define _GLOSSYENV 1
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
#include "UnityStandardBRDF.cginc"
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
#pragma multi_compile_fog
#pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
#pragma target 3.0
// Dithering function, to use with scene UVs (screen pixel coords)
// 4x4 Bayer matrix, based on https://en.wikipedia.org/wiki/Ordered_dithering
float BinaryDither4x4( float value, float2 sceneUVs ) {
float4x4 mtx = float4x4(
float4( 1, 9, 3, 11 )/17.0,
float4( 13, 5, 15, 7 )/17.0,
float4( 4, 12, 2, 10 )/17.0,
float4( 16, 8, 14, 6 )/17.0
);
float2 px = floor(_ScreenParams.xy * sceneUVs);
int xSmp = fmod(px.x,4);
int ySmp = fmod(px.y,4);
float4 xVec = 1-saturate(abs(float4(0,1,2,3) - xSmp));
float4 yVec = 1-saturate(abs(float4(0,1,2,3) - ySmp));
float4 pxMult = float4( dot(mtx[0],yVec), dot(mtx[1],yVec), dot(mtx[2],yVec), dot(mtx[3],yVec) );
return round(value + dot(pxMult, xVec));
}
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
uniform float _Alpha;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 vertexColor : COLOR;
};
struct VertexOutput {
V2F_SHADOW_CASTER;
float2 uv0 : TEXCOORD1;
float2 uv1 : TEXCOORD2;
float2 uv2 : TEXCOORD3;
float4 posWorld : TEXCOORD4;
float4 vertexColor : COLOR;
float4 projPos : TEXCOORD5;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
o.vertexColor = v.vertexColor;
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
o.pos = UnityObjectToClipPos( v.vertex );
o.projPos = ComputeScreenPos (o.pos);
COMPUTE_EYEDEPTH(o.projPos.z);
TRANSFER_SHADOW_CASTER(o)
return o;
}
float4 frag(VertexOutput i) : COLOR {
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
float2 sceneUVs = (i.projPos.xy / i.projPos.w);
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
clip( BinaryDither4x4((_MainTex_var.a*_Alpha*i.vertexColor.a*2.0) - 1.5, sceneUVs) );
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
Pass {
Name "Meta"
Tags {
"LightMode"="Meta"
}
Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#define SHOULD_SAMPLE_SH ( defined (LIGHTMAP_OFF) && defined(DYNAMICLIGHTMAP_OFF) )
#define _GLOSSYENV 1
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "UnityPBSLighting.cginc"
#include "UnityStandardBRDF.cginc"
#include "UnityMetaPass.cginc"
#pragma fragmentoption ARB_precision_hint_fastest
#pragma multi_compile_shadowcaster
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED DIRLIGHTMAP_SEPARATE
#pragma multi_compile DYNAMICLIGHTMAP_OFF DYNAMICLIGHTMAP_ON
#pragma multi_compile_fog
#pragma only_renderers d3d9 d3d11 glcore gles gles3 metal d3d11_9x xboxone ps4 psp2 n3ds wiiu
#pragma target 3.0
// Dithering function, to use with scene UVs (screen pixel coords)
// 4x4 Bayer matrix, based on https://en.wikipedia.org/wiki/Ordered_dithering
float BinaryDither4x4( float value, float2 sceneUVs ) {
float4x4 mtx = float4x4(
float4( 1, 9, 3, 11 )/17.0,
float4( 13, 5, 15, 7 )/17.0,
float4( 4, 12, 2, 10 )/17.0,
float4( 16, 8, 14, 6 )/17.0
);
float2 px = floor(_ScreenParams.xy * sceneUVs);
int xSmp = fmod(px.x,4);
int ySmp = fmod(px.y,4);
float4 xVec = 1-saturate(abs(float4(0,1,2,3) - xSmp));
float4 yVec = 1-saturate(abs(float4(0,1,2,3) - ySmp));
float4 pxMult = float4( dot(mtx[0],yVec), dot(mtx[1],yVec), dot(mtx[2],yVec), dot(mtx[3],yVec) );
return round(value + dot(pxMult, xVec));
}
uniform float4 _Color;
uniform sampler2D _MainTex; uniform float4 _MainTex_ST;
struct VertexInput {
float4 vertex : POSITION;
float2 texcoord0 : TEXCOORD0;
float2 texcoord1 : TEXCOORD1;
float2 texcoord2 : TEXCOORD2;
float4 vertexColor : COLOR;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
float2 uv2 : TEXCOORD2;
float4 posWorld : TEXCOORD3;
float4 vertexColor : COLOR;
float4 projPos : TEXCOORD4;
};
VertexOutput vert (VertexInput v) {
VertexOutput o = (VertexOutput)0;
o.uv0 = v.texcoord0;
o.uv1 = v.texcoord1;
o.uv2 = v.texcoord2;
o.vertexColor = v.vertexColor;
o.posWorld = mul(unity_ObjectToWorld, v.vertex);
o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST );
o.projPos = ComputeScreenPos (o.pos);
COMPUTE_EYEDEPTH(o.projPos.z);
return o;
}
float4 frag(VertexOutput i) : SV_Target {
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
float2 sceneUVs = (i.projPos.xy / i.projPos.w);
UnityMetaInput o;
UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );
o.Emission = 0;
float4 _MainTex_var = tex2D(_MainTex,TRANSFORM_TEX(i.uv0, _MainTex));
float3 diffColor = (_MainTex_var.rgb*_Color.rgb*i.vertexColor.rgb);
float node_6584 = 0.04;
float3 specColor = float3(node_6584,node_6584,node_6584);
float specularMonochrome = max(max(specColor.r, specColor.g),specColor.b);
diffColor *= (1.0-specularMonochrome);
float roughness = 1.0 - 0.3;
o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
return UnityMetaFragment( o );
}
ENDCG
}
}
FallBack "Particles/Additive (Soft)"
CustomEditor "ShaderForgeMaterialInspector"
}