Exemplo n.º 1
0
    // Token: 0x06002BC7 RID: 11207 RVA: 0x000A2E68 File Offset: 0x000A1068
    public void PostPreCull()
    {
        if (global::CameraFX.viewModelRootTransform)
        {
            Quaternion localRotation = base.transform.localRotation;
            Vector3    localPosition = base.transform.localPosition;
            if (this.viewModel)
            {
                this.viewModel.ModifyAiming(new Ray(base.transform.parent.position, base.transform.parent.forward), ref localPosition, ref localRotation);
            }
            global::CameraFX.viewModelRootTransform.localRotation = Quaternion.Inverse(localRotation);
            global::CameraFX.viewModelRootTransform.localPosition = -localPosition;
        }
        Precise.ExtractLocalToWorldToLocal(this.camera.transform, ref this.localToWorldMatrix, ref this.worldToLocalMatrix);
        if (this.adaptiveNearPlane)
        {
            int      num      = (this.camera.cullingMask & ~this.adaptiveNearPlane.ignoreLayers.value) | this.adaptiveNearPlane.forceLayers.value;
            Vector3G vector3G = default(Vector3G);
            Vector3G vector3G2;
            this.localToWorldMatrix.MultiplyPoint(ref vector3G, ref vector3G2);
            Collider[] array   = Physics.OverlapSphere(vector3G2.f, this.adaptiveNearPlane.minNear + this.adaptiveNearPlane.maxNear, num);
            float      num2    = float.PositiveInfinity;
            double     num3    = (double)this.camera.fieldOfView;
            double     num4    = (double)this.camera.aspect;
            double     num5    = (double)this.adaptiveNearPlane.minNear;
            double     num6    = (double)(this.adaptiveNearPlane.maxNear + this.adaptiveNearPlane.threshold);
            float      minNear = this.adaptiveNearPlane.minNear;
            float      num7    = this.adaptiveNearPlane.maxNear + this.adaptiveNearPlane.threshold - minNear;
            Matrix4x4G matrix4x4G;
            Matrix4x4G.Perspective(ref num3, ref num4, ref num5, ref num6, ref matrix4x4G);
            Matrix4x4G matrix4x4G2;
            Matrix4x4G.Inverse(ref matrix4x4G, ref matrix4x4G2);
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    Vector3G vector3G3;
                    vector3G3.x = ((double)i - 3.5) / 3.5;
                    vector3G3.y = ((double)j - 3.5) / 3.5;
                    vector3G3.z = 0.0;
                    Vector3G vector3G4;
                    matrix4x4G2.MultiplyPoint(ref vector3G3, ref vector3G4);
                    vector3G3.z = 1.0;
                    Vector3G vector3G5;
                    matrix4x4G2.MultiplyPoint(ref vector3G3, ref vector3G5);
                    vector3G4.x = -vector3G4.x;
                    vector3G4.y = -vector3G4.y;
                    vector3G4.z = -vector3G4.z;
                    vector3G5.x = -vector3G5.x;
                    vector3G5.y = -vector3G5.y;
                    vector3G5.z = -vector3G5.z;
                    Vector3G vector3G6;
                    this.localToWorldMatrix.MultiplyPoint(ref vector3G4, ref vector3G6);
                    Vector3G vector3G7;
                    this.localToWorldMatrix.MultiplyPoint(ref vector3G5, ref vector3G7);
                    Vector3G vector3G8;
                    vector3G8.x = vector3G7.x - vector3G6.x;
                    vector3G8.y = vector3G7.y - vector3G6.y;
                    vector3G8.z = vector3G7.z - vector3G6.z;
                    float num8 = (float)Math.Sqrt(vector3G8.x * vector3G8.x + vector3G8.y * vector3G8.y + vector3G8.z * vector3G8.z);
                    float num9 = num8;
                    Ray   ray;
                    ray..ctor(vector3G6.f, vector3G8.f);
                    foreach (Collider collider in array)
                    {
                        RaycastHit raycastHit;
                        if (collider.Raycast(ray, ref raycastHit, num9))
                        {
                            float distance = raycastHit.distance;
                            if (distance < num9)
                            {
                                num9 = distance;
                                float num10 = minNear + distance / num8 * num7;
                                if (num2 > num10)
                                {
                                    num2 = num10;
                                }
                            }
                        }
                    }
                }
            }
            if (float.IsInfinity(num2))
            {
                this.camera.nearClipPlane = this.adaptiveNearPlane.maxNear;
            }
            else
            {
                num2 -= this.adaptiveNearPlane.threshold;
                if (num2 >= this.adaptiveNearPlane.maxNear)
                {
                    this.camera.nearClipPlane = this.adaptiveNearPlane.maxNear;
                }
                else if (num2 <= this.adaptiveNearPlane.minNear)
                {
                    this.camera.nearClipPlane = this.adaptiveNearPlane.minNear;
                }
                else
                {
                    this.camera.nearClipPlane = num2;
                }
            }
        }
        global::PerspectiveMatrixBuilder perspectiveMatrixBuilder;

        perspectiveMatrixBuilder.fieldOfView = (double)this.camera.fieldOfView;
        perspectiveMatrixBuilder.aspectRatio = (double)this.camera.aspect;
        perspectiveMatrixBuilder.nearPlane   = (double)this.camera.nearClipPlane;
        perspectiveMatrixBuilder.farPlane    = (double)this.camera.farClipPlane;
        global::PerspectiveMatrixBuilder perspectiveMatrixBuilder2 = perspectiveMatrixBuilder;
        Matrix4x4G matrix4x4G3;

        if (this.camera.isOrthoGraphic)
        {
            this.projectionMatrix.f = this.camera.projectionMatrix;
            matrix4x4G3             = this.projectionMatrix;
        }
        else
        {
            if (this.viewModel)
            {
                this.viewModel.ModifyPerspective(ref perspectiveMatrixBuilder2);
            }
            if (global::CameraFX.vm_projuse)
            {
                perspectiveMatrixBuilder2.ToProjectionMatrix(out this.projectionMatrix);
            }
            else
            {
                perspectiveMatrixBuilder.ToProjectionMatrix(out this.projectionMatrix);
            }
            this.camera.projectionMatrix = this.projectionMatrix.f;
            perspectiveMatrixBuilder2.ToProjectionMatrix(out matrix4x4G3);
        }
        Vector4 vector;

        vector.y = (float)perspectiveMatrixBuilder2.nearPlane;
        vector.z = (float)perspectiveMatrixBuilder2.farPlane;
        vector.w = (float)(1.0 / perspectiveMatrixBuilder2.farPlane);
        if (global::CameraFX.vm_flip == global::CameraFX.PLATFORM_POLL.flipRequired)
        {
            vector.x = 1f;
            Shader.SetGlobalMatrix("V_MUNITY_MATRIX_P", matrix4x4G3.f);
        }
        else
        {
            vector.x = -1f;
            global::PerspectiveMatrixBuilder perspectiveMatrixBuilder3;
            perspectiveMatrixBuilder3.nearPlane   = perspectiveMatrixBuilder2.nearPlane;
            perspectiveMatrixBuilder3.farPlane    = perspectiveMatrixBuilder2.farPlane;
            perspectiveMatrixBuilder3.fieldOfView = -perspectiveMatrixBuilder2.fieldOfView;
            perspectiveMatrixBuilder3.aspectRatio = -perspectiveMatrixBuilder2.aspectRatio;
            Matrix4x4G matrix4x4G4;
            perspectiveMatrixBuilder3.ToProjectionMatrix(out matrix4x4G4);
            Shader.SetGlobalMatrix("V_MUNITY_MATRIX_P", matrix4x4G4.f);
        }
        Shader.SetGlobalVector("V_M_ProjectionParams", vector);
        if (this.recalcViewMatrix)
        {
            Vector3G    vector3G9;
            QuaternionG quaternionG;
            Vector3G    vector3G10;
            Precise.ExtractWorldCoordinates(this.camera.transform, ref vector3G9, ref quaternionG, ref vector3G10);
            vector3G10.x = 1.0;
            vector3G10.y = 1.0;
            vector3G10.z = -1.0;
            Matrix4x4G.TRS(ref vector3G9, ref quaternionG, ref vector3G10, ref this.cameraToWorldMatrix);
            if (Matrix4x4G.Inverse(ref this.cameraToWorldMatrix, ref this.worldToCameraMatrix))
            {
                this.camera.worldToCameraMatrix = this.worldToCameraMatrix.f;
            }
        }
        else
        {
            this.cameraToWorldMatrix.f = this.camera.cameraToWorldMatrix;
            this.worldToCameraMatrix.f = this.camera.worldToCameraMatrix;
        }
        this.worldToCameraMatrixUnAltered = this.worldToCameraMatrix;
        this.cameraToWorldMatrixUnAltered = this.cameraToWorldMatrix;
        this.projectionMatrixUnAltered    = this.projectionMatrix;
        global::CameraFX.ApplyTransitionAlterations(this.camera, this, true);
        this.projectScreen.modelview  = (this.projectViewport.modelview = this.worldToCameraMatrix);
        this.projectScreen.projection = (this.projectViewport.projection = this.projectionMatrix);
        Rect rect = this.camera.pixelRect;

        this.projectScreen.offset.x = (double)rect.x;
        this.projectScreen.offset.y = (double)rect.y;
        this.projectScreen.size.x   = (double)rect.width;
        this.projectScreen.size.y   = (double)rect.height;
        rect = this.camera.rect;
        this.projectViewport.offset.x = (double)rect.x;
        this.projectViewport.offset.y = (double)rect.y;
        this.projectViewport.size.x   = (double)rect.width;
        this.projectViewport.size.y   = (double)rect.height;
        Matrix4x4G matrix4x4G5;

        Matrix4x4G.Mult(ref this.localToWorldMatrix, ref this.worldToCameraMatrix, ref matrix4x4G5);
        Matrix4x4G matrix4x4G6;

        Matrix4x4G.Mult(ref matrix4x4G5, ref this.projectionMatrix, ref matrix4x4G6);
        Matrix4x4G matrix4x4G7;

        Matrix4x4G.Inverse(ref matrix4x4G5, ref matrix4x4G7);
        Matrix4x4G matrix4x4G8;

        Matrix4x4G.Inverse(ref matrix4x4G6, ref matrix4x4G8);
        Matrix4x4G matrix4x4G9;

        Matrix4x4G.Inverse(ref this.localToWorldMatrix, ref matrix4x4G9);
        Matrix4x4G matrix4x4G10;

        Matrix4x4G.Transpose(ref matrix4x4G8, ref matrix4x4G10);
        Matrix4x4G matrix4x4G11;

        Matrix4x4G.Transpose(ref matrix4x4G7, ref matrix4x4G11);
        Matrix4x4G matrix4x4G12;

        Matrix4x4G.Transpose(ref matrix4x4G9, ref matrix4x4G12);
        if (this.viewModel)
        {
            this.viewModel.UpdateProxies();
        }
        global::BoundHack.Achieve(base.transform.position);
        global::ContextSprite.UpdateSpriteFading(this.camera);
        global::PlayerClient localPlayerClient = global::PlayerClient.localPlayerClient;

        if (localPlayerClient)
        {
            localPlayerClient.ProcessLocalPlayerPreRender();
        }
        global::RPOS.BeforeSceneRender_Internal(this.camera);
    }