   Fog shader + phong shader
  Hi all,I am trying to write a phong shader that includes fog. But i am not sure this is "doable". I already have the Phong shader ready, i just don't know how to add the fog calculations. Plus I am not 100% confident in my Phong shader (not sure if it works for textures).Can some one help me?Vertex Shadervarying vec3 N, L, E;varying float D;void main(){vec3 ecPos = vec3(gl_ModelViewMatrix * gl_Vertex);N = normalize(gl_NormalMatrix * gl_Normal);vec3 aux = vec3(gl_LightSource[0].position.xyz - ecPos);L = normalize(aux);D = length(aux);E = -ecPos;gl_Position = ftransform();}Fragment Vertexvarying vec3 N, L, E;varying float D;void main(){vec4 Al = gl_LightSource[0].ambient;vec4 Am = gl_FrontMaterial.ambient;vec4 As = gl_FrontLightModelProduct.sceneColor;vec4 Ia = (Al * Am) + (As * Am);vec4 Dl = gl_LightSource[0].diffuse;vec4 Dm = gl_FrontMaterial.diffuse;float Lambert = dot(N, L);vec4 Id = Dl * Dm * Lambert;vec4 Sl = gl_LightSource[0].specular;vec4 Sm = gl_FrontMaterial.specular; float f = gl_FrontMaterial.shininess;vec3 R = reflect(-L, N);vec4 Is = Sm * Sl * pow( max( dot(R,E) , 0.0), f );vec4 If = Ia + Id + Is;gl_FragColor = If;}[Edited by - Forkaster on May 10, 2009 6:14:25 PM]
  In my vertex shader I havevarying float TheLength;eyeVertex = vec3(ModelviewMatrix * gl_Vertex);TheLength = length(eyeVertex);In my fragment shader I haveuniform vec4 FogColor;uniform float FogDensity;varying float TheLength;float fogFactor;vec4 ColorSum;...fogFactor = exp(-(FogDensity * TheLength));ColorSum = mix(FogColor, ColorSum, fogFactor);and color sum is the final resultgl_FragColor = clamp(ColorSum, 0.0, 1.0);   ;  In answer to your side-question, no, your shader will not work for textures. You need to add these lines into your shadersVertex Shader:gl_TexCoord[0] = gl_MultiTexCoord0;Fragment Shader:uniform sampler2D tex;void main(){vec4 colour = texture2D(tex, gl_TexCoord[0].st);gl_FragColor = colour;}However, rather than just making gl_FragColor = colour, you will need to use colour within your lighting & fog calculations (either by modulating or replacing).Hope this helps.   ;  Hi,I don't know how to correctly use the texture color on the fragment shader.What do you mean modulate or replace?   