Skip to main content
gamedev.net
🔒 Locked

Mirrors + Reflections

Started by Oniera 6 replies 1.4k views
Original Post
Oniera
Oniera
Can anyone point me in the direction of some sample code on how to create a mirrored surface in D3D? Documentation in this area is very much lacking. Let''s say I''m creating a pool of water, I want the pool to reflect the surrounding enviroment. Any ideas anyone? Demetrios G. Oniera Software Artists
Demetrios GeorgeadisDirector/ProgrammerOniera Software Artistswww.oniera.com
3dModelMan
3dModelMan
Hi,

I''m looking into rendering mirrors too.

I''m sure the principle is; change the render target from the back buffer, to another surface (possibly with another z buffer attached), set the view matrix in a suitable position, and run through the main render loop .

In reality, you''ll probably have to use a cut down version of the main render loop to keep the speed up.

Then render the scene from the normal position, onto the back buffer, but one object in the scene will be mapped with the previously rendered surface.

I can see some problems here, because the reflection will always be dependant on the viewing position, so the viewport in the bottom of the pool will have to be dynamically adjusted to remain correct to the main viewport.

I''m going to do some experimenting soon, and I''ll let you know how I get on. In the mean-time I''ll keep my eye on this thread for some more practical info...

Regards

Matt


Check out my project at: www.btinternet.com/~Matthew.Bennett
msn12b
msn12b
quote:
Original post by Oniera
Let's say I'm creating a pool of water, I want the pool to reflect the surrounding enviroment. Any ideas anyone?



Check this out.

I wrote this stuff a while ago, but it should work

It's under the second entry from the top.

MSN

Edited by - msn12b on 4/12/00 4:10:45 PM
Oniera
Oniera
Thanks for the help guys! The theory is sound, and I should be able to figure it out. (it will take some time)

3DModelMan: Sadly there seems to be no way to render directly onto a texture. You have to render onto a 3D surface, then copy each pixel to the texture surface. (SLOW)
Let me know if you get anywhere with it.....

Demetrios G
Oniera Software Artists
Demetrios GeorgeadisDirector/ProgrammerOniera Software Artistswww.oniera.com
Lars W.
Lars W.
Hi

There is anotherway for rendering reflections. You can Render your scene normaly, than render your waterpool to the Stencil Buffer.Then Mirror your Scene about your Watersurface, and Render again while checking against the Stencil Buffer.

Lars
WitchLord
WitchLord
Unfortunately most older cards don''t support stencil buffers. What you can do instead is to use clip planes to constrain the mirrored image to a convex polygon. You would need one clip plane for each edge in the polygon plus one for the surface of the polygon. With DX7 clip planes is supported directly in D3D so you don''t have to do it yourself anymore . This technique requires the mirror to be rendered before the rest of the scene otherwize you will get conflicts in the z-buffer.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Oniera
Oniera
The method of reflection by using the clipping plane, I think is in theory the fastest. However, for reflective surfaces which are not rectangular, I think you have to use stencil buffers.

I will of course be using both methods, but I''ve noticed that both seem to be on the difficult(ish) side. I''ve built our entire 3D engine from scratch, and this is the only thing I can''t wrap my head around. Blech! I will try both theories and let you know....

Demetrios G
Oniera
Demetrios GeorgeadisDirector/ProgrammerOniera Software Artistswww.oniera.com
WitchLord
WitchLord
You might want to take a look at the samples "clip mirror" and "stencil mirror" in the SDK

/ WitchLord
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel

Topic Locked

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

Sign in to reply to this topic.