计算高光反射的实例
//计算高光
fixed3 reflectDir = normalize( reflect(-lightDir,normalDir) );
fixed3 viewDir = normalize(_WorldSpaceCameraPos.xyz - mul(unity_ObjectToWorld,v.vertex));
fixed3 specularColor = _LightColor0.rgb * _Specular * (pow( max( dot(reflectDir,viewDir) ,0),_Gloss) );

f.color = diffuseColor + specularColor;

主要计算两个方向,反射光的方向和视野方向

_Specular是自定义属性,为高光颜色

反射光方向主要用reflect()方法得到,两个参数为入射光的方向和法线

视野方向用摄像机位置-点的位置来得到。


首页 我的博客
粤ICP备17103704号