示例#1
0
 public void CalculateVirtualCamera(CameraParameters cameraParams, RenderTexture textureToDownsample, float halfResWidth, float tanHalfFoV, float energyNormalizer, float focalDistance, bool isFirstRender)
 {
     if (cameraParams.cameraMode == CameraMode.Manual || cameraParams.cameraMode == CameraMode.Off)
     {
         return;
     }
     if (this.m_currentResult2 != null)
     {
         RenderTexture.ReleaseTemporary(this.m_currentResult2);
         this.m_currentResult2 = null;
     }
     this.BindVirtualCameraParams(this.m_virtualCameraMat, cameraParams, focalDistance, halfResWidth, isFirstRender);
     RenderTexture renderTexture = this.DownsampleTexture(textureToDownsample, energyNormalizer);
     this.m_virtualCameraMat.SetTexture("_DownsampledScene", renderTexture);
     if (this.m_previousExposureTexture != null)
     {
         this.m_virtualCameraMat.SetTexture("_PreviousExposureTexture", this.m_previousExposureTexture);
     }
     this.m_currentResult1 = RenderTexture.GetTemporary(1, 1, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
     this.m_currentResult2 = RenderTexture.GetTemporary(1, 1, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
     this.renderBuffers[0] = this.m_currentResult1.colorBuffer;
     this.renderBuffers[1] = this.m_currentResult2.colorBuffer;
     int passNr = cameraParams.cameraMode - CameraMode.AutoPriority;
     Graphics.SetRenderTarget(this.renderBuffers, this.m_currentResult1.depthBuffer);
     ScionGraphics.Blit(this.m_virtualCameraMat, passNr);
     RenderTexture.ReleaseTemporary(renderTexture);
     if (this.m_previousExposureTexture != null)
     {
         RenderTexture.ReleaseTemporary(this.m_previousExposureTexture);
     }
     this.m_previousExposureTexture = this.m_currentResult1;
 }
示例#2
0
        public void CalculateVirtualCamera(CameraParameters cameraParams, RenderTexture textureToDownsample, float halfResWidth, 
		                                   float tanHalfFoV, float focalDistance, bool isFirstRender)
        {
            if (cameraParams.cameraMode == CameraMode.Manual || cameraParams.cameraMode == CameraMode.Off) return;
            if (m_currentResult2 != null)
            {
                RenderTexture.ReleaseTemporary(m_currentResult2);
                m_currentResult2 = null;
            }

            BindVirtualCameraParams(m_virtualCameraMat, cameraParams, focalDistance, halfResWidth, isFirstRender);

            RenderTexture downsampledScene = DownsampleTexture(textureToDownsample);
            m_virtualCameraMat.SetTexture("_DownsampledScene", downsampledScene);
            if (m_previousExposureTexture != null) m_virtualCameraMat.SetTexture("_PreviousExposureTexture", m_previousExposureTexture);

            m_currentResult1 = RenderTexture.GetTemporary(1, 1, 0, VCTextureFormat, RenderTextureReadWrite.Linear);
            m_currentResult2 = RenderTexture.GetTemporary(1, 1, 0, VCTextureFormat, RenderTextureReadWrite.Linear);
            renderBuffers[0] = m_currentResult1.colorBuffer;
            renderBuffers[1] = m_currentResult2.colorBuffer;

            int passIndex = (int)cameraParams.cameraMode - 2;
            Graphics.SetRenderTarget(renderBuffers, m_currentResult1.depthBuffer);
            ScionGraphics.Blit(m_virtualCameraMat, passIndex);

            //			struct CameraOutput
            //			{
            //				float sceneLuminance;
            //				float shutterSpeed;
            //				float ISO;
            //				float fNumber;
            //				float exposure;
            //				float2 CoCScaleAndBias;
            //				float notUsed;
            //			};

            //			if (readBfr == null) readBfr = new ComputeBuffer(2, 16);
            //			if (readVec == null) readVec = new Vector4[2];
            //			ComputeShader shdr = HelpScript.HelpShader;
            //			shdr.SetTexture(0, "ReadTexture1", m_currentResult1);
            //			shdr.SetTexture(0, "ReadTexture2", m_currentResult2);
            //			shdr.SetBuffer(0, "ReadBackBuffer", readBfr);
            //			shdr.Dispatch(0,1,1,1);
            //			readBfr.GetData(readVec);
            //			Debug.Log("sceneLuminance: " + readVec[0].x +
            //			          "\nshutterSpeed: " + readVec[0].y +
            //			          "\nISO: " + readVec[0].z +
            //			          "\nfNumber: " + readVec[0].w +
            //			          "\nexposure: " + readVec[1].x +
            //						"\nCoC scale: " + readVec[1].y +
            //			          "\nCoC bias: " + readVec[1].z +
            //						"\ntargetEV: " + readVec[1].w);

            RenderTexture.ReleaseTemporary(downsampledScene);
            if (m_previousExposureTexture != null) RenderTexture.ReleaseTemporary(m_previousExposureTexture);
            m_previousExposureTexture = m_currentResult1;
        }
示例#3
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)
     });
 }
示例#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)
     });
 }
示例#5
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);
        }
示例#6
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);
            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);
        }
示例#7
0
 private void PrepareExposure(CameraParameters cameraParams, VirtualCamera virtualCamera)
 {
     if (cameraParams.cameraMode == CameraMode.Off)
     {
         m_combinationMat.SetFloat("_ManualExposure", 1.0f);
     }
     else if (cameraParams.cameraMode != CameraMode.Manual)
     {
         virtualCamera.BindVirtualCameraTextures(m_combinationMat);
     }
     else
     {
         m_combinationMat.SetFloat("_ManualExposure", virtualCamera.CalculateManualExposure(cameraParams));
     }
 }
示例#8
0
        //Standard Output Based Exposure
        public float CalculateManualExposure(CameraParameters cameraParams, float middleGrey = 0.18f)
        {
            float lAvg = (1000.0f / 65.0f) * cameraParams.fNumber * cameraParams.fNumber / (cameraParams.ISO * cameraParams.shutterSpeed);

            return(Mathf.Pow(2.0f, cameraParams.exposureCompensation) * LIGHT_INTENSITY_MULT * middleGrey / lAvg);
        }
示例#9
0
        public void CalculateVirtualCamera(CameraParameters cameraParams, RenderTexture textureToDownsample, float halfResWidth,
                                           float tanHalfFoV, float focalDistance, bool isFirstRender)
        {
            if (cameraParams.cameraMode == CameraMode.Manual || cameraParams.cameraMode == CameraMode.Off)
            {
                return;
            }
            if (m_currentResult2 != null)
            {
                RenderTexture.ReleaseTemporary(m_currentResult2);
                m_currentResult2 = null;
            }

            BindVirtualCameraParams(m_virtualCameraMat, cameraParams, focalDistance, halfResWidth, isFirstRender);

            RenderTexture downsampledScene = DownsampleTexture(textureToDownsample);

            m_virtualCameraMat.SetTexture("_DownsampledScene", downsampledScene);
            if (m_previousExposureTexture != null)
            {
                m_virtualCameraMat.SetTexture("_PreviousExposureTexture", m_previousExposureTexture);
            }

            m_currentResult1 = RenderTexture.GetTemporary(1, 1, 0, VCTextureFormat, RenderTextureReadWrite.Linear);
            m_currentResult2 = RenderTexture.GetTemporary(1, 1, 0, VCTextureFormat, RenderTextureReadWrite.Linear);
            renderBuffers[0] = m_currentResult1.colorBuffer;
            renderBuffers[1] = m_currentResult2.colorBuffer;

            int passIndex = (int)cameraParams.cameraMode - 2;

            Graphics.SetRenderTarget(renderBuffers, m_currentResult1.depthBuffer);
            ScionGraphics.Blit(m_virtualCameraMat, passIndex);


//			struct CameraOutput
//			{
//				float sceneLuminance;
//				float shutterSpeed;
//				float ISO;
//				float fNumber;
//				float exposure;
//				float2 CoCScaleAndBias;
//				float notUsed;
//			};


//			if (readBfr == null) readBfr = new ComputeBuffer(2, 16);
//			if (readVec == null) readVec = new Vector4[2];
//			ComputeShader shdr = HelpScript.HelpShader;
//			shdr.SetTexture(0, "ReadTexture1", m_currentResult1);
//			shdr.SetTexture(0, "ReadTexture2", m_currentResult2);
//			shdr.SetBuffer(0, "ReadBackBuffer", readBfr);
//			shdr.Dispatch(0,1,1,1);
//			readBfr.GetData(readVec);
//			Debug.Log("sceneLuminance: " + readVec[0].x +
//			          "\nshutterSpeed: " + readVec[0].y +
//			          "\nISO: " + readVec[0].z +
//			          "\nfNumber: " + readVec[0].w +
//			          "\nexposure: " + readVec[1].x +
//						"\nCoC scale: " + readVec[1].y +
//			          "\nCoC bias: " + readVec[1].z +
//						"\ntargetEV: " + readVec[1].w);



            RenderTexture.ReleaseTemporary(downsampledScene);
            if (m_previousExposureTexture != null)
            {
                RenderTexture.ReleaseTemporary(m_previousExposureTexture);
            }
            m_previousExposureTexture = m_currentResult1;
        }
示例#10
0
 //Standard Output Based Exposure
 public float CalculateManualExposure(CameraParameters cameraParams, float middleGrey = 0.18f)
 {
     float lAvg = (1000.0f / 65.0f) * cameraParams.fNumber*cameraParams.fNumber / (cameraParams.ISO * cameraParams.shutterSpeed);
     return Mathf.Pow(2.0f, cameraParams.exposureCompensation) * LIGHT_INTENSITY_MULT * middleGrey / lAvg;
 }
示例#11
0
        public float CalculateManualExposure(CameraParameters cameraParams, float middleGrey = 0.18f)
        {
            float num = 15.3846149f * cameraParams.fNumber * cameraParams.fNumber / (cameraParams.ISO * cameraParams.shutterSpeed);

            return(Mathf.Pow(2f, cameraParams.exposureCompensation) * 3000f * middleGrey / num);
        }
示例#12
0
 public PostProcessParameters()
 {
     glareParams = new GlareParameters();
     lensDirtParams = new LensDirtParameters();
     cameraParams = new CameraParameters();
     DoFParams = new DepthOfFieldParameters();
     colorGradingParams = new ColorGradingParameters();
     preCalcValues = new PreCalcValues();
     commonPostProcess = new CommonPostProcess();
 }
示例#13
0
 public float CalculateManualExposure(CameraParameters cameraParams, float middleGrey = 0.18f)
 {
     float num = 15.3846149f * cameraParams.fNumber * cameraParams.fNumber / (cameraParams.ISO * cameraParams.shutterSpeed);
     return Mathf.Pow(2f, cameraParams.exposureCompensation) * 3000f * middleGrey / num;
 }