Sign in to follow this  
Coluna

Refracting the framebuffer

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this