Unity 中的光照模型( 二 )


文章图片

Band-Lighting
这不太像是一个光照模型 , 而更像是一个光照扭曲 , 来给你看你如何在标准光照模型上使用简单的数学操作 。 这种方法通过打断光照的方向然后将其变成一条一条的光带 。 这种方法可以变成其他任何光照模型 , 只要用 banded NdotL 替换 NdotL, 正如下方所示的:
floatNdotL=max(0.0,dot(normalDirection,lightDirection ));
floatlightBandsMultiplier =_LightSteps/256;
floatlightBandsAdditive =_LightSteps/2;
fixedbandedNdotL =(floor((NdotL*256+lightBandsAdditive)/_LightSteps))*lightBandsMultiplier;
float3 lightingModel =bandedNdotL *diffuseColor;
floatattenuation =LIGHT_ATTENUATION(i);
float3 attenColor =attenuation *_LightColor0.rgb;
float4 finalDiffuse =float4(lightingModel *attenColor,1);
returnfinalDiffuse;
Unity 中的光照模型
文章图片

Unity 中的光照模型
文章图片

Minnaert 光照
Minnaert 光照模型最初设计用来复制月亮的着色 , 所以经常被称作月球着色器(shader) 。Minnnaert 很适合用来模拟多孔和纤维表面 , 比如月亮和丝绒 。 这些表面可以在背散射( back-scatter )中造成很多光线 。 这在纤维垂直于表面时特别明显 , 比如丝绒 , 地毯等 。
这种模拟提供的结果和 Oren-Nayar 十分接近 , 同样也经常被称作丝绒或月球着色器(shader) 。
下面是 Minnaert 光照的一个近似例子:
float3 viewDirection =normalize(_WorldSpaceCameraPos.xyz -i.posWorld.xyz);
floatNdotL=max(0,dot(normalDirection,lightDirection ));
floatNdotV=max(0,dot(normalDirection,viewDirection ));
float3 minnaert =saturate(NdotL*pow(NdotL*NdotV,_Roughness));
float3 lightingModel =minnaert *diffuseColor;
【Unity 中的光照模型】floatattenuation =LIGHT_ATTENUATION(i);
float3 attenColor =attenuation *_LightColor0.rgb;
float4 finalDiffuse =float4(lightingModel *attenColor,1);
UNITY_APPLY_FOG(i.fogCoord,finalDiffuse);
returnfinalDiffuse;
Unity 中的光照模型
文章图片

Unity 中的光照模型
文章图片

Oren-Nayer Lighting
Oren-Nayer 反射率模型是一个反射模型 , 用在漫反射或粗糙表面上 。 此模型是一个简单的办法来近似模拟光线在粗糙但仍然具有 lambertian 特性的表面上的效果 。
下面是一个简单的 Oren-Nayer 插入方式 。
floatroughness =_Roughness;floatroughnessSqr =roughness *roughness;
float3 o_n_fraction =roughnessSqr /(roughnessSqr +float3(0.33,0.13,0.09));
float3 oren_nayar =float3(1,0,0)+float3(-0.5,0.17,0.45)*o_n_fraction;
floatcos_ndotl =saturate(dot(normalDirection,lightDirection));
floatcos_ndotv =saturate(dot(normalDirection,viewDirection));
floatoren_nayar_s =saturate(dot(lightDirection,viewDirection))-cos_ndotl *cos_ndotv;
oren_nayar_s /=lerp(max(cos_ndotl,cos_ndotv),1,step (oren_nayar_s,0));
//lighting and final diffuse
floatattenuation =LIGHT_ATTENUATION(i);
float3 lightingModel =diffuseColor *cos_ndotl *(oren_nayar.x +diffuseColor *oren_nayar.y +oren_nayar.z *oren_nayar_s);
float3 attenColor =attenuation *_LightColor0.rgb;
float4 finalDiffuse =float4(lightingModel *attenColor,1);
Unity 中的光照模型
文章图片

Unity 中的光照模型

特别声明:本站内容均来自网友提供或互联网,仅供参考,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。