欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-06-10 20:59:07
...
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"

}