Jump to content
  • Advertisement
Sign in to follow this  
Eraser85

Blending over and over a shader's output

This topic is 3936 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!