PDA

View Full Version : GLSL cubemap reflection



remdul
08-29-2006, 06:24 AM
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?

HellKnight
08-29-2006, 10:14 AM
I came up with an algorithm and wrote that some time ago: CCMR paper (http://stud3.tuwien.ac.at/~e0427091/ccmr.pdf) . 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.

remdul
08-29-2006, 10:44 AM
Ah yes, that's it, I knew I had seen something similar around here before. :)

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

Thanks.

HellKnight
08-29-2006, 11:03 AM
You're welcome, could you send me some screenshots when you're done?

remdul
08-30-2006, 04:41 AM
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.)

knackered
08-30-2006, 05:43 AM
some pretty nice screenshots there!

HellKnight
08-30-2006, 08:03 AM
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.

mogumbo
08-30-2006, 09:25 AM
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.

remdul
08-30-2006, 12:44 PM
Originally posted by knackered:
some pretty nice screenshots there! Thanks! :)


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. :)