Bug记录:
鼠标一旦对shader操作,或者在模型前滑动,都会造成使用了shader的模型从无光照颜色的正常显示状态变成失去了diffuse和specular,只剩ambient的状态。
因此推断原因可能是diffuse和specular中的某些地方出了问题。
原因:
经过检查,发现在我计算diffuse和specular时,输入_LightColor0
时,编译器(Rider)会提醒我这个变量unity_LightColor0
。
因此我错误地将
unity_LightColor0.rgb
作为
_LightColor0.rgb
使用
代码参考来源是unity shader入门精要,由于与现在隔了许多版本,因此我以为是版本更新,unity_LightColor0
就是新版的_LightColor0
。犯了想当然的错误,经过前往unity官方手册的查询后才知道二者的区别。
二者区别:
名称 | 类型 | 值 |
---|---|---|
_LightColor0(在 Lighting.cginc 中声明) | fixed4 | 光源颜色。 |
unity_LightColor | half4[4] | (仅限 ForwardBase 通道)前四个非重要点光源的颜色。 |