Blending over and over a shader's output

Started by
0 comments, last by Eraser85 16 years, 5 months ago
Hi all, I'm doing an ambient occlusion plug-in for a mesh processing program. The calculation is done in a pre-pass so performance is not my primary concern at the moment. What I'm doing is basically this: - Store vertex normals & coordinates in 2 separate GL_RGBA32F_ARB textures - Generate coordinates for the camera all around the object - Bind the FBO as current rendering target (with color_attachment0 and depth_attachment) - glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_ONE); - Iterate through all the views and for each one: # Setup the camera & draw the mesh # Store in a GLfloat[16] the modelview matrix # Pass the vertex normal texture, vertex coordinate texture and depth buffer to the shader and render on a screen aligned quad the result - After those iterations, read from the color_attachment0 the final result - Modify vertex color according to the result - Unbind the FBO The shader code looks like this:

uniform sampler2D vTexture;
uniform sampler2D nTexture;
uniform sampler2D dTexture;
uniform vec3 viewDirection;
uniform mat4 mvMatrix;

void main(void)
{
   vec4 result = vec4(0.0, 0.0, 0.0, 0.0);
   
   vec3 normalDirection = texture2D(nTexture, gl_FragCoord.xy).rgb;
   vec4 vertexCoords    = texture2D(vTexture, gl_FragCoord.xy);
   vertexCoords *= mvMatrix;
   vec3 depthValue      = texture2D(dTexture, vertexCoords.xy).rgb;
   
   if (vertexCoords.z <= depthValue.z)
      result.a = cos(dot(normalDirection,viewDirection));
   
   gl_FragColor = result;
}



glEnable(GL_BLEND) is needed for accumulating the occlusion However what I've found is that: - At the end of the computation the vertex color is black for all of them - I use the color_attachment0 (which is always a GL_RGBA32F_ARB texture) as the target of the accumulation All seems fine but it doesn't work, if you need more code just ask. Thank you [Edited by - Eraser85 on November 4, 2007 7:07:57 AM]
Advertisement
I checked if textures were initialized and it's the case:
(the upper band is a small part of vertex coordinates, while the lower represent normals)
vertex status

the same is for depth texture, it works.

This topic is closed to new replies.

Advertisement