A question on fragment shaders, and PBuffers

Posts: 1,199
Joined: 2004.10
Post: #1
Two questions, I'd make two posts but they're related.

First, can a fragment shader read what's in the color buffer for the purpose of blending?

E.g., say I draw a quad across the screen and have a shader bound to that quad. Can I, for each pixel being written, read in whatever's in the destination color buffer and use that to affect how the result is written? Specifically, I'm writing a "death effect" and would like to drop the scene to grayscale before blending a color against it.

If this isn't possible, if I recall there was a problem with full-screen PBuffers. Is this still the case? Was it ever the case? I know that if the above isn't possible I can simply render my scene into a texture and let my shader run against that.

Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
a) no, you can't read any buffers from a fragment shader. blending happens as usual after the fragment shader has done its thing.

depending on what you're trying to do, you may be able to render the entire scene into a PBuffer, then draw the main view as a full-screen quad, which you can pixel shade to your heart's content.

b) No, there was never a problem with full-screen PBuffers AFAIK.
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #3
Too bad about the former, but given that there's no trouble with fullscreen PBuffers, I'll run thataway. Beats me where I got the idea that there was a problem...

Anyway, I'll give it a shot. Thanks OSC.
Quote this message in a reply
Posts: 1,199
Joined: 2004.10
Post: #4
I got it working this weekend. Thanks for the tip, OSC.

One thing, in case anybody else tries this stuff, none of my resources covered how to use the TEX shader command when you're dealing with non-POT textures. The books I've got mention "1D", "2D", "3D", "CUBE", but that's it.

I don't have internet access at home, so I just sort of figured it out, but, I passed "RECT" instead of "2D" when looking up texture data from the pbuffer texture and it worked.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  passing values from vertex to fragment shader Sumaleth 6 14,767 Feb 18, 2011 01:54 AM
Last Post: Holmes
  GLSL geometry- and multipass-shaders (nogo?) mcMike 3 6,979 May 2, 2008 05:51 AM
Last Post: mcMike
  GLSL fragment program limits on GMA950 (MacBook) memon 12 12,266 Oct 26, 2007 05:18 PM
Last Post: arekkusu
  PBuffers and setTextureImageToPBuffer:colorBuffer: Marjock 4 3,633 Jul 16, 2006 01:19 AM
Last Post: Marjock
  Enabling OGL fog in shaders kordova 7 7,414 Jul 12, 2006 10:12 AM
Last Post: kordova