CalculateReflectionMatrix() static private method

static private CalculateReflectionMatrix ( Matrix4x4 reflectionMat, Vector4 plane ) : Matrix4x4
reflectionMat Matrix4x4
plane Vector4
return Matrix4x4
    // Token: 0x0600148F RID: 5263 RVA: 0x00026968 File Offset: 0x00024B68
    private void RenderReflectionFor(Camera cam, Camera reflectCamera)
    {
        if (!reflectCamera)
        {
            return;
        }
        if (this.sharedMaterial && !this.sharedMaterial.HasProperty(this.reflectionSampler))
        {
            return;
        }
        reflectCamera.cullingMask = (this.reflectionMask & ~(1 << LayerMask.NameToLayer("Water")));
        this.SaneCameraSettings(reflectCamera);
        reflectCamera.backgroundColor = this.clearColor;
        reflectCamera.clearFlags      = ((!this.reflectSkybox) ? CameraClearFlags.Color : CameraClearFlags.Skybox);
        if (this.reflectSkybox && cam.gameObject.GetComponent(typeof(Skybox)))
        {
            Skybox skybox = (Skybox)reflectCamera.gameObject.GetComponent(typeof(Skybox));
            if (!skybox)
            {
                skybox = (Skybox)reflectCamera.gameObject.AddComponent(typeof(Skybox));
            }
            skybox.material = ((Skybox)cam.GetComponent(typeof(Skybox))).material;
        }
        GL.SetRevertBackfacing(true);
        Transform transform   = base.transform;
        Vector3   eulerAngles = cam.transform.eulerAngles;

        reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles.x, eulerAngles.y, eulerAngles.z);
        reflectCamera.transform.position    = cam.transform.position;
        Vector3 position = transform.transform.position;

        position.y = transform.position.y;
        Vector3   up       = transform.transform.up;
        float     w        = -Vector3.Dot(up, position) - this.clipPlaneOffset;
        Vector4   plane    = new Vector4(up.x, up.y, up.z, w);
        Matrix4x4 matrix4x = Matrix4x4.zero;

        matrix4x    = PlanarReflection.CalculateReflectionMatrix(matrix4x, plane);
        this.oldpos = cam.transform.position;
        Vector3 position2 = matrix4x.MultiplyPoint(this.oldpos);

        reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * matrix4x;
        Vector4   clipPlane = this.CameraSpacePlane(reflectCamera, position, up, 1f);
        Matrix4x4 matrix4x2 = cam.projectionMatrix;

        matrix4x2 = PlanarReflection.CalculateObliqueMatrix(matrix4x2, clipPlane);
        reflectCamera.projectionMatrix   = matrix4x2;
        reflectCamera.transform.position = position2;
        Vector3 eulerAngles2 = cam.transform.eulerAngles;

        reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles2.x, eulerAngles2.y, eulerAngles2.z);
        reflectCamera.Render();
        GL.SetRevertBackfacing(false);
    }
Beispiel #2
0
    private void RenderReflectionFor(Camera cam, Camera reflectCamera)
    {
        if (!reflectCamera)
        {
            return;
        }
        if (this.sharedMaterial && !this.sharedMaterial.HasProperty(this.reflectionSampler))
        {
            return;
        }
        if (GraphicsSettings.planarReflectionNeedsUpdate)
        {
            GraphicsSettings.planarReflectionNeedsUpdate = false;
            switch (GraphicsSettings.planarReflectionQuality)
            {
            case EGraphicQuality.LOW:
                reflectCamera.cullingMask = PlanarReflection.CULLING_MASK_LOW;
                break;

            case EGraphicQuality.MEDIUM:
                reflectCamera.cullingMask = PlanarReflection.CULLING_MASK_MEDIUM;
                break;

            case EGraphicQuality.HIGH:
                reflectCamera.cullingMask = PlanarReflection.CULLING_MASK_HIGH;
                break;

            case EGraphicQuality.ULTRA:
                reflectCamera.cullingMask = PlanarReflection.CULLING_MASK_ULTRA;
                break;
            }
            reflectCamera.layerCullDistances = cam.layerCullDistances;
            reflectCamera.layerCullSpherical = cam.layerCullSpherical;
        }
        this.SaneCameraSettings(reflectCamera);
        GL.invertCulling = true;
        Transform transform   = base.transform;
        Vector3   eulerAngles = cam.transform.eulerAngles;

        reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles.x, eulerAngles.y, eulerAngles.z);
        reflectCamera.transform.position    = cam.transform.position;
        Vector3 position = transform.transform.position;

        position.y = transform.position.y;
        Vector3 up  = transform.transform.up;
        float   num = -Vector3.Dot(up, position) - this.clipPlaneOffset;
        Vector4 plane;

        plane..ctor(up.x, up.y, up.z, num);
        Matrix4x4 matrix4x = Matrix4x4.zero;

        matrix4x    = PlanarReflection.CalculateReflectionMatrix(matrix4x, plane);
        this.oldpos = cam.transform.position;
        Vector3 position2 = matrix4x.MultiplyPoint(this.oldpos);

        reflectCamera.worldToCameraMatrix = cam.worldToCameraMatrix * matrix4x;
        Vector4 vector = this.CameraSpacePlane(reflectCamera, position, up, 1f);

        reflectCamera.projectionMatrix   = cam.CalculateObliqueMatrix(vector);
        reflectCamera.transform.position = position2;
        Vector3 eulerAngles2 = cam.transform.eulerAngles;

        reflectCamera.transform.eulerAngles = new Vector3(-eulerAngles2.x, eulerAngles2.y, eulerAngles2.z);
        float lodBias = QualitySettings.lodBias;

        QualitySettings.lodBias = 1f;
        if (PlanarReflection.preRender != null)
        {
            PlanarReflection.preRender();
        }
        reflectCamera.Render();
        if (PlanarReflection.postRender != null)
        {
            PlanarReflection.postRender();
        }
        QualitySettings.lodBias = lodBias;
        GL.invertCulling        = false;
    }