首页 > 学院 > 开发设计 > 正文

shader学习(8)

2019-11-11 02:08:37
字体:
来源:转载
供稿:网友

环境光和光源颜色叠加 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、渲染方式设置: 这里写图片描述


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表