problem with my reflection idea

Started by
2 comments, last by kop0113 9 years, 10 months ago

Hi biggrin.png ... it's my first question and my first topic but i am not really new in game making but still a beginner ...

i am using Unity3D engine and i really want to make a reflection shader like the really mirrors and reflections but i am not that good in coding...

so i had an easy idea for the reflection but have no right way for this i am thinking about putting a camera (not the main one ofc) in the mirror object (flat plane) and making it's direction forward the mirror and somehow making the camera view the same width and height and the same position of the plane but i don't know how to put 2 active cameras in the game

for explaining

[attachment=22162:Mirror Explain_00001.png]

and i don't want to use engine assets for my own experience smile.png

thanks ... and sorry for my bad english. happy.png

Advertisement

Yeah you usually do mirrors by rendering the scene from the mirrors perspective.

Think of the mirror as a plane.

Now, to render whatever the mirror should see, simply REFLECT MIRROR the real camera to the other side of the mirror and render (render only the area of screen covered by mirror) on top of the real scene. The mirrored camera should not render anything behind the mirror plane (so you only render the part of scene on one side of the mirror, the side that can actually be reflected off of it)

Idk how to do that in unity tho.

o3o

sooo is it possible? blink.png

and thanks for replying biggrin.png

I have recently implemented this technique using my own engine (a clone of the Unity API so should be quite similar) and it basically involved the following steps (There may be a better way to do this but this is simple):

1) add another camera just in front of the mirror facing outwards.

2) Set up this camera to render to a RenderTexture.

3) Set the mainTexture of the mirror's material to the same RenderTexture that you assigned to the mirror camera.

4) (Optional): Set the mirror's layer so that the mirror camera does not render it. Though it will probably just come out black anyway since a render texture cannot render itself to itself (if that makes sense). Luckily it is facing the other way so it wont make much difference.

http://tinyurl.com/shewonyay - Thanks so much for those who voted on my GF's Competition Cosplay Entry for Cosplayzine. She won! I owe you all beers :)

Mutiny - Open-source C++ Unity re-implementation.
Defile of Eden 2 - FreeBSD and OpenBSD binaries of our latest game.

This topic is closed to new replies.

Advertisement