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; }
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); }
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)); } }
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); }
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; }
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); }