Refracting the framebuffer

Started by
1 comment, last by Coluna 15 years, 9 months ago
Hi folks; Im trying to create a simple fx (well, the basic implementation is very simple): refract the framebuffer. As u will say, just render the normal objects to the screen, grap the framebuffer (FB for short) to a texture, and render your objects that refracts the screen. But there is a problem: what if between your refract object and the wall behind it, there is an particle system (blend, no z-write)? Ok, if I grab the FB after ALL objects, including the transparent ones, this case will still work. But what if the particle now is between our camera and the refract object? As there is no z-buffer in that part of the screen, the refract object will be drawn, overlaping the particle system that is in front of it!! Some games do this in the correct way (the last one I see this was Bioshock and its glass-walls, but in some games that have refracting water like crysis, it works too), but I couldnt find a simple solution to get that working...if I draw the refractors before the transparents, the particles behind them will be invisible, and it wont be possible to extend this to heat/haze effects. Can anybody helps me?
Advertisement
Well, the easiest solution is to render the to-be-refracted scene to a texture with a clip plane placed at the refracting object's position - (ab)using the near clip plane is a great way to do this in a very fast and portable manner. After that, you'd render normally to the frame buffer, using the said texture on the refractive objects. Reason grabbing the frame buffer is bad is because, as you've noticed, you'll always get ghost refractions of whatever is in front of the refractive object.
Ok, this solves for one object. But what if I have more objects that needs the FB? I had some ideas using the stencil masking and rendering twice (one before and one after the refractors) the blend objects, but I'll have some saturation where the blend object is between the refractor and the camera...

This topic is closed to new replies.

Advertisement