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;
}
Blending over and over a shader's output
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:
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement