Search Unity

Question Questions about mirror reflection effect

Discussion in 'General Graphics' started by RINNUXEI, Nov 8, 2021.

  1. RINNUXEI

    RINNUXEI

    Joined:
    Sep 3, 2015
    Posts:
    32
    Hello there,

    So I'm looking forward a mirror reflection effect and found that most implementations are based on Unity's standard water asset. This unitychan one gives a quite convincing result.

    What I'm confused is about these lines of code, where it sets the transform of the reflection camera before calling its render method.

    Code (CSharp):
    1. reflectionCamera.transform.position = newpos;
    2. Vector3 euler = cam.transform.eulerAngles;
    3. reflectionCamera.transform.eulerAngles = new Vector3(0, euler.y, euler.z);
    4. reflectionCamera.Render();
    As the document of Camera.worldToCameraMatrix says,
    Isn't it meaningless to change the position and rotation of the reflection camera since its worldToCameraMatrix has already been set before? And if I comment out these lines of code, the reflection effect seems not to change at all. So can I just safely remove these lines of code? Or am I missing something here?

    By the way, the document of Camera.projectionMatrix also says
    While the code is still setting the fieldOfView property of the reflection camera in the UpdateCameraModes method.

    Please any help would be appreciated.