PDA

View Full Version : copying stencil buffer to 8 bit luminance image -> problem



JernejL
04-13-2007, 02:31 PM
What i'm trying to do is, to copy the stencil buffer into a texture, and then render it over the scene with variable opacity as an texture to generate the shadow effect in 1 color buffer scene pass, the problem presented itself when i copy the stencil buffer i get a GL_UNSIGNED_BYTE data with values either 0 or 1, what i would prefer is 0..255, so i tried these methods to affect the pixel transfer to get stencil values 0 and 255 instead, i'm doing the transfer using glReadPixels,

First i tried remaping values:



test[0]:= 255;
test[1]:= 0;
glPixelMapuiv(GL_PIXEL_MAP_S_TO_S, 8, @test[0]);
glPixelTransferf(GL_MAP_STENCIL, 1);It works, but is unacceptably slow (2 seconds per 640*480 frame)

so i tried this:

glPixelTransferf(GL_INDEX_OFFSET, 255); The second method works good as well but creates inverted image (intentionally overflows the uint8), inverted image itself is not a problem since i can correct that with stencil buffer code generation, the problem itself is again speed, same slowness as the above method.

So, the problem is slowness of pixel transfer when it's using any sort of non-default settings. can i achieve the transfer any faster?

I am aware i could do this more efficiently with a fragment shader, but before i even get close to shaders, i want to test the concept itself, and program itself should be able to run on pre-shaders hardware. I think by projecting the stencil buffer i generate from shadow volumes onto the scene would produce much more controllable shadows.