varying float Z; // equal to -EC.z (dist in front of the eye) varying vec4 Color; varying vec3 MCposition; varying float LightIntensity; uniform float NoiseScale; uniform float NoiseFreq; uniform float DepthFront, DepthBack; uniform sampler3D Noise3; const vec4 FOG = vec4( 0.5, 0.5, 0.5, 1. ); void main( void ) { vec4 nv = texture3D( Noise3, NoiseFreq*MCposition ); float size = nv[0] + nv[1] + nv[2] + nv[3]; // [1.,3.] size -= 2.; // [-1.,+1.] float deltaz = NoiseScale * size; float fogFactor = ( (Z+deltaz) - DepthFront ) / ( DepthBack - DepthFront ); fogFactor = clamp( fogFactor, 0., 1. ); fogFactor = smoothstep( 0., 1., fogFactor ); Color.rgb *= LightIntensity; gl_FragColor = mix( Color, FOG, fogFactor ); }