Skip to main content
GameDev.net gamedev.net
🔒 Locked

Distortion Effects

Started by xycsoscyx Mar 15, 2007 at 6:30 PM 1 replies 1.5k views
Original Post
xycsoscyx
xycsoscyx
I'm trying to setup a refrected material type of effect (a glass effect basically), but having a bit of trouble. I've found plenty of information online about using cubemaps and such, but I am trying to do this all as a post processing effect. My setup is that I render the entire scene, so I have it all stored in a texture. I want to now render my glass objects, using the final image of my scene as the input. For the glassy surfaces, I want to distort them based on their index and surface normal. My problem is that I have a 2D coordinate for the scene image, and a world space normal for the surface. How do I convert that normal into an offset for my 2D coordinate, based on my index value?
Jason Z
Jason Z
Unfortunately I don't think you can. The problem is that you need a point in world space that you are going to refract the eye ray from. With only a 2D screen space position, you don't have the depth information of where that surface is in world space.

You could potentially get around this by writing the depth of each fragment out into the alpha channel of your scene render target, but there are a couple of downfalls to this:

1. You can't use alpha for anything else
2. You are limited to 0-255 depth values (similar precision problem as standard shadow mapping)

This is why a refraction map is typically generated before the final scene information. Plus, if you only use your pre-rendered scene, there will be times when the refracted material will be on the edge of the screen, and the refracted coordinates will point outside of the current render target. This will lead to artifacts around the edges of the screen on the refracted materials.
Jason Zink :: DirectX MVP   Direct3D 11 engine on CodePlex: Hieroglyph 3 Direct3D Books: 
xycsoscyx
xycsoscyx
Actually, I'm using deferred rendering, so I have any information for that point that I want. I know there are some artifacts (including objects in front of the glass surface), but I wanted something simple for now at least. So for every point, I already know the normals, position, etc, for that point (on my final image).

Aside from that, how can I do refraction type effects effectively? I don't want to have to do render to target's for each surface (which seems like it'd fail anyways if I get into things like spheres), but are there any other ways? I've been trying to search online, but nothing really productive (a lot of stuff uses prerendered cubemaps in their tutorials).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.