Mirror reflection effect

Started by
6 comments, last by GameDev.net 18 years, 2 months ago
I'm trying to get mirror reflections in my code. I was wondering what possible techniques exist to do this - preferably the simplest and easiest method that doesn't need to be extremely visually accurate. I would also prefer a non-render-to-texture method since a high-res texture is required (if I'm not wrong) to make it look non-pixellated, and I'm a little short on texture memory. Any suggestions anyone?
"There is no dark side of the moon." - Pink Floyd
Advertisement
Heres a simple technique off the top of my head (so it may be wrong and inefficient):
Render the scene as normal, but give the mirror a different stencil value.
Reflect the camera in the mirror (i.e. move it to the other side of the mirror and invert stuff somehow, I forget).
Clear the depth buffer.
Render the scene again, but only where the stencil is what you set it to.

This won't work in several cases. Like when there's stuff behind the mirror or you have backface culling turned off and probly more.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
Quote:Original post by RAZORUNREAL

Reflect the camera in the mirror (i.e. move it to the other side of the mirror and invert stuff somehow, I forget).


Er..that's the one thing I wanted to know most about: how *do* you actually reflect the object? :D

Someone suggested flipping on the Y-axis and rendering the object again, but that doesn't give a true reflection as the axis orientation isn't maintained.

"There is no dark side of the moon." - Pink Floyd
NeHe Lesson #26 has already covered this technique.

Try [google] with those term: "OpenGL" "Reflection", you'll find a lot more tutorials, Gamasutra and Code Projects also have some good articles.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Quote:Original post by Specchum
Quote:Original post by RAZORUNREAL

Reflect the camera in the mirror (i.e. move it to the other side of the mirror and invert stuff somehow, I forget).


Er..that's the one thing I wanted to know most about: how *do* you actually reflect the object? :D

Someone suggested flipping on the Y-axis and rendering the object again, but that doesn't give a true reflection as the axis orientation isn't maintained.


You draw a perpendicular line from the original object's center to the mirror (which is a 3D plane) then find the opposite center point on that line. The details are introduced in NeHe tutorial.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
There is a good tutorial on a news group ages ago - comp.graphics.api.opengl under "a how to for using opengl for rendering mirrors"

Bassically you work out the mirror matrix (which moves from mirror space to world space), it's inverse and also a reflection in the Z-axis matrix.

Then the reflectin matrix (which you multiply onto the modelview stack) is just..

MirrorT * RefZ * InvMirrorT

This method, combined with stenciling the window to limit it's reflections, reversing the winding order and an approriate clip plane will give correct reflections.

GOCP

Had almost forgotten about this one! I've way too much going on ATM to keep track of! Yikes!

Had a quick gander at NeHe tutorials and basically how he does the reflection is re-render the model with a scale of 1,-1,1, which is almost the same as what the Red book says about rendering mirror images (though it didn't work for me - it wasn't quite a mirror reflection). Will try that and see how it works. Thx!
"There is no dark side of the moon." - Pink Floyd
Assuming the mirror is a plane , u can construct a reflection matrix and redraw the scene with some stenciling .


There is this article at comp.graphics.api.opengl by Tim Hall called
A how to for using OpenGL to render mirrors.

This topic is closed to new replies.

Advertisement