環境光和光源顏色疊加 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、渲染方式設置:
新聞熱點
疑難解答