Jump to content
  • Advertisement
Sign in to follow this  
Lutz

OpenGL OpenGL Blending Question

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

Hey there! Yet another blending question. I've a fragment program computing TWO colours C1 and C2 and I'd like to perform the following blending operation: C_new = C2 + C_f * C1 where C_new is the new color of my fragment and C_f is the old one (the "destination values" as in the reference of glBlendFunc). Is this possible in 1 pass?

Share this post


Link to post
Share on other sites
Advertisement
I don't think that is possible in one pass, but the way I would do it is to render the scene into a texture and then using it to retrieve and substitute C_f in your sample code.

Share this post


Link to post
Share on other sites
Yes, that would probably work, although it's quite memory consuming.
(I already need a screen-sized texture to compute C1 and C2)

Share this post


Link to post
Share on other sites
If you're using a fragment program, how can you *not* do it in one pass? Sure enough, the ARB programs are annoying to code, but you can always use Cg to create the code for you...

Share this post


Link to post
Share on other sites
@Gorax:

How would you retrieve the frame buffer content in a fragment program (or shader for that matter?)
I'm curious to know that.
PS: ARB programs, although annoying per times, are soooooooooooo much fun, at least from my point of view :D

Share this post


Link to post
Share on other sites
JavaCoolDude, since Lutz is using the fragment program to calculate those colours (C1 and C2), and fragment programs are *supposed* to be used to take some input fragment and produce some output fragment, rather than create some new fragment that then has to be used in another rendering. Maybe I don't understand what Lutz is trying to do, but the whole thing sounds a lot more complex than it should be. Your render to texture method would work if this was necessary, but *why* would it be, when the fragment program is already giving you C1 and C2, and *should* already give you C_f?

Share this post


Link to post
Share on other sites
Gorax, it would be an easy task for me if I could read the a color from the color buffer in my fragment program, do some stuff with that color and put it back into the color buffer.
However, retrieving stuff from the color buffer (as from any frame buffer like stencil, depth etc.) is not possible in a fragment program AS FAR AS I KNOW.
Please correct me if I'm wrong, since I really want to know!

Share this post


Link to post
Share on other sites
I also tried to get information from the color buffer to calculate new color for the fragment. But I didn't find a way to access it. The workaround is to render in a pbuffer texture. Its even possible to bind the buffer you are rendering into to a texture and use it the way you describe. But in some case the information you'll get is not what you are expecting since you are drawing in the texture at the same time as using its information.
An alternative is to have a double buffer pbuffer and draw in one while using the other as texture then copying it over after you are done drawing.
Hope this helps.
Lauvak

Share this post


Link to post
Share on other sites
Lutz, assuming you understand English, perhaps you should re-read your original post before commenting on my reply. Perhaps you can point out the part where you mentioned the fact that you were using a frame/colour/whatever buffer, because I can't. Is it not fair to say that somebody, like myself, who manages to stumble upon this thread, with this *very* limited amount of information, would fail to see exactly what in the hell it was you were trying to accomplish?

Share this post


Link to post
Share on other sites
@Gorax;
As far as I know fragment programs and shaders for that matter do not take an input color or an existent fragment and act on it to produce the output. When the fragment is produced by the rasterizer its color is most likely undefined according to the spec (but then again I could be confusing things).
And one more important thing is, all fragments that you process in your pixel shaders are brand new.
So yeah, reading through Lutz blending equation in the first post, you can see that this effect could only be accomplished through several render to texture passes. Having said that, I don't think he needs shaders for the final result ;)

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!