View Full Version : how to compose two images according to their zbuffer values?

05-26-2003, 06:26 PM
i have got two images's RGB and their zbuffer values with glReadPixel.now i want to compose them together by comparision of zbuffer values. if i do it pixel by pixel, i'm afraid it will cost a lot time. i also want to reach 20 frames per second. who can give some suggestion on it? thanks

05-26-2003, 10:46 PM
Hi, how about

for each pixel
if z1<z2 then color = color1 else color = color2

If that's not fast enough, you could try rendering the two images into a texture, storing the depth value in an alpha channel. Then first render the first picture to the screen (if it's not there already) and then the second one on top of it. For the second one use multitexturing and texture_env_combine to place color2 into the rgb channel and depth1(alpha) - depth2 into the alpha channel. Then use alpha test to discard all fragments with alpha>0, meaning that depth2<depth1.


05-27-2003, 12:46 AM
Wow, you've just invented the triple post!

(see other forums)