8.3 Fog

First on the map

 

In fact, very simple, is light and fog coefficient interpolation, fog appears at a certain distance with the camera, in the distance, no fog, outside this distance, the greater the farther the fog that fog coefficient from 0-1, light coefficient from 1 to 0,

 

In the shader code is as follows:


cbuffer cbFixed
{
    float gFogStart = 5.0f;
    float gFogRange = 140.0f;
    float3 gFogColor = {0.7f, 0.7f, 0.7f};
};

 

vs calculated interpolation coefficients


    float d = distance(vOut.posW, gEyePosW );
    vOut.fogLerp = saturate((d- gFogStart) / gFogRange );
    

ps calculation of interpolated color


    float3 foggedColor = lerp( litColor, gFogColor, pIn.fogLerp);
  
    return float4(foggedColor, alpha);

 

Published 673 original articles · won praise 18 · views 280 000 +

Guess you like

Origin blog.csdn.net/directx3d_beginner/article/details/104532888