I'm trying to modify the fragment depths of my scene using a fragment shader and gl_FragDepth, but it's nowhere near giving me satisfactory results. Here's my short fragment shader:
uniform vec3 color;
uniform float depth;
void main()
{
gl_FragColor = vec4(color, 1.0);
if(depth < gl_FragDepth)
gl_FragDepth = depth;
}
set_shaders();
GLint loc, loc2, loc3;
loc = glGetUniformLocationARB(p, "color");
loc2 = glGetUniformLocationARB(p, "k");
loc3 = glGetUniformLocationARB(p, "depth");
float z1 = -2.0, z2 = -4.0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUniform3fARB(loc, 0.5, 0.0, 0.0);
glUniform1fARB(loc2, 0.2);
glUniform1fARB(loc3, 0.5);
glBegin(GL_QUADS);
glColor3ub(255, 0, 0); glVertex3f(-1.0, 1.0, z1);
glColor3ub(255, 0, 0); glVertex3f(1.0, 1.0, z1);
glColor3ub(255, 0, 0); glVertex3f(1.0, -1.0, z1);
glColor3ub(255, 0, 0); glVertex3f(-1.0, -1.0, z1);
glEnd();
glUniform3fARB(loc, 0.5, 0.5, 0.5);
glUniform1fARB(loc2, 0.2);
glUniform1fARB(loc3, 0.2);
glBegin(GL_QUADS);
glColor3ub(255, 0, 0); glVertex3f(-2.0, 1.0, z2);
glColor3ub(0, 255, 0); glVertex3f(1.0, 1.0, z2);
glColor3ub(0, 0, 255); glVertex3f(1.0, -1.0, z2);
glColor3ub(255, 255, 255); glVertex3f(-2.0, -1.0, z2);
glEnd();


