I just wondered how to create a mirror within a 3D game?
My suggestion is/was to trace rays, hitting the "mirror" object then drawing a picture of a second cam onto the "mirror" object which is located at the original camera's mirror "point" by using the hit side of the mirror object as mirroring plane.

We would have to use the one ray coming from the center of the original camera to determine the point where the center of the vision is located on the mirror plane.

1 Answer
1

If you are using OpenGL, the OpenGL FAQ section 9: Transformations covers exactly how to do this. And no, it doesn't involve raytracing, as that's understandably a very inefficient (but high quality) way to accomplish this.

Here is essentially what the FAQ entry says, and the example code demonstrates:

Set up a reflected view matrix. Doing this for axis-aligned mirrors is explained in the second paragraph.

Draw the scene

Restore the view matrix and clear the depth buffer

Render the scene again; the actual mirror geometry in this scene should be translucent or entirely transparent, in order to show through to the previously rendered mirrored scene.

Obviously there is a lot of room for optimization. When rendering the reflected scene, you should probably as much culling as possible, since mirrors are typically small and the default off-screen culling won't kick in for the geometry which is on screen but not seen through the mirror. You can also render just a simplified version of the scene through the mirror. For effects, and to obscure the user from noticing the reduced quality, you could apply a shader (e.g. blur, or maybe bright/washed-out) when you do your mirrored render.

I imagine, if you're using DirectX, the procedure would be much the same.

An alternative, if you have more memory than render time, is to simply reflect your world geometry through the mirror in your 3D editor, then you can modify it to look however you want (enforce lower mip levels, etc.). We did this on the PS1, where stuff sitting on a shiny floor was duplicated/inverted underground, and the floor itself was rendered semitransparent.
–
dash-tom-bangSep 30 '10 at 19:15