GLSL cubemap reflection

How can I get correct cubemapped reflections, where the viewer can move around an moving, rotating object without the reflection cubemap moving along, but staying ‘fixed’ to the world? I haven’t been able to find tutorials/demos that take the view position into acount (not even the nVidia demos).

Do I compute the reflection vector best in eye space, then transform it to world space to get the right color returned by textureCube(). Or should I calculate everything in world space?

Sample code would be very much appreciated.

PS: Right now I also have to flip the y axis of the reflection vector, why do I have to do this?

I came up with an algorithm and wrote that some time ago: CCMR paper . However, someone pointed out that apparently there’s a better way to do it.

Also, keep in mind that this still doesn’t circumvent the fundamental disatvantage of cube maps: lacking information for “hidden” geomtery. If you want to use it for arbitrary flat surfaces and save you the rerendering of your geometry, forget about it right now.

However, it may be good enough for moving models and similar stuff.

Ah yes, that’s it, I knew I had seen something similar around here before. :slight_smile:

I’m aware of the limitations, but am only looking for something to improve it slightly without having to re-render the cubemaps.

Thanks.

You’re welcome, could you send me some screenshots when you’re done?

I’m still playing with it, but it seems to do something even though it is broken at some angles. May have messed something up when porting (and alpha channel probably).

http://home.planet.nl/~buijs512/_temp/reflect.jpg

  • Edit: Reminds me, does anyone know if it is possible/feasible, in reasonable fashion, to do the following:
  1. have a cubemap of an environment with z-buffer in alpha channel (much like in case of CCMR)
  2. in realtime, render dynamic objects to a copy of this cubemap, and test them against the alpha ‘z-buffer’

That way you can avoid rendering the environment, only the moving objects, which should be cheaper. The only problem would be using alpha as z-buffer, perhaps a shader can take care of that (sounds slow though)? Accuracy (z-fighting etc.) would not be much of a problem, since usually your reflection is distorted anyway.

(Just thinking out loud.)

some pretty nice screenshots there!

Originally posted by remdul:
I’m still playing with it, but it seems to do something even though it is broken at some angles. May have messed something up when porting (and alpha channel probably).

Yep, it looks bad for some angles/points far away from the cubemap center. However, your shots look pretty good.

Originally posted by remdul:

That way you can avoid rendering the environment, only the moving objects, which should be cheaper. The only problem would be using alpha as z-buffer, perhaps a shader can take care of that (sounds slow though)? Accuracy (z-fighting etc.) would not be much of a problem, since usually your reflection is distorted anyway.

Well, I’d say just use a second cubemap and bind it to a z-buffer FBO (EDIT: are z-buffer cubemaps supported yet??). This way you’d also solve the alpha channel precision problem - it should look better then.

Hi remdul,
I don’t think this is exactly what you’re looking for because it rerenders a cubemap each frame, but it shows the pros and cons of cubemap environment mapping pretty well: http://www.infiscape.com/projects/pantheon/pantheon.zip

Sorry, I don’t have source code for you. The cubemap is rendered from the users eye position each frame. The hidden geometry problem is evident, but it’s a pretty good illusion for the untrained eye.

Originally posted by knackered:
some pretty nice screenshots there!
Thanks! :slight_smile:

Yep, it looks bad for some angles/points far away from the cubemap center. However, your shots look pretty good.
I think it works best for reflective floors/walls in a room where the viewer can’t move too much. Once you move out of the objects extends the effect is pretty much lost.

@mogumbo: Nice looking demo, especially those roofs. :slight_smile: