unity GradientAmbient映射方法

 fixed3 calculateAmbientLight(half3 normalWorld)
 {
     //Flat ambient is just the sky color
     fixed3 ambient = unity_AmbientSky.rgb * 0.75;
     
 #if defined(TRI_COLOR_AMBIENT)    
 
     //Magic constants used to tweak ambient to approximate pixel shader spherical harmonics 
     fixed3 worldUp = fixed3(0,1,0);
     float skyGroundDotMul = 2.5;
     float minEquatorMix = 0.5;
     float equatorColorBlur = 0.33;
     
     float upDot = dot(normalWorld, worldUp);
     
     //Fade between a flat lerp from sky to ground and a 3 way lerp based on how bright the equator light is.
     //This simulates how directional lights get blurred using spherical harmonics
     
     //Work out color from ground and sky, ignoring equator
     float adjustedDot = upDot * skyGroundDotMul;
     fixed3 skyGroundColor = lerp(unity_AmbientGround, unity_AmbientSky, saturate((adjustedDot + 1.0) * 0.5));
     
     //Work out equator lights brightness
     float equatorBright = saturate(dot(unity_AmbientEquator.rgb, unity_AmbientEquator.rgb));
     
     //Blur equator color with sky and ground colors based on how bright it is.
     fixed3 equatorBlurredColor = lerp(unity_AmbientEquator, saturate(unity_AmbientEquator + unity_AmbientGround + unity_AmbientSky), equatorBright * equatorColorBlur);
     
     //Work out 3 way lerp inc equator light
     float smoothDot = pow(abs(upDot), 1);
     fixed3 equatorColor = lerp(equatorBlurredColor, unity_AmbientGround, smoothDot) * step(upDot, 0) + lerp(equatorBlurredColor, unity_AmbientSky, smoothDot) * step(0, upDot);
     
     return lerp(skyGroundColor, equatorColor, saturate(equatorBright + minEquatorMix)) * 0.75;
     
 #endif // TRI_COLOR_AMBIENT    
 
     return ambient;
 }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值