示例#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);
    }
示例#2
0
 void Start()
 {
     m_WaterForceLayer = 1 << LayerMask.NameToLayer("Ignore Raycast");
     IW3DUtils.CreateGridPlane(m_WaterPlane, m_MatShading, m_Grid, m_Width, m_Width, new Vector3(-m_Width / 2f, 0, -m_Width / 2f));
     m_CamOrth = IW3DUtils.CreateOrthographicCamera(m_WaterPlane.transform, m_WaterForceLayer);
     CreateInternalMaps();
     CreateInternalCameras(gameObject.transform);
     m_CamOrth.targetTexture = m_RTHeightmaps[1];
 }
示例#3
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();
    }
示例#4
0
    void Update()
    {
        if (!enabled)
        {
            return;
        }

        // reflection and refraction rendering
        Camera cam = GetComponent <Camera>();

        if (cam)
        {
            IW3DUtils.SyncCameraParameters(cam, m_CamReflection);
            IW3DUtils.SyncCameraParameters(cam, m_CamRefraction);
            RenderToReflectionMap();
            RenderToRefractionMap();
        }

        // ripple
        UpdateCore();
        UpdateGPUParameters();
    }