Esempio n. 1
0
    void RenderToReflectionMap()
    {
        // reflection plane's position and normal in world space
        Vector3 pos    = m_WaterPlane.transform.position;
        Vector3 normal = m_WaterPlane.transform.up;

        // Reflect camera around reflection plane
        float   d = -Vector3.Dot(normal, pos) - m_ClipPlaneOffset;
        Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d);

        Matrix4x4 reflection = Matrix4x4.zero;

        IW3DUtils.CalculateReflectionMatrix(ref reflection, reflectionPlane);
        Camera  cam    = GetComponent <Camera> ();
        Vector3 oldpos = cam.transform.position;
        Vector3 newpos = reflection.MultiplyPoint(oldpos);

        m_CamReflection.worldToCameraMatrix = cam.worldToCameraMatrix * reflection;

        // render objects up side of water plane
        Vector4 clipPlane = IW3DUtils.CameraSpacePlane(m_CamReflection, pos, normal, 1f, m_ClipPlaneOffset);

        m_CamReflection.projectionMatrix = cam.CalculateObliqueMatrix(clipPlane);
        GL.SetRevertBackfacing(true);
        m_CamReflection.transform.position = newpos;
        Vector3 euler = cam.transform.eulerAngles;

        m_CamReflection.transform.eulerAngles = new Vector3(-euler.x, euler.y, euler.z);
        m_CamReflection.Render();
        m_CamReflection.transform.position = oldpos;
        GL.SetRevertBackfacing(false);
    }
Esempio n. 2
0
    void RenderToRefractionMap()
    {
        Vector3 pos    = m_WaterPlane.transform.position;
        Vector3 normal = m_WaterPlane.transform.up;

        Camera cam = GetComponent <Camera> ();

        m_CamRefraction.worldToCameraMatrix = cam.worldToCameraMatrix;

        // render objects bottom side of water plane
        Vector4 clipPlane = IW3DUtils.CameraSpacePlane(m_CamRefraction, pos, normal, -1f, m_ClipPlaneOffset);

        m_CamRefraction.projectionMatrix   = cam.CalculateObliqueMatrix(clipPlane);
        m_CamRefraction.transform.position = cam.transform.position;
        m_CamRefraction.transform.rotation = cam.transform.rotation;
        m_CamRefraction.Render();
    }