Jump to content
  • Advertisement
Sign in to follow this  
Amr Zewail

problem with my reflection idea

This topic is 1524 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post

Link to post
Share on other sites

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.

Edited by Waterlimon

Share this post

Link to post
Share on other sites

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.

Edited by Karsten_

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!