public void ApplyBokehFilter(RenderTexture source, Material material) { for (int i = 0; i < this.m_bokehOffsets.Count; i++) { this.m_bokehOffsets[i].BokehRenderTexture = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } material.SetVector(AmplifyUtils.BokehParamsId, this.m_bokehCameraProperties); for (int j = 0; j < this.m_bokehOffsets.Count; j++) { for (int k = 0; k < 8; k++) { material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[k], this.m_bokehOffsets[j].Offsets[k]); } Graphics.Blit(source, this.m_bokehOffsets[j].BokehRenderTexture, material, 27); } for (int l = 0; l < this.m_bokehOffsets.Count - 1; l++) { material.SetTexture(AmplifyUtils.AnamorphicRTS[l], this.m_bokehOffsets[l].BokehRenderTexture); } source.DiscardContents(); Graphics.Blit(this.m_bokehOffsets[this.m_bokehOffsets.Count - 1].BokehRenderTexture, source, material, 28 + (this.m_bokehOffsets.Count - 2)); for (int m = 0; m < this.m_bokehOffsets.Count; m++) { AmplifyUtils.ReleaseTempRenderTarget(this.m_bokehOffsets[m].BokehRenderTexture); this.m_bokehOffsets[m].BokehRenderTexture = null; } }
private void ApplyGaussianBlur(RenderTexture renderTexture, int amount, float radius = 1f, bool applyTemporal = false) { if (amount == 0) { return; } this.m_bloomMaterial.SetFloat(AmplifyUtils.BlurRadiusId, radius); RenderTexture tempRenderTarget = AmplifyUtils.GetTempRenderTarget(renderTexture.width, renderTexture.height); for (int i = 0; i < amount; i++) { tempRenderTarget.DiscardContents(); Graphics.Blit(renderTexture, tempRenderTarget, this.m_bloomMaterial, 14); if (this.m_temporalFilteringActive && applyTemporal && i == amount - 1) { if (this.m_tempFilterBuffer != null && this.m_temporalFilteringActive) { float value = this.m_temporalFilteringCurve.Evaluate(this.m_temporalFilteringValue); this.m_bloomMaterial.SetFloat(AmplifyUtils.TempFilterValueId, value); this.m_bloomMaterial.SetTexture(AmplifyUtils.AnamorphicRTS[0], this.m_tempFilterBuffer); renderTexture.DiscardContents(); Graphics.Blit(tempRenderTarget, renderTexture, this.m_bloomMaterial, 16); } else { renderTexture.DiscardContents(); Graphics.Blit(tempRenderTarget, renderTexture, this.m_bloomMaterial, 15); } bool flag = false; if (this.m_tempFilterBuffer != null) { if (this.m_tempFilterBuffer.format != renderTexture.format || this.m_tempFilterBuffer.width != renderTexture.width || this.m_tempFilterBuffer.height != renderTexture.height) { this.CleanTempFilterRT(); flag = true; } } else { flag = true; } if (flag) { this.CreateTempFilterRT(renderTexture); } this.m_tempFilterBuffer.DiscardContents(); Graphics.Blit(renderTexture, this.m_tempFilterBuffer); } else { renderTexture.DiscardContents(); Graphics.Blit(tempRenderTarget, renderTexture, this.m_bloomMaterial, 15); } } AmplifyUtils.ReleaseTempRenderTarget(tempRenderTarget); }
public RenderTexture ApplyFlare(Material material, RenderTexture source) { RenderTexture tempRenderTarget = AmplifyUtils.GetTempRenderTarget(source.width, source.height); material.SetVector(AmplifyUtils.LensFlareGhostsParamsId, this.m_lensFlareGhostsParams); material.SetTexture(AmplifyUtils.LensFlareLUTId, this.m_lensFlareGradTexture); material.SetVector(AmplifyUtils.LensFlareHaloParamsId, this.m_lensFlareHaloParams); material.SetFloat(AmplifyUtils.LensFlareGhostChrDistortionId, this.m_lensFlareGhostChrDistortion); material.SetFloat(AmplifyUtils.LensFlareHaloChrDistortionId, this.m_lensFlareHaloChrDistortion); Graphics.Blit(source, tempRenderTarget, material, 3 + this.m_lensFlareGhostAmount); return(tempRenderTarget); }
public void OnRenderFromCache(RenderTexture source, RenderTexture dest, Material material, float glareIntensity, float cameraRotation) { // ALLOCATE RENDER TEXTURES for (int i = 0; i < m_amplifyGlareCache.TotalRT; i++) { _rtBuffer[i] = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } int rtIdx = 0; for (int d = 0; d < m_amplifyGlareCache.StarDef.StarlinesCount; d++) { for (int p = 0; p < m_amplifyGlareCache.CurrentPassCount; p++) { // APPLY SHADER UpdateMatrixesForPass(material, m_amplifyGlareCache.Starlines[d].Passes[p].Offsets, m_amplifyGlareCache.Starlines[d].Passes[p].Weights, glareIntensity, cameraRotation * m_amplifyGlareCache.StarDef.CameraRotInfluence); //CREATED WEIGHTED TEXTURE if (p == 0) { Graphics.Blit(source, _rtBuffer[rtIdx], material, ( int )BloomPasses.AnamorphicGlare); } else { Graphics.Blit(_rtBuffer[rtIdx - 1], _rtBuffer[rtIdx], material, ( int )BloomPasses.AnamorphicGlare); } rtIdx += 1; } } //ADD TO MAIN RT for (int i = 0; i < m_amplifyGlareCache.StarDef.StarlinesCount; i++) { material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[i], m_amplifyGlareCache.AverageWeight); int idx = (i + 1) * m_amplifyGlareCache.CurrentPassCount - 1; material.SetTexture(AmplifyUtils.AnamorphicRTS[i], _rtBuffer[idx]); } int passId = ( int )BloomPasses.WeightedAddPS1 + m_amplifyGlareCache.StarDef.StarlinesCount - 1; dest.DiscardContents(); Graphics.Blit(_rtBuffer[0], dest, material, passId); //RELEASE RT's for (rtIdx = 0; rtIdx < _rtBuffer.Length; rtIdx++) { AmplifyUtils.ReleaseTempRenderTarget(_rtBuffer[rtIdx]); _rtBuffer[rtIdx] = null; } }
public void OnRenderFromCache(RenderTexture source, RenderTexture dest, Material material, float glareIntensity, float cameraRotation) { for (int i = 0; i < this.m_amplifyGlareCache.TotalRT; i++) { this._rtBuffer[i] = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } int index = 0; int num3 = 0; while (num3 < this.m_amplifyGlareCache.StarDef.StarlinesCount) { int num4 = 0; while (true) { if (num4 >= this.m_amplifyGlareCache.CurrentPassCount) { num3++; break; } this.UpdateMatrixesForPass(material, this.m_amplifyGlareCache.Starlines[num3].Passes[num4].Offsets, this.m_amplifyGlareCache.Starlines[num3].Passes[num4].Weights, glareIntensity, cameraRotation * this.m_amplifyGlareCache.StarDef.CameraRotInfluence); if (num4 == 0) { Graphics.Blit(source, this._rtBuffer[index], material, 2); } else { Graphics.Blit(this._rtBuffer[index - 1], this._rtBuffer[index], material, 2); } index++; num4++; } } for (int j = 0; j < this.m_amplifyGlareCache.StarDef.StarlinesCount; j++) { material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[j], this.m_amplifyGlareCache.AverageWeight); int num6 = ((j + 1) * this.m_amplifyGlareCache.CurrentPassCount) - 1; material.SetTexture(AmplifyUtils.AnamorphicRTS[j], this._rtBuffer[num6]); } int pass = (0x13 + this.m_amplifyGlareCache.StarDef.StarlinesCount) - 1; dest.DiscardContents(); Graphics.Blit(this._rtBuffer[0], dest, material, pass); for (index = 0; index < this._rtBuffer.Length; index++) { AmplifyUtils.ReleaseTempRenderTarget(this._rtBuffer[index]); this._rtBuffer[index] = null; } }
void ApplyUpscale() { int beginIdx = (m_bloomDownsampleCount - 1); int upscaleIdx = 0; for (int downscaleIdx = beginIdx; downscaleIdx > -1; downscaleIdx--) { m_tempUpscaleRTs[upscaleIdx] = AmplifyUtils.GetTempRenderTarget(( int )m_tempDownsamplesSizes[downscaleIdx].x, ( int )m_tempDownsamplesSizes[downscaleIdx].y); if (downscaleIdx == beginIdx) { Graphics.Blit(m_tempAuxDownsampleRTs[beginIdx], m_tempUpscaleRTs[upscaleIdx], m_bloomMaterial, ( int )BloomPasses.UpscaleFirstPass); } else { m_bloomMaterial.SetTexture(AmplifyUtils.AnamorphicRTS[0], m_tempUpscaleRTs[upscaleIdx - 1]); Graphics.Blit(m_tempAuxDownsampleRTs[downscaleIdx], m_tempUpscaleRTs[upscaleIdx], m_bloomMaterial, ( int )BloomPasses.Upscale); } upscaleIdx++; } }
private void ApplyUpscale() { int num = this.m_bloomDownsampleCount - 1; int num2 = 0; for (int i = num; i > -1; i--) { this.m_tempUpscaleRTs[num2] = AmplifyUtils.GetTempRenderTarget((int)this.m_tempDownsamplesSizes[i].x, (int)this.m_tempDownsamplesSizes[i].y); if (i == num) { Graphics.Blit(this.m_tempAuxDownsampleRTs[num], this.m_tempUpscaleRTs[num2], this.m_bloomMaterial, 17); } else { this.m_bloomMaterial.SetTexture(AmplifyUtils.AnamorphicRTS[0], this.m_tempUpscaleRTs[num2 - 1]); Graphics.Blit(this.m_tempAuxDownsampleRTs[i], this.m_tempUpscaleRTs[num2], this.m_bloomMaterial, 18); } num2++; } }
public void OnRenderFromCache(RenderTexture source, RenderTexture dest, Material material, float glareIntensity, float cameraRotation) { for (int i = 0; i < this.m_amplifyGlareCache.TotalRT; i++) { this._rtBuffer[i] = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } int j = 0; for (int k = 0; k < this.m_amplifyGlareCache.StarDef.StarlinesCount; k++) { for (int l = 0; l < this.m_amplifyGlareCache.CurrentPassCount; l++) { this.UpdateMatrixesForPass(material, this.m_amplifyGlareCache.Starlines[k].Passes[l].Offsets, this.m_amplifyGlareCache.Starlines[k].Passes[l].Weights, glareIntensity, cameraRotation * this.m_amplifyGlareCache.StarDef.CameraRotInfluence); if (l == 0) { Graphics.Blit(source, this._rtBuffer[j], material, 2); } else { Graphics.Blit(this._rtBuffer[j - 1], this._rtBuffer[j], material, 2); } j++; } } for (int m = 0; m < this.m_amplifyGlareCache.StarDef.StarlinesCount; m++) { material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[m], this.m_amplifyGlareCache.AverageWeight); int num = (m + 1) * this.m_amplifyGlareCache.CurrentPassCount - 1; material.SetTexture(AmplifyUtils.AnamorphicRTS[m], this._rtBuffer[num]); } int pass = 19 + this.m_amplifyGlareCache.StarDef.StarlinesCount - 1; dest.DiscardContents(); Graphics.Blit(this._rtBuffer[0], dest, material, pass); for (j = 0; j < this._rtBuffer.Length; j++) { AmplifyUtils.ReleaseTempRenderTarget(this._rtBuffer[j]); this._rtBuffer[j] = null; } }
public void ApplyBokehFilter(RenderTexture source, Material material) { for (int i = 0; i < this.m_bokehOffsets.Count; i++) { this.m_bokehOffsets[i].BokehRenderTexture = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } material.SetVector(AmplifyUtils.BokehParamsId, this.m_bokehCameraProperties); int num2 = 0; while (num2 < this.m_bokehOffsets.Count) { int index = 0; while (true) { if (index >= 8) { Graphics.Blit(source, this.m_bokehOffsets[num2].BokehRenderTexture, material, 0x1b); num2++; break; } material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[index], this.m_bokehOffsets[num2].Offsets[index]); index++; } } for (int j = 0; j < (this.m_bokehOffsets.Count - 1); j++) { material.SetTexture(AmplifyUtils.AnamorphicRTS[j], this.m_bokehOffsets[j].BokehRenderTexture); } source.DiscardContents(); Graphics.Blit(this.m_bokehOffsets[this.m_bokehOffsets.Count - 1].BokehRenderTexture, source, material, 0x1c + (this.m_bokehOffsets.Count - 2)); for (int k = 0; k < this.m_bokehOffsets.Count; k++) { AmplifyUtils.ReleaseTempRenderTarget(this.m_bokehOffsets[k].BokehRenderTexture); this.m_bokehOffsets[k].BokehRenderTexture = null; } }
public void ApplyBokehFilter(RenderTexture source, Material material) { // ALLOCATE RENDER TEXTURES for (int i = 0; i < m_bokehOffsets.Count; i++) { m_bokehOffsets[i].BokehRenderTexture = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } // SET CAMERA PARAMS AND APPLY EACH ROTATIONAL WEIGHTS material.SetVector(AmplifyUtils.BokehParamsId, m_bokehCameraProperties); for (int bId = 0; bId < m_bokehOffsets.Count; bId++) { for (int i = 0; i < PerPassSampleCount; i++) { material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[i], m_bokehOffsets[bId].Offsets[i]); } Graphics.Blit(source, m_bokehOffsets[bId].BokehRenderTexture, material, ( int )BloomPasses.BokehWeightedBlur); } for (int bId = 0; bId < m_bokehOffsets.Count - 1; bId++) { material.SetTexture(AmplifyUtils.AnamorphicRTS[bId], m_bokehOffsets[bId].BokehRenderTexture); } // FINAL COMPOSITION source.DiscardContents(); Graphics.Blit(m_bokehOffsets[m_bokehOffsets.Count - 1].BokehRenderTexture, source, material, ( int )BloomPasses.BokehComposition2S + (m_bokehOffsets.Count - 2)); //RELEASE RENDER TEXTURES for (int i = 0; i < m_bokehOffsets.Count; i++) { AmplifyUtils.ReleaseTempRenderTarget(m_bokehOffsets[i].BokehRenderTexture); m_bokehOffsets[i].BokehRenderTexture = null; } }
void OnRenderImage(RenderTexture src, RenderTexture dest) { if (silentError) { return; } if (!AmplifyUtils.IsInitialized) { AmplifyUtils.InitializeIds(); } if (m_highPrecision) { AmplifyUtils.EnsureKeywordEnabled(m_bloomMaterial, AmplifyUtils.HighPrecisionKeyword, true); AmplifyUtils.EnsureKeywordEnabled(m_finalCompositionMaterial, AmplifyUtils.HighPrecisionKeyword, true); AmplifyUtils.CurrentRTFormat = RenderTextureFormat.DefaultHDR; } else { AmplifyUtils.EnsureKeywordEnabled(m_bloomMaterial, AmplifyUtils.HighPrecisionKeyword, false); AmplifyUtils.EnsureKeywordEnabled(m_finalCompositionMaterial, AmplifyUtils.HighPrecisionKeyword, false); AmplifyUtils.CurrentRTFormat = RenderTextureFormat.Default; } float totalCamRot = Mathf.Acos(Vector3.Dot(m_cameraTransform.right, Vector3.right)); if (Vector3.Cross(m_cameraTransform.right, Vector3.right).y > 0) { totalCamRot = -totalCamRot; } RenderTexture lensFlareRT = null; RenderTexture lensGlareRT = null; if (!m_highPrecision) { m_bloomRange.y = 1 / m_bloomRange.x; m_bloomMaterial.SetVector(AmplifyUtils.BloomRangeId, m_bloomRange); m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomRangeId, m_bloomRange); } m_bloomParams.y = m_overallThreshold; m_bloomMaterial.SetVector(AmplifyUtils.BloomParamsId, m_bloomParams); m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomParamsId, m_bloomParams); int thresholdResDiv = 1; switch (m_mainThresholdSize) { case MainThresholdSizeEnum.Half: thresholdResDiv = 2; break; case MainThresholdSizeEnum.Quarter: thresholdResDiv = 4; break; } // CALCULATE THRESHOLD RenderTexture thresholdRT = AmplifyUtils.GetTempRenderTarget(src.width / thresholdResDiv, src.height / thresholdResDiv); if (m_maskTexture != null) { m_bloomMaterial.SetTexture(AmplifyUtils.MaskTextureId, m_maskTexture); Graphics.Blit(src, thresholdRT, m_bloomMaterial, ( int )BloomPasses.ThresholdMask); } else { Graphics.Blit(src, thresholdRT, m_bloomMaterial, ( int )BloomPasses.Threshold); } if (m_debugToScreen == DebugToScreenEnum.MainThreshold) { Graphics.Blit(thresholdRT, dest, m_bloomMaterial, ( int )BloomPasses.Decode); AmplifyUtils.ReleaseAllRT(); return; } // DOWNSAMPLE bool applyGaussian = true; RenderTexture downsampleRT = thresholdRT; if (m_bloomDownsampleCount > 0) { applyGaussian = false; int tempW = thresholdRT.width; int tempH = thresholdRT.height; for (int i = 0; i < m_bloomDownsampleCount; i++) { m_tempDownsamplesSizes[i].x = tempW; m_tempDownsamplesSizes[i].y = tempH; tempW = (tempW + 1) >> 1; tempH = (tempH + 1) >> 1; m_tempAuxDownsampleRTs[i] = AmplifyUtils.GetTempRenderTarget(tempW, tempH); if (i == 0) { if (!m_temporalFilteringActive || m_gaussianSteps[i] != 0) { if (m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(downsampleRT, m_tempAuxDownsampleRTs[i], m_bloomMaterial, ( int )BloomPasses.DownsampleWithKaris); } else { Graphics.Blit(downsampleRT, m_tempAuxDownsampleRTs[i], m_bloomMaterial, ( int )BloomPasses.DownsampleWithoutKaris); } } else { if (m_tempFilterBuffer != null && m_temporalFilteringActive) { float filterVal = m_temporalFilteringCurve.Evaluate(m_temporalFilteringValue); m_bloomMaterial.SetFloat(AmplifyUtils.TempFilterValueId, filterVal); m_bloomMaterial.SetTexture(AmplifyUtils.AnamorphicRTS[0], m_tempFilterBuffer); if (m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(downsampleRT, m_tempAuxDownsampleRTs[i], m_bloomMaterial, ( int )BloomPasses.DownsampleWithTempFilterWithKaris); } else { Graphics.Blit(downsampleRT, m_tempAuxDownsampleRTs[i], m_bloomMaterial, ( int )BloomPasses.DownsampleWithTempFilterWithoutKaris); } } else { if (m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(downsampleRT, m_tempAuxDownsampleRTs[i], m_bloomMaterial, ( int )BloomPasses.DownsampleWithKaris); } else { Graphics.Blit(downsampleRT, m_tempAuxDownsampleRTs[i], m_bloomMaterial, ( int )BloomPasses.DownsampleWithoutKaris); } } bool createRT = false; if (m_tempFilterBuffer != null) { if (m_tempFilterBuffer.format != m_tempAuxDownsampleRTs[i].format || m_tempFilterBuffer.width != m_tempAuxDownsampleRTs[i].width || m_tempFilterBuffer.height != m_tempAuxDownsampleRTs[i].height) { CleanTempFilterRT(); createRT = true; } } else { createRT = true; } if (createRT) { CreateTempFilterRT(m_tempAuxDownsampleRTs[i]); } m_tempFilterBuffer.DiscardContents(); Graphics.Blit(m_tempAuxDownsampleRTs[i], m_tempFilterBuffer); if (m_debugToScreen == DebugToScreenEnum.TemporalFilter) { Graphics.Blit(m_tempAuxDownsampleRTs[i], dest); AmplifyUtils.ReleaseAllRT(); return; } } } else { Graphics.Blit(m_tempAuxDownsampleRTs[i - 1], m_tempAuxDownsampleRTs[i], m_bloomMaterial, ( int )BloomPasses.DownsampleNoWeightedAvg); } if (m_gaussianSteps[i] > 0) { ApplyGaussianBlur(m_tempAuxDownsampleRTs[i], m_gaussianSteps[i], m_gaussianRadius[i], i == 0); if (m_temporalFilteringActive && m_debugToScreen == DebugToScreenEnum.TemporalFilter) { Graphics.Blit(m_tempAuxDownsampleRTs[i], dest); AmplifyUtils.ReleaseAllRT(); return; } } } downsampleRT = m_tempAuxDownsampleRTs[m_featuresSourceId]; AmplifyUtils.ReleaseTempRenderTarget(thresholdRT); } // BOKEH FILTER if (m_bokehFilter.ApplyBokeh && m_bokehFilter.ApplyOnBloomSource) { m_bokehFilter.ApplyBokehFilter(downsampleRT, m_bloomMaterial); if (m_debugToScreen == DebugToScreenEnum.BokehFilter) { Graphics.Blit(downsampleRT, dest); AmplifyUtils.ReleaseAllRT(); return; } } // FEATURES THRESHOLD RenderTexture featuresRT = null; bool releaseFeaturesRT = false; if (m_separateFeaturesThreshold) { m_bloomParams.y = m_featuresThreshold; m_bloomMaterial.SetVector(AmplifyUtils.BloomParamsId, m_bloomParams); m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomParamsId, m_bloomParams); featuresRT = AmplifyUtils.GetTempRenderTarget(downsampleRT.width, downsampleRT.height); releaseFeaturesRT = true; Graphics.Blit(downsampleRT, featuresRT, m_bloomMaterial, ( int )BloomPasses.Threshold); if (m_debugToScreen == DebugToScreenEnum.FeaturesThreshold) { Graphics.Blit(featuresRT, dest); AmplifyUtils.ReleaseAllRT(); return; } } else { featuresRT = downsampleRT; } if (m_bokehFilter.ApplyBokeh && !m_bokehFilter.ApplyOnBloomSource) { if (!releaseFeaturesRT) { releaseFeaturesRT = true; featuresRT = AmplifyUtils.GetTempRenderTarget(downsampleRT.width, downsampleRT.height); Graphics.Blit(downsampleRT, featuresRT); } m_bokehFilter.ApplyBokehFilter(featuresRT, m_bloomMaterial); if (m_debugToScreen == DebugToScreenEnum.BokehFilter) { Graphics.Blit(featuresRT, dest); AmplifyUtils.ReleaseAllRT(); return; } } // LENS FLARE if (m_lensFlare.ApplyLensFlare && m_debugToScreen != DebugToScreenEnum.Bloom) { lensFlareRT = m_lensFlare.ApplyFlare(m_bloomMaterial, featuresRT); ApplyGaussianBlur(lensFlareRT, m_lensFlare.LensFlareGaussianBlurAmount); if (m_debugToScreen == DebugToScreenEnum.LensFlare) { Graphics.Blit(lensFlareRT, dest); AmplifyUtils.ReleaseAllRT(); return; } } //ANAMORPHIC GLARE if (m_anamorphicGlare.ApplyLensGlare && m_debugToScreen != DebugToScreenEnum.Bloom) { lensGlareRT = AmplifyUtils.GetTempRenderTarget(downsampleRT.width, downsampleRT.height); m_anamorphicGlare.OnRenderImage(m_bloomMaterial, featuresRT, lensGlareRT, totalCamRot); if (m_debugToScreen == DebugToScreenEnum.LensGlare) { Graphics.Blit(lensGlareRT, dest); AmplifyUtils.ReleaseAllRT(); return; } } if (releaseFeaturesRT) { AmplifyUtils.ReleaseTempRenderTarget(featuresRT); } //BLUR if (applyGaussian) { ApplyGaussianBlur(downsampleRT, m_gaussianSteps[0], m_gaussianRadius[0]); } //UPSAMPLE if (m_bloomDownsampleCount > 0) { if (m_bloomDownsampleCount == 1) { if (m_upscaleQuality == UpscaleQualityEnum.Realistic) { ApplyUpscale(); m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], m_tempUpscaleRTs[0]); } else { m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], m_tempAuxDownsampleRTs[0]); } m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[0], m_upscaleWeights[0]); } else { if (m_upscaleQuality == UpscaleQualityEnum.Realistic) { ApplyUpscale(); for (int i = 0; i < m_bloomDownsampleCount; i++) { int id = m_bloomDownsampleCount - i - 1; m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[id], m_tempUpscaleRTs[i]); m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[id], m_upscaleWeights[i]); } } else { for (int i = 0; i < m_bloomDownsampleCount; i++) { int id = m_bloomDownsampleCount - 1 - i; m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[id], m_tempAuxDownsampleRTs[id]); m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[id], m_upscaleWeights[i]); } } } } else { m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], downsampleRT); m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[0], 1); } if (m_debugToScreen == DebugToScreenEnum.Bloom) { m_finalCompositionMaterial.SetFloat(AmplifyUtils.SourceContributionId, 0); FinalComposition(0, 1, src, dest, 0); return; } // FINAL COMPOSITION // LENS FLARE if (m_bloomDownsampleCount > 1) { for (int i = 0; i < m_bloomDownsampleCount; i++) { m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtWeightsStr[m_bloomDownsampleCount - i - 1], m_lensDirtWeights[i]); m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensStarburstWeightsStr[m_bloomDownsampleCount - i - 1], m_lensStarburstWeights[i]); } } else { m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtWeightsStr[0], m_lensDirtWeights[0]); m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensStarburstWeightsStr[0], m_lensStarburstWeights[0]); } if (m_lensFlare.ApplyLensFlare) { m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensFlareRTId, lensFlareRT); } //LENS GLARE if (m_anamorphicGlare.ApplyLensGlare) { m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensGlareRTId, lensGlareRT); } // LENS DIRT if (m_applyLensDirt) { m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensDirtRTId, m_lensDirtTexture); m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtStrengthId, m_lensDirtStrength * MaxDirtIntensity); if (m_debugToScreen == DebugToScreenEnum.LensDirt) { FinalComposition(0, 0, src, dest, 2); return; } } // LENS STARBURST if (m_applyLensStardurst) { m_starburstMat[0, 0] = Mathf.Cos(totalCamRot); m_starburstMat[0, 1] = -Mathf.Sin(totalCamRot); m_starburstMat[1, 0] = Mathf.Sin(totalCamRot); m_starburstMat[1, 1] = Mathf.Cos(totalCamRot); m_finalCompositionMaterial.SetMatrix(AmplifyUtils.LensFlareStarMatrixId, m_starburstMat); m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensFlareStarburstStrengthId, m_lensStarburstStrength * MaxStarburstIntensity); m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensStarburstRTId, m_lensStardurstTex); if (m_debugToScreen == DebugToScreenEnum.LensStarburst) { FinalComposition(0, 0, src, dest, 1); return; } } if (m_targetTexture != null) { m_targetTexture.DiscardContents(); FinalComposition(0, 1, src, m_targetTexture, -1); Graphics.Blit(src, dest); } else { FinalComposition(1, 1, src, dest, -1); } }
void ApplyGaussianBlur(RenderTexture renderTexture, int amount, float radius = 1.0f, bool applyTemporal = false) { if (amount == 0) { return; } m_bloomMaterial.SetFloat(AmplifyUtils.BlurRadiusId, radius); RenderTexture blurRT = AmplifyUtils.GetTempRenderTarget(renderTexture.width, renderTexture.height); for (int i = 0; i < amount; i++) { blurRT.DiscardContents(); Graphics.Blit(renderTexture, blurRT, m_bloomMaterial, ( int )BloomPasses.HorizontalBlur); if (m_temporalFilteringActive && applyTemporal && i == (amount - 1)) { if (m_tempFilterBuffer != null && m_temporalFilteringActive) { float filterVal = m_temporalFilteringCurve.Evaluate(m_temporalFilteringValue); m_bloomMaterial.SetFloat(AmplifyUtils.TempFilterValueId, filterVal); m_bloomMaterial.SetTexture(AmplifyUtils.AnamorphicRTS[0], m_tempFilterBuffer); renderTexture.DiscardContents(); Graphics.Blit(blurRT, renderTexture, m_bloomMaterial, ( int )BloomPasses.VerticalBlurWithTempFilter); } else { renderTexture.DiscardContents(); Graphics.Blit(blurRT, renderTexture, m_bloomMaterial, ( int )BloomPasses.VerticalBlur); } bool createRT = false; if (m_tempFilterBuffer != null) { if (m_tempFilterBuffer.format != renderTexture.format || m_tempFilterBuffer.width != renderTexture.width || m_tempFilterBuffer.height != renderTexture.height) { CleanTempFilterRT(); createRT = true; } } else { createRT = true; } if (createRT) { CreateTempFilterRT(renderTexture); } m_tempFilterBuffer.DiscardContents(); Graphics.Blit(renderTexture, m_tempFilterBuffer); } else { renderTexture.DiscardContents(); Graphics.Blit(blurRT, renderTexture, m_bloomMaterial, ( int )BloomPasses.VerticalBlur); } } AmplifyUtils.ReleaseTempRenderTarget(blurRT); }
private void OnRenderImage(RenderTexture src, RenderTexture dest) { if (!this.silentError) { if (!AmplifyUtils.IsInitialized) { AmplifyUtils.InitializeIds(); } if (this.m_highPrecision) { AmplifyUtils.EnsureKeywordEnabled(this.m_bloomMaterial, AmplifyUtils.HighPrecisionKeyword, true); AmplifyUtils.EnsureKeywordEnabled(this.m_finalCompositionMaterial, AmplifyUtils.HighPrecisionKeyword, true); AmplifyUtils.CurrentRTFormat = RenderTextureFormat.DefaultHDR; } else { AmplifyUtils.EnsureKeywordEnabled(this.m_bloomMaterial, AmplifyUtils.HighPrecisionKeyword, false); AmplifyUtils.EnsureKeywordEnabled(this.m_finalCompositionMaterial, AmplifyUtils.HighPrecisionKeyword, false); AmplifyUtils.CurrentRTFormat = RenderTextureFormat.Default; } float cameraRot = Mathf.Acos(Vector3.Dot(this.m_cameraTransform.right, Vector3.right)); if (Vector3.Cross(this.m_cameraTransform.right, Vector3.right).y > 0f) { cameraRot = -cameraRot; } RenderTexture renderTexture = null; RenderTexture texture2 = null; if (!this.m_highPrecision) { this.m_bloomRange.y = 1f / this.m_bloomRange.x; this.m_bloomMaterial.SetVector(AmplifyUtils.BloomRangeId, this.m_bloomRange); this.m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomRangeId, this.m_bloomRange); } this.m_bloomParams.y = this.m_overallThreshold; this.m_bloomMaterial.SetVector(AmplifyUtils.BloomParamsId, this.m_bloomParams); this.m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomParamsId, this.m_bloomParams); int num2 = 1; MainThresholdSizeEnum mainThresholdSize = this.m_mainThresholdSize; if (mainThresholdSize == MainThresholdSizeEnum.Half) { num2 = 2; } else if (mainThresholdSize == MainThresholdSizeEnum.Quarter) { num2 = 4; } RenderTexture tempRenderTarget = AmplifyUtils.GetTempRenderTarget(src.width / num2, src.height / num2); if (this.m_maskTexture == null) { Graphics.Blit(src, tempRenderTarget, this.m_bloomMaterial, 0); } else { this.m_bloomMaterial.SetTexture(AmplifyUtils.MaskTextureId, this.m_maskTexture); Graphics.Blit(src, tempRenderTarget, this.m_bloomMaterial, 1); } if (this.m_debugToScreen == DebugToScreenEnum.MainThreshold) { Graphics.Blit(tempRenderTarget, dest, this.m_bloomMaterial, 0x21); AmplifyUtils.ReleaseAllRT(); } else { bool flag = true; RenderTexture source = tempRenderTarget; if (this.m_bloomDownsampleCount > 0) { flag = false; int width = tempRenderTarget.width; int height = tempRenderTarget.height; int index = 0; while (true) { if (index >= this.m_bloomDownsampleCount) { source = this.m_tempAuxDownsampleRTs[this.m_featuresSourceId]; AmplifyUtils.ReleaseTempRenderTarget(tempRenderTarget); break; } this.m_tempDownsamplesSizes[index].x = width; this.m_tempDownsamplesSizes[index].y = height; width = (width + 1) >> 1; height = (height + 1) >> 1; this.m_tempAuxDownsampleRTs[index] = AmplifyUtils.GetTempRenderTarget(width, height); if (index != 0) { Graphics.Blit(this.m_tempAuxDownsampleRTs[index - 1], this.m_tempAuxDownsampleRTs[index], this.m_bloomMaterial, 9); } else if (!this.m_temporalFilteringActive || (this.m_gaussianSteps[index] != 0)) { if (this.m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(source, this.m_tempAuxDownsampleRTs[index], this.m_bloomMaterial, 10); } else { Graphics.Blit(source, this.m_tempAuxDownsampleRTs[index], this.m_bloomMaterial, 11); } } else { if ((this.m_tempFilterBuffer == null) || !this.m_temporalFilteringActive) { if (this.m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(source, this.m_tempAuxDownsampleRTs[index], this.m_bloomMaterial, 10); } else { Graphics.Blit(source, this.m_tempAuxDownsampleRTs[index], this.m_bloomMaterial, 11); } } else { float num6 = this.m_temporalFilteringCurve.Evaluate(this.m_temporalFilteringValue); this.m_bloomMaterial.SetFloat(AmplifyUtils.TempFilterValueId, num6); this.m_bloomMaterial.SetTexture(AmplifyUtils.AnamorphicRTS[0], this.m_tempFilterBuffer); if (this.m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(source, this.m_tempAuxDownsampleRTs[index], this.m_bloomMaterial, 12); } else { Graphics.Blit(source, this.m_tempAuxDownsampleRTs[index], this.m_bloomMaterial, 13); } } bool flag2 = false; if (this.m_tempFilterBuffer == null) { flag2 = true; } else if ((this.m_tempFilterBuffer.format != this.m_tempAuxDownsampleRTs[index].format) || ((this.m_tempFilterBuffer.width != this.m_tempAuxDownsampleRTs[index].width) || (this.m_tempFilterBuffer.height != this.m_tempAuxDownsampleRTs[index].height))) { this.CleanTempFilterRT(); flag2 = true; } if (flag2) { this.CreateTempFilterRT(this.m_tempAuxDownsampleRTs[index]); } this.m_tempFilterBuffer.DiscardContents(); Graphics.Blit(this.m_tempAuxDownsampleRTs[index], this.m_tempFilterBuffer); if (this.m_debugToScreen == DebugToScreenEnum.TemporalFilter) { Graphics.Blit(this.m_tempAuxDownsampleRTs[index], dest); AmplifyUtils.ReleaseAllRT(); return; } } if (this.m_gaussianSteps[index] > 0) { this.ApplyGaussianBlur(this.m_tempAuxDownsampleRTs[index], this.m_gaussianSteps[index], this.m_gaussianRadius[index], index == 0); if (this.m_temporalFilteringActive && (this.m_debugToScreen == DebugToScreenEnum.TemporalFilter)) { Graphics.Blit(this.m_tempAuxDownsampleRTs[index], dest); AmplifyUtils.ReleaseAllRT(); return; } } index++; } } if (this.m_bokehFilter.ApplyBokeh && this.m_bokehFilter.ApplyOnBloomSource) { this.m_bokehFilter.ApplyBokehFilter(source, this.m_bloomMaterial); if (this.m_debugToScreen == DebugToScreenEnum.BokehFilter) { Graphics.Blit(source, dest); AmplifyUtils.ReleaseAllRT(); return; } } RenderTexture texture5 = null; bool flag3 = false; if (!this.m_separateFeaturesThreshold) { texture5 = source; } else { this.m_bloomParams.y = this.m_featuresThreshold; this.m_bloomMaterial.SetVector(AmplifyUtils.BloomParamsId, this.m_bloomParams); this.m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomParamsId, this.m_bloomParams); texture5 = AmplifyUtils.GetTempRenderTarget(source.width, source.height); flag3 = true; Graphics.Blit(source, texture5, this.m_bloomMaterial, 0); if (this.m_debugToScreen == DebugToScreenEnum.FeaturesThreshold) { Graphics.Blit(texture5, dest); AmplifyUtils.ReleaseAllRT(); return; } } if (this.m_bokehFilter.ApplyBokeh && !this.m_bokehFilter.ApplyOnBloomSource) { if (!flag3) { flag3 = true; texture5 = AmplifyUtils.GetTempRenderTarget(source.width, source.height); Graphics.Blit(source, texture5); } this.m_bokehFilter.ApplyBokehFilter(texture5, this.m_bloomMaterial); if (this.m_debugToScreen == DebugToScreenEnum.BokehFilter) { Graphics.Blit(texture5, dest); AmplifyUtils.ReleaseAllRT(); return; } } if (this.m_lensFlare.ApplyLensFlare && (this.m_debugToScreen != DebugToScreenEnum.Bloom)) { renderTexture = this.m_lensFlare.ApplyFlare(this.m_bloomMaterial, texture5); this.ApplyGaussianBlur(renderTexture, this.m_lensFlare.LensFlareGaussianBlurAmount, 1f, false); if (this.m_debugToScreen == DebugToScreenEnum.LensFlare) { Graphics.Blit(renderTexture, dest); AmplifyUtils.ReleaseAllRT(); return; } } if (this.m_anamorphicGlare.ApplyLensGlare && (this.m_debugToScreen != DebugToScreenEnum.Bloom)) { texture2 = AmplifyUtils.GetTempRenderTarget(source.width, source.height); this.m_anamorphicGlare.OnRenderImage(this.m_bloomMaterial, texture5, texture2, cameraRot); if (this.m_debugToScreen == DebugToScreenEnum.LensGlare) { Graphics.Blit(texture2, dest); AmplifyUtils.ReleaseAllRT(); return; } } if (flag3) { AmplifyUtils.ReleaseTempRenderTarget(texture5); } if (flag) { this.ApplyGaussianBlur(source, this.m_gaussianSteps[0], this.m_gaussianRadius[0], false); } if (this.m_bloomDownsampleCount <= 0) { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], source); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[0], 1f); } else if (this.m_bloomDownsampleCount == 1) { if (this.m_upscaleQuality != UpscaleQualityEnum.Realistic) { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], this.m_tempAuxDownsampleRTs[0]); } else { this.ApplyUpscale(); this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], this.m_tempUpscaleRTs[0]); } this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[0], this.m_upscaleWeights[0]); } else if (this.m_upscaleQuality != UpscaleQualityEnum.Realistic) { for (int i = 0; i < this.m_bloomDownsampleCount; i++) { int index = (this.m_bloomDownsampleCount - 1) - i; this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[index], this.m_tempAuxDownsampleRTs[index]); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[index], this.m_upscaleWeights[i]); } } else { this.ApplyUpscale(); for (int i = 0; i < this.m_bloomDownsampleCount; i++) { int index = (this.m_bloomDownsampleCount - i) - 1; this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[index], this.m_tempUpscaleRTs[i]); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[index], this.m_upscaleWeights[i]); } } if (this.m_debugToScreen == DebugToScreenEnum.Bloom) { this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.SourceContributionId, 0f); this.FinalComposition(0f, 1f, src, dest, 0); } else { if (this.m_bloomDownsampleCount <= 1) { this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtWeightsStr[0], this.m_lensDirtWeights[0]); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensStarburstWeightsStr[0], this.m_lensStarburstWeights[0]); } else { for (int i = 0; i < this.m_bloomDownsampleCount; i++) { this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtWeightsStr[(this.m_bloomDownsampleCount - i) - 1], this.m_lensDirtWeights[i]); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensStarburstWeightsStr[(this.m_bloomDownsampleCount - i) - 1], this.m_lensStarburstWeights[i]); } } if (this.m_lensFlare.ApplyLensFlare) { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensFlareRTId, renderTexture); } if (this.m_anamorphicGlare.ApplyLensGlare) { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensGlareRTId, texture2); } if (this.m_applyLensDirt) { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensDirtRTId, this.m_lensDirtTexture); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtStrengthId, this.m_lensDirtStrength * 1f); if (this.m_debugToScreen == DebugToScreenEnum.LensDirt) { this.FinalComposition(0f, 0f, src, dest, 2); return; } } if (this.m_applyLensStardurst) { this.m_starburstMat[0, 0] = Mathf.Cos(cameraRot); this.m_starburstMat[0, 1] = -Mathf.Sin(cameraRot); this.m_starburstMat[1, 0] = Mathf.Sin(cameraRot); this.m_starburstMat[1, 1] = Mathf.Cos(cameraRot); this.m_finalCompositionMaterial.SetMatrix(AmplifyUtils.LensFlareStarMatrixId, this.m_starburstMat); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensFlareStarburstStrengthId, this.m_lensStarburstStrength * 1f); this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensStarburstRTId, this.m_lensStardurstTex); if (this.m_debugToScreen == DebugToScreenEnum.LensStarburst) { this.FinalComposition(0f, 0f, src, dest, 1); return; } } if (this.m_targetTexture == null) { this.FinalComposition(1f, 1f, src, dest, -1); } else { this.m_targetTexture.DiscardContents(); this.FinalComposition(0f, 1f, src, this.m_targetTexture, -1); Graphics.Blit(src, dest); } } } } }
public unsafe void OnRenderImage(Material material, RenderTexture source, RenderTexture dest, float cameraRot) { Graphics.Blit(Texture2D.blackTexture, dest); if (!this.m_isDirty && ((this.m_currentWidth == source.width) && (this.m_currentHeight == source.height))) { this.OnRenderFromCache(source, dest, material, this.m_intensity, cameraRot); } else { this.m_isDirty = false; this.m_currentWidth = source.width; this.m_currentHeight = source.height; GlareDefData data = null; bool flag = false; if (this.m_currentGlareType != GlareLibType.Custom) { data = this.m_glareDefArr[this.m_currentGlareIdx]; } else if ((this.m_customGlareDef == null) || (this.m_customGlareDef.Length <= 0)) { data = this.m_glareDefArr[0]; } else { data = this.m_customGlareDef[this.m_customGlareDefIdx]; flag = true; } this.m_amplifyGlareCache.GlareDef = data; float width = source.width; float height = source.height; StarDefData data2 = !flag ? this.m_starDefArr[(int)data.StarType] : data.CustomStarData; this.m_amplifyGlareCache.StarDef = data2; int num3 = (this.m_glareMaxPassCount >= data2.PassCount) ? data2.PassCount : this.m_glareMaxPassCount; this.m_amplifyGlareCache.CurrentPassCount = num3; float num4 = data.StarInclination + data2.Inclination; int num5 = 0; while (num5 < this.m_glareMaxPassCount) { float t = ((float)(num5 + 1)) / ((float)this.m_glareMaxPassCount); int num7 = 0; while (true) { if (num7 >= 8) { num5++; break; } Color b = this._overallTint * Color.Lerp(this.m_cromaticAberrationGrad.Evaluate(((float)num7) / 7f), this.m_whiteReference, t); *(this.m_amplifyGlareCache.CromaticAberrationMat[num5, num7]) = Color.Lerp(this.m_whiteReference, b, data.ChromaticAberration); num7++; } } this.m_amplifyGlareCache.TotalRT = data2.StarlinesCount * num3; for (int i = 0; i < this.m_amplifyGlareCache.TotalRT; i++) { this._rtBuffer[i] = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } int index = 0; int num10 = 0; while (num10 < data2.StarlinesCount) { StarLineData data3 = data2.StarLinesArr[num10]; float f = num4 + data3.Inclination; float num12 = Mathf.Sin(f); float num13 = Mathf.Cos(f); Vector2 vector = new Vector2 { x = (num13 / width) * (data3.SampleLength * this.m_overallStreakScale), y = (num12 / height) * (data3.SampleLength * this.m_overallStreakScale) }; float num14 = (((this.m_aTanFoV + 0.1f) * 280f) / (width + height)) * 1.2f; int num15 = 0; while (true) { if (num15 >= num3) { num10++; break; } int num16 = 0; while (true) { if (num16 >= 8) { int num18 = 8; while (true) { if (num18 >= 0x10) { this.UpdateMatrixesForPass(material, this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets, this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights, this.m_intensity, data2.CameraRotInfluence * cameraRot); if (num15 == 0) { Graphics.Blit(source, this._rtBuffer[index], material, 2); } else { Graphics.Blit(this._rtBuffer[index - 1], this._rtBuffer[index], material, 2); } index++; vector *= this.m_perPassDisplacement; num14 *= this.m_perPassDisplacement; num15++; break; } this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num18] = -this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num18 - 8]; this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights[num18] = this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights[num18 - 8]; num18++; } break; } float num17 = Mathf.Pow(data3.Attenuation, num14 * num16); this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights[num16] = ((this.m_amplifyGlareCache.CromaticAberrationMat[(num3 - 1) - num15, num16] * num17) * (num15 + 1f)) * 0.5f; this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].x = vector.x * num16; this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].y = vector.y * num16; if ((Mathf.Abs(this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].x) >= 0.9f) || (Mathf.Abs(this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].y) >= 0.9f)) { this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].x = 0f; this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Offsets[num16].y = 0f; Vector4 *vectorPtr1 = &(this.m_amplifyGlareCache.Starlines[num10].Passes[num15].Weights[num16]); vectorPtr1[0] *= 0f; } num16++; } } } this.m_amplifyGlareCache.AverageWeight = Vector4.one / ((float)data2.StarlinesCount); for (int j = 0; j < data2.StarlinesCount; j++) { material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[j], this.m_amplifyGlareCache.AverageWeight); int num20 = ((j + 1) * num3) - 1; material.SetTexture(AmplifyUtils.AnamorphicRTS[j], this._rtBuffer[num20]); } int pass = (0x13 + data2.StarlinesCount) - 1; dest.DiscardContents(); Graphics.Blit(this._rtBuffer[0], dest, material, pass); for (index = 0; index < this._rtBuffer.Length; index++) { AmplifyUtils.ReleaseTempRenderTarget(this._rtBuffer[index]); this._rtBuffer[index] = null; } } }
private void OnRenderImage(RenderTexture src, RenderTexture dest) { if (this.silentError) { return; } if (!AmplifyUtils.IsInitialized) { AmplifyUtils.InitializeIds(); } if (this.m_highPrecision) { AmplifyUtils.EnsureKeywordEnabled(this.m_bloomMaterial, AmplifyUtils.HighPrecisionKeyword, true); AmplifyUtils.EnsureKeywordEnabled(this.m_finalCompositionMaterial, AmplifyUtils.HighPrecisionKeyword, true); AmplifyUtils.CurrentRTFormat = RenderTextureFormat.DefaultHDR; } else { AmplifyUtils.EnsureKeywordEnabled(this.m_bloomMaterial, AmplifyUtils.HighPrecisionKeyword, false); AmplifyUtils.EnsureKeywordEnabled(this.m_finalCompositionMaterial, AmplifyUtils.HighPrecisionKeyword, false); AmplifyUtils.CurrentRTFormat = RenderTextureFormat.Default; } float num = Mathf.Acos(Vector3.Dot(this.m_cameraTransform.right, Vector3.right)); if (Vector3.Cross(this.m_cameraTransform.right, Vector3.right).y > 0f) { num = -num; } RenderTexture renderTexture = null; RenderTexture renderTexture2 = null; if (!this.m_highPrecision) { this.m_bloomRange.y = 1f / this.m_bloomRange.x; this.m_bloomMaterial.SetVector(AmplifyUtils.BloomRangeId, this.m_bloomRange); this.m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomRangeId, this.m_bloomRange); } this.m_bloomParams.y = this.m_overallThreshold; this.m_bloomMaterial.SetVector(AmplifyUtils.BloomParamsId, this.m_bloomParams); this.m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomParamsId, this.m_bloomParams); int num2 = 1; MainThresholdSizeEnum mainThresholdSize = this.m_mainThresholdSize; if (mainThresholdSize != MainThresholdSizeEnum.Half) { if (mainThresholdSize == MainThresholdSizeEnum.Quarter) { num2 = 4; } } else { num2 = 2; } RenderTexture tempRenderTarget = AmplifyUtils.GetTempRenderTarget(src.width / num2, src.height / num2); if (this.m_maskTexture != null) { this.m_bloomMaterial.SetTexture(AmplifyUtils.MaskTextureId, this.m_maskTexture); Graphics.Blit(src, tempRenderTarget, this.m_bloomMaterial, 1); } else { Graphics.Blit(src, tempRenderTarget, this.m_bloomMaterial, 0); } if (this.m_debugToScreen == DebugToScreenEnum.MainThreshold) { Graphics.Blit(tempRenderTarget, dest, this.m_bloomMaterial, 33); AmplifyUtils.ReleaseAllRT(); return; } bool flag = true; RenderTexture renderTexture3 = tempRenderTarget; if (this.m_bloomDownsampleCount > 0) { flag = false; int num3 = tempRenderTarget.width; int num4 = tempRenderTarget.height; for (int i = 0; i < this.m_bloomDownsampleCount; i++) { this.m_tempDownsamplesSizes[i].x = (float)num3; this.m_tempDownsamplesSizes[i].y = (float)num4; num3 = num3 + 1 >> 1; num4 = num4 + 1 >> 1; this.m_tempAuxDownsampleRTs[i] = AmplifyUtils.GetTempRenderTarget(num3, num4); if (i == 0) { if (!this.m_temporalFilteringActive || this.m_gaussianSteps[i] != 0) { if (this.m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(renderTexture3, this.m_tempAuxDownsampleRTs[i], this.m_bloomMaterial, 10); } else { Graphics.Blit(renderTexture3, this.m_tempAuxDownsampleRTs[i], this.m_bloomMaterial, 11); } } else { if (this.m_tempFilterBuffer != null && this.m_temporalFilteringActive) { float value = this.m_temporalFilteringCurve.Evaluate(this.m_temporalFilteringValue); this.m_bloomMaterial.SetFloat(AmplifyUtils.TempFilterValueId, value); this.m_bloomMaterial.SetTexture(AmplifyUtils.AnamorphicRTS[0], this.m_tempFilterBuffer); if (this.m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(renderTexture3, this.m_tempAuxDownsampleRTs[i], this.m_bloomMaterial, 12); } else { Graphics.Blit(renderTexture3, this.m_tempAuxDownsampleRTs[i], this.m_bloomMaterial, 13); } } else if (this.m_upscaleQuality == UpscaleQualityEnum.Realistic) { Graphics.Blit(renderTexture3, this.m_tempAuxDownsampleRTs[i], this.m_bloomMaterial, 10); } else { Graphics.Blit(renderTexture3, this.m_tempAuxDownsampleRTs[i], this.m_bloomMaterial, 11); } bool flag2 = false; if (this.m_tempFilterBuffer != null) { if (this.m_tempFilterBuffer.format != this.m_tempAuxDownsampleRTs[i].format || this.m_tempFilterBuffer.width != this.m_tempAuxDownsampleRTs[i].width || this.m_tempFilterBuffer.height != this.m_tempAuxDownsampleRTs[i].height) { this.CleanTempFilterRT(); flag2 = true; } } else { flag2 = true; } if (flag2) { this.CreateTempFilterRT(this.m_tempAuxDownsampleRTs[i]); } this.m_tempFilterBuffer.DiscardContents(); Graphics.Blit(this.m_tempAuxDownsampleRTs[i], this.m_tempFilterBuffer); if (this.m_debugToScreen == DebugToScreenEnum.TemporalFilter) { Graphics.Blit(this.m_tempAuxDownsampleRTs[i], dest); AmplifyUtils.ReleaseAllRT(); return; } } } else { Graphics.Blit(this.m_tempAuxDownsampleRTs[i - 1], this.m_tempAuxDownsampleRTs[i], this.m_bloomMaterial, 9); } if (this.m_gaussianSteps[i] > 0) { this.ApplyGaussianBlur(this.m_tempAuxDownsampleRTs[i], this.m_gaussianSteps[i], this.m_gaussianRadius[i], i == 0); if (this.m_temporalFilteringActive && this.m_debugToScreen == DebugToScreenEnum.TemporalFilter) { Graphics.Blit(this.m_tempAuxDownsampleRTs[i], dest); AmplifyUtils.ReleaseAllRT(); return; } } } renderTexture3 = this.m_tempAuxDownsampleRTs[this.m_featuresSourceId]; AmplifyUtils.ReleaseTempRenderTarget(tempRenderTarget); } if (this.m_bokehFilter.ApplyBokeh && this.m_bokehFilter.ApplyOnBloomSource) { this.m_bokehFilter.ApplyBokehFilter(renderTexture3, this.m_bloomMaterial); if (this.m_debugToScreen == DebugToScreenEnum.BokehFilter) { Graphics.Blit(renderTexture3, dest); AmplifyUtils.ReleaseAllRT(); return; } } bool flag3 = false; RenderTexture renderTexture4; if (this.m_separateFeaturesThreshold) { this.m_bloomParams.y = this.m_featuresThreshold; this.m_bloomMaterial.SetVector(AmplifyUtils.BloomParamsId, this.m_bloomParams); this.m_finalCompositionMaterial.SetVector(AmplifyUtils.BloomParamsId, this.m_bloomParams); renderTexture4 = AmplifyUtils.GetTempRenderTarget(renderTexture3.width, renderTexture3.height); flag3 = true; Graphics.Blit(renderTexture3, renderTexture4, this.m_bloomMaterial, 0); if (this.m_debugToScreen == DebugToScreenEnum.FeaturesThreshold) { Graphics.Blit(renderTexture4, dest); AmplifyUtils.ReleaseAllRT(); return; } } else { renderTexture4 = renderTexture3; } if (this.m_bokehFilter.ApplyBokeh && !this.m_bokehFilter.ApplyOnBloomSource) { if (!flag3) { flag3 = true; renderTexture4 = AmplifyUtils.GetTempRenderTarget(renderTexture3.width, renderTexture3.height); Graphics.Blit(renderTexture3, renderTexture4); } this.m_bokehFilter.ApplyBokehFilter(renderTexture4, this.m_bloomMaterial); if (this.m_debugToScreen == DebugToScreenEnum.BokehFilter) { Graphics.Blit(renderTexture4, dest); AmplifyUtils.ReleaseAllRT(); return; } } if (this.m_lensFlare.ApplyLensFlare && this.m_debugToScreen != DebugToScreenEnum.Bloom) { renderTexture = this.m_lensFlare.ApplyFlare(this.m_bloomMaterial, renderTexture4); this.ApplyGaussianBlur(renderTexture, this.m_lensFlare.LensFlareGaussianBlurAmount, 1f, false); if (this.m_debugToScreen == DebugToScreenEnum.LensFlare) { Graphics.Blit(renderTexture, dest); AmplifyUtils.ReleaseAllRT(); return; } } if (this.m_anamorphicGlare.ApplyLensGlare && this.m_debugToScreen != DebugToScreenEnum.Bloom) { renderTexture2 = AmplifyUtils.GetTempRenderTarget(renderTexture3.width, renderTexture3.height); this.m_anamorphicGlare.OnRenderImage(this.m_bloomMaterial, renderTexture4, renderTexture2, num); if (this.m_debugToScreen == DebugToScreenEnum.LensGlare) { Graphics.Blit(renderTexture2, dest); AmplifyUtils.ReleaseAllRT(); return; } } if (flag3) { AmplifyUtils.ReleaseTempRenderTarget(renderTexture4); } if (flag) { this.ApplyGaussianBlur(renderTexture3, this.m_gaussianSteps[0], this.m_gaussianRadius[0], false); } if (this.m_bloomDownsampleCount > 0) { if (this.m_bloomDownsampleCount == 1) { if (this.m_upscaleQuality == UpscaleQualityEnum.Realistic) { this.ApplyUpscale(); this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], this.m_tempUpscaleRTs[0]); } else { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], this.m_tempAuxDownsampleRTs[0]); } this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[0], this.m_upscaleWeights[0]); } else if (this.m_upscaleQuality == UpscaleQualityEnum.Realistic) { this.ApplyUpscale(); for (int j = 0; j < this.m_bloomDownsampleCount; j++) { int num5 = this.m_bloomDownsampleCount - j - 1; this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[num5], this.m_tempUpscaleRTs[j]); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[num5], this.m_upscaleWeights[j]); } } else { for (int k = 0; k < this.m_bloomDownsampleCount; k++) { int num6 = this.m_bloomDownsampleCount - 1 - k; this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[num6], this.m_tempAuxDownsampleRTs[num6]); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[num6], this.m_upscaleWeights[k]); } } } else { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.MipResultsRTS[0], renderTexture3); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.UpscaleWeightsStr[0], 1f); } if (this.m_debugToScreen == DebugToScreenEnum.Bloom) { this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.SourceContributionId, 0f); this.FinalComposition(0f, 1f, src, dest, 0); return; } if (this.m_bloomDownsampleCount > 1) { for (int l = 0; l < this.m_bloomDownsampleCount; l++) { this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtWeightsStr[this.m_bloomDownsampleCount - l - 1], this.m_lensDirtWeights[l]); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensStarburstWeightsStr[this.m_bloomDownsampleCount - l - 1], this.m_lensStarburstWeights[l]); } } else { this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtWeightsStr[0], this.m_lensDirtWeights[0]); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensStarburstWeightsStr[0], this.m_lensStarburstWeights[0]); } if (this.m_lensFlare.ApplyLensFlare) { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensFlareRTId, renderTexture); } if (this.m_anamorphicGlare.ApplyLensGlare) { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensGlareRTId, renderTexture2); } if (this.m_applyLensDirt) { this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensDirtRTId, this.m_lensDirtTexture); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensDirtStrengthId, this.m_lensDirtStrength * 1f); if (this.m_debugToScreen == DebugToScreenEnum.LensDirt) { this.FinalComposition(0f, 0f, src, dest, 2); return; } } if (this.m_applyLensStardurst) { this.m_starburstMat[0, 0] = Mathf.Cos(num); this.m_starburstMat[0, 1] = -Mathf.Sin(num); this.m_starburstMat[1, 0] = Mathf.Sin(num); this.m_starburstMat[1, 1] = Mathf.Cos(num); this.m_finalCompositionMaterial.SetMatrix(AmplifyUtils.LensFlareStarMatrixId, this.m_starburstMat); this.m_finalCompositionMaterial.SetFloat(AmplifyUtils.LensFlareStarburstStrengthId, this.m_lensStarburstStrength * 1f); this.m_finalCompositionMaterial.SetTexture(AmplifyUtils.LensStarburstRTId, this.m_lensStardurstTex); if (this.m_debugToScreen == DebugToScreenEnum.LensStarburst) { this.FinalComposition(0f, 0f, src, dest, 1); return; } } if (this.m_targetTexture != null) { this.m_targetTexture.DiscardContents(); this.FinalComposition(0f, 1f, src, this.m_targetTexture, -1); Graphics.Blit(src, dest); } else { this.FinalComposition(1f, 1f, src, dest, -1); } }
public void OnRenderImage(Material material, RenderTexture source, RenderTexture dest, float cameraRot) { //NEED TO SET DESTINATION RENDER TARGET TO COMPLETELLY BLACK SO WE CAN SUM ALL THE GLARE/STAR PASSES ON IT Graphics.Blit(Texture2D.blackTexture, dest); if (m_isDirty || m_currentWidth != source.width || m_currentHeight != source.height) { m_isDirty = false; m_currentWidth = source.width; m_currentHeight = source.height; } else { OnRenderFromCache(source, dest, material, m_intensity, cameraRot); return; } GlareDefData glareDef = null; bool validCustom = false; if (m_currentGlareType == GlareLibType.Custom) { if (m_customGlareDef != null && m_customGlareDef.Length > 0) { glareDef = m_customGlareDef[m_customGlareDefIdx]; validCustom = true; } else { glareDef = m_glareDefArr[0]; } } else { glareDef = m_glareDefArr[m_currentGlareIdx]; } m_amplifyGlareCache.GlareDef = glareDef; float srcW = source.width; float srcH = source.height; StarDefData starDef = (validCustom) ? glareDef.CustomStarData : m_starDefArr[( int )glareDef.StarType]; m_amplifyGlareCache.StarDef = starDef; int currPassCount = (m_glareMaxPassCount < starDef.PassCount) ? m_glareMaxPassCount : starDef.PassCount; m_amplifyGlareCache.CurrentPassCount = currPassCount; float radOffset = glareDef.StarInclination + starDef.Inclination; for (int p = 0; p < m_glareMaxPassCount; p++) { float ratio = ( float )(p + 1) / ( float )m_glareMaxPassCount; for (int s = 0; s < MaxLineSamples; s++) { Color chromaticAberrColor = _overallTint * Color.Lerp(m_cromaticAberrationGrad.Evaluate(( float )s / ( float )(MaxLineSamples - 1)), m_whiteReference, ratio); m_amplifyGlareCache.CromaticAberrationMat[p, s] = Color.Lerp(m_whiteReference, chromaticAberrColor, glareDef.ChromaticAberration); } } m_amplifyGlareCache.TotalRT = starDef.StarlinesCount * currPassCount; for (int i = 0; i < m_amplifyGlareCache.TotalRT; i++) { _rtBuffer[i] = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } int rtIdx = 0; for (int d = 0; d < starDef.StarlinesCount; d++) { StarLineData starLine = starDef.StarLinesArr[d]; float angle = radOffset + starLine.Inclination; float sinAngle = Mathf.Sin(angle); float cosAngle = Mathf.Cos(angle); Vector2 vtStepUV = new Vector2(); vtStepUV.x = cosAngle / srcW * (starLine.SampleLength * m_overallStreakScale); vtStepUV.y = sinAngle / srcH * (starLine.SampleLength * m_overallStreakScale); float attnPowScale = (m_aTanFoV + 0.1f) * (280.0f) / (srcW + srcH) * 1.2f; for (int p = 0; p < currPassCount; p++) { for (int i = 0; i < MaxLineSamples; i++) { float lum = Mathf.Pow(starLine.Attenuation, attnPowScale * i); m_amplifyGlareCache.Starlines[d].Passes[p].Weights[i] = m_amplifyGlareCache.CromaticAberrationMat[currPassCount - 1 - p, i] * lum * (p + 1.0f) * 0.5f; // OFFSET OF SAMPLING COORDINATE m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].x = vtStepUV.x * i; m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].y = vtStepUV.y * i; if (Mathf.Abs(m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].x) >= 0.9f || Mathf.Abs(m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].y) >= 0.9f) { m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].x = 0.0f; m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i].y = 0.0f; m_amplifyGlareCache.Starlines[d].Passes[p].Weights[i] *= 0.0f; } } // MIRROR STARLINE for (int i = MaxLineSamples; i < MaxTotalSamples; i++) { m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i] = -m_amplifyGlareCache.Starlines[d].Passes[p].Offsets[i - MaxLineSamples]; m_amplifyGlareCache.Starlines[d].Passes[p].Weights[i] = m_amplifyGlareCache.Starlines[d].Passes[p].Weights[i - MaxLineSamples]; } // APPLY SHADER UpdateMatrixesForPass(material, m_amplifyGlareCache.Starlines[d].Passes[p].Offsets, m_amplifyGlareCache.Starlines[d].Passes[p].Weights, m_intensity, starDef.CameraRotInfluence * cameraRot); //CREATED WEIGHTED TEXTURE if (p == 0) { Graphics.Blit(source, _rtBuffer[rtIdx], material, ( int )BloomPasses.AnamorphicGlare); } else { Graphics.Blit(_rtBuffer[rtIdx - 1], _rtBuffer[rtIdx], material, ( int )BloomPasses.AnamorphicGlare); } rtIdx += 1; vtStepUV *= m_perPassDisplacement; attnPowScale *= m_perPassDisplacement; } } //ADD TO MAIN RT m_amplifyGlareCache.AverageWeight = Vector4.one / starDef.StarlinesCount; for (int i = 0; i < starDef.StarlinesCount; i++) { material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[i], m_amplifyGlareCache.AverageWeight); int idx = (i + 1) * currPassCount - 1; material.SetTexture(AmplifyUtils.AnamorphicRTS[i], _rtBuffer[idx]); } int passId = ( int )BloomPasses.WeightedAddPS1 + starDef.StarlinesCount - 1; dest.DiscardContents(); Graphics.Blit(_rtBuffer[0], dest, material, passId); //RELEASE RT's for (rtIdx = 0; rtIdx < _rtBuffer.Length; rtIdx++) { AmplifyUtils.ReleaseTempRenderTarget(_rtBuffer[rtIdx]); _rtBuffer[rtIdx] = null; } }
public void OnRenderImage(Material material, RenderTexture source, RenderTexture dest, float cameraRot) { Graphics.Blit(Texture2D.blackTexture, dest); if (this.m_isDirty || this.m_currentWidth != source.width || this.m_currentHeight != source.height) { this.m_isDirty = false; this.m_currentWidth = source.width; this.m_currentHeight = source.height; bool flag = false; GlareDefData glareDefData; if (this.m_currentGlareType == GlareLibType.Custom) { if (this.m_customGlareDef != null && this.m_customGlareDef.Length != 0) { glareDefData = this.m_customGlareDef[this.m_customGlareDefIdx]; flag = true; } else { glareDefData = this.m_glareDefArr[0]; } } else { glareDefData = this.m_glareDefArr[this.m_currentGlareIdx]; } this.m_amplifyGlareCache.GlareDef = glareDefData; float num = (float)source.width; float num2 = (float)source.height; StarDefData starDefData = flag ? glareDefData.CustomStarData : this.m_starDefArr[(int)glareDefData.StarType]; this.m_amplifyGlareCache.StarDef = starDefData; int num3 = (this.m_glareMaxPassCount < starDefData.PassCount) ? this.m_glareMaxPassCount : starDefData.PassCount; this.m_amplifyGlareCache.CurrentPassCount = num3; float num4 = glareDefData.StarInclination + starDefData.Inclination; for (int i = 0; i < this.m_glareMaxPassCount; i++) { float t = (float)(i + 1) / (float)this.m_glareMaxPassCount; for (int j = 0; j < 8; j++) { Color b = this._overallTint * Color.Lerp(this.m_cromaticAberrationGrad.Evaluate((float)j / 7f), this.m_whiteReference, t); this.m_amplifyGlareCache.CromaticAberrationMat[i, j] = Color.Lerp(this.m_whiteReference, b, glareDefData.ChromaticAberration); } } this.m_amplifyGlareCache.TotalRT = starDefData.StarlinesCount * num3; for (int k = 0; k < this.m_amplifyGlareCache.TotalRT; k++) { this._rtBuffer[k] = AmplifyUtils.GetTempRenderTarget(source.width, source.height); } int l = 0; for (int m = 0; m < starDefData.StarlinesCount; m++) { StarLineData starLineData = starDefData.StarLinesArr[m]; float f = num4 + starLineData.Inclination; float num5 = Mathf.Sin(f); float num6 = Mathf.Cos(f); Vector2 vector = default(Vector2); vector.x = num6 / num * (starLineData.SampleLength * this.m_overallStreakScale); vector.y = num5 / num2 * (starLineData.SampleLength * this.m_overallStreakScale); float num7 = (this.m_aTanFoV + 0.1f) * 280f / (num + num2) * 1.2f; for (int n = 0; n < num3; n++) { for (int num8 = 0; num8 < 8; num8++) { float d = Mathf.Pow(starLineData.Attenuation, num7 * (float)num8); this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights[num8] = this.m_amplifyGlareCache.CromaticAberrationMat[num3 - 1 - n, num8] * d * ((float)n + 1f) * 0.5f; this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].x = vector.x * (float)num8; this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].y = vector.y * (float)num8; if (Mathf.Abs(this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].x) >= 0.9f || Mathf.Abs(this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].y) >= 0.9f) { this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].x = 0f; this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num8].y = 0f; this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights[num8] *= 0f; } } for (int num9 = 8; num9 < 16; num9++) { this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num9] = -this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets[num9 - 8]; this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights[num9] = this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights[num9 - 8]; } this.UpdateMatrixesForPass(material, this.m_amplifyGlareCache.Starlines[m].Passes[n].Offsets, this.m_amplifyGlareCache.Starlines[m].Passes[n].Weights, this.m_intensity, starDefData.CameraRotInfluence * cameraRot); if (n == 0) { Graphics.Blit(source, this._rtBuffer[l], material, 2); } else { Graphics.Blit(this._rtBuffer[l - 1], this._rtBuffer[l], material, 2); } l++; vector *= this.m_perPassDisplacement; num7 *= this.m_perPassDisplacement; } } this.m_amplifyGlareCache.AverageWeight = Vector4.one / (float)starDefData.StarlinesCount; for (int num10 = 0; num10 < starDefData.StarlinesCount; num10++) { material.SetVector(AmplifyUtils.AnamorphicGlareWeightsStr[num10], this.m_amplifyGlareCache.AverageWeight); int num11 = (num10 + 1) * num3 - 1; material.SetTexture(AmplifyUtils.AnamorphicRTS[num10], this._rtBuffer[num11]); } int pass = 19 + starDefData.StarlinesCount - 1; dest.DiscardContents(); Graphics.Blit(this._rtBuffer[0], dest, material, pass); for (l = 0; l < this._rtBuffer.Length; l++) { AmplifyUtils.ReleaseTempRenderTarget(this._rtBuffer[l]); this._rtBuffer[l] = null; } return; } this.OnRenderFromCache(source, dest, material, this.m_intensity, cameraRot); }