Render to texture and Blending
This is driving me nuts...
If I render all my cloud particles using blend mode GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, They look how I want.
If I then call glCopyTexSubImage2D() to create an imposter texture and render the result with the same alpha mode, the result looks way too transparent.
I've tried premultiplying the particle texture - (R,G,B * alpha). This looks wrong with an assortment of blend modes, including GL_ONE, GL_ONE_MINUS_SRC_ALPHA, which I believe should work. And this is just rendering the particles, without worrying about copying to the imposter texture. In this case, everything is either full white or zero alpha. No color, no partial alpha.
Can anyone tell me the proper way of dealing with alpha when rendering to a texture? There seems to be absolutely no information about this anywhere. It's like it should "just work" or something.
Cheers,
Frustrated Dave.
If I render all my cloud particles using blend mode GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, They look how I want.
If I then call glCopyTexSubImage2D() to create an imposter texture and render the result with the same alpha mode, the result looks way too transparent.
I've tried premultiplying the particle texture - (R,G,B * alpha). This looks wrong with an assortment of blend modes, including GL_ONE, GL_ONE_MINUS_SRC_ALPHA, which I believe should work. And this is just rendering the particles, without worrying about copying to the imposter texture. In this case, everything is either full white or zero alpha. No color, no partial alpha.
Can anyone tell me the proper way of dealing with alpha when rendering to a texture? There seems to be absolutely no information about this anywhere. It's like it should "just work" or something.
Cheers,
Frustrated Dave.
Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
You probably want a saturated alpha mode.
Download KochPaint and play with the layer blending for a while. The UI is very non-intuitive but:
1) all controls have tooltips
2) at the top left is a checkbox that exposes additional layer blending controls for control of the glblendfunc when mixing the offscreen particle render into the canvas. checking this box also draws a few colored blobs onto the background so you have something to blend against.
3) the two blendfunc rows are the full GL_COMBINE controls for RGB, ALPHA
4) on the right are checkboxes for premultiply (this sets the layer RGBA to alpha, alpha, alpha, alpha instead of 1,1,1,alpha) and Saturate. Saturate toggles the particle (not layer) blendfunc between (GL_SRC_ALPHA_SATURATE, GL_ONE) and (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
If you use the bottom left popup to set the primitive mode to points and make a big mess, you should see that the following settings produce what you want:
particles blended with (GL_SRC_ALPHA_SATURATE, GL_ONE) into offscreen texture. The particle color is always premultiplied by the paint alpha.
texture composited to viewport with (GL_ONE, GL_ONE_MINUS_SRC_ALPHA) and premultiplication (the default setting.)
Dumping out your rendered texture and examining the alpha channel is probably also a good idea.
And, btw, this is where a pbuffer (or an offscreen window context in 10.2) is good. Copying from framebuffer to texture over and over is just burning fillrate.
[Edit: noted that particle RGB is premultiplied]
Download KochPaint and play with the layer blending for a while. The UI is very non-intuitive but:
1) all controls have tooltips

2) at the top left is a checkbox that exposes additional layer blending controls for control of the glblendfunc when mixing the offscreen particle render into the canvas. checking this box also draws a few colored blobs onto the background so you have something to blend against.
3) the two blendfunc rows are the full GL_COMBINE controls for RGB, ALPHA
4) on the right are checkboxes for premultiply (this sets the layer RGBA to alpha, alpha, alpha, alpha instead of 1,1,1,alpha) and Saturate. Saturate toggles the particle (not layer) blendfunc between (GL_SRC_ALPHA_SATURATE, GL_ONE) and (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
If you use the bottom left popup to set the primitive mode to points and make a big mess, you should see that the following settings produce what you want:
particles blended with (GL_SRC_ALPHA_SATURATE, GL_ONE) into offscreen texture. The particle color is always premultiplied by the paint alpha.
texture composited to viewport with (GL_ONE, GL_ONE_MINUS_SRC_ALPHA) and premultiplication (the default setting.)
Dumping out your rendered texture and examining the alpha channel is probably also a good idea.
And, btw, this is where a pbuffer (or an offscreen window context in 10.2) is good. Copying from framebuffer to texture over and over is just burning fillrate.
[Edit: noted that particle RGB is premultiplied]
Thanks again, the saturated alpha worked perfectly.
I'll have to have a good play with KochPaint at some stage. I'm still not sure why saturated alpha is what I needed, but at least it works now
Cheers
Happy Dave
I'll have to have a good play with KochPaint at some stage. I'm still not sure why saturated alpha is what I needed, but at least it works now

Cheers
Happy Dave
Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
The "why" is best explained by just looking at your texture's alpha channel. Saturation will build up an alpha mask of overlapping particles correctly; other modes will instead replace the alpha channel with the values from the last drawn primitive, this comes out looking too "light".
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Render video (e.g. QuickTime) to buffer or texture? | Ingemar | 14 | 11,037 |
Jun 8, 2011 04:09 PM Last Post: mdejong1024 |
|
| Render to Texture? | IBethune | 5 | 5,232 |
May 2, 2007 04:25 AM Last Post: IBethune |
|
| general blending versus texture blending questions | WhatMeWorry | 2 | 4,255 |
Dec 7, 2006 02:43 PM Last Post: arekkusu |
|
| PBuffer & Render to Texture (read & write) | habicht | 4 | 3,429 |
Feb 7, 2005 05:33 PM Last Post: habicht |
|
| Render-To-Texture? | MacFiend | 11 | 4,224 |
May 30, 2003 04:46 AM Last Post: OneSadCookie |
|

