Sign in to follow this  
Specchum

Mirror reflection effect

Recommended Posts

Specchum    242
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?

Share this post


Link to post
Share on other sites
RAZORUNREAL    567
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.

Share this post


Link to post
Share on other sites
Specchum    242
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.

Share this post


Link to post
Share on other sites
Skeleton_V@T    512
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.

Share this post


Link to post
Share on other sites
GOCP    122
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

Share this post


Link to post
Share on other sites
Specchum    242
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!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this