上一篇讲了自定义光照的HalfLambert,这一次和它有些类似,但是计算的时候,不再用方向和atten相乘了.
将光入射方向与法相的点乘积HalfLam作为坐标,找到RampTexture中(HalfLam,HalfLam)点的rgb值作为混合值与s.的Albedo和入射光颜色相乘.
代码如下:
Shader"Custom/11.26/2"{ Properties{ _RampTex("Ramp Texture",2D)="white"{} _MainTex("Ramp Texture",2D)="white"{} } SubShader{ Tags{"RenderType"="Opaque"} LOD 200 CGPROGRAM #pragma surface surf Ramp sampler2D _RampTex; sampler2D _MainTex; struct Input{ float2 uv_MainTex; }; void surf(Input In,inout SurfaceOutput o){ half4 c=tex2D(_MainTex,In.uv_MainTex); o.Albedo=c.rgb; o.Alpha=c.a; } inline float4 LightingRamp(SurfaceOutput s,fixed3 LightDir,fixed atten){ float lightDif=dot(s.Normal,LightDir); float halfLam=0.5*lightDif+0.5; float3 ramp=tex2D(_RampTex,float2(halfLam,halfLam)).rgb; float4 col; col.rgb=s.Albedo*_LightColor0.rgb*ramp; col.a=s.Alpha; return col; } ENDCG } FallBack "Diffuse" }
效果图:
时间: 2024-10-04 12:19:26