Wasabi
08-08-2011, 03:34 PM
I'm writing a program that uses OpenGL 3.3 and I've been using a pretty simple fragment shader to deal with the colors. However, I've just noticed that, even though gl_FragColor is given an alpha value of 1.0, I can still see objects that occur behind any given object.
Should it be relevant, here's my fragment shader code.
#version 330
precision highp float;
uniform vec3 EyeAxis = vec3(0.0,0.0,1.0);
uniform mat4 Modelview;
uniform mat4 Projection;
in vec3 ex_Color;
in vec4 ex_Normal;
out vec4 gl_FragColor;
void main(void)
{
vec4 Normal = Projection*Modelview*ex_Normal;
vec4 Eye = vec4(EyeAxis,1.0);
float c = abs(dot(normalize(Eye.xyz),normalize(Normal.xyz))) ;
gl_FragColor = vec4((0.2+0.8*c)*ex_Color,1.0);
}
Is there some rendering attribute I need to activate in the shader or in my code?
I've annexed an image to demonstrate what happens. It's a lateral view of a surface, and that central mess is really just the surface changing direction and moving "behind itself" from this view, but the meshes from both parts (near us and behind itself) can be seen. It's not just the meshes. If I turn them off, I can still see what seems to be some serious aliasing, with a mess of slightly-differently-coloured triangles.
Should it be relevant, here's my fragment shader code.
#version 330
precision highp float;
uniform vec3 EyeAxis = vec3(0.0,0.0,1.0);
uniform mat4 Modelview;
uniform mat4 Projection;
in vec3 ex_Color;
in vec4 ex_Normal;
out vec4 gl_FragColor;
void main(void)
{
vec4 Normal = Projection*Modelview*ex_Normal;
vec4 Eye = vec4(EyeAxis,1.0);
float c = abs(dot(normalize(Eye.xyz),normalize(Normal.xyz))) ;
gl_FragColor = vec4((0.2+0.8*c)*ex_Color,1.0);
}
Is there some rendering attribute I need to activate in the shader or in my code?
I've annexed an image to demonstrate what happens. It's a lateral view of a surface, and that central mess is really just the surface changing direction and moving "behind itself" from this view, but the meshes from both parts (near us and behind itself) can be seen. It's not just the meshes. If I turn them off, I can still see what seems to be some serious aliasing, with a mess of slightly-differently-coloured triangles.