Jump to content

  • Log In with Google      Sign In   
  • Create Account


Mirror reflection effect


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Specchum   Members   -  Reputation: 238

Like
0Likes
Like

Posted 21 February 2006 - 08:26 PM

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?

Sponsor:

#2 RAZORUNREAL   Members   -  Reputation: 567

Like
0Likes
Like

Posted 21 February 2006 - 09:02 PM

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!

#3 Specchum   Members   -  Reputation: 238

Like
0Likes
Like

Posted 21 February 2006 - 09:21 PM

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.



#4 Skeleton_V@T   Members   -  Reputation: 512

Like
0Likes
Like

Posted 21 February 2006 - 09:23 PM

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.

#5 Skeleton_V@T   Members   -  Reputation: 512

Like
0Likes
Like

Posted 21 February 2006 - 09:26 PM

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.

#6 GOCP   Members   -  Reputation: 122

Like
0Likes
Like

Posted 21 February 2006 - 09:32 PM

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



#7 Specchum   Members   -  Reputation: 238

Like
0Likes
Like

Posted 01 March 2006 - 08:13 PM

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!


#8 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

0Likes

Posted 02 March 2006 - 02:24 AM

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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS