Sign in to follow this  

Accumulative Fragment Shader

This topic is 2633 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

I'm trying to write a fragment shader that performs
accumulation of colors as the render progresses.
ie I render a first polygon in the background
with a color c0=(0.5,0,0) then another polygon
in the front of it with a color c1=(0,0.5,0)
and I would like the final output
to be c0+c1=(0.5,0.5,0)

But I don't seem to be able to get the previously
computed fragment value.
Is there any way to get it ?

Share this post


Link to post
Share on other sites
Have you tried enabling glEnable(GL_BLEND) and setting the blend function to glBlendFunc(GL_ONE,GL_ONE)

This will add a new fragment's colour to the colour currently at that location. That way you don't even need to read the current colour within the fragment shader as blending is done after the fragment shader.

Share this post


Link to post
Share on other sites
Ergh.. i see

Well I can only think of using an FBO. Render your background to a texture attached to the FBO. Then bind that texture and read it in your fragment shader when drawing your foreground. Hopefully you're not wanting to have multiple layers of backgrounds because you'd need a pass for each.

Share this post


Link to post
Share on other sites
You could alternatively perform three renders per primitive. The first render you setup glBlendFunc and glBlendEquation to the operations you need for the red channel ; as well as setting glColorMask for GL_TRUE only for red channel.
Then you do a similar thing for green and blue.

Unfortunately it requires three renders per primitive, but I think it should get the job done and is definitely faster than the FBO technique

Share this post


Link to post
Share on other sites

This topic is 2633 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this