Glass-Reflection effect

Hi,

Im making a TicTacToe game with some friends of mine, just to get started on XNA. We are now beginning to be done with the gameplay, and now it could be great to do some effects, and boost the GFX a bit.

So I whould really like the board to have surface that reflects the pieces, in a reflection, glass like way.

Can anyone point be to a solution, sample code, or article or other way to do this?

Thanks in advance.

[450 byte] By [Deldy] at [2007-12-27]
# 1
To achieve the glass effect you need to flip all the objects in the world about your glass/mirror plane, draw the flipped objects, then draw the glass/mirror surface with some type of blending, then draw the unflipped world.

To add more robustness to the effect you'll probably want to use the stencil buffer to create a mask so that when you draw the flipped world you only draw in the glass/mirror area. Also, you'll want to set up up a user clip plane so that objects that pierce the mirror (if any) don't create weird rendering errors. The clip plane also removes errors for objects behind the mirror and also when/if you look at the mirror/glass surface from the back side.

I uploaded a project, with source code, on my site which that demonstrates how to do glass/mirror surfaces, taking into account all the things I mentioned. You can find it at http://www.threesixbox.com/project/?id=6c3eea10eb
The project has two types of mirrors (which you can see in the main screenshot): transparent mirrors (which is probably the glass effect you want) and solid mirrors (similar to a mirror on the wall that you can't see through). It also renders the mirror surface into a texture, which (if you want) allows you to render into lower resolution than the back buffer for achieving a slightly blurred reflection and faster rendering times.

Also, if you want something really quick and dirty, you can take a look at my Balls project at http://www.threesixbox.com/project/?id=2a9221cf3d It does the glass/mirror surface thing, but without the stencil masking and user plane clipping. To prevent drawing errors I designed the world so that you can't really see the edge of the mirror surface and I prevent objects or the view from going to the back side of the mirror surface. It also renders straight into the back buffer, yielding a very sharp, perfect reflection.

DerekNedelman at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 2

Thanks for your quick response Derek.

I get the idea, of the stuff you tell me, although your samples are quite hard for me to figure out. I cant use the quick and dirty one unfortunaly. I need the user clipping, as the board is a limited area of the screen.

I quess my problem here was that I dug to deep into it, as im really new to 3D game programming, so all the consepts are knocking me down.

If anyone could point me to a tutorial that whould be great, as I need only the effect, and nothing else - no much stuff confuses me. :D

Deldy at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 3
Well, I don't know of any tutorials but I would imagine that most tutorials you'll find will not cover everything you need and will not be written in C# for XNA.

If you find your way back to my source code for the 3DS Viewer, you'll want to take a look at the DrawMirrors() method in Scene.cs. The steps for drawing the mirrors are commented. No, it's not easy, but it's not very diffiicult either.

DerekNedelman at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 4
Hey Derek,

I just wanna jump in and say thank you for your projects. The Balls project was a big help to me in learning about particle systems and point sprites about a month ago. Your new 3DS viewer project looks like it will be at least as illuminating about things like stencil buffers and environment mapping and all that good stuff. So thanks for the work you are doing and keep it up!

-Aaron

a.d.m at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 5
a.d.m wrote:
Hey Derek,

I just wanna jump in and say thank you for your projects. The Balls project was a big help to me in learning about particle systems and point sprites about a month ago. Your new 3DS viewer project looks like it will be at least as illuminating about things like stencil buffers and environment mapping and all that good stuff. So thanks for the work you are doing and keep it up!

-Aaron

Wow, thanks a lot. I appreciate that.

DerekNedelman at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 6
Wouldnt it be more efficent to just render the scene from a different angle and use render targets to map this onto the reflective plane? I don't know the specific syntax. But I believe it involved setting up a seperate camera which mirrors the players orientation through the reflective plane. Using render targets or specifically render-to-texture functions you should be able to overlay that with the floors texture. The duplicating objects method will also work, however it might cause overhead in large scenes. Seems more optimized to use shaders for this type of effect (especially if you want the floor to be bumpy and not just a straight mirror).

// cybereality

cybereality at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...
# 7
cybereality wrote:
Wouldnt it be more efficent to just render the scene from a different angle and use render targets to map this onto the reflective plane? I don't know the specific syntax. But I believe it involved setting up

a seperate camera which mirrors the players orientation through the

reflective plane. Using render targets or specifically render-to-texture functions you should be able to overlay that with the floors texture.


That's what I do

cybereality wrote:

The duplicating objects method will also work, however it might cause overhead in large scenes.

I don't duplicate objects.

cybereality wrote:

Seems more optimized to use shaders for this type of effect

I use shaders.
DerekNedelman at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Framework...