View Full Version : dynamic generated reflections
02-26-2001, 03:48 AM
I'm looking for a method to do reflections. the entire scene should be reflected in the celing or a wall. like in 3dmark2k pool-scene http://www.opengl.org/discussion_boards/ubb/smile.gif
I tried environment mapping but here you have to use pre-generated textures. is there a way to generate the texture out of the scene? (generate it dynamically?)
02-26-2001, 04:26 AM
If you have axis aligned reflectors, that is actually very easy to do. You just need to mirror all vertices at the plane of the reflector, draw the stuff, clear the zbuffer and draw a shape of the reflector only to the zbuffer.
Sphere mapping doesn't have to be pregenerated. There's an article on the nVidia website about this. Basically, you render the scene in 6 directions from the viewpoint of the reflecting object, like you would for a cube map. You then distort it to work as a sphere map.
The article is in the presentations section of the nVidia developer page, if you are interested.
02-26-2001, 04:09 PM
If you want to reflect the entire scene in a flat ceiling or wall do you draw the scene a second time using the stencil buffer to restrict it to the wall or ceiling. Lots of good stuff about this by Mark Kilgard is available from the nvidia site. One of the Nehe tutorials is also about this.
02-27-2001, 02:05 AM
don't really know what you meant with the zbuffer and why to clean it.
but I solved the prob. wasn't hard to make a fake mirror http://www.opengl.org/discussion_boards/ubb/smile.gif
I draw the scene, mirror it, (building a vector which is 90° (orthogonal) to the plane and points to a vertex. then multiply it by -1, calculate the new vertex, draw it, do this with all vertices....texture and then put the plane (wall) in the scene with blending and a marble texture or so. looks great http://www.opengl.org/discussion_boards/ubb/smile.gif
next prob is to do this on a water surface... but shouldn't be as hard....
[This message has been edited by mcbastian (edited 02-27-2001).]
02-27-2001, 02:50 AM
yeah, this is quite simple.
I understood it so:
-render scene in a buffer, placing cam in center of reflective object rendering 6 times
one time looking in direction of positive x axis, one time neg, x axis same with y and z axis, taking every time a "photo", then "placing the photos on the inside of a cube" then draw the reflective object reflecting the cube and the rest on screen http://www.opengl.org/discussion_boards/ubb/smile.gif
one problem left: how to take the "photos"?
(generate the 6 textures)
sonething like glReadPixel??
thanks for your help.
02-27-2001, 04:59 AM
The way I did my dynamic cube map was to do this.
glViewPort with dimensions of 128,128
this meant the renderings would only be 128x128 pixels high in the frame buffer, (which a) speeds stuff up lots. and b) means the entire rendered image fits nicely into the cube map textures)
Setup the camera in the right position and direcion.
Render the scene
then use glTexSubImage to grab the backbuffer rendered image into the cube map's textures.
after all 6 images have been done,
do glViewport with your normal dimensions.
To do reflectios with a sphere map, you need to do one more step beyond what nutty said.
After all your cube map textures are done, you need to distort them into a sphere map by rendering a sphere using orthographic projection, with your textures mapped onto it appropriately.
The presentation on how to do this is here: http://www.nvidia.com/marketing/Develope...mkspheremap.ppt (http://www.nvidia.com/marketing/Developer/DevRel.nsf/045cfdb95e306a4d882568170059fa93/c40ca48af2dff9908825681f00045c68/$FILE/gdc99_mkspheremap.ppt)
By the way, this is only important if you don't have cube mapping on your card. Otherwise, it is a waste of time, and you should just do what nutty said.
Most cards out there today don't have cube mapping, so either stick to sphere mapping or add support for both. I happen to have a GeForce2 GTS, so it doesn't really matter to me, except the cube maps look better http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.