PDA

View Full Version : Environment cubemapping (again)

HellKnight
02-09-2006, 08:40 AM
I know this has been discussed a billion times, however I haven't found an exact way of doing right looking reflections on large flat surfaces on these forums (or on the net - there was an ATI doc explaining how to *approximate* the right reflection vector tough, I believe)...

You all know what I mean (http://stud3.tuwien.ac.at/~e0427091/approx_env.JPG).

The question is now, is there any way to do that apart from true, honest ray/cubemap planes per-pixel intersections?

dorbie
02-09-2006, 11:08 AM
Yes, it's just a planar reflection, your example isn't a correct reflection it looks like the errors are caused by an inappropriate approach like an incorrect RTT approach (maybe even caused by something simple like a slerp instead of lerp for the view vector), planar reflections can be done exactly even for local stuff.

Depending on the scenario reflections are possible using a mix of techniques, here's the best one for your scenario:

http://www.opengl.org/resources/code/rendering/mjktips/Reflect.html

If you need to add peturbations it could be done mixing this approach and RTT.

HellKnight
02-09-2006, 02:02 PM
Rereading my initial post now, I see I haven't mentioned that I'm using cubemaps apart from the title (which can easily be overseen). Sorry, my mistake...

Actually there's no way to copmute exact cubemap reflections without using some sort of iterative algorhtitm in order to find the "real" reflection vector (not just the parallel one from the center), thinking more about it.

HellKnight
02-09-2006, 02:29 PM
Here's what I came up with so far:

* Use 2 cubemaps; 1st one for the color, 2nd one for the radial distance from the center of the cubemap

* For every fragment with position P:
1. Compute the reflection vector R; R1 = R
2. Get the radial distance d from the 2nd cubemap at texel R1; D = |R1| * d, i.e. the position of this fragment
3. Compute D - P and compare to R
4. Based on the result from 3, slightly modify R1 and proceed with 2

Do so untill a good enough match is found. Now R1 should be a *pretty* good approximation of the vector needed to access the real color value of the reflective fragment. Use it to get the color from the first cubemap.

Some sort of binary search could be hacked in. This shouldnt be any slower than relief mapping f.e. and the advantages are huge (i.e. dont need to rerender the world every frame for every flat reflective surface), but of course at a higher memory cost.

EDIT: or use one 16 bit/float cubemap and store the distance in the alpha channel.

HellKnight
02-09-2006, 04:00 PM
Proof of concept:

http://stud3.tuwien.ac.at/~e0427091/correct_env.JPG

This image was rendered using the above algo with 5 iterations. There are still some minor artefacts towards the edges tough. Apart from these, the reflections are ABSOLUTELY correct. I used a single RGBA16 cubemap.

Ahh, I love the feeling when something finally works :)

V-man
02-09-2006, 08:02 PM