Environment cubemapping (again)

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?

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:


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

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.

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.

Any comments/ideas?

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

Proof of concept:


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 :slight_smile:

Could it be that you are using shaders for your first pic you posted and your shader is wrong?

Yeah it was wrong, thats why I posted here in the first place… As I said I wasn’t able to find more info on doing correct cubemap reflections. If you have any links or whatever, share them…

The second one is right tough :wink:

Ok I uploaded a doc explaining that in more detail: