Beispiel #1
0
        public void Combine(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams, VirtualCamera virtualCamera)
        {
            if (postProcessParams.bloom)
            {
                this.PrepareBloomSampling(postProcessParams.bloomTexture, postProcessParams.bloomParams);
            }
            if (postProcessParams.lensDirt)
            {
                this.PrepareLensDirtSampling(postProcessParams.lensDirtTexture, postProcessParams.lensDirtParams);
            }
            this.PrepareExposure(postProcessParams.cameraParams, virtualCamera);
            this.PrepareColorGrading(postProcessParams.colorGradingParams);
            this.UploadVariables(postProcessParams.commonPostProcess);
            int num = 0;

            if (!postProcessParams.tonemapping)
            {
                num += 3;
            }
            if (!postProcessParams.bloom)
            {
                num += 2;
            }
            else if (!postProcessParams.lensDirt)
            {
                num++;
            }
            source.filterMode = FilterMode.Bilinear;
            source.wrapMode   = TextureWrapMode.Clamp;
            Graphics.Blit(source, dest, this.m_combinationMat, num);
        }
Beispiel #2
0
 private void SetupPostProcessParameters(PostProcessParameters postProcessParams, RenderTexture source)
 {
     this.focalDistance = ((this.focalDistance >= this.m_camera.nearClipPlane + 0.3f) ? this.focalDistance : (this.m_camera.nearClipPlane + 0.3f));
     postProcessParams.halfResSource = null;
     postProcessParams.halfResDepth  = this.m_downsampling.DownsampleDepthTexture(source.width, source.height);
     postProcessParams.width         = source.width;
     postProcessParams.height        = source.height;
     postProcessParams.halfWidth     = source.width / 2;
     postProcessParams.halfHeight    = source.height / 2;
     if (this.prevCamFoV != this.m_camera.fieldOfView)
     {
         postProcessParams.preCalcValues.tanHalfFoV = Mathf.Tan(this.m_camera.fieldOfView * 0.5f * 0.0174532924f);
         this.prevCamFoV = this.m_camera.fieldOfView;
     }
     postProcessParams.DoFParams.useMedianFilter = true;
     if (!this.userControlledFocalLength)
     {
         postProcessParams.cameraParams.focalLength = ScionUtility.GetFocalLength(postProcessParams.preCalcValues.tanHalfFoV);
     }
     else
     {
         postProcessParams.cameraParams.focalLength = this.focalLength * 0.001f;
     }
     postProcessParams.cameraParams.apertureDiameter = ScionUtility.ComputeApertureDiameter(this.fNumber, postProcessParams.cameraParams.focalLength);
     postProcessParams.cameraParams.fieldOfView      = this.m_camera.fieldOfView;
     postProcessParams.cameraParams.aspect           = this.m_camera.aspect;
     postProcessParams.cameraParams.nearPlane        = this.m_camera.nearClipPlane;
     postProcessParams.cameraParams.farPlane         = this.m_camera.farClipPlane;
     postProcessParams.isFirstRender = this.m_isFirstRender;
     this.m_isFirstRender            = false;
 }
Beispiel #3
0
        private void SetGlobalParameters(PostProcessParameters postProcessParams)
        {
            Vector4 value = default(Vector4);

            value.x = postProcessParams.cameraParams.nearPlane;
            value.y = postProcessParams.cameraParams.farPlane;
            value.z = 1f / value.y;
            value.w = value.x * value.z;
            Shader.SetGlobalVector("_ScionNearFarParams", value);
            Shader.SetGlobalTexture("_HalfResSourceTexture", postProcessParams.halfResSource);
            Shader.SetGlobalTexture("_HalfResDepthTexture", postProcessParams.halfResDepth);
            Shader.SetGlobalVector("_ScionResolutionParameters1", new Vector4
            {
                x = (float)postProcessParams.halfWidth,
                y = (float)postProcessParams.halfHeight,
                z = (float)postProcessParams.width,
                w = (float)postProcessParams.height
            });
            Shader.SetGlobalVector("_ScionResolutionParameters2", new Vector4
            {
                x = 1f / (float)postProcessParams.halfWidth,
                y = 1f / (float)postProcessParams.halfHeight,
                z = 1f / (float)postProcessParams.width,
                w = 1f / (float)postProcessParams.height
            });
            Shader.SetGlobalVector("_ScionCameraParams1", new Vector4
            {
                x = postProcessParams.cameraParams.apertureDiameter,
                y = postProcessParams.cameraParams.focalLength,
                z = postProcessParams.cameraParams.aspect
            });
        }
Beispiel #4
0
        private void UploadVariables(PostProcessParameters postProcessParams)
        {
            Vector4 postProcessParams1 = new Vector4();

            postProcessParams1.x = postProcessParams.commonPostProcess.grainIntensity;
            postProcessParams1.y = postProcessParams.commonPostProcess.vignetteIntensity;
            postProcessParams1.z = postProcessParams.commonPostProcess.vignetteScale;
            postProcessParams1.w = postProcessParams.commonPostProcess.chromaticAberrationDistortion;
            m_combinationMat.SetVector("_PostProcessParams1", postProcessParams1);

            Vector4 postProcessParams2 = new Vector4();

            postProcessParams2.x = postProcessParams.commonPostProcess.vignetteColor.r;
            postProcessParams2.y = postProcessParams.commonPostProcess.vignetteColor.g;
            postProcessParams2.z = postProcessParams.commonPostProcess.vignetteColor.b;
            postProcessParams2.w = postProcessParams.commonPostProcess.chromaticAberrationIntensity;
            m_combinationMat.SetVector("_PostProcessParams2", postProcessParams2);

            Vector4 postProcessParams3 = new Vector4();

            postProcessParams3.x = Random.value;
            postProcessParams3.y = ScionUtility.GetWhitePointMultiplier(postProcessParams.commonPostProcess.whitePoint);
            postProcessParams3.z = 1.0f / postProcessParams.commonPostProcess.whitePoint;
            m_combinationMat.SetVector("_PostProcessParams3", postProcessParams3);
        }
Beispiel #5
0
        //This function is also responsible for downsampling the depth buffer and binding it
        protected RenderTexture DepthOfFieldStep(PostProcessParameters postProcessParams, RenderTexture source)
        {
            if (postProcessParams.depthOfField == false)
            {
                return(source);
            }

            RenderTexture exclusionMask = null;

            if (postProcessParams.DoFParams.depthOfFieldMask != 0)             //If objects are masked out
            {
                exclusionMask = m_depthOfFieldClass.RenderExclusionMask(postProcessParams.width, postProcessParams.height, postProcessParams.camera,
                                                                        postProcessParams.cameraTransform, postProcessParams.DoFParams.depthOfFieldMask);
                //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(exclusionMask, false, false, false);
                RenderTexture downsampledExclusionMask = m_downsampling.DownsampleMinFilter(source.width, source.height, exclusionMask);
                RenderTexture.ReleaseTemporary(exclusionMask);
                exclusionMask = downsampledExclusionMask;
            }

            //postProcessParams.halfResSource = m_downsampling.DownsampleFireflyRemoving(source);
            postProcessParams.halfResSource = m_downsampling.DownsampleFireflyRemovingBilateral(source, postProcessParams.halfResDepth);

            source = m_depthOfFieldClass.RenderDepthOfField(postProcessParams, source, m_virtualCamera, exclusionMask);

            //Downsample scene again, this time with DoF applied
            RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
            if (exclusionMask != null)
            {
                RenderTexture.ReleaseTemporary(exclusionMask);
            }

            return(source);
        }
Beispiel #6
0
        protected virtual void SetShaderKeyWords(PostProcessParameters postProcessParams)
        {
            if (postProcessParams.cameraParams.cameraMode == CameraMode.Off ||
                postProcessParams.cameraParams.cameraMode == CameraMode.Manual)
            {
                ShaderSettings.ExposureSettings.SetIndex(1);
            }
            else
            {
                ShaderSettings.ExposureSettings.SetIndex(0);
            }

            switch (postProcessParams.DoFParams.depthFocusMode)
            {
            case (DepthFocusMode.ManualDistance):
                ShaderSettings.DepthFocusSettings.SetIndex(0);
                break;

            case (DepthFocusMode.ManualRange):
                ShaderSettings.DepthFocusSettings.SetIndex(1);
                break;

            case (DepthFocusMode.PointAverage):
                ShaderSettings.DepthFocusSettings.SetIndex(2);
                break;
            }

            if (postProcessParams.DoFParams.depthOfFieldMask != 0)
            {
                ShaderSettings.DepthOfFieldMask.SetIndex(1);
            }
            else
            {
                ShaderSettings.DepthOfFieldMask.SetIndex(0);
            }

            switch (postProcessParams.colorGradingParams.colorGradingMode)
            {
            case (ColorGradingMode.Off):
                ShaderSettings.ColorGradingSettings.SetIndex(0);
                break;

            case (ColorGradingMode.On):
                ShaderSettings.ColorGradingSettings.SetIndex(1);
                break;

            case (ColorGradingMode.Blend):
                ShaderSettings.ColorGradingSettings.SetIndex(2);
                break;
            }

            if (postProcessParams.commonPostProcess.chromaticAberration == true)
            {
                ShaderSettings.ChromaticAberrationSettings.SetIndex(1);
            }
            else
            {
                ShaderSettings.ChromaticAberrationSettings.SetIndex(0);
            }
        }
Beispiel #7
0
        protected void SetGlobalParameters(PostProcessParameters postProcessParams)
        {
            Vector4 nearFarParams = new Vector4();

            nearFarParams.x = postProcessParams.cameraParams.nearPlane;
            nearFarParams.y = postProcessParams.cameraParams.farPlane;
            nearFarParams.z = 1.0f / nearFarParams.y;
            nearFarParams.w = nearFarParams.x * nearFarParams.z;
            Shader.SetGlobalVector("_ScionNearFarParams", nearFarParams);

            Vector4 resolutionParams1 = new Vector4();

            resolutionParams1.x = postProcessParams.halfWidth;
            resolutionParams1.y = postProcessParams.halfHeight;
            resolutionParams1.z = postProcessParams.width;
            resolutionParams1.w = postProcessParams.height;
            Shader.SetGlobalVector("_ScionResolutionParameters1", resolutionParams1);

            Vector4 resolutionParams2 = new Vector4();

            resolutionParams2.x = 1.0f / postProcessParams.halfWidth;
            resolutionParams2.y = 1.0f / postProcessParams.halfHeight;
            resolutionParams2.z = 1.0f / postProcessParams.width;
            resolutionParams2.w = 1.0f / postProcessParams.height;
            Shader.SetGlobalVector("_ScionResolutionParameters2", resolutionParams2);

            Vector4 cameraParams1 = new Vector4();

            cameraParams1.x = postProcessParams.cameraParams.apertureDiameter;
            cameraParams1.y = postProcessParams.cameraParams.focalLength;
            cameraParams1.z = postProcessParams.cameraParams.aspect;
            Shader.SetGlobalVector("_ScionCameraParams1", cameraParams1);

            Shader.SetGlobalTexture("_HalfResDepthTexture", postProcessParams.halfResDepth);
        }
Beispiel #8
0
        private void SetShaderKeyWords(PostProcessParameters postProcessParams)
        {
            if (postProcessParams.cameraParams.cameraMode == CameraMode.Off || postProcessParams.cameraParams.cameraMode == CameraMode.Manual)
            {
                Debug.LogError("This functionality has been removed for The Forest to save on keywords!");
            }
            ColorGradingMode colorGradingMode = postProcessParams.colorGradingParams.colorGradingMode;

            if (colorGradingMode != ColorGradingMode.Off)
            {
                if (colorGradingMode == ColorGradingMode.On)
                {
                    ShaderSettings.ColorGradingSettings.SetIndex(1);
                }
            }
            else
            {
                ShaderSettings.ColorGradingSettings.SetIndex(0);
            }
            if (postProcessParams.commonPostProcess.chromaticAberration)
            {
                ShaderSettings.ChromaticAberrationSettings.SetIndex(1);
            }
            else
            {
                ShaderSettings.ChromaticAberrationSettings.SetIndex(0);
            }
        }
Beispiel #9
0
 public RenderTexture RenderDepthOfField(PostProcessParameters postProcessParams, RenderTexture source, RenderTexture dest, VirtualCamera virtualCamera)
 {
     this.CreateDX11Mat();
     virtualCamera.BindVirtualCameraTextures(this.m_DoFMat);
     if (postProcessParams.DoFParams.quality == DepthOfFieldQuality.High_DX11)
     {
         virtualCamera.BindVirtualCameraTextures(this.m_DoFMatDX11);
     }
     virtualCamera.BindVirtualCameraParams(this.m_DoFMat, postProcessParams.cameraParams, postProcessParams.DoFParams.focalDistance, (float)postProcessParams.halfWidth, postProcessParams.isFirstRender);
     if (postProcessParams.DoFParams.quality == DepthOfFieldQuality.High_DX11)
     {
         virtualCamera.BindVirtualCameraParams(this.m_DoFMatDX11, postProcessParams.cameraParams, postProcessParams.DoFParams.focalDistance, (float)postProcessParams.halfWidth, postProcessParams.isFirstRender);
     }
     RenderTexture depthCenterAverage = null;
     if (postProcessParams.DoFParams.depthFocusMode == DepthFocusMode.PointAverage)
     {
         depthCenterAverage = this.PrepatePointAverage(postProcessParams, dest);
     }
     RenderTexture renderTexture = this.CreateTiledData(postProcessParams.halfResDepth, postProcessParams.preCalcValues.tanHalfFoV, postProcessParams.cameraParams.fNumber, postProcessParams.DoFParams.focalDistance, postProcessParams.DoFParams.focalRange, postProcessParams.cameraParams.apertureDiameter, postProcessParams.cameraParams.focalLength, postProcessParams.DoFParams.maxCoCRadius, postProcessParams.cameraParams.nearPlane, postProcessParams.cameraParams.farPlane);
     RenderTexture renderTexture2 = this.TileNeighbourhoodDataGathering(renderTexture);
     RenderTexture renderTexture3 = this.PrefilterSource(postProcessParams.halfResSource);
     RenderTexture renderTexture4 = this.BlurTapPass(renderTexture3, renderTexture, renderTexture2, depthCenterAverage, postProcessParams.DoFParams.quality);
     if (postProcessParams.DoFParams.useMedianFilter)
     {
         renderTexture4 = this.MedianFilterPass(renderTexture4);
     }
     RenderTexture result = this.UpsampleDepthOfField(source, renderTexture4, renderTexture2);
     RenderTexture.ReleaseTemporary(renderTexture);
     RenderTexture.ReleaseTemporary(renderTexture2);
     RenderTexture.ReleaseTemporary(renderTexture3);
     RenderTexture.ReleaseTemporary(renderTexture4);
     return result;
 }
Beispiel #10
0
 protected void SRGBSettings(PostProcessParameters postProcessParams)
 {
     //If color grading is on the sRGB conversion is handled manually instead
     if (postProcessParams.colorGradingParams.colorGradingMode != ColorGradingMode.Off)
     {
         GL.sRGBWrite = false;
     }
 }
Beispiel #11
0
        public RenderTexture RenderDepthOfField(PostProcessParameters postProcessParams, RenderTexture source, VirtualCamera virtualCamera, RenderTexture exclusionMask)
        {
            CreateDX11Mat();

            if (ShaderSettings.ExposureSettings.IsActive("SC_EXPOSURE_AUTO") == true)
            {
                virtualCamera.BindVirtualCameraTextures(m_DoFMat);
                if (postProcessParams.DoFParams.quality == DepthOfFieldQuality.High_DX11)
                {
                    virtualCamera.BindVirtualCameraTextures(m_DoFMatDX11);
                }
            }

            virtualCamera.BindVirtualCameraParams(m_DoFMat, postProcessParams.cameraParams, postProcessParams.DoFParams.focalDistance, postProcessParams.halfWidth, postProcessParams.isFirstRender);
            if (postProcessParams.DoFParams.quality == DepthOfFieldQuality.High_DX11)
            {
                virtualCamera.BindVirtualCameraParams(m_DoFMatDX11, postProcessParams.cameraParams, postProcessParams.DoFParams.focalDistance, postProcessParams.halfWidth, postProcessParams.isFirstRender);
            }

            RenderTexture depthCenterAverage = null;

            if (postProcessParams.DoFParams.depthFocusMode == DepthFocusMode.PointAverage)
            {
                depthCenterAverage = PrepatePointAverage(postProcessParams);
                //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(depthCenterAverage, false, false, false);
            }

            RenderTexture tiledData = CreateTiledData(postProcessParams.halfResDepth,
                                                      postProcessParams.preCalcValues.tanHalfFoV,
                                                      postProcessParams.cameraParams.fNumber,
                                                      postProcessParams.DoFParams.focalDistance,
                                                      postProcessParams.DoFParams.focalRange,
                                                      postProcessParams.cameraParams.apertureDiameter,
                                                      postProcessParams.cameraParams.focalLength,
                                                      postProcessParams.DoFParams.maxCoCRadius,
                                                      postProcessParams.cameraParams.nearPlane,
                                                      postProcessParams.cameraParams.farPlane);

            //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(exclusionMask, false, false, false);
            RenderTexture neighbourhoodData   = TileNeighbourhoodDataGathering(tiledData);
            RenderTexture prefilteredSource   = PrefilterSource(postProcessParams.halfResSource);
            RenderTexture depthOfFieldTexture = BlurTapPass(prefilteredSource, tiledData, neighbourhoodData, exclusionMask, depthCenterAverage, postProcessParams.DoFParams.quality);

            if (postProcessParams.DoFParams.useMedianFilter == true)
            {
                depthOfFieldTexture = MedianFilterPass(depthOfFieldTexture);
            }

            RenderTexture compositedDoF = UpsampleDepthOfField(source, depthOfFieldTexture, neighbourhoodData, exclusionMask);

            RenderTexture.ReleaseTemporary(tiledData);
            RenderTexture.ReleaseTemporary(neighbourhoodData);
            RenderTexture.ReleaseTemporary(prefilteredSource);
            RenderTexture.ReleaseTemporary(depthOfFieldTexture);

            return(compositedDoF);
        }
Beispiel #12
0
 private bool ShouldInvertVAxis(PostProcessParameters postProcessParams)
 {
     if (postProcessParams.camera.actualRenderingPath == RenderingPath.Forward && QualitySettings.antiAliasing > 0)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #13
0
        public void Combine(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams, VirtualCamera virtualCamera)
        {
            if (postProcessParams.bloom == true)
            {
                PrepareBloomSampling(postProcessParams.bloomTexture, postProcessParams.glareParams);
            }
            if (postProcessParams.lensDirt == true)
            {
                PrepareLensDirtSampling(postProcessParams.lensDirtTexture, postProcessParams.lensDirtParams, postProcessParams.glareParams);
            }
            if (postProcessParams.lensFlare == true)
            {
                PrepareLensFlareSampling(postProcessParams.lensFlareParams, postProcessParams.lensFlareTexture, postProcessParams.cameraTransform);
            }
            PrepareExposure(postProcessParams.cameraParams, virtualCamera);
            PrepareColorGrading(postProcessParams.colorGradingParams);
            UploadVariables(postProcessParams);

            //The reasoning behind the passIndex stuff is keyword avoidance
            int passIndex = 0;

            if (postProcessParams.tonemapping == false)
            {
                passIndex += 4;
            }
            if (postProcessParams.bloom == false)
            {
                passIndex += 2;
            }
            if (postProcessParams.lensDirt == false || postProcessParams.lensDirtTexture == null)
            {
                passIndex += 1;
            }

            source.filterMode = FilterMode.Bilinear;
            source.wrapMode   = TextureWrapMode.Clamp;
            Graphics.Blit(source, dest, m_combinationMat, passIndex);

            //Graphics.Blit(postProcessParams.blurTexture, dest);
            //Graphics.Blit(postProcessParams.halfResSource, dest);
            //Graphics.Blit(source, dest);
        }
Beispiel #14
0
        protected void SetupPostProcessParameters(PostProcessParameters postProcessParams, RenderTexture source)
        {
            focalDistance = focalDistance < m_camera.nearClipPlane + 0.3f ? m_camera.nearClipPlane + 0.3f : focalDistance;

            postProcessParams.camera          = m_camera;
            postProcessParams.cameraTransform = m_cameraTransform;

            //Done later
            postProcessParams.halfResSource = null;
            postProcessParams.halfResDepth  = m_downsampling.DownsampleDepthTexture(source.width, source.height);

            postProcessParams.width      = source.width;
            postProcessParams.height     = source.height;
            postProcessParams.halfWidth  = source.width / 2;
            postProcessParams.halfHeight = source.height / 2;

            if (prevCamFoV != m_camera.fieldOfView)
            {
                postProcessParams.preCalcValues.tanHalfFoV = Mathf.Tan(m_camera.fieldOfView * 0.5f * Mathf.Deg2Rad);
                prevCamFoV = m_camera.fieldOfView;
            }

            postProcessParams.DoFParams.useMedianFilter = true;             //This could technically be a user choice, but its a lot of quality for a low price

            if (userControlledFocalLength == false)
            {
                postProcessParams.cameraParams.focalLength = ScionUtility.GetFocalLength(postProcessParams.preCalcValues.tanHalfFoV);
            }
            else
            {
                postProcessParams.cameraParams.focalLength = focalLength * 0.001f;              //Millimeter to meter
            }
            postProcessParams.cameraParams.apertureDiameter = ScionUtility.ComputeApertureDiameter(fNumber, postProcessParams.cameraParams.focalLength);

            postProcessParams.cameraParams.fieldOfView = m_camera.fieldOfView;
            postProcessParams.cameraParams.aspect      = m_camera.aspect;
            postProcessParams.cameraParams.nearPlane   = m_camera.nearClipPlane;
            postProcessParams.cameraParams.farPlane    = m_camera.farClipPlane;

            postProcessParams.isFirstRender = m_isFirstRender;
            m_isFirstRender = false;
        }
Beispiel #15
0
		protected override void SetShaderKeyWords(PostProcessParameters postProcessParams)
		{
			base.SetShaderKeyWords(postProcessParams);

			switch (m_tonemappingMode)
			{
				case (TonemappingMode.Reinhard):
					ShaderSettings.TonemappingSettings.SetIndex(0);
					break;
				case (TonemappingMode.LumaReinhard):
					ShaderSettings.TonemappingSettings.SetIndex(1);
					break;
				case (TonemappingMode.Filmic):
					ShaderSettings.TonemappingSettings.SetIndex(2);
					break;
				case (TonemappingMode.Photographic):  
					ShaderSettings.TonemappingSettings.SetIndex(3);
				break;
			}
		} 
Beispiel #16
0
 private void PerformPostProcessing(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams)
 {
     if (postProcessParams.depthOfField)
     {
         postProcessParams.halfResSource = this.m_downsampling.DownsampleFireflyRemovingBilateral(source, postProcessParams.halfResDepth);
         source = this.m_depthOfFieldClass.RenderDepthOfField(postProcessParams, source, dest, this.m_virtualCamera);
         RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
     }
     postProcessParams.halfResSource = this.m_downsampling.DownsampleFireflyRemoving(source);
     if (postProcessParams.bloom)
     {
         postProcessParams.bloomTexture = this.m_bloomClass.CreateBloomTexture(postProcessParams.halfResSource, postProcessParams.bloomParams);
         if (postProcessParams.exposure)
         {
             RenderTexture renderTexture    = this.m_bloomClass.TryGetSmallBloomTexture(50);
             float         energyNormalizer = this.m_bloomClass.GetEnergyNormalizer();
             if (renderTexture == null)
             {
                 renderTexture    = postProcessParams.halfResSource;
                 energyNormalizer = 1f;
             }
             this.m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, renderTexture, (float)postProcessParams.halfWidth, postProcessParams.preCalcValues.tanHalfFoV, energyNormalizer, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
         }
     }
     else if (postProcessParams.exposure)
     {
         this.m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, postProcessParams.halfResSource, (float)postProcessParams.halfWidth, postProcessParams.preCalcValues.tanHalfFoV, 1f, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
     }
     this.m_combinationPass.Combine(source, dest, postProcessParams, this.m_virtualCamera);
     this.m_scionDebug.VisualizeDebug(dest);
     RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
     RenderTexture.ReleaseTemporary(postProcessParams.halfResDepth);
     RenderTexture.ReleaseTemporary(postProcessParams.dofTexture);
     this.m_bloomClass.EndOfFrameCleanup();
     this.m_virtualCamera.EndOfFrameCleanup();
     this.m_depthOfFieldClass.EndOfFrameCleanup();
     if (postProcessParams.depthOfField)
     {
         RenderTexture.ReleaseTemporary(source);
     }
 }
Beispiel #17
0
        protected override void SetShaderKeyWords(PostProcessParameters postProcessParams)
        {
            base.SetShaderKeyWords(postProcessParams);

            switch (m_tonemappingMode)
            {
            case (TonemappingMode.Reinhard):
                ShaderSettings.TonemappingSettings.SetIndex(0);
                break;

            case (TonemappingMode.LumaReinhard):
                ShaderSettings.TonemappingSettings.SetIndex(1);
                break;

            case (TonemappingMode.Filmic):
                ShaderSettings.TonemappingSettings.SetIndex(2);
                break;

            case (TonemappingMode.Photographic):
                ShaderSettings.TonemappingSettings.SetIndex(3);
                break;
            }
        }
Beispiel #18
0
        public void Combine(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams, VirtualCamera virtualCamera)
        {
            if (postProcessParams.bloom == true) PrepareBloomSampling(postProcessParams.bloomTexture, postProcessParams.glareParams);
            if (postProcessParams.lensDirt == true) PrepareLensDirtSampling(postProcessParams.lensDirtTexture, postProcessParams.lensDirtParams, postProcessParams.glareParams);
            if (postProcessParams.lensFlare == true) PrepareLensFlareSampling(postProcessParams.lensFlareParams, postProcessParams.lensFlareTexture, postProcessParams.cameraTransform);
            PrepareExposure(postProcessParams.cameraParams, virtualCamera);
            PrepareColorGrading(postProcessParams.colorGradingParams);
            UploadVariables(postProcessParams);

            //The reasoning behind the passIndex stuff is keyword avoidance
            int passIndex = 0;
            if (postProcessParams.tonemapping == false) 	passIndex += 4;
            if (postProcessParams.bloom == false)  			passIndex += 2;
            if (postProcessParams.lensDirt == false || postProcessParams.lensDirtTexture == null) passIndex += 1;

            source.filterMode = FilterMode.Bilinear;
            source.wrapMode = TextureWrapMode.Clamp;
            Graphics.Blit(source, dest, m_combinationMat, passIndex);

            //Graphics.Blit(postProcessParams.blurTexture, dest);
            //Graphics.Blit(postProcessParams.halfResSource, dest);
            //Graphics.Blit(source, dest);
        }
Beispiel #19
0
        public void Combine(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams, VirtualCamera virtualCamera)
        {
            if (postProcessParams.bloom == true)
            {
                PrepareBloomSampling(postProcessParams.bloomTexture, postProcessParams.bloomParams);
            }
            if (postProcessParams.lensDirt == true)
            {
                PrepareLensDirtSampling(postProcessParams.lensDirtTexture, postProcessParams.lensDirtParams);
            }
            PrepareExposure(postProcessParams.cameraParams, virtualCamera);
            PrepareColorGrading(postProcessParams.colorGradingParams);
            UploadVariables(postProcessParams.commonPostProcess);

            int passIndex = 0;

            if (postProcessParams.tonemapping == false)
            {
                passIndex += 3;
            }
            if (postProcessParams.bloom == false)
            {
                passIndex += 2;
            }
            else if (postProcessParams.lensDirt == false)
            {
                passIndex += 1;
            }

            source.filterMode = FilterMode.Bilinear;
            source.wrapMode   = TextureWrapMode.Clamp;
            Graphics.Blit(source, dest, m_combinationMat, passIndex);

            //Graphics.Blit(postProcessParams.blurTexture, dest);
            //Graphics.Blit(postProcessParams.halfResSource, dest);
            //Graphics.Blit(source, dest);
        }
Beispiel #20
0
        public RenderTexture RenderDepthOfField(PostProcessParameters postProcessParams, RenderTexture source, RenderTexture dest, VirtualCamera virtualCamera)
        {
            this.CreateDX11Mat();
            virtualCamera.BindVirtualCameraTextures(this.m_DoFMat);
            if (postProcessParams.DoFParams.quality == DepthOfFieldQuality.High_DX11)
            {
                virtualCamera.BindVirtualCameraTextures(this.m_DoFMatDX11);
            }
            virtualCamera.BindVirtualCameraParams(this.m_DoFMat, postProcessParams.cameraParams, postProcessParams.DoFParams.focalDistance, (float)postProcessParams.halfWidth, postProcessParams.isFirstRender);
            if (postProcessParams.DoFParams.quality == DepthOfFieldQuality.High_DX11)
            {
                virtualCamera.BindVirtualCameraParams(this.m_DoFMatDX11, postProcessParams.cameraParams, postProcessParams.DoFParams.focalDistance, (float)postProcessParams.halfWidth, postProcessParams.isFirstRender);
            }
            RenderTexture depthCenterAverage = null;

            if (postProcessParams.DoFParams.depthFocusMode == DepthFocusMode.PointAverage)
            {
                depthCenterAverage = this.PrepatePointAverage(postProcessParams, dest);
            }
            RenderTexture renderTexture  = this.CreateTiledData(postProcessParams.halfResDepth, postProcessParams.preCalcValues.tanHalfFoV, postProcessParams.cameraParams.fNumber, postProcessParams.DoFParams.focalDistance, postProcessParams.DoFParams.focalRange, postProcessParams.cameraParams.apertureDiameter, postProcessParams.cameraParams.focalLength, postProcessParams.DoFParams.maxCoCRadius, postProcessParams.cameraParams.nearPlane, postProcessParams.cameraParams.farPlane);
            RenderTexture renderTexture2 = this.TileNeighbourhoodDataGathering(renderTexture);
            RenderTexture renderTexture3 = this.PrefilterSource(postProcessParams.halfResSource);
            RenderTexture renderTexture4 = this.BlurTapPass(renderTexture3, renderTexture, renderTexture2, depthCenterAverage, postProcessParams.DoFParams.quality);

            if (postProcessParams.DoFParams.useMedianFilter)
            {
                renderTexture4 = this.MedianFilterPass(renderTexture4);
            }
            RenderTexture result = this.UpsampleDepthOfField(source, renderTexture4, renderTexture2);

            RenderTexture.ReleaseTemporary(renderTexture);
            RenderTexture.ReleaseTemporary(renderTexture2);
            RenderTexture.ReleaseTemporary(renderTexture3);
            RenderTexture.ReleaseTemporary(renderTexture4);
            return(result);
        }
Beispiel #21
0
        private void UploadTemporalReprojectionVariables(PostProcessParameters postProcessParams)        //Transform cameraTransform, float tanHalfFoV, float aspect, float farClipPlane)
        {
            float dy = postProcessParams.preCalcValues.tanHalfFoV;
            float dx = dy * postProcessParams.cameraParams.aspect;

            Vector3 centerVP = postProcessParams.cameraTransform.forward;
            Vector3 rightVP  = postProcessParams.cameraTransform.right * dx;
            Vector3 upVP     = postProcessParams.cameraTransform.up * dy;

            m_DoFMatTemporal.SetVector("_FrustumCornerBottomLeftVP", centerVP - rightVP - upVP);
            m_DoFMatTemporal.SetVector("_FrustumCornerWidthVP", rightVP * 2.0f);
            m_DoFMatTemporal.SetVector("_FrustumCornerHeightVP", upVP * 2.0f);
            m_DoFMatTemporal.SetMatrix("_PreviousViewProjection", postProcessParams.cameraParams.previousViewProjection);

            float temporalBlend = postProcessParams.DoFParams.temporalBlend;

            m_DoFMatTemporal.SetFloat("_TemporalBlendFactor", temporalBlend);

            const float temporalIncrement = 1.372f;
            int         temporalSteps     = postProcessParams.DoFParams.temporalSteps;

            if (temporalSteps > 0)
            {
                temporalUVOffset = temporalUVOffset + temporalIncrement;
                while (temporalUVOffset > temporalIncrement * temporalSteps - 0.01f)
                {
                    temporalUVOffset -= temporalIncrement * temporalSteps;
                }
            }
            else
            {
                temporalUVOffset = 0.0f;
            }

            m_DoFMat.SetFloat("_TemporalUVOffset", temporalUVOffset);
        }
Beispiel #22
0
        protected void SetGlobalParameters(PostProcessParameters postProcessParams)
        {
            Vector4 nearFarParams = new Vector4();
            nearFarParams.x = postProcessParams.cameraParams.nearPlane;
            nearFarParams.y = postProcessParams.cameraParams.farPlane;
            nearFarParams.z = 1.0f / nearFarParams.y;
            nearFarParams.w = nearFarParams.x * nearFarParams.z;
            Shader.SetGlobalVector("_ScionNearFarParams", nearFarParams);

            Vector4 resolutionParams1 = new Vector4();
            resolutionParams1.x = postProcessParams.halfWidth;
            resolutionParams1.y = postProcessParams.halfHeight;
            resolutionParams1.z = postProcessParams.width;
            resolutionParams1.w = postProcessParams.height;
            Shader.SetGlobalVector("_ScionResolutionParameters1", resolutionParams1);

            Vector4 resolutionParams2 = new Vector4();
            resolutionParams2.x = 1.0f / postProcessParams.halfWidth;
            resolutionParams2.y = 1.0f / postProcessParams.halfHeight;
            resolutionParams2.z = 1.0f / postProcessParams.width;
            resolutionParams2.w = 1.0f / postProcessParams.height;
            Shader.SetGlobalVector("_ScionResolutionParameters2", resolutionParams2);

            Vector4 cameraParams1 = new Vector4();
            cameraParams1.x = postProcessParams.cameraParams.apertureDiameter;
            cameraParams1.y = postProcessParams.cameraParams.focalLength;
            cameraParams1.z = postProcessParams.cameraParams.aspect;
            cameraParams1.w = 1.0f / postProcessParams.cameraParams.aspect;
            Shader.SetGlobalVector("_ScionCameraParams1", cameraParams1);

            Vector4 cameraPosition = new Vector4();
            cameraPosition.x = postProcessParams.cameraTransform.position.x;
            cameraPosition.y = postProcessParams.cameraTransform.position.y;
            cameraPosition.z = postProcessParams.cameraTransform.position.z;
            Shader.SetGlobalVector("_ScionCameraPosition", cameraPosition);

            //UnityEngine.Rendering.GraphicsDeviceType deviceType = SystemInfo.graphicsDeviceType;
            //float forwardMSAAFix = 0.0f;
            //			if (deviceType == UnityEngine.Rendering.GraphicsDeviceType.Direct3D9 &&
            //			    camera.actualRenderingPath == RenderingPath.Forward &&
            //			    camera.hdr == false && QualitySettings.antiAliasing > 0) forwardMSAAFix = 1.0f;
            //Shader.SetGlobalFloat("_ScionForwardMSAAFix", forwardMSAAFix);
        }
Beispiel #23
0
        protected virtual void SetShaderKeyWords(PostProcessParameters postProcessParams)
        {
            if (postProcessParams.cameraParams.cameraMode == CameraMode.Off ||
                postProcessParams.cameraParams.cameraMode == CameraMode.Manual)
            {
                ShaderSettings.ExposureSettings.SetIndex(1);
            }
            else ShaderSettings.ExposureSettings.SetIndex(0);

            switch (postProcessParams.DoFParams.depthFocusMode)
            {
                case (DepthFocusMode.ManualDistance):
                    ShaderSettings.DepthFocusSettings.SetIndex(0);
                    break;
                case (DepthFocusMode.ManualRange):
                    ShaderSettings.DepthFocusSettings.SetIndex(1);
                    break;
                case (DepthFocusMode.TargetTransform):
                    ShaderSettings.DepthFocusSettings.SetIndex(0);
                    break;
                case (DepthFocusMode.PointAverage):
                    ShaderSettings.DepthFocusSettings.SetIndex(2);
                    break;
            }

            if (postProcessParams.DoFParams.depthOfFieldMask != 0) ShaderSettings.DepthOfFieldMaskSettings.SetIndex(0);
            else ShaderSettings.DepthOfFieldMaskSettings.Disable();

            if (postProcessParams.lensFlare == true) ShaderSettings.LensFlareSettings.SetIndex(0);
            else ShaderSettings.LensFlareSettings.Disable();

            if (postProcessParams.colorGradingParams.colorGradingMode == ColorGradingMode.Off ||
                postProcessParams.colorGradingParams.colorGradingTex1 == null)
            {
                ShaderSettings.ColorGradingSettings.Disable();
            }
            else
            {
                if (postProcessParams.colorGradingParams.colorGradingMode == ColorGradingMode.On) ShaderSettings.ColorGradingSettings.SetIndex(0);
                if (postProcessParams.colorGradingParams.colorGradingMode == ColorGradingMode.Blend) ShaderSettings.ColorGradingSettings.SetIndex(1);
            }

            if (postProcessParams.commonPostProcess.chromaticAberration == true) ShaderSettings.ChromaticAberrationSettings.SetIndex(0);
            else ShaderSettings.ChromaticAberrationSettings.Disable();
        }
Beispiel #24
0
		public RenderTexture RenderDepthOfField(PostProcessParameters postProcessParams, RenderTexture source, RenderTexture downsampledClrDepth, 
		                                        VirtualCamera virtualCamera, RenderTexture exclusionMask)
		{
			if (ShaderSettings.ExposureSettings.IsActive("SC_EXPOSURE_AUTO") == true)
			{
				virtualCamera.BindVirtualCameraTextures(m_DoFMat);
			}

			virtualCamera.BindVirtualCameraParams(m_DoFMat, postProcessParams.cameraParams, postProcessParams.DoFParams.focalDistance, postProcessParams.halfWidth, postProcessParams.isFirstRender);	

			RenderTexture depthCenterAverage = null;
			if (postProcessParams.DoFParams.depthFocusMode == DepthFocusMode.PointAverage)
			{
				depthCenterAverage = PrepatePointAverage(postProcessParams, downsampledClrDepth);
				//ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(depthCenterAverage, false, false, false);
			}	

			RenderTexture tiledData = CreateTiledData(downsampledClrDepth, 
			                                          postProcessParams.preCalcValues.tanHalfFoV,
			                                          postProcessParams.cameraParams.fNumber,
			                                          postProcessParams.DoFParams.focalDistance,
			                                          postProcessParams.DoFParams.focalRange,
			                                          postProcessParams.cameraParams.apertureDiameter,
			                                          postProcessParams.cameraParams.focalLength,
			                                          postProcessParams.DoFParams.maxCoCRadius,
			                                          postProcessParams.cameraParams.nearPlane,
			                                          postProcessParams.cameraParams.farPlane);
			
			//ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(exclusionMask, false, false, false);

			RenderTexture neighbourhoodData 	= TileNeighbourhoodDataGathering(tiledData);
			RenderTexture prefilteredSource 	= PrefilterSource(downsampledClrDepth);		
			RenderTexture.ReleaseTemporary(downsampledClrDepth);
			
			RenderTexture presortTexture		= Presort(prefilteredSource, neighbourhoodData);

			if (postProcessParams.DoFParams.useTemporal == true) UploadTemporalReprojectionVariables(postProcessParams);

			RenderTexture tapsTexture;
			RenderTexture alphaTexture;
			BlurTapPass(prefilteredSource, tiledData, neighbourhoodData, exclusionMask, depthCenterAverage, presortTexture,
			            postProcessParams.DoFParams.quality, out tapsTexture, out alphaTexture);

			const bool temporalAlpha = false;
			
			//Only do temporal super sampling in editor if its playing
			#if UNITY_EDITOR
				if (UnityEditor.EditorApplication.isPlaying == true && 
				    postProcessParams.DoFParams.useTemporal == true && 
				    previousTapsTexture != null) 
				{
					if (temporalAlpha == true) TemporalPass(ref tapsTexture, ref alphaTexture, previousTapsTexture, previousAlphaTexture);
					else TemporalPass(ref tapsTexture, previousTapsTexture);
				}
			#else
			if (postProcessParams.DoFParams.useTemporal == true && previousTapsTexture != null) 
			{
				if (temporalAlpha == true) TemporalPass(ref tapsTexture, ref alphaTexture, previousTapsTexture, previousAlphaTexture);
				else TemporalPass(ref tapsTexture, previousTapsTexture);
			}
			#endif

			//alphaTexture = BilateralAlphaFilter(alphaTexture, tapsTexture);
			//alphaTexture = MedianFilterPass(alphaTexture);
			
			if (postProcessParams.DoFParams.useMedianFilter == true) tapsTexture = MedianFilterPass(tapsTexture);
			
			if (postProcessParams.DoFParams.visualizeFocalDistance == true) VisualizeFocalDistance(tapsTexture);
			
			//ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(presort, true, false, false);
			//ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(alphaTexture, false, false, false);
			//ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(previousTapsTexture, false, false, false);

			RenderTexture compositedDoF = UpsampleDepthOfField(source, tapsTexture, alphaTexture, neighbourhoodData, exclusionMask);
			RenderTexture.ReleaseTemporary(tiledData);
			RenderTexture.ReleaseTemporary(neighbourhoodData);
			RenderTexture.ReleaseTemporary(prefilteredSource);
			RenderTexture.ReleaseTemporary(presortTexture);

			if (copiedDepthBuffer != null) 		{ RenderTexture.ReleaseTemporary(copiedDepthBuffer); copiedDepthBuffer = null; }			
			if (previousTapsTexture != null) 	{ RenderTexture.ReleaseTemporary(previousTapsTexture); previousTapsTexture = null; }
			if (previousAlphaTexture != null) 	{ RenderTexture.ReleaseTemporary(previousAlphaTexture); previousAlphaTexture = null; }

			if (postProcessParams.DoFParams.useTemporal == true) 
			{
				previousTapsTexture = tapsTexture;
				previousAlphaTexture = alphaTexture;
			}
			else 
			{
				RenderTexture.ReleaseTemporary(tapsTexture);
				RenderTexture.ReleaseTemporary(alphaTexture);
			}

			return compositedDoF;
		}
Beispiel #25
0
        protected void PerformPostProcessing(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams)
        {
            //Graphics.Blit(source, dest);
            source = DepthOfFieldStep(postProcessParams, source);

            //Do this after DoF so DoF gets included (if active)
            postProcessParams.halfResSource = m_downsampling.DownsampleFireflyRemoving(source);
            //postProcessParams.halfResSource = m_downsampling.Downsample(source);

            if (postProcessParams.bloom == true)
            {
                postProcessParams.bloomTexture = m_bloomClass.CreateBloomTexture(postProcessParams.halfResSource, postProcessParams.bloomParams);
                if (postProcessParams.exposure == true)
                {
                    const int     minimumReqPixels = 100;
                    int           numSearches;
                    RenderTexture textureToAverage = m_bloomClass.TryGetSmallBloomTexture(minimumReqPixels, out numSearches);
                    float         energyNormalizer = m_bloomClass.GetEnergyNormalizer(numSearches);
                    if (textureToAverage == null)
                    {
                        textureToAverage = postProcessParams.halfResSource; energyNormalizer = 1.0f;
                    }
                    m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, textureToAverage, postProcessParams.halfWidth, postProcessParams.preCalcValues.tanHalfFoV,
                                                           energyNormalizer, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
                }
            }
            else if (postProcessParams.exposure == true)
            {
                m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, postProcessParams.halfResSource, postProcessParams.halfWidth,
                                                       postProcessParams.preCalcValues.tanHalfFoV, 1.0f, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
            }

            //Graphics.Blit(source, dest);
            m_combinationPass.Combine(source, dest, postProcessParams, m_virtualCamera);
            m_scionDebug.VisualizeDebug(dest);

            RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
            RenderTexture.ReleaseTemporary(postProcessParams.halfResDepth);
            RenderTexture.ReleaseTemporary(postProcessParams.dofTexture);

            m_bloomClass.EndOfFrameCleanup();
            m_virtualCamera.EndOfFrameCleanup();
            m_depthOfFieldClass.EndOfFrameCleanup();

            if (postProcessParams.depthOfField == true)
            {
                RenderTexture.ReleaseTemporary(source);
            }
        }
Beispiel #26
0
 private RenderTexture PrepatePointAverage(PostProcessParameters postProcessParams, RenderTexture dest)
 {
     float num = this.Max(10f / (float)postProcessParams.halfResDepth.width, postProcessParams.DoFParams.pointAverageRange);
     Vector4 vector = default(Vector4);
     vector.x = Mathf.Clamp01(postProcessParams.DoFParams.pointAveragePosition.x);
     vector.y = Mathf.Clamp01(postProcessParams.DoFParams.pointAveragePosition.y);
     vector.z = num * num;
     vector.w = 1f / (num * num);
     this.m_DoFMat.SetVector("_DownsampleWeightedParams", vector);
     if (this.previousPointAverage != null && !postProcessParams.isFirstRender)
     {
         this.m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1f - Mathf.Exp(-Time.deltaTime * postProcessParams.DoFParams.depthAdaptionSpeed));
         this.m_DoFMat.SetTexture("_PreviousWeightedResult", this.previousPointAverage);
     }
     else
     {
         this.m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1f);
         this.m_DoFMat.SetTexture("_PreviousWeightedResult", null);
     }
     postProcessParams.halfResDepth.filterMode = FilterMode.Bilinear;
     int num2 = this.Max(postProcessParams.halfWidth / 2, 1);
     int num3 = this.Max(postProcessParams.halfHeight / 2, 1);
     RenderTexture temporary = RenderTexture.GetTemporary(num2, num3, 0, RenderTextureFormat.RGHalf);
     temporary.filterMode = FilterMode.Bilinear;
     temporary.wrapMode = TextureWrapMode.Clamp;
     Graphics.Blit(postProcessParams.halfResDepth, temporary, this.m_DoFMat, 7);
     if (postProcessParams.DoFParams.visualizePointFocus)
     {
         RenderTexture temporary2 = RenderTexture.GetTemporary(num2, num3, 0, RenderTextureFormat.ARGB32);
         Graphics.Blit(temporary, temporary2, this.m_DoFMat, 9);
         ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(temporary2, true, true, false);
     }
     RenderTexture renderTexture = temporary;
     int i = this.Max(num2, num3);
     while (i > 1)
     {
         num2 = this.Max(1, num2 / 2 + num2 % 2);
         num3 = this.Max(1, num3 / 2 + num3 % 2);
         i = i / 2 + i % 2;
         RenderTexture temporary3;
         if (i > 1)
         {
             temporary3 = RenderTexture.GetTemporary(num2, num3, 0, RenderTextureFormat.RGHalf);
             temporary3.filterMode = FilterMode.Bilinear;
             temporary3.wrapMode = TextureWrapMode.Clamp;
             Graphics.Blit(renderTexture, temporary3, this.m_DoFMat, 10);
         }
         else
         {
             temporary3 = RenderTexture.GetTemporary(num2, num3, 0, RenderTextureFormat.RHalf);
             temporary3.filterMode = FilterMode.Bilinear;
             temporary3.wrapMode = TextureWrapMode.Clamp;
             Graphics.Blit(renderTexture, temporary3, this.m_DoFMat, 8);
         }
         RenderTexture.ReleaseTemporary(renderTexture);
         renderTexture = temporary3;
     }
     RenderTexture result = renderTexture;
     if (this.previousPointAverage != null)
     {
         RenderTexture.ReleaseTemporary(this.previousPointAverage);
     }
     this.previousPointAverage = result;
     return result;
 }
Beispiel #27
0
 private bool ShouldInvertVAxis(PostProcessParameters postProcessParams)
 {
     if (postProcessParams.camera.actualRenderingPath == RenderingPath.Forward && QualitySettings.antiAliasing > 0) return true;
     else return false;
 }
Beispiel #28
0
 private void SetGlobalParameters(PostProcessParameters postProcessParams)
 {
     Vector4 vec = default(Vector4);
     vec.x = postProcessParams.cameraParams.nearPlane;
     vec.y = postProcessParams.cameraParams.farPlane;
     vec.z = 1f / vec.y;
     vec.w = vec.x * vec.z;
     Shader.SetGlobalVector("_ScionNearFarParams", vec);
     Shader.SetGlobalTexture("_HalfResSourceTexture", postProcessParams.halfResSource);
     Shader.SetGlobalTexture("_HalfResDepthTexture", postProcessParams.halfResDepth);
     Shader.SetGlobalVector("_ScionResolutionParameters1", new Vector4
     {
         x = (float)postProcessParams.halfWidth,
         y = (float)postProcessParams.halfHeight,
         z = (float)postProcessParams.width,
         w = (float)postProcessParams.height
     });
     Shader.SetGlobalVector("_ScionResolutionParameters2", new Vector4
     {
         x = 1f / (float)postProcessParams.halfWidth,
         y = 1f / (float)postProcessParams.halfHeight,
         z = 1f / (float)postProcessParams.width,
         w = 1f / (float)postProcessParams.height
     });
     Shader.SetGlobalVector("_ScionCameraParams1", new Vector4
     {
         x = postProcessParams.cameraParams.apertureDiameter,
         y = postProcessParams.cameraParams.focalLength,
         z = postProcessParams.cameraParams.aspect
     });
 }
Beispiel #29
0
 private void PerformPostProcessing(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams)
 {
     if (postProcessParams.depthOfField)
     {
         postProcessParams.halfResSource = this.m_downsampling.DownsampleFireflyRemovingBilateral(source, postProcessParams.halfResDepth);
         source = this.m_depthOfFieldClass.RenderDepthOfField(postProcessParams, source, dest, this.m_virtualCamera);
         RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
     }
     postProcessParams.halfResSource = this.m_downsampling.DownsampleFireflyRemoving(source);
     if (postProcessParams.bloom)
     {
         postProcessParams.bloomTexture = this.m_bloomClass.CreateBloomTexture(postProcessParams.halfResSource, postProcessParams.bloomParams);
         if (postProcessParams.exposure)
         {
             RenderTexture renderTexture = this.m_bloomClass.TryGetSmallBloomTexture(50);
             float energyNormalizer = this.m_bloomClass.GetEnergyNormalizer();
             if (renderTexture == null)
             {
                 renderTexture = postProcessParams.halfResSource;
                 energyNormalizer = 1f;
             }
             this.m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, renderTexture, (float)postProcessParams.halfWidth, postProcessParams.preCalcValues.tanHalfFoV, energyNormalizer, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
         }
     }
     else if (postProcessParams.exposure)
     {
         this.m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, postProcessParams.halfResSource, (float)postProcessParams.halfWidth, postProcessParams.preCalcValues.tanHalfFoV, 1f, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
     }
     this.m_combinationPass.Combine(source, dest, postProcessParams, this.m_virtualCamera);
     this.m_scionDebug.VisualizeDebug(dest);
     RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
     RenderTexture.ReleaseTemporary(postProcessParams.halfResDepth);
     RenderTexture.ReleaseTemporary(postProcessParams.dofTexture);
     this.m_bloomClass.EndOfFrameCleanup();
     this.m_virtualCamera.EndOfFrameCleanup();
     this.m_depthOfFieldClass.EndOfFrameCleanup();
     if (postProcessParams.depthOfField)
     {
         RenderTexture.ReleaseTemporary(source);
     }
 }
Beispiel #30
0
        public RenderTexture RenderDepthOfField(PostProcessParameters postProcessParams, RenderTexture source, RenderTexture downsampledClrDepth,
                                                VirtualCamera virtualCamera, RenderTexture exclusionMask)
        {
            if (ShaderSettings.ExposureSettings.IsActive("SC_EXPOSURE_AUTO") == true)
            {
                virtualCamera.BindVirtualCameraTextures(m_DoFMat);
            }

            virtualCamera.BindVirtualCameraParams(m_DoFMat, postProcessParams.cameraParams, postProcessParams.DoFParams.focalDistance, postProcessParams.halfWidth, postProcessParams.isFirstRender);

            RenderTexture depthCenterAverage = null;

            if (postProcessParams.DoFParams.depthFocusMode == DepthFocusMode.PointAverage)
            {
                depthCenterAverage = PrepatePointAverage(postProcessParams, downsampledClrDepth);
                //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(depthCenterAverage, false, false, false);
            }

            RenderTexture tiledData = CreateTiledData(downsampledClrDepth,
                                                      postProcessParams.preCalcValues.tanHalfFoV,
                                                      postProcessParams.cameraParams.fNumber,
                                                      postProcessParams.DoFParams.focalDistance,
                                                      postProcessParams.DoFParams.focalRange,
                                                      postProcessParams.cameraParams.apertureDiameter,
                                                      postProcessParams.cameraParams.focalLength,
                                                      postProcessParams.DoFParams.maxCoCRadius,
                                                      postProcessParams.cameraParams.nearPlane,
                                                      postProcessParams.cameraParams.farPlane);

            //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(exclusionMask, false, false, false);

            RenderTexture neighbourhoodData = TileNeighbourhoodDataGathering(tiledData);
            RenderTexture prefilteredSource = PrefilterSource(downsampledClrDepth);

            RenderTexture.ReleaseTemporary(downsampledClrDepth);

            RenderTexture presortTexture = Presort(prefilteredSource, neighbourhoodData);

            if (postProcessParams.DoFParams.useTemporal == true)
            {
                UploadTemporalReprojectionVariables(postProcessParams);
            }

            RenderTexture tapsTexture;
            RenderTexture alphaTexture;

            BlurTapPass(prefilteredSource, tiledData, neighbourhoodData, exclusionMask, depthCenterAverage, presortTexture,
                        postProcessParams.DoFParams.quality, out tapsTexture, out alphaTexture);

            const bool temporalAlpha = false;

            //Only do temporal super sampling in editor if its playing
                        #if UNITY_EDITOR
            if (UnityEditor.EditorApplication.isPlaying == true &&
                postProcessParams.DoFParams.useTemporal == true &&
                previousTapsTexture != null)
            {
                if (temporalAlpha == true)
                {
                    TemporalPass(ref tapsTexture, ref alphaTexture, previousTapsTexture, previousAlphaTexture);
                }
                else
                {
                    TemporalPass(ref tapsTexture, previousTapsTexture);
                }
            }
                        #else
            if (postProcessParams.DoFParams.useTemporal == true && previousTapsTexture != null)
            {
                if (temporalAlpha == true)
                {
                    TemporalPass(ref tapsTexture, ref alphaTexture, previousTapsTexture, previousAlphaTexture);
                }
                else
                {
                    TemporalPass(ref tapsTexture, previousTapsTexture);
                }
            }
                        #endif

            //alphaTexture = BilateralAlphaFilter(alphaTexture, tapsTexture);
            //alphaTexture = MedianFilterPass(alphaTexture);

            if (postProcessParams.DoFParams.useMedianFilter == true)
            {
                tapsTexture = MedianFilterPass(tapsTexture);
            }

            if (postProcessParams.DoFParams.visualizeFocalDistance == true)
            {
                VisualizeFocalDistance(tapsTexture);
            }

            //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(presort, true, false, false);
            //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(alphaTexture, false, false, false);
            //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(previousTapsTexture, false, false, false);

            RenderTexture compositedDoF = UpsampleDepthOfField(source, tapsTexture, alphaTexture, neighbourhoodData, exclusionMask);
            RenderTexture.ReleaseTemporary(tiledData);
            RenderTexture.ReleaseTemporary(neighbourhoodData);
            RenderTexture.ReleaseTemporary(prefilteredSource);
            RenderTexture.ReleaseTemporary(presortTexture);

            if (copiedDepthBuffer != null)
            {
                RenderTexture.ReleaseTemporary(copiedDepthBuffer); copiedDepthBuffer = null;
            }
            if (previousTapsTexture != null)
            {
                RenderTexture.ReleaseTemporary(previousTapsTexture); previousTapsTexture = null;
            }
            if (previousAlphaTexture != null)
            {
                RenderTexture.ReleaseTemporary(previousAlphaTexture); previousAlphaTexture = null;
            }

            if (postProcessParams.DoFParams.useTemporal == true)
            {
                previousTapsTexture  = tapsTexture;
                previousAlphaTexture = alphaTexture;
            }
            else
            {
                RenderTexture.ReleaseTemporary(tapsTexture);
                RenderTexture.ReleaseTemporary(alphaTexture);
            }

            return(compositedDoF);
        }
Beispiel #31
0
        private RenderTexture PrepatePointAverage(PostProcessParameters postProcessParams, RenderTexture downsampledClrDepth)
        {
            const int weightedDownsamplePassID = 7;
            const int finalPassID             = 8;
            const int visualizationPassID     = 9;
            const int downsamplePassID        = 10;
            const RenderTextureFormat format  = RenderTextureFormat.RGHalf;
            const RenderTextureFormat format2 = RenderTextureFormat.RHalf;

            //Force at least 10x10 pixels to always effect the depth
            //Because stuff goes south if the circle is too small
            float range = Max(10.0f / postProcessParams.halfWidth, postProcessParams.DoFParams.pointAverageRange);

            Vector4 weightedDownsampleParams = new Vector4();

            weightedDownsampleParams.x = Mathf.Clamp01(postProcessParams.DoFParams.pointAveragePosition.x);
            weightedDownsampleParams.y = Mathf.Clamp01(postProcessParams.DoFParams.pointAveragePosition.y);
            weightedDownsampleParams.z = range * range;
            weightedDownsampleParams.w = 1.0f / (range * range);
            m_DoFMat.SetVector("_DownsampleWeightedParams", weightedDownsampleParams);

            if (previousPointAverage != null && postProcessParams.isFirstRender == false)
            {
#if UNITY_EDITOR
                if (UnityEditor.EditorApplication.isPlaying == false)
                {
                    m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1.0f);
                }
                else
#endif
                {
                    m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1.0f - Mathf.Exp(-Time.deltaTime * postProcessParams.DoFParams.depthAdaptionSpeed));
                }
                m_DoFMat.SetTexture("_PreviousWeightedResult", previousPointAverage);
            }
            else
            {
                m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1.0f);
                m_DoFMat.SetTexture("_PreviousWeightedResult", null);
            }

            downsampledClrDepth.filterMode = FilterMode.Bilinear;

            const int maxSize   = 1;
            int       texWidth  = Max(postProcessParams.halfWidth / 2, maxSize);
            int       texHeight = Max(postProcessParams.halfHeight / 2, maxSize);

            RenderTexture weightedDownsample = RenderTexture.GetTemporary(texWidth, texHeight, 0, format);
            weightedDownsample.filterMode = FilterMode.Bilinear;
            weightedDownsample.wrapMode   = TextureWrapMode.Clamp;

            Graphics.Blit(downsampledClrDepth, weightedDownsample, m_DoFMat, weightedDownsamplePassID);

            if (postProcessParams.DoFParams.visualizePointFocus == true)
            {
                RenderTexture visTexture = RenderTexture.GetTemporary(texWidth, texHeight, 0, RenderTextureFormat.ARGB32);
                m_DoFMat.SetTexture("_HalfResSourceDepthTexture", downsampledClrDepth);
                Graphics.Blit(weightedDownsample, visTexture, m_DoFMat, visualizationPassID);
                //Graphics.Blit(visTexture, dest);
                //RenderTexture.ReleaseTemporary(visTexture);
                ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(visTexture, true, true, false);
            }

            RenderTexture input       = weightedDownsample;
            int           largestSide = Max(texWidth, texHeight);

            while (largestSide > maxSize)
            {
                texWidth    = Max(maxSize, texWidth / 2 + texWidth % 2);
                texHeight   = Max(maxSize, texHeight / 2 + texHeight % 2);
                largestSide = largestSide / 2 + largestSide % 2;

                RenderTexture downsample;
                if (largestSide > maxSize)
                {
                    downsample            = RenderTexture.GetTemporary(texWidth, texHeight, 0, format);
                    downsample.filterMode = FilterMode.Bilinear;
                    downsample.wrapMode   = TextureWrapMode.Clamp;
                    Graphics.Blit(input, downsample, m_DoFMat, downsamplePassID);
                }
                else                 //Final pass
                {
                    downsample            = RenderTexture.GetTemporary(texWidth, texHeight, 0, format2);
                    downsample.filterMode = FilterMode.Bilinear;
                    downsample.wrapMode   = TextureWrapMode.Clamp;
                    Graphics.Blit(input, downsample, m_DoFMat, finalPassID);
                }

                RenderTexture.ReleaseTemporary(input);
                input = downsample;
            }

            RenderTexture pointAverage = input;
            if (previousPointAverage != null)
            {
                RenderTexture.ReleaseTemporary(previousPointAverage);
            }
            previousPointAverage = pointAverage;

            downsampledClrDepth.filterMode = FilterMode.Point;

            return(pointAverage);
        }
Beispiel #32
0
        protected void SetupPostProcessParameters(PostProcessParameters postProcessParams, RenderTexture source)
        {
            focalDistance = focalDistance < camera.nearClipPlane + 0.01f ? camera.nearClipPlane + 0.01f : focalDistance;

            postProcessParams.camera = camera;
            postProcessParams.cameraTransform = m_cameraTransform;

            //Done later
            postProcessParams.halfResSource 	= null;

            postProcessParams.width 			= source.width;
            postProcessParams.height 			= source.height;
            postProcessParams.halfWidth 		= source.width / 2;
            postProcessParams.halfHeight 		= source.height / 2;

            if (prevCamFoV != camera.fieldOfView || postProcessParams.preCalcValues.tanHalfFoV == 0.0f)
            {
                postProcessParams.preCalcValues.tanHalfFoV = Mathf.Tan(camera.fieldOfView * 0.5f * Mathf.Deg2Rad);
                prevCamFoV = camera.fieldOfView;
            }

            postProcessParams.DoFParams.useMedianFilter = true; //This could technically be a user choice, but its a lot of quality for a low price

            if (userControlledFocalLength == false) postProcessParams.cameraParams.focalLength = ScionUtility.GetFocalLength(postProcessParams.preCalcValues.tanHalfFoV);
            else postProcessParams.cameraParams.focalLength = focalLength * 0.001f; //Millimeter to meter
            postProcessParams.cameraParams.apertureDiameter = ScionUtility.ComputeApertureDiameter(fNumber, postProcessParams.cameraParams.focalLength);

            postProcessParams.cameraParams.fieldOfView	= camera.fieldOfView;
            postProcessParams.cameraParams.aspect		= camera.aspect;
            postProcessParams.cameraParams.nearPlane	= camera.nearClipPlane;
            postProcessParams.cameraParams.farPlane		= camera.farClipPlane;

            if (m_isFirstRender == true) postProcessParams.cameraParams.previousViewProjection = camera.projectionMatrix * camera.worldToCameraMatrix;
            postProcessParams.isFirstRender = m_isFirstRender;
            m_isFirstRender 				= false;

            if (m_depthFocusMode == DepthFocusMode.TargetTransform)
            {
                if (depthOfFieldTargetTransform == null) { postProcessParams.DoFParams.focalDistance = 10.0f; return; }
                Vector3 direction = depthOfFieldTargetTransform.position - m_cameraTransform.position;
                float depth = Mathf.Max(Vector3.Dot(direction, m_cameraTransform.forward), camera.nearClipPlane + 0.01f);
                postProcessParams.DoFParams.focalDistance = depth;
            }
        }
Beispiel #33
0
        protected void PerformPostProcessing(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams)
        {
            if (postProcessParams.depthOfField == true) source = DepthOfFieldStep(postProcessParams, source);

            //Do this after DoF so DoF gets included (if active)
            postProcessParams.halfResSource = m_downsampling.DownsampleFireflyRemoving(source);
            //postProcessParams.halfResSource = m_downsampling.Downsample(source);

            //If either is true
            bool downsampledGlareChainExists = false;
            if (postProcessParams.bloom == true || postProcessParams.lensFlare == true)
            {
                int bloomDownsamples 		= postProcessParams.bloom == true 		? postProcessParams.glareParams.downsamples : 0;
                int lensFlareDownsamples 	= postProcessParams.lensFlare == true 	? postProcessParams.lensFlareParams.downsamples : 0;
                int numDownsamples 			= Mathf.Max(bloomDownsamples, lensFlareDownsamples);

                m_bloomClass.RunDownsamplingChain(postProcessParams.halfResSource, numDownsamples, postProcessParams.glareParams.distanceMultiplier);
                downsampledGlareChainExists = true;
            }

            //Run lens flare generation first so that lens flares can access the downsampled textures from the downsampling chain
            //When the upsampling chain is run these textures are overwritten with gaussian blurred values (central limit therom)
            if (postProcessParams.lensFlare == true)
            {
                m_virtualCamera.BindVirtualCameraTextures(m_lensFlareClass.m_lensFlareMat);
                int numDownsamples = postProcessParams.lensFlareParams.downsamples;

                RenderTexture downsampledGlare = null;
                if (numDownsamples > 1) downsampledGlare = m_bloomClass.GetGlareTexture(numDownsamples-1);
                else if (numDownsamples == 1) downsampledGlare = postProcessParams.halfResSource;
                else downsampledGlare = source;

                postProcessParams.lensFlareTexture = m_lensFlareClass.RenderLensFlare(downsampledGlare, postProcessParams.lensFlareParams, source.width);
            }

            if (downsampledGlareChainExists == true && postProcessParams.exposure == true)
            {
                //Semi high value or logarithmic average works poorly (everything down to this limit is bilinearly downsampled)
                const int minimumReqPixels = 100;
                int numSearches;
                RenderTexture textureToAverage = m_bloomClass.TryGetSmallGlareTexture(minimumReqPixels, out numSearches);

                if (textureToAverage == null) { textureToAverage = postProcessParams.halfResSource; }
                m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, textureToAverage, postProcessParams.halfWidth, postProcessParams.preCalcValues.tanHalfFoV,
                                                       postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
            }
            else if (postProcessParams.exposure == true)
            {
                m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, postProcessParams.halfResSource, postProcessParams.halfWidth,
                                                       postProcessParams.preCalcValues.tanHalfFoV, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
            }

            if (postProcessParams.bloom == true)
            {
                //Run upsampling chain to create a gaussian blurred half res texture
                m_bloomClass.RunUpsamplingChain(postProcessParams.halfResSource);
                postProcessParams.bloomTexture = m_bloomClass.GetGlareTexture(0);
                postProcessParams.glareParams.bloomNormalizationTerm = m_bloomClass.GetEnergyNormalizer(postProcessParams.glareParams.downsamples);
            }

            //Graphics.Blit(source, dest);
            m_combinationPass.Combine(source, dest, postProcessParams, m_virtualCamera);
            m_scionDebug.VisualizeDebug(dest);

            RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
            RenderTexture.ReleaseTemporary(postProcessParams.dofTexture);

            m_bloomClass.EndOfFrameCleanup();
            m_virtualCamera.EndOfFrameCleanup();
            m_depthOfFieldClass.EndOfFrameCleanup();

            if (postProcessParams.lensFlare == true) RenderTexture.ReleaseTemporary(postProcessParams.lensFlareTexture);
            if (postProcessParams.depthOfField == true) RenderTexture.ReleaseTemporary(source);
        }
Beispiel #34
0
 private void SetShaderKeyWords(PostProcessParameters postProcessParams)
 {
     if (postProcessParams.cameraParams.cameraMode == CameraMode.Off || postProcessParams.cameraParams.cameraMode == CameraMode.Manual)
     {
         Debug.LogError("This functionality has been removed for The Forest to save on keywords!");
     }
     ColorGradingMode colorGradingMode = postProcessParams.colorGradingParams.colorGradingMode;
     if (colorGradingMode != ColorGradingMode.Off)
     {
         if (colorGradingMode == ColorGradingMode.On)
         {
             ShaderSettings.ColorGradingSettings.SetIndex(1);
         }
     }
     else
     {
         ShaderSettings.ColorGradingSettings.SetIndex(0);
     }
     if (postProcessParams.commonPostProcess.chromaticAberration)
     {
         ShaderSettings.ChromaticAberrationSettings.SetIndex(1);
     }
     else
     {
         ShaderSettings.ChromaticAberrationSettings.SetIndex(0);
     }
 }
Beispiel #35
0
        //This function is also responsible for downsampling the depth buffer and binding it
        protected RenderTexture DepthOfFieldStep(PostProcessParameters postProcessParams, RenderTexture source)
        {
            RenderTexture downsampledClrDepth = m_downsampling.DownsampleForDepthOfField(source);

            RenderTexture exclusionMask = null;
            if (postProcessParams.DoFParams.depthOfFieldMask != 0) //If objects are masked out
            {
                exclusionMask = m_depthOfFieldClass.RenderExclusionMask(postProcessParams.width, postProcessParams.height, postProcessParams.camera,
                                                                        postProcessParams.cameraTransform, postProcessParams.DoFParams.depthOfFieldMask);
                RenderTexture downsampledExclusionMask = m_downsampling.DownsampleMinFilter(source.width, source.height, exclusionMask);
                RenderTexture.ReleaseTemporary(exclusionMask);
                exclusionMask = downsampledExclusionMask;
                //ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(exclusionMask, false, false, false);
            }

            source = m_depthOfFieldClass.RenderDepthOfField(postProcessParams, source, downsampledClrDepth, m_virtualCamera, exclusionMask);

            //Downsample scene again, this time with DoF applied
            RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
            if (exclusionMask != null) RenderTexture.ReleaseTemporary(exclusionMask);

            return source;
        }
Beispiel #36
0
 private void SetupPostProcessParameters(PostProcessParameters postProcessParams, RenderTexture source)
 {
     this.focalDistance = ((this.focalDistance >= this.m_camera.nearClipPlane + 0.3f) ? this.focalDistance : (this.m_camera.nearClipPlane + 0.3f));
     postProcessParams.halfResSource = null;
     postProcessParams.halfResDepth = this.m_downsampling.DownsampleDepthTexture(source.width, source.height);
     postProcessParams.width = source.width;
     postProcessParams.height = source.height;
     postProcessParams.halfWidth = source.width / 2;
     postProcessParams.halfHeight = source.height / 2;
     if (this.prevCamFoV != this.m_camera.fieldOfView)
     {
         postProcessParams.preCalcValues.tanHalfFoV = Mathf.Tan(this.m_camera.fieldOfView * 0.5f * 0.0174532924f);
         this.prevCamFoV = this.m_camera.fieldOfView;
     }
     postProcessParams.DoFParams.useMedianFilter = true;
     if (!this.userControlledFocalLength)
     {
         postProcessParams.cameraParams.focalLength = ScionUtility.GetFocalLength(postProcessParams.preCalcValues.tanHalfFoV);
     }
     else
     {
         postProcessParams.cameraParams.focalLength = this.focalLength * 0.001f;
     }
     postProcessParams.cameraParams.apertureDiameter = ScionUtility.ComputeApertureDiameter(this.fNumber, postProcessParams.cameraParams.focalLength);
     postProcessParams.cameraParams.fieldOfView = this.m_camera.fieldOfView;
     postProcessParams.cameraParams.aspect = this.m_camera.aspect;
     postProcessParams.cameraParams.nearPlane = this.m_camera.nearClipPlane;
     postProcessParams.cameraParams.farPlane = this.m_camera.farClipPlane;
     postProcessParams.isFirstRender = this.m_isFirstRender;
     this.m_isFirstRender = false;
 }
Beispiel #37
0
        private void UploadVariables(PostProcessParameters postProcessParams)
        {
            Vector4 postProcessParams1 = new Vector4();
            postProcessParams1.x = postProcessParams.commonPostProcess.grainIntensity;
            postProcessParams1.y = postProcessParams.commonPostProcess.vignetteIntensity;
            postProcessParams1.z = postProcessParams.commonPostProcess.vignetteScale;
            postProcessParams1.w = postProcessParams.commonPostProcess.chromaticAberrationDistortion;
            m_combinationMat.SetVector("_PostProcessParams1", postProcessParams1);

            Vector4 postProcessParams2 = new Vector4();
            postProcessParams2.x = postProcessParams.commonPostProcess.vignetteColor.r;
            postProcessParams2.y = postProcessParams.commonPostProcess.vignetteColor.g;
            postProcessParams2.z = postProcessParams.commonPostProcess.vignetteColor.b;
            postProcessParams2.w = -postProcessParams.commonPostProcess.chromaticAberrationIntensity;
            m_combinationMat.SetVector("_PostProcessParams2", postProcessParams2);

            Vector4 postProcessParams3 = new Vector4();
            postProcessParams3.x = Random.value;
            postProcessParams3.y = ScionUtility.GetWhitePointMultiplier(postProcessParams.commonPostProcess.whitePoint);
            postProcessParams3.z = 1.0f / postProcessParams.commonPostProcess.whitePoint;
            m_combinationMat.SetVector("_PostProcessParams3", postProcessParams3);
        }
Beispiel #38
0
		private void UploadTemporalReprojectionVariables(PostProcessParameters postProcessParams)//Transform cameraTransform, float tanHalfFoV, float aspect, float farClipPlane)
		{
			float dy = postProcessParams.preCalcValues.tanHalfFoV;
			float dx = dy * postProcessParams.cameraParams.aspect;
			
			Vector3 centerVP 	= postProcessParams.cameraTransform.forward;
			Vector3 rightVP 	= postProcessParams.cameraTransform.right * dx;
			Vector3 upVP		= postProcessParams.cameraTransform.up * dy;
			
			m_DoFMatTemporal.SetVector("_FrustumCornerBottomLeftVP", centerVP - rightVP - upVP);
			m_DoFMatTemporal.SetVector("_FrustumCornerWidthVP", rightVP * 2.0f);
			m_DoFMatTemporal.SetVector("_FrustumCornerHeightVP", upVP * 2.0f);
			m_DoFMatTemporal.SetMatrix("_PreviousViewProjection", postProcessParams.cameraParams.previousViewProjection);

			float temporalBlend = postProcessParams.DoFParams.temporalBlend;
			m_DoFMatTemporal.SetFloat("_TemporalBlendFactor", temporalBlend);

			const float temporalIncrement = 1.372f;
			int temporalSteps = postProcessParams.DoFParams.temporalSteps;
			if (temporalSteps > 0) 
			{
				temporalUVOffset = temporalUVOffset + temporalIncrement;
				while (temporalUVOffset > temporalIncrement*temporalSteps - 0.01f) temporalUVOffset -= temporalIncrement*temporalSteps;
			}
			else temporalUVOffset = 0.0f;

			m_DoFMat.SetFloat("_TemporalUVOffset", temporalUVOffset);
		}
 protected override void SetShaderKeyWords(PostProcessParameters postProcessParams)
 {
     base.SetShaderKeyWords(postProcessParams);
 }
Beispiel #40
0
		private RenderTexture PrepatePointAverage(PostProcessParameters postProcessParams, RenderTexture downsampledClrDepth)
		{				
			const int weightedDownsamplePassID = 7;
			const int finalPassID = 8;
			const int visualizationPassID = 9;
			const int downsamplePassID = 10;
			const RenderTextureFormat format = RenderTextureFormat.RGHalf;
			const RenderTextureFormat format2 = RenderTextureFormat.RHalf;
			
			//Force at least 10x10 pixels to always effect the depth
			//Because stuff goes south if the circle is too small
			float range = Max(10.0f/postProcessParams.halfWidth, postProcessParams.DoFParams.pointAverageRange);
			
			Vector4 weightedDownsampleParams = new Vector4();
			weightedDownsampleParams.x = Mathf.Clamp01(postProcessParams.DoFParams.pointAveragePosition.x);
			weightedDownsampleParams.y = Mathf.Clamp01(postProcessParams.DoFParams.pointAveragePosition.y);
			weightedDownsampleParams.z = range*range;
			weightedDownsampleParams.w = 1.0f / (range*range);
			m_DoFMat.SetVector("_DownsampleWeightedParams", weightedDownsampleParams);
			
			if (previousPointAverage != null && postProcessParams.isFirstRender == false)
			{
#if UNITY_EDITOR
				if (UnityEditor.EditorApplication.isPlaying == false) m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1.0f);
				else
#endif
				{
					m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1.0f - Mathf.Exp(-Time.deltaTime * postProcessParams.DoFParams.depthAdaptionSpeed));
				}
				m_DoFMat.SetTexture("_PreviousWeightedResult", previousPointAverage);
			}
			else
			{
				m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1.0f);
				m_DoFMat.SetTexture("_PreviousWeightedResult", null);
			}
			
			downsampledClrDepth.filterMode = FilterMode.Bilinear;
			
			const int maxSize = 1;
			int texWidth = Max(postProcessParams.halfWidth / 2, maxSize);
			int texHeight = Max(postProcessParams.halfHeight / 2, maxSize);
			
			RenderTexture weightedDownsample = RenderTexture.GetTemporary(texWidth, texHeight, 0, format);
			weightedDownsample.filterMode = FilterMode.Bilinear;
			weightedDownsample.wrapMode = TextureWrapMode.Clamp;
			
			Graphics.Blit(downsampledClrDepth, weightedDownsample, m_DoFMat, weightedDownsamplePassID);
			
			if (postProcessParams.DoFParams.visualizePointFocus == true)
			{
				RenderTexture visTexture = RenderTexture.GetTemporary(texWidth, texHeight, 0, RenderTextureFormat.ARGB32);
				m_DoFMat.SetTexture("_HalfResSourceDepthTexture", downsampledClrDepth);
				Graphics.Blit(weightedDownsample, visTexture, m_DoFMat, visualizationPassID);
				//Graphics.Blit(visTexture, dest);
				//RenderTexture.ReleaseTemporary(visTexture);
				ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(visTexture, true, true, false);
			}
			
			RenderTexture input = weightedDownsample;
			int largestSide = Max(texWidth, texHeight);
			
			while (largestSide > maxSize)
			{
				texWidth = Max(maxSize, texWidth/2 + texWidth%2);
				texHeight = Max(maxSize, texHeight/2 + texHeight%2);
				largestSide = largestSide / 2 + largestSide%2;
				
				RenderTexture downsample;
				if (largestSide > maxSize)
				{
					downsample = RenderTexture.GetTemporary(texWidth, texHeight, 0, format);
					downsample.filterMode = FilterMode.Bilinear;
					downsample.wrapMode = TextureWrapMode.Clamp;
					Graphics.Blit(input, downsample, m_DoFMat, downsamplePassID);
				}
				else //Final pass
				{
					downsample = RenderTexture.GetTemporary(texWidth, texHeight, 0, format2);
					downsample.filterMode = FilterMode.Bilinear;
					downsample.wrapMode = TextureWrapMode.Clamp;
					Graphics.Blit(input, downsample, m_DoFMat, finalPassID);
				}
				
				RenderTexture.ReleaseTemporary(input);
				input = downsample;
			}
			
			RenderTexture pointAverage = input;
			if (previousPointAverage != null) RenderTexture.ReleaseTemporary(previousPointAverage);
			previousPointAverage = pointAverage;

			downsampledClrDepth.filterMode = FilterMode.Point;
			
			return pointAverage;
		}
Beispiel #41
0
        private RenderTexture PrepatePointAverage(PostProcessParameters postProcessParams, RenderTexture dest)
        {
            float   num   = this.Max(10f / (float)postProcessParams.halfResDepth.width, postProcessParams.DoFParams.pointAverageRange);
            Vector4 value = default(Vector4);

            value.x = Mathf.Clamp01(postProcessParams.DoFParams.pointAveragePosition.x);
            value.y = Mathf.Clamp01(postProcessParams.DoFParams.pointAveragePosition.y);
            value.z = num * num;
            value.w = 1f / (num * num);
            this.m_DoFMat.SetVector("_DownsampleWeightedParams", value);
            if (this.previousPointAverage != null && !postProcessParams.isFirstRender)
            {
                this.m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1f - Mathf.Exp(-Time.deltaTime * postProcessParams.DoFParams.depthAdaptionSpeed));
                this.m_DoFMat.SetTexture("_PreviousWeightedResult", this.previousPointAverage);
            }
            else
            {
                this.m_DoFMat.SetFloat("_DownsampleWeightedAdaptionSpeed", 1f);
                this.m_DoFMat.SetTexture("_PreviousWeightedResult", null);
            }
            postProcessParams.halfResDepth.filterMode = FilterMode.Bilinear;
            int           num2      = this.Max(postProcessParams.halfWidth / 2, 1);
            int           num3      = this.Max(postProcessParams.halfHeight / 2, 1);
            RenderTexture temporary = RenderTexture.GetTemporary(num2, num3, 0, RenderTextureFormat.RGHalf);

            temporary.filterMode = FilterMode.Bilinear;
            temporary.wrapMode   = TextureWrapMode.Clamp;
            Graphics.Blit(postProcessParams.halfResDepth, temporary, this.m_DoFMat, 7);
            if (postProcessParams.DoFParams.visualizePointFocus)
            {
                RenderTexture temporary2 = RenderTexture.GetTemporary(num2, num3, 0, RenderTextureFormat.ARGB32);
                Graphics.Blit(temporary, temporary2, this.m_DoFMat, 9);
                ScionPostProcess.ActiveDebug.RegisterTextureForVisualization(temporary2, true, true, false);
            }
            RenderTexture renderTexture = temporary;
            int           i             = this.Max(num2, num3);

            while (i > 1)
            {
                num2 = this.Max(1, num2 / 2 + num2 % 2);
                num3 = this.Max(1, num3 / 2 + num3 % 2);
                i    = i / 2 + i % 2;
                RenderTexture temporary3;
                if (i > 1)
                {
                    temporary3            = RenderTexture.GetTemporary(num2, num3, 0, RenderTextureFormat.RGHalf);
                    temporary3.filterMode = FilterMode.Bilinear;
                    temporary3.wrapMode   = TextureWrapMode.Clamp;
                    Graphics.Blit(renderTexture, temporary3, this.m_DoFMat, 10);
                }
                else
                {
                    temporary3            = RenderTexture.GetTemporary(num2, num3, 0, RenderTextureFormat.RHalf);
                    temporary3.filterMode = FilterMode.Bilinear;
                    temporary3.wrapMode   = TextureWrapMode.Clamp;
                    Graphics.Blit(renderTexture, temporary3, this.m_DoFMat, 8);
                }
                RenderTexture.ReleaseTemporary(renderTexture);
                renderTexture = temporary3;
            }
            RenderTexture result = renderTexture;

            if (this.previousPointAverage != null)
            {
                RenderTexture.ReleaseTemporary(this.previousPointAverage);
            }
            this.previousPointAverage = result;
            return(result);
        }
 protected override void SetShaderKeyWords(PostProcessParameters postProcessParams)
 {
     base.SetShaderKeyWords(postProcessParams);
 }