|
|
- Shader "VG/VertexAnimation" {
- Properties {
- _Color ("Color", Color) = (1,1,0.7,1)
- _Diffuse ("Diffuse", 2D) = "white" {}
- _Normal ("Normal", 2D) = "bump" {}
- _Bright ("Bright", Range(0, 1)) = 1
- _VertexIntensity ("VertexIntensity", Range(0, 1)) = 0.02
- [HideInInspector]_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
- }
- SubShader {
- Tags {
- "Queue"="AlphaTest"
- "RenderType"="TransparentCutout"
- }
- Pass {
- Name "FORWARD"
- Tags {
- "LightMode"="ForwardBase"
- }
- Cull Off
-
-
- AlphaToMask On
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #define UNITY_PASS_FORWARDBASE
- #include "AutoLight.cginc"
- #include "Lighting.cginc"
- #pragma multi_compile_fwdbase_fullshadows
- #pragma multi_compile_fog
-
- uniform float4 _TimeEditor;
- uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
- uniform sampler2D _Normal; uniform float4 _Normal_ST;
- uniform float _Bright;
- uniform float4 _Color;
- uniform float _VertexIntensity;
- 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;
- LIGHTING_COORDS(7,8)
- UNITY_FOG_COORDS(9)
- #if defined(LIGHTMAP_ON) || defined(UNITY_SHOULD_SAMPLE_SH)
- float4 ambientOrLightmapUV : TEXCOORD10;
- #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);
- float4 AllTime = _Time + _TimeEditor;
- v.vertex.xyz += (normalize((float3(1,0,0)+v.normal))*o.vertexColor.r*sin(((o.vertexColor.r*3.141592654)+AllTime.g))*_VertexIntensity);
- o.posWorld = mul(unity_ObjectToWorld, v.vertex);
- float3 lightColor = _LightColor0.rgb;
- o.pos = UnityObjectToClipPos( v.vertex );
- UNITY_TRANSFER_FOG(o,o.pos);
- TRANSFER_VERTEX_TO_FRAGMENT(o)
- return o;
- }
- float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
- float isFrontFace = ( facing >= 0 ? 1 : 0 );
- float faceSign = ( facing >= 0 ? 1 : -1 );
- i.normalDir = normalize(i.normalDir);
- i.normalDir *= faceSign;
- float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
- float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
- float3 _Normal_var = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal)));
- float3 normalLocal = _Normal_var.rgb;
- float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
- float3 viewReflectDirection = reflect( -viewDirection, normalDirection );
- float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse));
- clip(_Diffuse_var.a - 0.5);
- float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
- float3 lightColor = _LightColor0.rgb;
- float3 halfDirection = normalize(viewDirection+lightDirection);
-
- float attenuation = LIGHT_ATTENUATION(i);
- float3 attenColor = attenuation * _LightColor0.xyz;
- float gloss = 0.4;
- float specPow = exp2( gloss * 10.0 + 1.0 );
- 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
- 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;
- float NdotL = saturate(dot( normalDirection, lightDirection ));
- float3 specularColor = float3(0.2,0.2,0.2);
- float3 directSpecular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow)*specularColor;
- float3 specular = directSpecular;
-
- NdotL = max(0.0,dot( normalDirection, lightDirection ));
- float3 directDiffuse = max( 0.0, NdotL) * attenColor;
- float3 indirectDiffuse = float3(0,0,0);
- indirectDiffuse += gi.indirect.diffuse;
- float3 diffuseColor = (_Color.rgb*_Diffuse_var.rgb);
- float3 diffuse = (directDiffuse + indirectDiffuse) * diffuseColor;
- float3 emissive = (_Diffuse_var.rgb*_Bright);
-
- float3 finalColor = diffuse + specular + emissive;
- fixed4 finalRGBA = fixed4(finalColor,(_Diffuse_var.a) * 2.0 - 1.0);
- UNITY_APPLY_FOG(i.fogCoord, finalRGBA);
- return finalRGBA;
- }
- ENDCG
- }
- Pass {
- Name "FORWARD_DELTA"
- Tags {
- "LightMode"="ForwardAdd"
- }
- Blend One One
- Cull Off
-
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #define UNITY_PASS_FORWARDADD
- #include "AutoLight.cginc"
- #include "Lighting.cginc"
- #pragma multi_compile_fog
-
- uniform float4 _TimeEditor;
- uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
- uniform sampler2D _Normal; uniform float4 _Normal_ST;
- uniform float _Bright;
- uniform float4 _Color;
- uniform float _VertexIntensity;
- 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;
- LIGHTING_COORDS(7,8)
- UNITY_FOG_COORDS(9)
- };
- 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);
- float4 AllTime = _Time + _TimeEditor;
- v.vertex.xyz += (normalize((float3(1,0,0)+v.normal))*o.vertexColor.r*sin(((o.vertexColor.r*3.141592654)+AllTime.g))*_VertexIntensity);
- o.posWorld = mul(unity_ObjectToWorld, v.vertex);
- float3 lightColor = _LightColor0.rgb;
- o.pos = UnityObjectToClipPos( v.vertex );
- UNITY_TRANSFER_FOG(o,o.pos);
- TRANSFER_VERTEX_TO_FRAGMENT(o)
- return o;
- }
- float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
- float isFrontFace = ( facing >= 0 ? 1 : 0 );
- float faceSign = ( facing >= 0 ? 1 : -1 );
- i.normalDir = normalize(i.normalDir);
- i.normalDir *= faceSign;
- float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);
- float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
- float3 _Normal_var = UnpackNormal(tex2D(_Normal,TRANSFORM_TEX(i.uv0, _Normal)));
- float3 normalLocal = _Normal_var.rgb;
- float3 normalDirection = normalize(mul( normalLocal, tangentTransform )); // Perturbed normals
- float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse));
- clip(_Diffuse_var.a - 0.5);
- float3 lightDirection = normalize(lerp(_WorldSpaceLightPos0.xyz, _WorldSpaceLightPos0.xyz - i.posWorld.xyz,_WorldSpaceLightPos0.w));
- float3 lightColor = _LightColor0.rgb;
- float3 halfDirection = normalize(viewDirection+lightDirection);
-
- float attenuation = LIGHT_ATTENUATION(i);
- float3 attenColor = attenuation * _LightColor0.xyz;
- float gloss = 0.4;
- float specPow = exp2( gloss * 10.0 + 1.0 );
- float NdotL = saturate(dot( normalDirection, lightDirection ));
- float3 specularColor = float3(0.2,0.2,0.2);
- float3 directSpecular = attenColor * pow(max(0,dot(halfDirection,normalDirection)),specPow)*specularColor;
- float3 specular = directSpecular;
-
- NdotL = max(0.0,dot( normalDirection, lightDirection ));
- float3 directDiffuse = max( 0.0, NdotL) * attenColor;
- float3 diffuseColor = (_Color.rgb*_Diffuse_var.rgb);
- float3 diffuse = directDiffuse * diffuseColor;
-
- 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 Off
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #define UNITY_PASS_SHADOWCASTER
- #include "Lighting.cginc"
- #pragma multi_compile_shadowcaster
- #pragma multi_compile_fog
-
- uniform float4 _TimeEditor;
- uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
- uniform float _VertexIntensity;
- struct VertexInput {
- float4 vertex : POSITION;
- float3 normal : NORMAL;
- 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;
- float3 normalDir : TEXCOORD5;
- float4 vertexColor : COLOR;
- };
- 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);
- float4 AllTime = _Time + _TimeEditor;
- v.vertex.xyz += (normalize((float3(1,0,0)+v.normal))*o.vertexColor.r*sin(((o.vertexColor.r*3.141592654)+AllTime.g))*_VertexIntensity);
- o.posWorld = mul(unity_ObjectToWorld, v.vertex);
- o.pos = UnityObjectToClipPos( v.vertex );
- TRANSFER_SHADOW_CASTER(o)
- return o;
- }
- float4 frag(VertexOutput i, float facing : VFACE) : COLOR {
- float isFrontFace = ( facing >= 0 ? 1 : 0 );
- float faceSign = ( facing >= 0 ? 1 : -1 );
- i.normalDir = normalize(i.normalDir);
- i.normalDir *= faceSign;
- float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
- float3 normalDirection = i.normalDir;
- float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse));
- clip(_Diffuse_var.a - 0.5);
- SHADOW_CASTER_FRAGMENT(i)
- }
- ENDCG
- }
- Pass {
- Name "Meta"
- Tags {
- "LightMode"="Meta"
- }
- Cull Off
-
- CGPROGRAM
- #pragma vertex vert
- #pragma fragment frag
- #define UNITY_PASS_META 1
- #include "Lighting.cginc"
- #include "UnityMetaPass.cginc"
- #pragma multi_compile_shadowcaster
- #pragma multi_compile_fog
-
- uniform float4 _TimeEditor;
- uniform sampler2D _Diffuse; uniform float4 _Diffuse_ST;
- uniform float _Bright;
- uniform float4 _Color;
- uniform float _VertexIntensity;
- struct VertexInput {
- float4 vertex : POSITION;
- float3 normal : NORMAL;
- 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;
- float4 vertexColor : COLOR;
- };
- 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);
- float4 AllTime = _Time + _TimeEditor;
- v.vertex.xyz += (normalize((float3(1,0,0)+v.normal))*o.vertexColor.r*sin(((o.vertexColor.r*3.141592654)+AllTime.g))*_VertexIntensity);
- o.posWorld = mul(unity_ObjectToWorld, v.vertex);
- o.pos = UnityMetaVertexPosition(v.vertex, v.texcoord1.xy, v.texcoord2.xy, unity_LightmapST, unity_DynamicLightmapST );
- return o;
- }
- float4 frag(VertexOutput i, float facing : VFACE) : SV_Target {
- float isFrontFace = ( facing >= 0 ? 1 : 0 );
- float faceSign = ( facing >= 0 ? 1 : -1 );
- i.normalDir = normalize(i.normalDir);
- i.normalDir *= faceSign;
- float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.posWorld.xyz);
- float3 normalDirection = i.normalDir;
- UnityMetaInput o;
- UNITY_INITIALIZE_OUTPUT( UnityMetaInput, o );
-
- float4 _Diffuse_var = tex2D(_Diffuse,TRANSFORM_TEX(i.uv0, _Diffuse));
- o.Emission = (_Diffuse_var.rgb*_Bright);
- float3 diffColor = (_Color.rgb*_Diffuse_var.rgb);
- float3 specColor = float3(0.2,0.2,0.2);
- float roughness = 1.0 - 0.4;
- o.Albedo = diffColor + specColor * roughness * roughness * 0.5;
- return UnityMetaFragment( o );
- }
- ENDCG
- }
- }
- FallBack "Transparent/Cutout/Diffuse"
- }
|