Skip to main content
gamedev.net
🔒 Locked

Reflective Surfaces

Started by Bad Monkey Mar 19, 2000 at 9:54 PM 3 replies 1.1k views
Original Post
Bad Monkey
Bad Monkey
Hi all, I''ve been cooking my brain trying to come up with a practical way to do a reflective surface (i.e. mirror) in OpenGL. If anyone could help me out (even with just some theory, not OGL-specific stuff), that would rock my world. I know in theory what I should be rendering (calculating angle of incidence (from eye) to surface, and reversing it, then treating the plane normal to this as a viewport to project to... its kinda hard to put into words, but I know what I''m getting at ), but I''m having trouble deciding on how to actually determine what to draw, and how to map it onto a poly. Can I have a separate OpenGL state machine which treats this surface as a viewport, projecting onto the poly (I know, it sounds very unlikely to me too)? I assume I have to implement some sort of (software) clipping and hidden surface determination, and ''project'' what can be ''seen'' onto a texture, which I then apply to the poly (does this sound feasible?). This sounds like a real bitch, ''coz I want it to work with a perspective projection (i.e. a clipping frustum, rather than a ''box''... screw doing that in software ) Would environment mapping do this, or is that just a smoke-and-mirrors (d''oh, bad analogy ) way of doing reflection? Even some links on the topic would be much appreciated. Thankyou, bye. ------------- squirrels are a remarkable source of protein...
Spellbound
Spellbound
You can draw the reflected image by first mirroring the world around the plane of the mirror. This can easily be done with a mirrormatrix.

Don''t forget that as you mirror the world the vertices of the triangles will change order so you need to change the backface culling as well.

Then you need to add some clippers (Can be done with OpenGL, don''t remember the function though) so that you don''t render outside the surface of the mirror.

The clipping around the edges of the mirror can also be done with the help of stencil buffering. You must still add a clipper along the surface of the mirror though.
Bad Monkey
Bad Monkey

Thanks Spellbound,

I actually checked your answer after I had found a heap of stuff about the subject by Mike Kilgard linked from www.opengl.org (amazing what you''ll find when you take your head out of your arse ).

He also explained it the same way you did (which was very clear, thankyou), and showed how to use stenciling to clip it to a poly.... sweeeet

Makes my previous plan of attack seem a little overly-complex

Thanks again man.


-------------
squirrels are a remarkable source of protein...
ga
ga
The OpenGL command to add clippers is
glClipPlane(GLenum plane, double *equation);

where plane is GL_CLIP_PLANE0, GL_CLIP_PLANE1, ...
and equation is a pointer to the four coefficients of the plane equation (ax + by + cz +d = 0).

Before you define a plane, you have to enable it:
glEnable(GLenum plane);

where plane is the same as above.

Visit our site: www.rarebyte.de.st

GA @ Rarebyte

Edited by - ga on 3/22/00 2:33:06 PM
Visit our homepage: www.rarebyte.de.stGA
Ped
Ped
stencil buffer is a bitch ... not widely supported today, and usually only in truecolor modes, so switching application into 16bpp mode will force the driver to do stenciling in sw emulation ...
If you have just one mirror in scene, you may use some rectangular OGL clipping to around the mirror, than render the mirrored scene (as desribed above), than clear the z-buffer to infinity, render mirror surface to set z-buffer in mirror''s space, and then render normal scene (which will overdraw the mirrored scene rendered out of mirror boundaries) ... this doesn''t need stencil, but in some cases you do a lot of overdraw... and clearing z-buffer is also a time expensive thing, but I do believe it should be at all faster than stencil approarch... in case you have more mirrors in same view, this may cause troubles... I''m lazy to think about it now... do som exercise...

---------------------------------------------------
Ped - Peter Helcmanovsky - 7 Gods demo group
http://7gods.rulez.sk
First Sight Entertainment - http://members.xoom.com/fseteam
---------------------------------------------------
---------------------------------------------------Ped - Peter Helcmanovsky - 7 Gods demo grouphttp://7gods.rulez.skFirst Sight Entertainment - http://members.xoom.com/fseteam---------------------------------------------------

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.