Jump to content

  • Log In with Google      Sign In   
  • Create Account

problem with my reflection idea


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Amr Zewail   Members   -  Reputation: 111

Like
0Likes
Like

Posted 14 June 2014 - 03:28 PM

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

 

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



Sponsor:

#2 Waterlimon   Crossbones+   -  Reputation: 2562

Like
4Likes
Like

Posted 14 June 2014 - 05:31 PM

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, 14 June 2014 - 05:32 PM.

o3o


#3 Amr Zewail   Members   -  Reputation: 111

Like
0Likes
Like

Posted 15 June 2014 - 11:09 AM

sooo is it possible? blink.png

 

and thanks for replying biggrin.png



#4 Karsten_   Members   -  Reputation: 1603

Like
0Likes
Like

Posted 16 June 2014 - 10:09 AM

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_, 16 June 2014 - 10:11 AM.

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





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS