要实现双面透明无光照只有纹理色的surface shader。
错误的写法:(导致带有曝光)
Shader "Custom/doubleFaceTranspTexColor" {
Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Transparent" } LOD 200 Cull Off Blend SrcAlpha OneMinusSrcAlpha // Alpha blending CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf MyTexColor alpha:fade half4 LightingMyTexColor(SurfaceOutput s, half3 lightDir, half atten){ half4 c; c.rgb=s.Albedo; c.a=s.Alpha; return c; } // Use shader model 3.0 target, to get nicer looking lighting #pragma target 3.0sampler2D _MainTex;
struct Input {
float2 uv_MainTex; };fixed4 _Color;
void surf (Input IN, inout SurfaceOutput o) {
// Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } FallBack "Diffuse"}正确的写法:
Shader "Custom/doubleFaceTranspTexColor" { Properties { _Color ("Color", Color) = (1,1,1,1) _MainTex ("Albedo (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Transparent" "RenderQueue"="Transparent"} LOD 200 Cull Off Lighting Off Blend SrcAlpha OneMinusSrcAlpha // Alpha blending CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma surface surf MyTexColor alpha:fade half4 LightingMyTexColor(SurfaceOutput s, half3 lightDir, half atten){ half4 c; c.rgb=half3(0,0,0); c.a=s.Alpha; return c; } // Use shader model 3.0 target, to get nicer looking lighting #pragma target 3.0 sampler2D _MainTex; struct Input { float2 uv_MainTex; }; fixed4 _Color; void surf (Input IN, inout SurfaceOutput o) { // Albedo comes from a texture tinted by color fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color; o.Emission = c.rgb; o.Albedo = fixed3(0,0,0); o.Alpha = c.a; } ENDCG } FallBack "Diffuse"}
参考:http://answers.unity3d.com/questions/272749/how-to-write-unlit-surface-shader.html