GLSL vertex shaders and fog

Started by
6 comments, last by Duel93 16 years, 2 months ago
If I am just using a GLSL vertex shader and my GL_FOG_COORDINATE_SRC is set to default (GL_FRAGMENT_DEPTH), how do I get the fixed pipeline to handle the fog? Do I set gl_FogFragCoord = abs((gl_ModelViewMatrix * pos).z) ? When I do this, I get very strange colors. Or do I have to use GL_FOG_COORDINATE and set the fog coordinates in order to access gl_FogCoord? I don't recall having to do that with vertex shaders using Cg. I'm only using a vertex shader for my object.
Advertisement
just a guess:

The vertex shader has a varying output variable gl_FogFragCoord (float). If the fragments are handled by the fixed function pipeline than it will use the default varying output and input variables.

Just try something like:

vec3 ecposition = vec3(gl_ModelViewMatrix * gl_Vertex);
gl_FogFragCoord = ecposition.z/ecposition.w;
Thank you. That worked.
Actually, that does not work on ATI cards. That is where I am having my problem. NVIDIA works ok.
Any reason why you don't create a fragment shader?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I have used a fragment shader to make it work on ATI, without the color anomalies. But the only purpose of this shader is to make foliage sway in the wind. I can do this with a vertex shader only. And it works on nVidia. But ATI gives me strange color anomalies. Reading the 2.0 spec, all I should have to do is give gl_FogFragCoord my eyepoint position, as shown in the previous post.(??)

I've noticed that ATI is less forgiving than nVidia with shader specs, so hopefully someone can point out what I am missing by using only a Vertex Shader.

Quote:Original post by Duel93
I have used a fragment shader to make it work on ATI, without the color anomalies. But the only purpose of this shader is to make foliage sway in the wind. I can do this with a vertex shader only. And it works on nVidia. But ATI gives me strange color anomalies.
This is just to point out that there's no prize in using FFP instead of a simple FFP-like shader stage. You're not winning anything and nobody will ever think this is an awesome idea, especially if when doing that, you run in this kind of issues.
The fact that mixing FFP with shaders on ATi gives headaches is a point to leave FFP alone and begin starting to think that "it's better to do that with shaders anyway" for safety.

Previously "Krohm"

I agree with your post. And to get it working, I have done just that.

I'm still curious about why it does not work on ATI. I don't like "not knowing".


This topic is closed to new replies.

Advertisement