Shader Example
//测试viewDir对顶点的影响
Shader "Example/TestViewDir" { Properties{ _RimColor("Rim Color", Color) = (0.26,0.19,0.16,0.0) _RimPower("Rim Power", Range(0.5,8.0)) = 3.0 } SubShader{ Tags{ "RenderType" = "Opaque" } CGPROGRAM #pragma surface surf Lambert struct Input { float2 uv_MainTex; float2 uv_BumpMap; float3 viewDir; }; sampler2D _MainTex; sampler2D _BumpMap; float4 _RimColor; float _RimPower; float _Test; void surf(Input IN, inout SurfaceOutput o) { half rim = 1 - saturate(dot(o.Normal,normalize(IN.viewDir))); float3 col = _RimColor.rgb * pow(rim, _RimPower); float4 c = float4(col, rim); o.Emission = c; } ENDCG } Fallback "Diffuse" }
结果:最终输出颜色*ColorMask后再与屏幕上颜色进行混合叠加
Shader "Example/ColorMask" { Properties{ _Color("Texture to blend", Color) = (1,1,1,1) } SubShader{ Tags{ "Queue" = "Transparent" } ColorMask B Pass{ Blend SrcColor one CGPROGRAM #include "UnityCG.cginc" #pragma vertex vert #pragma fragment frag float4 _Color; float4 vert(appdata_base v) : POSITION { return mul(UNITY_MATRIX_MVP, v.vertex); } float4 frag(float4 pos:POSITION) : COLOR { return _Color; } ENDCG } } Fallback Off }