Пример #1
0
    public void PreCullEnd(bool postCamFX)
    {
        if (this.mount != null)
        {
            Transform transform = this.mount.transform;
            base.transform.position = transform.position;
            base.transform.rotation = transform.rotation;
            CameraClearFlags clearFlags       = this.camera.clearFlags;
            int cullingMask                   = this.camera.cullingMask;
            DepthTextureMode depthTextureMode = this.camera.depthTextureMode;
            this.camera.ResetProjectionMatrix();
            this.camera.ResetWorldToCameraMatrix();
            this.mount.camera.depthTextureMode = depthTextureMode;
            this.camera.CopyFrom(this.mount.camera);
            if (!postCamFX)
            {
                CameraFX.ApplyTransitionAlterations(this.camera, null, false);
            }
            this.camera.clearFlags  = clearFlags;
            this.camera.cullingMask = cullingMask;
            if (this.camera.depthTextureMode != depthTextureMode)
            {
                Debug.Log("Yea this is changing depth texture mode!", this.mount);
                this.camera.depthTextureMode = depthTextureMode;
            }
            this.mount.OnPostMount(this);
            this.lastView = this.camera.worldToCameraMatrix;
            this.lastProj = this.camera.projectionMatrix;
            this.once     = true;
        }
        else
        {
            if (!this.once)
            {
                this.lastView = this.camera.worldToCameraMatrix;
                this.lastProj = this.camera.projectionMatrix;
                this.once     = true;
            }
            this.camera.ResetProjectionMatrix();
            this.camera.ResetWorldToCameraMatrix();
            this.camera.worldToCameraMatrix = this.lastView;
            this.camera.projectionMatrix    = this.lastProj;
            if (!postCamFX)
            {
                CameraFX.ApplyTransitionAlterations(this.camera, null, false);
            }
        }
        Matrix4x4 cameraToWorldMatrix = this.camera.cameraToWorldMatrix;

        base.transform.position = cameraToWorldMatrix.MultiplyPoint(Vector3.zero);
        Vector3 forward = cameraToWorldMatrix.MultiplyVector(-Vector3.forward);

        base.transform.rotation = Quaternion.LookRotation(forward, cameraToWorldMatrix.MultiplyVector(Vector3.up));
        Shader.SetGlobalMatrix("_RUST_MATRIX_CAMERA_TO_WORLD", cameraToWorldMatrix * negateZMatrix);
        Shader.SetGlobalMatrix("_RUST_MATRIX_WORLD_TO_CAMERA", this.camera.worldToCameraMatrix * negateZMatrix);
    }
Пример #2
0
    public void PostPreCull()
    {
        Vector3G   vector3G;
        Matrix4x4G matrix4x4G;
        Matrix4x4G matrix4x4G1;
        Vector3G   vector3G1 = new Vector3G();
        Vector3G   vector3G2;
        Vector3G   vector3G3;
        Vector3G   vector3G4;
        Vector3G   vector3G5;
        Vector3G   vector3G6 = new Vector3G();
        RaycastHit raycastHit;
        Matrix4x4G matrix4x4G2;
        PerspectiveMatrixBuilder perspectiveMatrixBuilder = new PerspectiveMatrixBuilder();
        Vector4 vector4 = new Vector4();
        PerspectiveMatrixBuilder perspectiveMatrixBuilder1 = new PerspectiveMatrixBuilder();
        Matrix4x4G  matrix4x4G3;
        Vector3G    vector3G7;
        QuaternionG quaternionG;
        Vector3G    vector3G8;
        Matrix4x4G  matrix4x4G4;
        Matrix4x4G  matrix4x4G5;
        Matrix4x4G  matrix4x4G6;
        Matrix4x4G  matrix4x4G7;
        Matrix4x4G  matrix4x4G8;
        Matrix4x4G  matrix4x4G9;
        Matrix4x4G  matrix4x4G10;
        Matrix4x4G  matrix4x4G11;

        if (CameraFX.viewModelRootTransform)
        {
            Quaternion quaternion = base.transform.localRotation;
            Vector3    vector3    = base.transform.localPosition;
            if (this.viewModel)
            {
                this.viewModel.ModifyAiming(new Ray(base.transform.parent.position, base.transform.parent.forward), ref vector3, ref quaternion);
            }
            CameraFX.viewModelRootTransform.localRotation = Quaternion.Inverse(quaternion);
            CameraFX.viewModelRootTransform.localPosition = -vector3;
        }
        this.camera.transform.ExtractLocalToWorldToLocal(out this.localToWorldMatrix, out this.worldToLocalMatrix);
        if (this.adaptiveNearPlane)
        {
            int      num       = this.camera.cullingMask & ~this.adaptiveNearPlane.ignoreLayers.@value | this.adaptiveNearPlane.forceLayers.@value;
            Vector3G vector3G9 = new Vector3G();
            this.localToWorldMatrix.MultiplyPoint(ref vector3G9, out vector3G);
            Collider[] colliderArray = Physics.OverlapSphere(vector3G.f, this.adaptiveNearPlane.minNear + this.adaptiveNearPlane.maxNear, num);
            int        num1          = -1;
            float      single        = Single.PositiveInfinity;
            double     num2          = (double)this.camera.fieldOfView;
            double     num3          = (double)this.camera.aspect;
            double     num4          = (double)this.adaptiveNearPlane.minNear;
            double     num5          = (double)(this.adaptiveNearPlane.maxNear + this.adaptiveNearPlane.threshold);
            float      single1       = this.adaptiveNearPlane.minNear;
            float      single2       = this.adaptiveNearPlane.maxNear + this.adaptiveNearPlane.threshold - single1;
            Matrix4x4G.Perspective(ref num2, ref num3, ref num4, ref num5, out matrix4x4G);
            Matrix4x4G.Inverse(ref matrix4x4G, out matrix4x4G1);
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    vector3G1.x = ((double)i - 3.5) / 3.5;
                    vector3G1.y = ((double)j - 3.5) / 3.5;
                    vector3G1.z = 0;
                    matrix4x4G1.MultiplyPoint(ref vector3G1, out vector3G2);
                    vector3G1.z = 1;
                    matrix4x4G1.MultiplyPoint(ref vector3G1, out vector3G3);
                    vector3G2.x = -vector3G2.x;
                    vector3G2.y = -vector3G2.y;
                    vector3G2.z = -vector3G2.z;
                    vector3G3.x = -vector3G3.x;
                    vector3G3.y = -vector3G3.y;
                    vector3G3.z = -vector3G3.z;
                    this.localToWorldMatrix.MultiplyPoint(ref vector3G2, out vector3G4);
                    this.localToWorldMatrix.MultiplyPoint(ref vector3G3, out vector3G5);
                    vector3G6.x = vector3G5.x - vector3G4.x;
                    vector3G6.y = vector3G5.y - vector3G4.y;
                    vector3G6.z = vector3G5.z - vector3G4.z;
                    float single3 = (float)Math.Sqrt(vector3G6.x * vector3G6.x + vector3G6.y * vector3G6.y + vector3G6.z * vector3G6.z);
                    float single4 = single3;
                    Ray   ray     = new Ray(vector3G4.f, vector3G6.f);
                    for (int k = 0; k < (int)colliderArray.Length; k++)
                    {
                        if (colliderArray[k].Raycast(ray, out raycastHit, single4))
                        {
                            float single5 = raycastHit.distance;
                            if (single5 < single4)
                            {
                                single4 = single5;
                                float single6 = single1 + single5 / single3 * single2;
                                if (single > single6)
                                {
                                    single = single6;
                                    num1   = k;
                                }
                            }
                        }
                    }
                }
            }
            if (!float.IsInfinity(single))
            {
                single = single - this.adaptiveNearPlane.threshold;
                if (single >= this.adaptiveNearPlane.maxNear)
                {
                    this.camera.nearClipPlane = this.adaptiveNearPlane.maxNear;
                }
                else if (single > this.adaptiveNearPlane.minNear)
                {
                    this.camera.nearClipPlane = single;
                }
                else
                {
                    this.camera.nearClipPlane = this.adaptiveNearPlane.minNear;
                }
            }
            else
            {
                this.camera.nearClipPlane = this.adaptiveNearPlane.maxNear;
            }
        }
        perspectiveMatrixBuilder.fieldOfView = (double)this.camera.fieldOfView;
        perspectiveMatrixBuilder.aspectRatio = (double)this.camera.aspect;
        perspectiveMatrixBuilder.nearPlane   = (double)this.camera.nearClipPlane;
        perspectiveMatrixBuilder.farPlane    = (double)this.camera.farClipPlane;
        PerspectiveMatrixBuilder perspectiveMatrixBuilder2 = perspectiveMatrixBuilder;

        if (!this.camera.isOrthoGraphic)
        {
            if (this.viewModel)
            {
                this.viewModel.ModifyPerspective(ref perspectiveMatrixBuilder2);
            }
            if (!CameraFX.vm_projuse)
            {
                perspectiveMatrixBuilder.ToProjectionMatrix(out this.projectionMatrix);
            }
            else
            {
                perspectiveMatrixBuilder2.ToProjectionMatrix(out this.projectionMatrix);
            }
            this.camera.projectionMatrix = this.projectionMatrix.f;
            perspectiveMatrixBuilder2.ToProjectionMatrix(out matrix4x4G2);
        }
        else
        {
            this.projectionMatrix.f = this.camera.projectionMatrix;
            matrix4x4G2             = this.projectionMatrix;
        }
        vector4.y = (float)perspectiveMatrixBuilder2.nearPlane;
        vector4.z = (float)perspectiveMatrixBuilder2.farPlane;
        vector4.w = (float)(1 / perspectiveMatrixBuilder2.farPlane);
        if (CameraFX.vm_flip != CameraFX.PLATFORM_POLL.flipRequired)
        {
            vector4.x = -1f;
            perspectiveMatrixBuilder1.nearPlane   = perspectiveMatrixBuilder2.nearPlane;
            perspectiveMatrixBuilder1.farPlane    = perspectiveMatrixBuilder2.farPlane;
            perspectiveMatrixBuilder1.fieldOfView = -perspectiveMatrixBuilder2.fieldOfView;
            perspectiveMatrixBuilder1.aspectRatio = -perspectiveMatrixBuilder2.aspectRatio;
            perspectiveMatrixBuilder1.ToProjectionMatrix(out matrix4x4G3);
            Shader.SetGlobalMatrix("V_MUNITY_MATRIX_P", matrix4x4G3.f);
        }
        else
        {
            vector4.x = 1f;
            Shader.SetGlobalMatrix("V_MUNITY_MATRIX_P", matrix4x4G2.f);
        }
        Shader.SetGlobalVector("V_M_ProjectionParams", vector4);
        if (!this.recalcViewMatrix)
        {
            this.cameraToWorldMatrix.f = this.camera.cameraToWorldMatrix;
            this.worldToCameraMatrix.f = this.camera.worldToCameraMatrix;
        }
        else
        {
            this.camera.transform.ExtractWorldCoordinates(out vector3G7, out quaternionG, out vector3G8);
            vector3G8.x = 1;
            vector3G8.y = 1;
            vector3G8.z = -1;
            Matrix4x4G.TRS(ref vector3G7, ref quaternionG, ref vector3G8, out this.cameraToWorldMatrix);
            if (Matrix4x4G.Inverse(ref this.cameraToWorldMatrix, out this.worldToCameraMatrix))
            {
                this.camera.worldToCameraMatrix = this.worldToCameraMatrix.f;
            }
        }
        this.worldToCameraMatrixUnAltered = this.worldToCameraMatrix;
        this.cameraToWorldMatrixUnAltered = this.cameraToWorldMatrix;
        this.projectionMatrixUnAltered    = this.projectionMatrix;
        CameraFX.ApplyTransitionAlterations(this.camera, this, true);
        Matrix4x4G matrix4x4G12 = this.worldToCameraMatrix;
        Matrix4x4G matrix4x4G13 = matrix4x4G12;

        this.projectViewport.modelview = matrix4x4G12;
        this.projectScreen.modelview   = matrix4x4G13;
        Matrix4x4G matrix4x4G14 = this.projectionMatrix;

        matrix4x4G13 = matrix4x4G14;
        this.projectViewport.projection = matrix4x4G14;
        this.projectScreen.projection   = matrix4x4G13;
        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.Mult(ref this.localToWorldMatrix, ref this.worldToCameraMatrix, out matrix4x4G7);
        Matrix4x4G.Mult(ref matrix4x4G7, ref this.projectionMatrix, out matrix4x4G4);
        Matrix4x4G.Inverse(ref matrix4x4G7, out matrix4x4G8);
        Matrix4x4G.Inverse(ref matrix4x4G4, out matrix4x4G5);
        Matrix4x4G.Inverse(ref this.localToWorldMatrix, out matrix4x4G10);
        Matrix4x4G.Transpose(ref matrix4x4G5, out matrix4x4G6);
        Matrix4x4G.Transpose(ref matrix4x4G8, out matrix4x4G9);
        Matrix4x4G.Transpose(ref matrix4x4G10, out matrix4x4G11);
        if (this.viewModel)
        {
            this.viewModel.UpdateProxies();
        }
        BoundHack.Achieve(base.transform.position);
        ContextSprite.UpdateSpriteFading(this.camera);
        PlayerClient playerClient = PlayerClient.localPlayerClient;

        if (playerClient)
        {
            playerClient.ProcessLocalPlayerPreRender();
        }
        RPOS.BeforeSceneRender_Internal(this.camera);
    }