Flat mirror (NEED HELP)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
$L!M
Posts: 28
Joined: Thu May 04, 2006 1:21 pm
Location: Ukraine :)

Flat mirror (NEED HELP)

Post by $L!M »

Hi everyone.
Can you tell me how to make flat mirror reflections???
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

You mean like have a mirror on the wall?

I made a mirror by messing around with the render to texture demo. Not quite sure how detrimental it was to the frame rate though, but it's probably the only way to do it i would think.
Image Image Image
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

Stenciling

Post by Blizzard »

You can try to make a stencil mirror.

1 Get the direct3d device! (irrlicht)
2 Render the scene! (irrlicht)
3 Set and enable the stencil buffer (direct3D)
4 render the mirror only(irrlicht)
5 set the stencil buffer to take data from it (direct3D)
6 get the view matrix of the camera (irrlicht)
7 mirror the view matrix (direct3D)
8 set the face rendering to clockwise (direct3D)
9 clear the Zbuffer (direct3D/irrlicht)
10 re-render the scene (irrlicht)
11 deactivate the stencil buffer (direct3D)

you can set a clip plane to make the render good, it's important but not foundamental.

I hope to no write wrong things...
Good luck!
Everyone for the game and the game for everyone
$L!M
Posts: 28
Joined: Thu May 04, 2006 1:21 pm
Location: Ukraine :)

Post by $L!M »

JP wrote:You mean like have a mirror on the wall?

I made a mirror by messing around with the render to texture demo. Not quite sure how detrimental it was to the frame rate though, but it's probably the only way to do it i would think.
Thanks, I'll try this. But now new question appears. How to determine the position of camera which would be used for render to texture.
Is this right?
Image

2Blizzard
I have very poor knowledge about all that stencil buffers and directx :(, so this is very complex way for me. :wink:
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

I didn't actually play around with moving the camera, is it necessary? I've got a niggling thought that it would!

I was just doing it for a bit of fun to ease the boredom of revision, and i just had a static faerie model in front of the mirror and had the camera situated inside the mirror facing outwards, and it worked nicely with the faerie in front of the mirror, but i didn't try anything more complicated like moving objects, maybe in that sort of case you would need to move the camera around.
Image Image Image
Blizzard
Posts: 71
Joined: Thu Apr 20, 2006 5:27 pm
Location: Italy

Post by Blizzard »

Hi,
if you are poor of direct3d you can read some books or find tutorials (I'm not a guru, but I study a lot and slowly I've learned most pretty features ^_^ )

To get the real time reflection you must reflect the view matrix! It's possible trasforming it using a reflection matrix generated by a plane. Irrlicht don't have this matrix.

You can try to do it manually. Assume that the center of the plane is the (0,0,0)coordinates. Take the of your camera relative to the plane and reflect the coordinate that you want simply multiply the coordinate * -1 and adding it to the position of your camera.

Example:

the mirror look throug the x axis
MirrorPosition (MP)=(10,5,0);
CameraPosition (CP)=(15,0,-1);

value= MP-CP = (-5,5,1);

take the x coordinate tha you want to reflect

newCameraPosition=CP;
newCameraPosition.X =MP.X+ value.X = (5,0,-1);

The position is reflected on X axis

You reflect now the Y rotation of the camera.
Take the rotation

CameraRotation (CR)= (0,45,0);

CR.Y=360-CR.Y = (0,315,0);

With these formulas (If I've not write wrong things... this is possible, I've invented it at moment T_T ) you may reflect the camera.

Pay attention!! The reflection you can make is only on the vertical plane that look on X or Z axis. If you want a plane at 45° the formulas are too strong, If you want to reflect horizontal surfaces you must reflect all the view matrix using direct3D

Good luck!!
Everyone for the game and the game for everyone
$L!M
Posts: 28
Joined: Thu May 04, 2006 1:21 pm
Location: Ukraine :)

Post by $L!M »

Thanx. I'll try and show you results. :wink:
funcdoobiest
Posts: 48
Joined: Thu Jun 15, 2006 6:35 pm

Post by funcdoobiest »

1 Get the direct3d device! (irrlicht)
2 Render the scene! (irrlicht)
3 Set and enable the stencil buffer (direct3D)
4 render the mirror only(irrlicht)
5 set the stencil buffer to take data from it (direct3D)
6 get the view matrix of the camera (irrlicht)
7 mirror the view matrix (direct3D)
8 set the face rendering to clockwise (direct3D)
9 clear the Zbuffer (direct3D/irrlicht)
10 re-render the scene (irrlicht)
11 deactivate the stencil buffer (direct3D)
I have done this before in DX but I was just wandering, how I can set the stencile buffer? You say to do it through D3D, is there a way to get access to the Dx device directly or would i have to go into the engine and do some rewriting?
Post Reply