Exemplo n.º 1
0
        public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC, Vector2 taaJitter, float taaBlending)
        {
            DepthOfFieldModel.Settings settings = base.model.settings;
            RenderTextureFormat        aRGBHalf = RenderTextureFormat.ARGBHalf;
            RenderTextureFormat        format   = this.SelectFormat(RenderTextureFormat.R8, RenderTextureFormat.RHalf);
            float    b    = this.CalculateFocalLength();
            float    num2 = Mathf.Max(settings.focusDistance, b);
            float    num3 = ((float)source.width) / ((float)source.height);
            float    num4 = (b * b) / (((settings.aperture * (num2 - b)) * 0.024f) * 2f);
            float    num5 = this.CalculateMaxCoCRadius(source.height);
            Material mat  = base.context.materialFactory.Get("Hidden/Post FX/Depth Of Field");

            mat.SetFloat(Uniforms._Distance, num2);
            mat.SetFloat(Uniforms._LensCoeff, num4);
            mat.SetFloat(Uniforms._MaxCoC, num5);
            mat.SetFloat(Uniforms._RcpMaxCoC, 1f / num5);
            mat.SetFloat(Uniforms._RcpAspect, 1f / num3);
            RenderTexture dest = base.context.renderTextureFactory.Get(base.context.width, base.context.height, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            Graphics.Blit(null, dest, mat, 0);
            if (antialiasCoC)
            {
                mat.SetTexture(Uniforms._CoCTex, dest);
                float z = !this.CheckHistory(base.context.width, base.context.height) ? 0f : taaBlending;
                mat.SetVector(Uniforms._TaaParams, new Vector3(taaJitter.x, taaJitter.y, z));
                RenderTexture texture2 = RenderTexture.GetTemporary(base.context.width, base.context.height, 0, format);
                Graphics.Blit(this.m_CoCHistory, texture2, mat, 1);
                base.context.renderTextureFactory.Release(dest);
                if (this.m_CoCHistory != null)
                {
                    RenderTexture.ReleaseTemporary(this.m_CoCHistory);
                }
                this.m_CoCHistory = dest = texture2;
            }
            RenderTexture texture3 = base.context.renderTextureFactory.Get(base.context.width / 2, base.context.height / 2, 0, aRGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            mat.SetTexture(Uniforms._CoCTex, dest);
            Graphics.Blit(source, texture3, mat, 2);
            RenderTexture texture4 = base.context.renderTextureFactory.Get(base.context.width / 2, base.context.height / 2, 0, aRGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            Graphics.Blit(texture3, texture4, mat, 3 + settings.kernelSize);
            Graphics.Blit(texture4, texture3, mat, 7);
            uberMaterial.SetVector(Uniforms._DepthOfFieldParams, new Vector3(num2, num4, num5));
            if (base.context.profile.debugViews.IsModeActive(BuiltinDebugViewsModel.Mode.FocusPlane))
            {
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
                base.context.Interrupt();
            }
            else
            {
                uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, texture3);
                uberMaterial.SetTexture(Uniforms._DepthOfFieldCoCTex, dest);
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
            }
            base.context.renderTextureFactory.Release(texture4);
        }
Exemplo n.º 2
0
        public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC, Vector2 taaJitter, float taaBlending)
        {
            DepthOfFieldModel.Settings settings = base.model.settings;
            RenderTextureFormat        format   = RenderTextureFormat.DefaultHDR;
            RenderTextureFormat        format2  = this.SelectFormat(RenderTextureFormat.R8, RenderTextureFormat.RHalf);
            float    num      = this.CalculateFocalLength();
            float    num2     = Mathf.Max(settings.focusDistance, num);
            float    num3     = (float)source.width / (float)source.height;
            float    num4     = num * num / (settings.aperture * (num2 - num) * 0.024f * 2f);
            float    num5     = this.CalculateMaxCoCRadius(source.height);
            Material material = this.context.materialFactory.Get("Hidden/Post FX/Depth Of Field");

            material.SetFloat(DepthOfFieldComponent.Uniforms._Distance, num2);
            material.SetFloat(DepthOfFieldComponent.Uniforms._LensCoeff, num4);
            material.SetFloat(DepthOfFieldComponent.Uniforms._MaxCoC, num5);
            material.SetFloat(DepthOfFieldComponent.Uniforms._RcpMaxCoC, 1f / num5);
            material.SetFloat(DepthOfFieldComponent.Uniforms._RcpAspect, 1f / num3);
            RenderTexture renderTexture = this.context.renderTextureFactory.Get(this.context.width, this.context.height, 0, format2, RenderTextureReadWrite.Linear, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            Graphics.Blit(null, renderTexture, material, 0);
            if (antialiasCoC)
            {
                material.SetTexture(DepthOfFieldComponent.Uniforms._CoCTex, renderTexture);
                float z = (!this.CheckHistory(this.context.width, this.context.height)) ? 0f : taaBlending;
                material.SetVector(DepthOfFieldComponent.Uniforms._TaaParams, new Vector3(taaJitter.x, taaJitter.y, z));
                RenderTexture temporary = RenderTexture.GetTemporary(this.context.width, this.context.height, 0, format2);
                Graphics.Blit(this.m_CoCHistory, temporary, material, 1);
                this.context.renderTextureFactory.Release(renderTexture);
                if (this.m_CoCHistory != null)
                {
                    RenderTexture.ReleaseTemporary(this.m_CoCHistory);
                }
                renderTexture = (this.m_CoCHistory = temporary);
            }
            RenderTexture renderTexture2 = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            material.SetTexture(DepthOfFieldComponent.Uniforms._CoCTex, renderTexture);
            Graphics.Blit(source, renderTexture2, material, 2);
            RenderTexture renderTexture3 = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            Graphics.Blit(renderTexture2, renderTexture3, material, (int)(3 + settings.kernelSize));
            Graphics.Blit(renderTexture3, renderTexture2, material, 7);
            uberMaterial.SetVector(DepthOfFieldComponent.Uniforms._DepthOfFieldParams, new Vector3(num2, num4, num5));
            if (this.context.profile.debugViews.IsModeActive(BuiltinDebugViewsModel.Mode.FocusPlane))
            {
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
                this.context.Interrupt();
            }
            else
            {
                uberMaterial.SetTexture(DepthOfFieldComponent.Uniforms._DepthOfFieldTex, renderTexture2);
                uberMaterial.SetTexture(DepthOfFieldComponent.Uniforms._DepthOfFieldCoCTex, renderTexture);
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
            }
            this.context.renderTextureFactory.Release(renderTexture3);
        }
Exemplo n.º 3
0
        // Token: 0x06003AF7 RID: 15095 RVA: 0x001C8598 File Offset: 0x001C6998
        private float CalculateFocalLength()
        {
            DepthOfFieldModel.Settings settings = base.model.settings;
            if (!settings.useCameraFov)
            {
                return(settings.focalLength / 1000f);
            }
            float num = this.context.camera.fieldOfView * 0.0174532924f;

            return(0.012f / Mathf.Tan(0.5f * num));
        }
 public void UpdateDof(float newDoF)
 {
     try
     {
         DepthOfFieldModel.Settings DoFModelSettings = m_DepthOfField.model.settings;
         DoFModelSettings.focusDistance = newDoF;
         m_DepthOfField.model.settings  = DoFModelSettings;
     }
     catch (Exception e)
     {
         Debug.Log(e.Message);
     }
 }
Exemplo n.º 5
0
    void Start()
    {
        profile = Camera.GetComponent <UnityEngine.PostProcessing.PostProcessingBehaviour>().profile;

        DOFModel = profile.depthOfField;
        CGModel  = profile.colorGrading;

        DOFModel.enabled = false;
        CGModel.enabled  = false;

        DOFsetting = DOFModel.settings;
        CGsetting  = CGModel.settings;
    }
Exemplo n.º 6
0
        // Token: 0x06003AF9 RID: 15097 RVA: 0x001C8630 File Offset: 0x001C6A30
        public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC)
        {
            DepthOfFieldModel.Settings settings = base.model.settings;
            Material material = this.context.materialFactory.Get("Hidden/Post FX/Depth Of Field");

            material.shaderKeywords = null;
            float num  = settings.focusDistance;
            float num2 = this.CalculateFocalLength();

            num = Mathf.Max(num, num2);
            material.SetFloat(DepthOfFieldComponent.Uniforms._Distance, num);
            float num3 = num2 * num2 / (settings.aperture * (num - num2) * 0.024f * 2f);

            material.SetFloat(DepthOfFieldComponent.Uniforms._LensCoeff, num3);
            float num4 = this.CalculateMaxCoCRadius(source.height);

            material.SetFloat(DepthOfFieldComponent.Uniforms._MaxCoC, num4);
            material.SetFloat(DepthOfFieldComponent.Uniforms._RcpMaxCoC, 1f / num4);
            float value = (float)source.height / (float)source.width;

            material.SetFloat(DepthOfFieldComponent.Uniforms._RcpAspect, value);
            RenderTexture renderTexture = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            source.filterMode = FilterMode.Point;
            Graphics.Blit(source, renderTexture, material, 0);
            RenderTexture renderTexture2 = renderTexture;

            if (antialiasCoC)
            {
                renderTexture2 = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");
                if (this.m_CoCHistory == null || !this.m_CoCHistory.IsCreated() || this.m_CoCHistory.width != this.context.width / 2 || this.m_CoCHistory.height != this.context.height / 2)
                {
                    this.m_CoCHistory            = RenderTexture.GetTemporary(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.RHalf);
                    this.m_CoCHistory.filterMode = FilterMode.Point;
                    this.m_CoCHistory.name       = "CoC History";
                    Graphics.Blit(renderTexture, this.m_CoCHistory, material, 6);
                }
                RenderTexture temporary = RenderTexture.GetTemporary(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.RHalf);
                temporary.filterMode = FilterMode.Point;
                temporary.name       = "CoC History";
                this.m_MRT[0]        = renderTexture2.colorBuffer;
                this.m_MRT[1]        = temporary.colorBuffer;
                material.SetTexture(DepthOfFieldComponent.Uniforms._MainTex, renderTexture);
                material.SetTexture(DepthOfFieldComponent.Uniforms._HistoryCoC, this.m_CoCHistory);
                Graphics.SetRenderTarget(this.m_MRT, renderTexture.depthBuffer);
                GraphicsUtils.Blit(material, 5);
                RenderTexture.ReleaseTemporary(this.m_CoCHistory);
                this.m_CoCHistory = temporary;
            }
            RenderTexture renderTexture3 = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            Graphics.Blit(renderTexture2, renderTexture3, material, (int)(1 + settings.kernelSize));
            if (this.context.profile.debugViews.IsModeActive(BuiltinDebugViewsModel.Mode.FocusPlane))
            {
                uberMaterial.SetTexture(DepthOfFieldComponent.Uniforms._DepthOfFieldTex, renderTexture);
                uberMaterial.SetVector(DepthOfFieldComponent.Uniforms._DepthOfFieldParams, new Vector2(num, num3));
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
                this.context.Interrupt();
            }
            else
            {
                uberMaterial.SetTexture(DepthOfFieldComponent.Uniforms._DepthOfFieldTex, renderTexture3);
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
            }
            if (antialiasCoC)
            {
                this.context.renderTextureFactory.Release(renderTexture2);
            }
            this.context.renderTextureFactory.Release(renderTexture);
            source.filterMode = FilterMode.Bilinear;
        }
Exemplo n.º 7
0
 // Token: 0x0600678A RID: 26506 RVA: 0x0002788F File Offset: 0x00025A8F
 public void KMDFEEPLPIH(DepthOfFieldModel.Settings BGBMIEJJQKC)
 {
     this.m_Settings = BGBMIEJJQKC;
 }
Exemplo n.º 8
0
 // Token: 0x06006788 RID: 26504 RVA: 0x0002788F File Offset: 0x00025A8F
 public void GQEOEDENQNF(DepthOfFieldModel.Settings BGBMIEJJQKC)
 {
     this.m_Settings = BGBMIEJJQKC;
 }
Exemplo n.º 9
0
 // Token: 0x06006787 RID: 26503 RVA: 0x0002788F File Offset: 0x00025A8F
 public void GJOHNHLCMID(DepthOfFieldModel.Settings BGBMIEJJQKC)
 {
     this.m_Settings = BGBMIEJJQKC;
 }
Exemplo n.º 10
0
 // Token: 0x0600677E RID: 26494 RVA: 0x0002788F File Offset: 0x00025A8F
 public void NEBHFCDDQGL(DepthOfFieldModel.Settings BGBMIEJJQKC)
 {
     this.m_Settings = BGBMIEJJQKC;
 }
Exemplo n.º 11
0
 private float CalculateFocalLength()
 {
     DepthOfFieldModel.Settings settings = base.model.settings;
     return(settings.useCameraFov ? (0.012f / Mathf.Tan(0.5f * (base.context.camera.fieldOfView * 0.01745329f))) : (settings.focalLength / 1000f));
 }
 void Start()
 {
     dof_          = GetComponent <UnityEngine.PostProcessing.PostProcessingBehaviour>().profile.depthOfField;
     dof_settings_ = dof_.settings;
 }
Exemplo n.º 13
0
    void FreeCamera(float deltaTime)
    {
        offset             = offset.normalized * freeDistance;
        transform.position = CameraPivot.transform.position + offset; //更新位置
        if (CanControlDirection)                                      //控制角色方向开关
        {
            Quaternion TargetBodyCurrentRotation = TargetBody.transform.rotation;
            if (Input.GetKey(KeyCode.A))
            {
                if (Input.GetKey(KeyCode.W))
                {
                    TargetBody.transform.rotation = Quaternion.Lerp(TargetBodyCurrentRotation, Quaternion.Euler(new Vector3(TargetBody.transform.localEulerAngles.x, transform.localEulerAngles.y - 45, TargetBody.transform.localEulerAngles.z)), TargetBodyRotateLerp);
                }
                else if (Input.GetKey(KeyCode.S))
                {
                    TargetBody.transform.rotation = Quaternion.Lerp(TargetBodyCurrentRotation, Quaternion.Euler(new Vector3(TargetBody.transform.localEulerAngles.x, transform.localEulerAngles.y - 135, TargetBody.transform.localEulerAngles.z)), TargetBodyRotateLerp);
                }
                else if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
                {
                    TargetBody.transform.rotation = Quaternion.Lerp(TargetBodyCurrentRotation, Quaternion.Euler(new Vector3(TargetBody.transform.localEulerAngles.x, transform.localEulerAngles.y - 90, TargetBody.transform.localEulerAngles.z)), TargetBodyRotateLerp);
                }
            }
            else if (Input.GetKey(KeyCode.D))
            {
                if (Input.GetKey(KeyCode.W))
                {
                    TargetBody.transform.rotation = Quaternion.Lerp(TargetBodyCurrentRotation, Quaternion.Euler(new Vector3(TargetBody.transform.localEulerAngles.x, transform.localEulerAngles.y + 45, TargetBody.transform.localEulerAngles.z)), TargetBodyRotateLerp);
                }
                else if (Input.GetKey(KeyCode.S))
                {
                    TargetBody.transform.rotation = Quaternion.Lerp(TargetBodyCurrentRotation, Quaternion.Euler(new Vector3(TargetBody.transform.localEulerAngles.x, transform.localEulerAngles.y + 135, TargetBody.transform.localEulerAngles.z)), TargetBodyRotateLerp);
                }
                else if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
                {
                    TargetBody.transform.rotation = Quaternion.Lerp(TargetBodyCurrentRotation, Quaternion.Euler(new Vector3(TargetBody.transform.localEulerAngles.x, transform.localEulerAngles.y + 90, TargetBody.transform.localEulerAngles.z)), TargetBodyRotateLerp);
                }
            }
            else if (Input.GetKey(KeyCode.W))
            {
                TargetBody.transform.rotation = Quaternion.Lerp(TargetBodyCurrentRotation, Quaternion.Euler(new Vector3(TargetBody.transform.localEulerAngles.x, transform.localEulerAngles.y, TargetBody.transform.localEulerAngles.z)), TargetBodyRotateLerp);
            }
            else if (Input.GetKey(KeyCode.S))
            {
                TargetBody.transform.rotation = Quaternion.Lerp(TargetBodyCurrentRotation, Quaternion.Euler(new Vector3(TargetBody.transform.localEulerAngles.x, transform.localEulerAngles.y - 180, TargetBody.transform.localEulerAngles.z)), TargetBodyRotateLerp);
            }
        }
        if (canControlDistance)//控制距离开关
        {
            freeDistance -= Input.GetAxis("Mouse ScrollWheel") * distanceSpeed;
        }
        freeDistance = Mathf.Clamp(freeDistance, minDistance, maxDistance);
        if (!lockTarget)
        {
            transform.LookAt(CameraPivot.transform);
        }
        else
        {
            Quaternion tmp = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(lockTarget.transform.position - transform.position), lockSlerp * deltaTime);
            transform.rotation = tmp;
        }
        float eulerX = transform.localEulerAngles.x;//相机的x欧拉角,也就是垂直方向
        float inputY = Input.GetAxis("Mouse Y");

        if (!lockTarget && Input.GetMouseButton(1))
        {
            if (!lockTarget)
            {
                transform.RotateAround(CameraPivot.transform.position, Vector3.up, rotateSpeed * Input.GetAxis("Mouse X"));
            }

            Vector3 cameraToPlayer = transform.position - CameraPivot.transform.position;
            float   curAngle       = -Vector3.SignedAngle(cameraToPlayer.normalized, new Vector3(cameraToPlayer.x, 0, cameraToPlayer.z).normalized, transform.right);
            if (inputY > 0)
            {
                float angle = Mathf.Clamp(-rotateSpeed * inputY, Mathf.Min(-maxDepression - curAngle, 0), 0);
                transform.RotateAround(ThirdPersonPlayer.Instance.BeAtkPoint.position, transform.right, angle);
            }
            else if (inputY < 0)
            {
                float angle = Mathf.Clamp(-rotateSpeed * inputY, 0, Mathf.Max(maxEvelation - curAngle, 0));
                transform.RotateAround(ThirdPersonPlayer.Instance.BeAtkPoint.position, transform.right, angle);
            }
        }
        if (lockTarget)
        {
            offset = CameraPivot.transform.position - (lockTarget.transform.position);
        }
        else
        {
            offset = transform.position - CameraPivot.transform.position;//以上方向发生了变化,记录新的方向向量
        }
        offset = offset.normalized * freeDistance;
        ///在一次Update中,随时记录新的旋转后的位置,然后得到方向,然后判断是否即将被遮挡,如果要被遮挡,将相机移动到计算后的不会被遮挡的位置
        ///如果不会被遮挡,则更新位置为相机焦点位置+方向的单位向量*距离
        float distance = freeDistance;

        if (Inwall())//预测会被遮挡
        {
            transform.position = CameraPivot.transform.position + (wallHit - CameraPivot.transform.position) * 0.8f;
            distance           = Vector3.Distance(wallHit, CameraPivot.transform.position) * 0.8f;
        }
        else
        {
            transform.position = CameraPivot.transform.position + offset;
        }
        distance += depthOfSceneOffset;
        if (ppBehavior)
        {
            UnityEngine.PostProcessing.DepthOfFieldModel.Settings set = ppBehavior.profile.depthOfField.settings;
            if (set.focusDistance != distance)
            {
                set.focusDistance = distance;
                ppBehavior.profile.depthOfField.settings = set;
            }
        }
    }