GLSL Texture splatting + Fog

Started by
1 comment, last by dpadam450 13 years, 8 months ago
I'm trying to use glfog() to hide clipping points in my terrain editor.

However, because I am playing around with matrix multiplications, the glFog() seems to be working on the wrong axis.

Here is my renderFrame() method:

void RenderFrame(){    glEnable(GL_DEPTH_TEST);    glEnable(GL_CULL_FACE);    glViewport(0, 0, g_windowWidth, g_windowHeight);    glClearColor(0.3f, 0.5f, 0.9f, 0.0f);    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    glMultMatrixf(&g_camera.getProjectionMatrix()[0][0]);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();    glMultMatrixf(&g_camera.getViewMatrix()[0][0]);    RenderTerrain();	    RenderText();}


Here are a few screenshots to illustrate the problem:
image 1

image 2

image 3

As the camera turns to look down the Y axis, the fog takes affect. How can I fix this?

Any help would be much appreciated thank you!

[Edited by - Total_Titillation on August 1, 2010 3:13:08 PM]
Advertisement
The problem was my lighting. glFog is not working because I am using a shader.

Shader:

[vert]uniform float tilingFactor;varying vec4 normal;varying float gl_FogFragCoord;void main(){	gl_FogFragCoord = gl_Position.z;    normal.xyz = normalize(gl_NormalMatrix * gl_Normal);    normal.w = gl_Vertex.y;    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;    gl_TexCoord[0] = gl_MultiTexCoord0 * tilingFactor;}[frag]struct TerrainRegion{    float min;    float max;};uniform TerrainRegion region1;uniform TerrainRegion region2;uniform TerrainRegion region3;uniform TerrainRegion region4;uniform TerrainRegion region5;uniform sampler2D region1ColorMap;uniform sampler2D region2ColorMap;uniform sampler2D region3ColorMap;uniform sampler2D region4ColorMap;uniform sampler2D region5ColorMap;varying vec4 normal;varying float gl_FogFragCoord;vec4 GenerateTerrainColor(){    vec4 terrainColor = vec4(0.0, 0.0, 0.0, 1.0);    float height = normal.w;    float regionMin = 0.0;    float regionMax = 0.0;    float regionRange = 0.0;    float regionWeight = 0.0;        // Terrain region 1.    regionMin = region1.min;    regionMax = region1.max;    regionRange = regionMax - regionMin;    regionWeight = (regionRange - abs(height - regionMax)) / regionRange;    regionWeight = max(0.0, 0.5 * regionWeight);    terrainColor += regionWeight * texture2D(region1ColorMap, gl_TexCoord[0].st);    // Terrain region 2.    regionMin = region2.min;    regionMax = region2.max;    regionRange = regionMax - regionMin;    regionWeight = (regionRange - abs(height - regionMax)) / (regionRange * 2) ;    regionWeight = max(0.0,regionWeight);    terrainColor += regionWeight * texture2D(region2ColorMap, gl_TexCoord[0].st);    // Terrain region 3.    regionMin = region3.min;    regionMax = region3.max;    regionRange = regionMax - regionMin;    regionWeight = (regionRange - abs(height - regionMax)) / regionRange;    regionWeight = max(0.0, regionWeight);    terrainColor += regionWeight * texture2D(region3ColorMap, gl_TexCoord[0].st);    // Terrain region 4.    regionMin = region4.min;    regionMax = region4.max;    regionRange = regionMax - regionMin;    regionWeight = (regionRange - abs(height - regionMax)) / regionRange;    regionWeight = max(0.0, regionWeight);    terrainColor += regionWeight * texture2D(region4ColorMap, gl_TexCoord[0].st);	// Terrain region 5.    regionMin = region5.min;    regionMax = region5.max;    regionRange = regionMax - regionMin;    regionWeight = (regionRange - abs(height - regionMax)) / regionRange;    regionWeight = max(0.0, regionWeight);    terrainColor += regionWeight * texture2D(region5ColorMap, gl_TexCoord[0].st);    return terrainColor;}void main(){ 	 	float fog;     vec3 n = normalize(normal.xyz);    float nDotL = max(0.0, dot(n, gl_LightSource[0].position.xyz));            vec4 ambient = gl_FrontLightProduct[0].ambient;    vec4 diffuse = gl_FrontLightProduct[0].diffuse * nDotL;    vec4 color = gl_FrontLightModelProduct.sceneColor + ambient + diffuse;   	fog = (gl_Fog.end - gl_FogFragCoord) * gl_Fog.scale;        gl_FragColor = mix(gl_Fog.color, (color * GenerateTerrainColor()), fog);}


The texture splatting is still working, but random patches are appearing each frame, can anyone point out what I am doing wrong please?
Post a screenshot.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement