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;
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页