Vertex and Pixel shader freaking out, please help

Hello,

my vertex shader and my pixel aren´t doing what i
think they should do.
This is the vertex shader:

uniform float MyZAxis;

void main () {
  vec4 v = gl_Vertex;
  v.z = MyZAxis;
  gl_Position = gl_ModelViewProjectionMatrix * v;
}

and this the pixel shader:

uniform vec4 MyColor;

void main () {
  gl_FragColor = vec4(MyColor);
}

i am passing the color value to the fragment shader
and the z-axis to the vertex shader.
There are three vertices in the programm, that
span a triangle. Sounds simple enough.
You can download the source from here:
http://www.dotbox.org/stuff/ogsl.tar.gz
it was developed on linux, it needs the libGL,
libGLU and the SDL-Libs and headers.
The code is not like the one i normaly write,
but it should work.
And here is the problem:
if a parse a static value to the vertex shader, lets
say 0.0f, than everything (in the vertex shader)
is allright. As soon as i start incrementing the
z-axis in the main-loop the triangle starts
flickering around in z-direction.
The second problem is the fragment-shader:
I am parsing the color value for the fragment
to the shader. The call is:
glUniform4fARB(color_loc,1.0f,1.0f,1.0f,0.5f);
So it should get white an 50% transparent,
but it gets green !?!?
I also tried to use an attribute instead of
uniforms, but it changes nothing, it´s exactly
the same strange behavior.

kind regards

Florian Engelhardt

I test this shaders in Shader Designer and it works on my comp (WinXP, 6800GT, FW 71.83).
Your shader is correct, so it might be a driver bug.

Flickering might appear because you are rendering FRONT and BACK faces. Try to turn on backface culling. It might help you. Also, check your perspective matrix. If you use gluPerspective call, zNear and zFar must be GREATER than 0.0. If zNear is too close to 0.0 and zFar is big number, than you may have trouble with z-fighting.

Result of fragment shader is SRC color in blending equation. If blending is disabled, the fragment color are written into framebuffer. If you enable blending fragment color will be modifyed by blending equation before writing into framebuffer.

If you want 50% transparency you have to turn on blending.

Thank you, but i tried using an older driver,
turning on backface-culling and i also checked
the zFar and zNear values. No changes.
Is there anyone out there, who could test this code,
maybe it is a driver bug, so it would be great if
that persons owns an ati card.

Regards

Florian

Is it possible to get some values back from
the shaders into the programm?
Something like: glUniformRead3fARB

Only to read what you put into them:
glGetUniform*
Uniforms are input variables, the program cannot alter them!
The only output of shaders is color and depth. For floating point data debugging use a floating point p-buffer with 32 bit per channel (FP32) and write the data you’re interested in as color and read it back with glReadPixels in GL_FLOAT format to check the result.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.