private RenderTexture BlurTapPass(RenderTexture halfResSource, RenderTexture tiledData, RenderTexture neighbourhoodData, RenderTexture exclusionMask, RenderTexture depthCenterAverage, DepthOfFieldQuality qualityLevel) { Material dofMat = qualityLevel == DepthOfFieldQuality.Normal ? m_DoFMat : m_DoFMatDX11; dofMat.SetTexture("_TiledData", tiledData); dofMat.SetTexture("_TiledNeighbourhoodData", neighbourhoodData); dofMat.SetTexture("_HalfResSourceTexture", halfResSource); //Actually the prefiltered half res if (exclusionMask != null) { dofMat.SetTexture("_ExclusionMask", exclusionMask); } if (depthCenterAverage != null) { dofMat.SetTexture("_AvgCenterDepth", depthCenterAverage); } halfResSource.filterMode = FilterMode.Point; RenderTexture blurTexture = RenderTexture.GetTemporary(halfResSource.width, halfResSource.height, 0, halfResSource.format); blurTexture.filterMode = FilterMode.Point; blurTexture.wrapMode = TextureWrapMode.Clamp; if (qualityLevel == DepthOfFieldQuality.Normal) { ScionGraphics.Blit(blurTexture, m_DoFMat, 5); } else if (qualityLevel == DepthOfFieldQuality.High_DX11) { ScionGraphics.Blit(blurTexture, m_DoFMatDX11, 0); } return(blurTexture); }
private RenderTexture BlurTapPass(RenderTexture halfResSource, RenderTexture tiledData, RenderTexture neighbourhoodData, RenderTexture depthCenterAverage, DepthOfFieldQuality qualityLevel) { Material material = (qualityLevel != DepthOfFieldQuality.Normal) ? this.m_DoFMatDX11 : this.m_DoFMat; material.SetTexture("_TiledData", tiledData); material.SetTexture("_TiledNeighbourhoodData", neighbourhoodData); material.SetTexture("_HalfResSourceTexture", halfResSource); if (depthCenterAverage != null) { material.SetTexture("_AvgCenterDepth", depthCenterAverage); } halfResSource.filterMode = FilterMode.Point; RenderTexture temporary = RenderTexture.GetTemporary(halfResSource.width, halfResSource.height, 0, halfResSource.format); temporary.filterMode = FilterMode.Point; temporary.wrapMode = TextureWrapMode.Clamp; if (qualityLevel == DepthOfFieldQuality.Normal) { ScionGraphics.Blit(temporary, this.m_DoFMat, 5); } else if (qualityLevel == DepthOfFieldQuality.High_DX11) { ScionGraphics.Blit(temporary, this.m_DoFMatDX11, 0); } return(temporary); }
public RenderTexture RenderExclusionMask(int width, int height, Camera camera, Transform cameraTransform, LayerMask mask) { //First copy entire depth buffer (it's horrible I know, but no other choice) copiedDepthBuffer = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.RHalf); ScionGraphics.Blit(copiedDepthBuffer, m_DoFMat, 15); Shader.SetGlobalTexture("_ScionCopiedFullResDepth", copiedDepthBuffer); RenderTexture exclusionMask = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.R8); exclusionMask.filterMode = FilterMode.Point; exclusionMask.wrapMode = TextureWrapMode.Clamp; maskCameraTransform.position = cameraTransform.position; maskCameraTransform.rotation = cameraTransform.rotation; maskCamera.CopyFrom(camera); maskCamera.cullingMask = mask; maskCamera.SetTargetBuffers(exclusionMask.colorBuffer, exclusionMask.depthBuffer); maskCamera.clearFlags = CameraClearFlags.SolidColor; maskCamera.backgroundColor = Color.white; maskCamera.renderingPath = RenderingPath.Forward; maskCamera.hdr = false; maskCamera.RenderWithShader(maskShader, "RenderType"); return(exclusionMask); }
private void TemporalPass(ref RenderTexture tapsTexture, ref RenderTexture alphaTexture, RenderTexture previousTapsTexture, RenderTexture previousAlphaTexture) { RenderTexture temporalTaps = RenderTexture.GetTemporary(tapsTexture.width, tapsTexture.height, 0, tapsTexture.format); temporalTaps.filterMode = FilterMode.Point; temporalTaps.wrapMode = TextureWrapMode.Clamp; RenderTexture temporalAlpha = RenderTexture.GetTemporary(alphaTexture.width, alphaTexture.height, 0, alphaTexture.format); temporalAlpha.filterMode = FilterMode.Point; temporalAlpha.wrapMode = TextureWrapMode.Clamp; previousTapsTexture.filterMode = FilterMode.Bilinear; previousAlphaTexture.filterMode = FilterMode.Bilinear; m_DoFMatTemporal.SetTexture("_TapsCurrentTexture", tapsTexture); m_DoFMatTemporal.SetTexture("_AlphaCurrentTexture", alphaTexture); m_DoFMatTemporal.SetTexture("_TapsHistoryTexture", previousTapsTexture); m_DoFMatTemporal.SetTexture("_AlphaHistoryTexture", previousAlphaTexture); renderBuffers[0] = temporalTaps.colorBuffer; renderBuffers[1] = temporalAlpha.colorBuffer; Graphics.SetRenderTarget(renderBuffers, temporalTaps.depthBuffer); ScionGraphics.Blit(m_DoFMatTemporal, 1); RenderTexture.ReleaseTemporary(tapsTexture); RenderTexture.ReleaseTemporary(alphaTexture); tapsTexture = temporalTaps; alphaTexture = temporalAlpha; }
public void CalculateVirtualCamera(CameraParameters cameraParams, RenderTexture textureToDownsample, float halfResWidth, float tanHalfFoV, float energyNormalizer, float focalDistance, bool isFirstRender) { if (cameraParams.cameraMode == CameraMode.Manual || cameraParams.cameraMode == CameraMode.Off) { return; } if (this.m_currentResult2 != null) { RenderTexture.ReleaseTemporary(this.m_currentResult2); this.m_currentResult2 = null; } this.BindVirtualCameraParams(this.m_virtualCameraMat, cameraParams, focalDistance, halfResWidth, isFirstRender); RenderTexture renderTexture = this.DownsampleTexture(textureToDownsample, energyNormalizer); this.m_virtualCameraMat.SetTexture("_DownsampledScene", renderTexture); if (this.m_previousExposureTexture != null) { this.m_virtualCameraMat.SetTexture("_PreviousExposureTexture", this.m_previousExposureTexture); } this.m_currentResult1 = RenderTexture.GetTemporary(1, 1, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); this.m_currentResult2 = RenderTexture.GetTemporary(1, 1, 0, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear); this.renderBuffers[0] = this.m_currentResult1.colorBuffer; this.renderBuffers[1] = this.m_currentResult2.colorBuffer; int passNr = cameraParams.cameraMode - CameraMode.AutoPriority; Graphics.SetRenderTarget(this.renderBuffers, this.m_currentResult1.depthBuffer); ScionGraphics.Blit(this.m_virtualCameraMat, passNr); RenderTexture.ReleaseTemporary(renderTexture); if (this.m_previousExposureTexture != null) { RenderTexture.ReleaseTemporary(this.m_previousExposureTexture); } this.m_previousExposureTexture = this.m_currentResult1; }
private RenderTexture CreateTiledData(RenderTexture halfResDepth, float tanHalfFoV, float fNumber, float focalDistance, float focalRange, float apertureDiameter, float focalLength, float maxCoCRadius, float nearPlane, float farPlane) { int tileWidth = halfResDepth.width / 10 + (halfResDepth.width % 10 == 0 ? 0 : 1); int tileHeight = halfResDepth.height / 10 + (halfResDepth.height % 10 == 0 ? 0 : 1); float CoCScale = apertureDiameter * focalLength * focalDistance / (focalDistance - focalLength); float CoCBias = -apertureDiameter * focalLength / (focalDistance - focalLength); float toPixels = ScionUtility.CoCToPixels(halfResDepth.width); CoCScale *= toPixels; CoCBias *= toPixels; Vector4 CoCParams1 = new Vector4(); CoCParams1.x = CoCScale; CoCParams1.y = CoCBias; CoCParams1.z = focalDistance; CoCParams1.w = focalRange * 0.5f; m_DoFMat.SetVector("_CoCParams1", CoCParams1); Vector4 CoCParams2 = new Vector4(); CoCParams2.x = maxCoCRadius * 0.5f; //We're in half res, so halve it CoCParams2.y = 1.0f / maxCoCRadius; m_DoFMat.SetVector("_CoCParams2", CoCParams2); if (m_DoFMatDX11 != null) { m_DoFMatDX11.SetVector("_CoCParams1", CoCParams1); m_DoFMatDX11.SetVector("_CoCParams2", CoCParams2); } m_DoFMat.SetFloat("_CoCUVOffset", 1.0f / halfResDepth.width); //Width for horizontal RenderTexture tiledDataHorizontal = RenderTexture.GetTemporary(tileWidth, halfResDepth.height, 0, RenderTextureFormat.RHalf); tiledDataHorizontal.filterMode = FilterMode.Point; tiledDataHorizontal.wrapMode = TextureWrapMode.Clamp; RenderTexture tiledData = RenderTexture.GetTemporary(tileWidth, tileHeight, 0, RenderTextureFormat.RHalf); tiledData.filterMode = FilterMode.Point; tiledData.wrapMode = TextureWrapMode.Clamp; halfResDepth.filterMode = FilterMode.Point; ScionGraphics.Blit(tiledDataHorizontal, m_DoFMat, 0); m_DoFMat.SetTexture("_HorizontalTileResult", tiledDataHorizontal); m_DoFMat.SetFloat("_CoCUVOffset", 1.0f / halfResDepth.height); //Height for vertical ScionGraphics.Blit(tiledData, m_DoFMat, 1); RenderTexture.ReleaseTemporary(tiledDataHorizontal); return(tiledData); }
public RenderTexture DownsampleDepthTexture(int width, int height) { int width2 = width / 2; int height2 = height / 2; RenderTexture temporary = RenderTexture.GetTemporary(width2, height2, 0, RenderTextureFormat.RHalf); temporary.filterMode = FilterMode.Point; temporary.wrapMode = TextureWrapMode.Clamp; ScionGraphics.Blit(temporary, this.m_downsampleMat, 2); return(temporary); }
private RenderTexture PrefilterSource(RenderTexture halfResSource) { this.m_DoFMat.SetTexture("_HalfResSourceTexture", halfResSource); halfResSource.filterMode = FilterMode.Point; RenderTexture temporary = RenderTexture.GetTemporary(halfResSource.width, halfResSource.height, 0, halfResSource.format); temporary.filterMode = FilterMode.Point; temporary.wrapMode = TextureWrapMode.Clamp; ScionGraphics.Blit(temporary, this.m_DoFMat, 4); return(temporary); }
private RenderTexture PrefilterSource(RenderTexture halfResSource) { m_DoFMat.SetTexture("_HalfResSourceTexture", halfResSource); halfResSource.filterMode = FilterMode.Bilinear; RenderTexture prefilteredSource = RenderTexture.GetTemporary(halfResSource.width, halfResSource.height, 0, halfResSource.format); prefilteredSource.filterMode = FilterMode.Point; prefilteredSource.wrapMode = TextureWrapMode.Clamp; ScionGraphics.Blit(prefilteredSource, m_DoFMat, 4); return(prefilteredSource); }
private RenderTexture UpsampleDepthOfField(RenderTexture source, RenderTexture depthOfFieldTexture, RenderTexture neighbourhoodData) { this.m_DoFMat.SetTexture("_DepthOfFieldTexture", depthOfFieldTexture); this.m_DoFMat.SetTexture("_FullResolutionSource", source); this.m_DoFMat.SetTexture("_TiledNeighbourhoodData", neighbourhoodData); neighbourhoodData.filterMode = FilterMode.Bilinear; RenderTexture temporary = RenderTexture.GetTemporary(source.width, source.height, 0, source.format); source.filterMode = FilterMode.Point; source.wrapMode = TextureWrapMode.Clamp; ScionGraphics.Blit(temporary, this.m_DoFMat, 6); return(temporary); }
private RenderTexture PrefilterSource(RenderTexture downsampledClrDepth) { m_DoFMat.SetTexture("_HalfResSourceDepthTexture", downsampledClrDepth); downsampledClrDepth.filterMode = FilterMode.Point; RenderTexture prefilteredSource = RenderTexture.GetTemporary(downsampledClrDepth.width, downsampledClrDepth.height, 0, downsampledClrDepth.format); prefilteredSource.filterMode = FilterMode.Point; prefilteredSource.wrapMode = TextureWrapMode.Clamp; ScionGraphics.Blit(prefilteredSource, m_DoFMat, 4); return(prefilteredSource); }
public RenderTexture DownsampleDepthTexture(int width, int height) { int halfWidth = width / 2; int halfHeight = height / 2; RenderTexture downsampled = RenderTexture.GetTemporary(halfWidth, halfHeight, 0, RenderTextureFormat.RHalf); downsampled.filterMode = FilterMode.Point; downsampled.wrapMode = TextureWrapMode.Clamp; ScionGraphics.Blit(downsampled, m_downsampleMat, DepthPass); return(downsampled); }
private RenderTexture Presort(RenderTexture downsampledClrDepth, RenderTexture neighbourhoodData) { RenderTexture presort = RenderTexture.GetTemporary(downsampledClrDepth.width, downsampledClrDepth.height, 0, RenderTextureFormat.ARGB2101010); presort.filterMode = FilterMode.Point; presort.wrapMode = TextureWrapMode.Clamp; m_DoFMat.SetTexture("_HalfResSourceDepthTexture", downsampledClrDepth); m_DoFMat.SetTexture("_TiledNeighbourhoodData", neighbourhoodData); ScionGraphics.Blit(presort, m_DoFMat, 11); return(presort); }
private void VisualizeFocalDistance(RenderTexture downsampledClrDepth) { const int visualizationPassID = 13; RenderTexture visualized = RenderTexture.GetTemporary(downsampledClrDepth.width, downsampledClrDepth.height, 0, RenderTextureFormat.ARGB32); visualized.filterMode = FilterMode.Bilinear; visualized.wrapMode = TextureWrapMode.Clamp; m_DoFMat.SetTexture("_HalfResSourceDepthTexture", downsampledClrDepth); ScionGraphics.Blit(visualized, m_DoFMat, visualizationPassID); ScionPostProcessBase.ActiveDebug.RegisterTextureForVisualization(visualized, true); }
private RenderTexture TileNeighbourhoodDataGathering(RenderTexture tiledData) { Vector4 value = default(Vector4); value.x = 1f / (float)tiledData.width; value.y = 1f / (float)tiledData.height; this.m_DoFMat.SetVector("_NeighbourhoodParams", value); RenderTexture temporary = RenderTexture.GetTemporary(tiledData.width, tiledData.height, 0, RenderTextureFormat.RHalf); temporary.filterMode = FilterMode.Point; temporary.wrapMode = TextureWrapMode.Clamp; this.m_DoFMat.SetTexture("_TiledData", tiledData); ScionGraphics.Blit(temporary, this.m_DoFMat, 2); return(temporary); }
private void TemporalPass(ref RenderTexture tapsTexture, RenderTexture previousTapsTexture) { RenderTexture temporalTaps = RenderTexture.GetTemporary(tapsTexture.width, tapsTexture.height, 0, tapsTexture.format); temporalTaps.filterMode = FilterMode.Point; temporalTaps.wrapMode = TextureWrapMode.Clamp; previousTapsTexture.filterMode = FilterMode.Bilinear; m_DoFMatTemporal.SetTexture("_TapsCurrentTexture", tapsTexture); m_DoFMatTemporal.SetTexture("_TapsHistoryTexture", previousTapsTexture); ScionGraphics.Blit(temporalTaps, m_DoFMatTemporal, 0); RenderTexture.ReleaseTemporary(tapsTexture); tapsTexture = temporalTaps; }
//RGB: Color, A: Depth public RenderTexture DownsampleForDepthOfField(RenderTexture source) { int halfWidth = source.width / 2; int halfHeight = source.height / 2; RenderTexture downsampled = RenderTexture.GetTemporary(halfWidth, halfHeight, 0, RenderTextureFormat.ARGBHalf); downsampled.filterMode = FilterMode.Point; downsampled.wrapMode = TextureWrapMode.Clamp; source.filterMode = FilterMode.Point; source.wrapMode = TextureWrapMode.Clamp; m_downsampleMat.SetTexture("_MainTex", source); ScionGraphics.Blit(downsampled, m_downsampleMat, DoFDownsamplePass); return(downsampled); }
private RenderTexture TileNeighbourhoodDataGathering(RenderTexture tiledData) { Vector4 neighbourhoodParams = new Vector4(); neighbourhoodParams.x = 1.0f / tiledData.width; neighbourhoodParams.y = 1.0f / tiledData.height; m_DoFMat.SetVector("_NeighbourhoodParams", neighbourhoodParams); RenderTexture neighbourhoodData = RenderTexture.GetTemporary(tiledData.width, tiledData.height, 0, RenderTextureFormat.RGHalf); neighbourhoodData.filterMode = FilterMode.Point; neighbourhoodData.wrapMode = TextureWrapMode.Clamp; m_DoFMat.SetTexture("_TiledData", tiledData); ScionGraphics.Blit(neighbourhoodData, m_DoFMat, 2); return(neighbourhoodData); }
public void HexagonalBlur(RenderTexture lensFlareTex, LensFlareBlurSamples blurSamples) { if (blurSamples == LensFlareBlurSamples.Off) { return; } int blurPass1ID = blurSamples == LensFlareBlurSamples.x4 ? 0 : 1; int blurPass2ID = blurSamples == LensFlareBlurSamples.x4 ? 2 : 3; RenderTexture blurTarget0 = RenderTexture.GetTemporary(lensFlareTex.width, lensFlareTex.height, 0, lensFlareTex.format, RenderTextureReadWrite.Linear); RenderTexture blurTarget1 = RenderTexture.GetTemporary(lensFlareTex.width, lensFlareTex.height, 0, lensFlareTex.format, RenderTextureReadWrite.Linear); lensFlareTex.filterMode = FilterMode.Bilinear; blurTarget0.filterMode = FilterMode.Bilinear; blurTarget1.filterMode = FilterMode.Bilinear; targetBuffers[0] = blurTarget0.colorBuffer; targetBuffers[1] = blurTarget1.colorBuffer; Graphics.SetRenderTarget(targetBuffers, blurTarget0.depthBuffer); m_lensFlareMat.SetTexture("_MainTex", lensFlareTex); ScionGraphics.Blit(m_lensFlareMat, blurPass1ID); m_lensFlareMat.SetTexture("_BlurTexture1", blurTarget1); Graphics.Blit(blurTarget0, lensFlareTex, m_lensFlareMat, blurPass2ID); //Graphics.Blit(blurTarget0, lensFlareTex); //ScionPostProcessBase.ActiveDebug.RegisterTextureForVisualization(blurTarget0, false); RenderTexture.ReleaseTemporary(blurTarget0); RenderTexture.ReleaseTemporary(blurTarget1); // uniform sampler2D _BlurTexture1; // // // First blur pass. // // texture0 - output of CalculateCoCSize // BlurOutput BlurPass1(v2f i) // // texture0 - SV_Target0 from BlurPass1 // // texture1 - SV_Target1 from BlurPass1 // float4 BlurPass2(v2f i) : SV_Target0 }
private RenderTexture CreateTiledData(RenderTexture halfResDepth, float tanHalfFoV, float fNumber, float focalDistance, float focalRange, float apertureDiameter, float focalLength, float maxCoCRadius, float nearPlane, float farPlane) { int width = halfResDepth.width / 10 + ((halfResDepth.width % 10 != 0) ? 1 : 0); int height = halfResDepth.height / 10 + ((halfResDepth.height % 10 != 0) ? 1 : 0); float num = apertureDiameter * focalLength * focalDistance / (focalDistance - focalLength); float num2 = -apertureDiameter * focalLength / (focalDistance - focalLength); float num3 = ScionUtility.CoCToPixels((float)halfResDepth.width); num *= num3; num2 *= num3; Vector4 value = default(Vector4); value.x = num; value.y = num2; value.z = focalDistance; value.w = focalRange * 0.5f; this.m_DoFMat.SetVector("_CoCParams1", value); Vector4 value2 = default(Vector4); value2.x = maxCoCRadius * 0.5f; value2.y = 1f / maxCoCRadius; this.m_DoFMat.SetVector("_CoCParams2", value2); if (this.m_DoFMatDX11 != null) { this.m_DoFMatDX11.SetVector("_CoCParams1", value); this.m_DoFMatDX11.SetVector("_CoCParams2", value2); } this.m_DoFMat.SetFloat("_CoCUVOffset", 1f / (float)halfResDepth.width); RenderTexture temporary = RenderTexture.GetTemporary(width, halfResDepth.height, 0, RenderTextureFormat.RHalf); temporary.filterMode = FilterMode.Point; temporary.wrapMode = TextureWrapMode.Clamp; RenderTexture temporary2 = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.RHalf); temporary2.filterMode = FilterMode.Point; temporary2.wrapMode = TextureWrapMode.Clamp; halfResDepth.filterMode = FilterMode.Point; ScionGraphics.Blit(temporary, this.m_DoFMat, 0); this.m_DoFMat.SetTexture("_HorizontalTileResult", temporary); this.m_DoFMat.SetFloat("_CoCUVOffset", 1f / (float)halfResDepth.height); ScionGraphics.Blit(temporary2, this.m_DoFMat, 1); RenderTexture.ReleaseTemporary(temporary); return(temporary2); }
private RenderTexture UpsampleDepthOfField(RenderTexture source, RenderTexture depthOfFieldTexture, RenderTexture neighbourhoodData, RenderTexture exclusionMask) { m_DoFMat.SetTexture("_DepthOfFieldTexture", depthOfFieldTexture); m_DoFMat.SetTexture("_FullResolutionSource", source); m_DoFMat.SetTexture("_TiledNeighbourhoodData", neighbourhoodData); if (exclusionMask != null) { m_DoFMat.SetTexture("_ExclusionMask", exclusionMask); } neighbourhoodData.filterMode = FilterMode.Bilinear; RenderTexture compositedDoF = RenderTexture.GetTemporary(source.width, source.height, 0, source.format); source.filterMode = FilterMode.Point; source.wrapMode = TextureWrapMode.Clamp; ScionGraphics.Blit(compositedDoF, m_DoFMat, 6); return(compositedDoF); }
private void BlurTapPass(RenderTexture prefilteredSource, RenderTexture tiledData, RenderTexture neighbourhoodData, RenderTexture exclusionMask, RenderTexture depthCenterAverage, RenderTexture presortTexture, DepthOfFieldSamples qualityLevel, out RenderTexture tapsTexture, out RenderTexture alphaTexture) { m_DoFMat.SetTexture("_TiledData", tiledData); m_DoFMat.SetTexture("_TiledNeighbourhoodData", neighbourhoodData); m_DoFMat.SetTexture("_HalfResSourceDepthTexture", prefilteredSource); //Actually the prefiltered half res m_DoFMat.SetTexture("_PresortTexture", presortTexture); if (exclusionMask != null) { m_DoFMat.SetTexture("_ExclusionMask", exclusionMask); } if (depthCenterAverage != null) { m_DoFMat.SetTexture("_AvgCenterDepth", depthCenterAverage); } prefilteredSource.filterMode = FilterMode.Point; tapsTexture = RenderTexture.GetTemporary(prefilteredSource.width, prefilteredSource.height, 0, prefilteredSource.format); tapsTexture.filterMode = FilterMode.Point; tapsTexture.wrapMode = TextureWrapMode.Clamp; alphaTexture = RenderTexture.GetTemporary(prefilteredSource.width, prefilteredSource.height, 0, RenderTextureFormat.R8); alphaTexture.filterMode = FilterMode.Point; alphaTexture.wrapMode = TextureWrapMode.Clamp; renderBuffers[0] = tapsTexture.colorBuffer; renderBuffers[1] = alphaTexture.colorBuffer; Graphics.SetRenderTarget(renderBuffers, tapsTexture.depthBuffer); if (qualityLevel == DepthOfFieldSamples.Normal_25) { ScionGraphics.Blit(m_DoFMat, 12); } if (qualityLevel == DepthOfFieldSamples.High_49) { ScionGraphics.Blit(m_DoFMat, 5); } }
public void HexagonalBlur(RenderTexture lensFlareTex, LensFlareBlurSamples blurSamples) { if (blurSamples == LensFlareBlurSamples.Off) { return; } int passNr = (blurSamples != LensFlareBlurSamples.x4) ? 1 : 0; int pass = (blurSamples != LensFlareBlurSamples.x4) ? 3 : 2; RenderTexture temporary = RenderTexture.GetTemporary(lensFlareTex.width, lensFlareTex.height, 0, lensFlareTex.format, RenderTextureReadWrite.Linear); RenderTexture temporary2 = RenderTexture.GetTemporary(lensFlareTex.width, lensFlareTex.height, 0, lensFlareTex.format, RenderTextureReadWrite.Linear); lensFlareTex.filterMode = FilterMode.Bilinear; temporary.filterMode = FilterMode.Bilinear; temporary2.filterMode = FilterMode.Bilinear; this.targetBuffers[0] = temporary.colorBuffer; this.targetBuffers[1] = temporary2.colorBuffer; Graphics.SetRenderTarget(this.targetBuffers, temporary.depthBuffer); this.m_lensFlareMat.SetTexture("_MainTex", lensFlareTex); ScionGraphics.Blit(this.m_lensFlareMat, passNr); this.m_lensFlareMat.SetTexture("_BlurTexture1", temporary2); Graphics.Blit(temporary, lensFlareTex, this.m_lensFlareMat, pass); RenderTexture.ReleaseTemporary(temporary); RenderTexture.ReleaseTemporary(temporary2); }
public void CalculateVirtualCamera(CameraParameters cameraParams, RenderTexture textureToDownsample, float halfResWidth, float tanHalfFoV, float focalDistance, bool isFirstRender) { if (cameraParams.cameraMode == CameraMode.Manual || cameraParams.cameraMode == CameraMode.Off) { return; } if (m_currentResult2 != null) { RenderTexture.ReleaseTemporary(m_currentResult2); m_currentResult2 = null; } BindVirtualCameraParams(m_virtualCameraMat, cameraParams, focalDistance, halfResWidth, isFirstRender); RenderTexture downsampledScene = DownsampleTexture(textureToDownsample); m_virtualCameraMat.SetTexture("_DownsampledScene", downsampledScene); if (m_previousExposureTexture != null) { m_virtualCameraMat.SetTexture("_PreviousExposureTexture", m_previousExposureTexture); } m_currentResult1 = RenderTexture.GetTemporary(1, 1, 0, VCTextureFormat, RenderTextureReadWrite.Linear); m_currentResult2 = RenderTexture.GetTemporary(1, 1, 0, VCTextureFormat, RenderTextureReadWrite.Linear); renderBuffers[0] = m_currentResult1.colorBuffer; renderBuffers[1] = m_currentResult2.colorBuffer; int passIndex = (int)cameraParams.cameraMode - 2; Graphics.SetRenderTarget(renderBuffers, m_currentResult1.depthBuffer); ScionGraphics.Blit(m_virtualCameraMat, passIndex); // struct CameraOutput // { // float sceneLuminance; // float shutterSpeed; // float ISO; // float fNumber; // float exposure; // float2 CoCScaleAndBias; // float notUsed; // }; // if (readBfr == null) readBfr = new ComputeBuffer(2, 16); // if (readVec == null) readVec = new Vector4[2]; // ComputeShader shdr = HelpScript.HelpShader; // shdr.SetTexture(0, "ReadTexture1", m_currentResult1); // shdr.SetTexture(0, "ReadTexture2", m_currentResult2); // shdr.SetBuffer(0, "ReadBackBuffer", readBfr); // shdr.Dispatch(0,1,1,1); // readBfr.GetData(readVec); // Debug.Log("sceneLuminance: " + readVec[0].x + // "\nshutterSpeed: " + readVec[0].y + // "\nISO: " + readVec[0].z + // "\nfNumber: " + readVec[0].w + // "\nexposure: " + readVec[1].x + // "\nCoC scale: " + readVec[1].y + // "\nCoC bias: " + readVec[1].z + // "\ntargetEV: " + readVec[1].w); RenderTexture.ReleaseTemporary(downsampledScene); if (m_previousExposureTexture != null) { RenderTexture.ReleaseTemporary(m_previousExposureTexture); } m_previousExposureTexture = m_currentResult1; }