环境光和光源颜色叠加 1、shader内容:
Shader "xxx/ddd"{ SubShader { pass { tags{"LightMode"="ForwardBase"} //使用光照模型必须有一个LightMode模式 //reference: https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html CGPROGRAM #pragma vertex vert #pragma fragment frag #include "unitycg.cginc" #include "lighting.cginc" struct v2f { float4 pos:POSITION; float4 color:COLOR; }; v2f vert(appdata_base data) { v2f o; o.pos = mul(UNITY_MATRIX_MVP, data.vertex); float3 N = normalize(data.normal); //法向量的方向 float3 L = normalize(_WorldSpaceLightPos0); //光源的方向 float ndotl = saturate(dot(N,L)); //clamp the range to 0~1 o.color = _LightColor0 * ndotl; //将光的颜色和点积相乘得到最终的颜色值 return o; } fixed4 frag(v2f tmp):COLOR { return tmp.color + UNITY_LIGHTMODEL_AMBIENT; //将环境光的颜色直接加入到灯光的颜色之后,以至于不会太暗 } ENDCG } }}2、效果:
3、环境光设置:
4、渲染方式设置:
新闻热点
疑难解答