1#ifdef FOG
2
3#ifdef FOG_TEXTURE
4uniform sampler2D m_FogTexture;
5#endif
6
7uniform vec3 m_FogColor;
8
9// x == density
10// y == factor
11// z == ystart
12// w == yend
13uniform vec4 m_FogParams;
14
15varying vec3 fogCoord;
16
17void Fog_PerVertex(inout vec4 color, in vec3 wvPosition){
18    float density = g_FogParams.x;
19    float factor  = g_FogParams.y;
20    float dist    = length(wvPosition.xyz);
21
22    float yf = wvPosition.y;
23    float y0 = g_FogParams.z;
24    float y1 = g_FogParams.w;
25    float yh = (y1 - y0) * 0.5;
26
27    float fogAmt1 = max(step(yh, 0.0), smoothstep(0, yh, max(y1-yf, yf-y0)));
28    float fogAmt2 = exp(-density * density * dist * dist);
29
30    color.rgb = mix(color.rgb, m_FogColor, fogAmt1 * fogAmt2);
31}
32
33void Fog_PerPixel(inout vec4 color){
34    Fog_PerVertex(color, fogCoord);
35}
36
37void Fog_WVPos(in vec4 wvPosition){
38    fogCoord = wvPosition.xyz;
39}
40
41#endif