Jump to content
  • Advertisement
Sign in to follow this  
jalway

GLSL, Blending with Framebuffer Fragments via Shader?

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

Hello,
 
I've been trying to find a way to mix fragment color values in the framebuffer with newly applied source colors.      I realize there is a glBlendFunction(), but I can't see a way to blend  the way I wish.   I want to use an equation to blend the two colors the way I want.  I don't have the exact equation as of now, but I know that it will be more sophisticated than the operations I see available via the blend function ( I need to experiment).  It might be  a non-linear ramping function, for example.
 
I'm using GLSL.  So, I looked into the fragment shader, and I discovered that it's in a part of the pipeline that doesn't allow you to blend with the framebuffer values.
 
So, my question is, is there a way to blend the pixel in the framebuffer with the newly applied color by applying an equation you invent?  I'd like this to happen real time as the colors are applied.
 
Side Note: I'm not using the backbuffer or animation in this case, so there is no frame rate. This is just the application of the values to the front buffer.  No animation is required.  This is for a drawing application I'm writing.  A pen on a tablet.  When the pen draws, the screen is refreshed.
 
Some information: this is on Windows 10, a Microsoft Surface 3, and with GLSL version 4.0, although I think I can go as high as version 4.4.
 
Thanks for any feedback!
 
...John

Share this post


Link to post
Share on other sites
Advertisement

"Programmable blending" is the magic keyword for what you want. It's available via extensions on some hardware but you won't be able to do it in the general case.

 

In portable code, it's common to render to an offscreen target (a render-to-texture), then sample from that texture to implement whatever fancy blending equation you need. In some cases this might involve 'ping-ponging' between two offscreen targets as you apply multiple layers of custom blended stuff.

Share this post


Link to post
Share on other sites

Like the previous post mentioned, you could use your own fragment shader input ( render target textures ) to do your blending as the current framebuffer does not allow access ( for the most part, as a few drivers expose some sort of frame buffer fetch ). There are also extension like pixel local storage that could help, but by default blending uses fix function hw..

Share this post


Link to post
Share on other sites

+ in modern opengl theres possibility to switch between render tagets COLOR0 COLOR1 something like that you can read and write in one fragment shader to it,

 

 

 

 

edit

 

additionally you could just render first scene to texture and then blend that texture with anything you want in fragment shader

Edited by WiredCat

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!