示例#1
0
        public void BindVirtualCameraParams(Material mat, CameraParameters cameraParams, float focalDistance, float halfResWidth, bool isFirstRender)
        {
            Vector4 shaderParams1 = new Vector4();

            shaderParams1.x = 1.0f / (cameraParams.focalLength * 1000.0f);             //From meter to millimeter
            shaderParams1.y = cameraParams.fNumber;
            shaderParams1.z = cameraParams.shutterSpeed;
            shaderParams1.w = isFirstRender == true ? 1.0f : 1.0f - Mathf.Exp(-Time.deltaTime * cameraParams.adaptionSpeed);
                        #if UNITY_EDITOR
            if (UnityEditor.EditorApplication.isPlaying == false)
            {
                shaderParams1.w = 1.0f;
            }
                        #endif
            mat.SetVector("_VirtualCameraParams1", shaderParams1);

            Vector4 shaderParams2 = new Vector4();
            shaderParams2.x = cameraParams.exposureCompensation + BuiltinExposureCompensation;
            shaderParams2.y = cameraParams.focalLength;
            shaderParams2.z = focalDistance;
            shaderParams2.w = ScionUtility.CoCToPixels(halfResWidth);
            mat.SetVector("_VirtualCameraParams2", shaderParams2);

            Vector4 shaderParams3 = new Vector4();
            shaderParams3.x = Mathf.Pow(2.0f, cameraParams.minMaxExposure.x);
            shaderParams3.y = Mathf.Pow(2.0f, cameraParams.minMaxExposure.y);
            mat.SetVector("_VirtualCameraParams3", shaderParams3);
        }
示例#2
0
        private RenderTexture CreateTiledData(RenderTexture halfResDepth, float tanHalfFoV, float fNumber, float focalDistance, float focalRange,
                                              float apertureDiameter, float focalLength, float maxCoCRadius, float nearPlane, float farPlane)
        {
            int tileWidth  = halfResDepth.width / 10 + (halfResDepth.width % 10 == 0 ? 0 : 1);
            int tileHeight = halfResDepth.height / 10 + (halfResDepth.height % 10 == 0 ? 0 : 1);

            float CoCScale = apertureDiameter * focalLength * focalDistance / (focalDistance - focalLength);
            float CoCBias  = -apertureDiameter * focalLength / (focalDistance - focalLength);

            float toPixels = ScionUtility.CoCToPixels(halfResDepth.width);

            CoCScale *= toPixels;
            CoCBias  *= toPixels;

            Vector4 CoCParams1 = new Vector4();

            CoCParams1.x = CoCScale;
            CoCParams1.y = CoCBias;
            CoCParams1.z = focalDistance;
            CoCParams1.w = focalRange * 0.5f;
            m_DoFMat.SetVector("_CoCParams1", CoCParams1);

            Vector4 CoCParams2 = new Vector4();

            CoCParams2.x = maxCoCRadius * 0.5f;             //We're in half res, so halve it
            CoCParams2.y = 1.0f / maxCoCRadius;
            m_DoFMat.SetVector("_CoCParams2", CoCParams2);

            if (m_DoFMatDX11 != null)
            {
                m_DoFMatDX11.SetVector("_CoCParams1", CoCParams1);
                m_DoFMatDX11.SetVector("_CoCParams2", CoCParams2);
            }

            m_DoFMat.SetFloat("_CoCUVOffset", 1.0f / halfResDepth.width);             //Width for horizontal

            RenderTexture tiledDataHorizontal = RenderTexture.GetTemporary(tileWidth, halfResDepth.height, 0, RenderTextureFormat.RHalf);

            tiledDataHorizontal.filterMode = FilterMode.Point;
            tiledDataHorizontal.wrapMode   = TextureWrapMode.Clamp;

            RenderTexture tiledData = RenderTexture.GetTemporary(tileWidth, tileHeight, 0, RenderTextureFormat.RHalf);

            tiledData.filterMode = FilterMode.Point;
            tiledData.wrapMode   = TextureWrapMode.Clamp;

            halfResDepth.filterMode = FilterMode.Point;

            ScionGraphics.Blit(tiledDataHorizontal, m_DoFMat, 0);

            m_DoFMat.SetTexture("_HorizontalTileResult", tiledDataHorizontal);
            m_DoFMat.SetFloat("_CoCUVOffset", 1.0f / halfResDepth.height);             //Height for vertical

            ScionGraphics.Blit(tiledData, m_DoFMat, 1);
            RenderTexture.ReleaseTemporary(tiledDataHorizontal);

            return(tiledData);
        }
示例#3
0
        private RenderTexture CreateTiledData(RenderTexture halfResDepth, float tanHalfFoV, float fNumber, float focalDistance, float focalRange, float apertureDiameter, float focalLength, float maxCoCRadius, float nearPlane, float farPlane)
        {
            int   width  = halfResDepth.width / 10 + ((halfResDepth.width % 10 != 0) ? 1 : 0);
            int   height = halfResDepth.height / 10 + ((halfResDepth.height % 10 != 0) ? 1 : 0);
            float num    = apertureDiameter * focalLength * focalDistance / (focalDistance - focalLength);
            float num2   = -apertureDiameter * focalLength / (focalDistance - focalLength);
            float num3   = ScionUtility.CoCToPixels((float)halfResDepth.width);

            num  *= num3;
            num2 *= num3;
            Vector4 value = default(Vector4);

            value.x = num;
            value.y = num2;
            value.z = focalDistance;
            value.w = focalRange * 0.5f;
            this.m_DoFMat.SetVector("_CoCParams1", value);
            Vector4 value2 = default(Vector4);

            value2.x = maxCoCRadius * 0.5f;
            value2.y = 1f / maxCoCRadius;
            this.m_DoFMat.SetVector("_CoCParams2", value2);
            if (this.m_DoFMatDX11 != null)
            {
                this.m_DoFMatDX11.SetVector("_CoCParams1", value);
                this.m_DoFMatDX11.SetVector("_CoCParams2", value2);
            }
            this.m_DoFMat.SetFloat("_CoCUVOffset", 1f / (float)halfResDepth.width);
            RenderTexture temporary = RenderTexture.GetTemporary(width, halfResDepth.height, 0, RenderTextureFormat.RHalf);

            temporary.filterMode = FilterMode.Point;
            temporary.wrapMode   = TextureWrapMode.Clamp;
            RenderTexture temporary2 = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.RHalf);

            temporary2.filterMode   = FilterMode.Point;
            temporary2.wrapMode     = TextureWrapMode.Clamp;
            halfResDepth.filterMode = FilterMode.Point;
            ScionGraphics.Blit(temporary, this.m_DoFMat, 0);
            this.m_DoFMat.SetTexture("_HorizontalTileResult", temporary);
            this.m_DoFMat.SetFloat("_CoCUVOffset", 1f / (float)halfResDepth.height);
            ScionGraphics.Blit(temporary2, this.m_DoFMat, 1);
            RenderTexture.ReleaseTemporary(temporary);
            return(temporary2);
        }
示例#4
0
 public void BindVirtualCameraParams(Material mat, CameraParameters cameraParams, float focalDistance, float halfResWidth, bool isFirstRender)
 {
     mat.SetVector("_VirtualCameraParams1", new Vector4
     {
         x = 1f / (cameraParams.focalLength * 1000f),
         y = cameraParams.fNumber,
         z = cameraParams.shutterSpeed,
         w = ((!isFirstRender) ? (1f - Mathf.Exp(-Time.deltaTime * cameraParams.adaptionSpeed)) : 1f)
     });
     mat.SetVector("_VirtualCameraParams2", new Vector4
     {
         x = cameraParams.exposureCompensation + 1.8f,
         y = cameraParams.focalLength,
         z = focalDistance,
         w = ScionUtility.CoCToPixels(halfResWidth)
     });
     mat.SetVector("_VirtualCameraParams3", new Vector4
     {
         x = Mathf.Pow(2f, cameraParams.minMaxExposure.x),
         y = Mathf.Pow(2f, cameraParams.minMaxExposure.y)
     });
 }