View Full Version : Color Mask / Stencil
08-07-2001, 03:42 PM
Hi, I'm trying to "mask" a frame, in order that only the pixels that match a specified color, be written in the stencil buffer. For example let's suppose we have a 3 color (red yellow and orange) scene, I'd like to have only the orange component written i the stencil buffer, all the others cells of the stencil would be left blank. I know how to write in the stencil, but I don't how how to write a specific color. Hope everybody understood ...
Thx for the precious help.
08-07-2001, 09:37 PM
I've never used the stencil buffer, but maybe you could assign an alpha of 1 to those colours you want to write, and an alpha of 0 to the others, then use the alpha test to only write the colours with the alpha of 1.
Hope that helps.
08-08-2001, 04:51 AM
Nope, this won't work, because I can't assign an alpha value to some pixels on some textures. Suppose your scene is made up of a sphere, but with three different colors on its surface, and you would like to print in the stencil only the red component of the sphere, and then only the yellow/green one ... And this has to work for any 24bits color ...
Having a hard time finding out, Lolo
08-08-2001, 06:07 AM
Just to complete the explanation of my problem :
The perfect method would be to render in the stencil buffer the entire frame but with a reference value specified to the desired colour. If I want to keep only the red component, I'll have to tell the glStencilOp to write in the buffer only the pixels that match this exact colour ... But how can I perform this ?
08-08-2001, 06:34 AM
If you can't mark the pixels with alpha, and use an alpha test to determine which of those pixels sets the stencil buffer (which would be the fast way to do this), then it would seem your only other option, is to draw the scene without lighting and read the framebuffer. Redraw the scene with lighting if needed. Then draw to the stencil buffer whereever you find the color mask in the copy. This would be exceedingly slow on most hardware.
[This message has been edited by DFrey (edited 08-08-2001).]
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.