View Full Version : Destination alpha test
12-30-2001, 12:04 PM
I posted this in the nehe forum but no-one knew. Do you have any ideas?
I have (after a few passes) a screen consisting of shades of gray. Each pixel has an rgba color of k, k, k, k (0<=k<=1). Now, I want to draw on the screen another texture, but only on the parts of the screen of color (1, 1, 1, 1), and not on the rest. Is there any way to do this in (preferably unextended) openGL?
12-30-2001, 12:17 PM
You could create an alpha texture from the screen with glCopyTexImage2D (or glCopyTexSubImage2D for better performance) and use source alpha test. This requires multitexturing, but thats supported on nearly every card.
I don't know a way to do this with unextended opengl.
A completely different approach would be to use the stencil buffer. If thats usable for you depends on the way you generate your alpha values.
Hope that helps
12-31-2001, 12:11 AM
A little bit sick way to do, but it should work, you've to do this depending on the amount of colorbufferbits with lower or higher alpha value, let's say we'd a 24 bit colorbuffer:
-Blend a black polygon over the screen with alpha of 254/255. All RGBs which were lower than 255 are 0 then, all which were 255 are 1. Draw multiplicative now a white one again over the whole screen. The area which was
1,1,1,1 before should be white now, the rest 0,0,0,0. Now paint what you wanted to do multiplicative as well and it will just appear in the area which was 1,1,1,1.
01-01-2002, 09:19 AM
What blending factors should I use?
01-01-2002, 09:24 AM
How are you generating the grayscale in the dest alpha in the first place? Could this be done in the stencil buffer instead? If so, the masking you want on a subsequent pass would be more straightforward than masking based on dest alpha.
01-03-2002, 04:20 AM
I draw my scene with two grayscale textures (auto texcoord generation), and use additive blending. If the result is 1.0f, I want to draw in a third texture. Other places, the scene can be left as it is or cleared. I cannot use multitexture since texgen will not work independently for both texture units on a TNT2.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.