1#import "Common/ShaderLib/MultiSample.glsllib"
2
3uniform COLORTEXTURE m_Texture;
4uniform DEPTHTEXTURE m_DepthTexture;
5
6uniform vec4 m_FogColor;
7uniform float m_FogDensity;
8uniform float m_FogDistance;
9
10in vec2 texCoord;
11
12vec2 m_FrustumNearFar=vec2(1.0,m_FogDistance);
13const float LOG2 = 1.442695;
14
15void main() {
16       vec4 texVal = getColor(m_Texture, texCoord);
17       float fogVal = getDepth(m_DepthTexture,texCoord).r;
18       float depth= (2.0 * m_FrustumNearFar.x) / (m_FrustumNearFar.y + m_FrustumNearFar.x - fogVal* (m_FrustumNearFar.y-m_FrustumNearFar.x));
19
20       float fogFactor = exp2( -m_FogDensity * m_FogDensity * depth *  depth * LOG2 );
21       fogFactor = clamp(fogFactor, 0.0, 1.0);
22       gl_FragColor =mix(m_FogColor,texVal,fogFactor);
23
24}