正反面都正确接受光源的双面材质

Shader "Transparent/Diffuse DoubleSided" {


Properties {

	 _Color ("Main Color", Color) = (1,1,1,1)

	 _MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}

}




SubShader {

		 Tags { "RenderType"="Opaque" }

 		 LOD 300

 		

	 	Pass {

			 Tags { "LightMode" = "Vertex" }

				

			 Cull Back

			 ZWrite On

			 Lighting On

			

			 CGPROGRAM

			

			 #pragma vertex vert

			 #pragma fragment frag

			

			 #include "UnityCG.cginc"

			

			 sampler _MainTex;

			 float4 _MainTex_ST;

			 float4 _Color;

			

			 struct a2v {

				 float4 vertex : POSITION;

				 float3 normal : NORMAL;

				 float4 texcoord : TEXCOORD0;

			 };

			

			 struct v2f {

				 float4 pos : POSITION;

				 float2 uv : TEXCOORD0;

				 float3 color : TEXCOORD1;

			 };

			

			 v2f vert(a2v v) {

				 v2f o;o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

				 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

				 o.color = ShadeVertexLights(v.vertex, v.normal);

				 return o;

			 }

			

			 float4 frag(v2f i) : COLOR {

				 float4 c = tex2D(_MainTex, i.uv)*_Color;

				 clip(c.a-0.9);

				 c.rgb = c.rgb * i.color * 2;

				 return c;

			 }

			

			 ENDCG

		 }

		

		

		 Pass {

			 Tags { "LightMode" = "Vertex" }

				

			 Cull Front

			 ZWrite On

			 Lighting On

			

			 CGPROGRAM

			

			 #pragma vertex vert

			 #pragma fragment frag

			

			 #include "UnityCG.cginc"

			

			 sampler _MainTex;

			 float4 _MainTex_ST;

			 float4 _Color;

			

			 struct a2v {

				 float4 vertex : POSITION;

				 float3 normal : NORMAL;

				 float4 texcoord : TEXCOORD0;

			 };

			

			 struct v2f {

				 float4 pos : POSITION;

				 float2 uv : TEXCOORD0;

				 float3 color : TEXCOORD1;

			 };

			

			 v2f vert(a2v v) {

				 v2f o;o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

				 o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);

				 o.color = ShadeVertexLights(v.vertex, -v.normal);

				 return o;

			 }

			

			 float4 frag(v2f i) : COLOR {

				 float4 c = tex2D(_MainTex, i.uv)*_Color;

				 clip(c.a-0.9);

				 c.rgb = c.rgb * i.color * 2;

				 return c;

			 }

			

			 ENDCG

		 }

	 } 

	 FallBack "Diffuse"

}

  

posted @ 2015-08-22 18:39  softimagewht  阅读(610)  评论(0编辑  收藏  举报