void OnDisable() { // Clear command buffers foreach (var cb in m_CommandBuffers.Values) { m_Camera.RemoveCommandBuffer(cb.Key, cb.Value); cb.Value.Dispose(); } m_CommandBuffers.Clear(); // Clear components if (profile != null) { DisableComponents(); } m_Components.Clear(); // Factories m_MaterialFactory.Dispose(); m_RenderTextureFactory.Dispose(); GraphicsUtils.Dispose(); }
// Token: 0x06003AF9 RID: 15097 RVA: 0x001C8630 File Offset: 0x001C6A30 public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC) { DepthOfFieldModel.Settings settings = base.model.settings; Material material = this.context.materialFactory.Get("Hidden/Post FX/Depth Of Field"); material.shaderKeywords = null; float num = settings.focusDistance; float num2 = this.CalculateFocalLength(); num = Mathf.Max(num, num2); material.SetFloat(DepthOfFieldComponent.Uniforms._Distance, num); float num3 = num2 * num2 / (settings.aperture * (num - num2) * 0.024f * 2f); material.SetFloat(DepthOfFieldComponent.Uniforms._LensCoeff, num3); float num4 = this.CalculateMaxCoCRadius(source.height); material.SetFloat(DepthOfFieldComponent.Uniforms._MaxCoC, num4); material.SetFloat(DepthOfFieldComponent.Uniforms._RcpMaxCoC, 1f / num4); float value = (float)source.height / (float)source.width; material.SetFloat(DepthOfFieldComponent.Uniforms._RcpAspect, value); RenderTexture renderTexture = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture"); source.filterMode = FilterMode.Point; Graphics.Blit(source, renderTexture, material, 0); RenderTexture renderTexture2 = renderTexture; if (antialiasCoC) { renderTexture2 = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture"); if (this.m_CoCHistory == null || !this.m_CoCHistory.IsCreated() || this.m_CoCHistory.width != this.context.width / 2 || this.m_CoCHistory.height != this.context.height / 2) { this.m_CoCHistory = RenderTexture.GetTemporary(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.RHalf); this.m_CoCHistory.filterMode = FilterMode.Point; this.m_CoCHistory.name = "CoC History"; Graphics.Blit(renderTexture, this.m_CoCHistory, material, 6); } RenderTexture temporary = RenderTexture.GetTemporary(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.RHalf); temporary.filterMode = FilterMode.Point; temporary.name = "CoC History"; this.m_MRT[0] = renderTexture2.colorBuffer; this.m_MRT[1] = temporary.colorBuffer; material.SetTexture(DepthOfFieldComponent.Uniforms._MainTex, renderTexture); material.SetTexture(DepthOfFieldComponent.Uniforms._HistoryCoC, this.m_CoCHistory); Graphics.SetRenderTarget(this.m_MRT, renderTexture.depthBuffer); GraphicsUtils.Blit(material, 5); RenderTexture.ReleaseTemporary(this.m_CoCHistory); this.m_CoCHistory = temporary; } RenderTexture renderTexture3 = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture"); Graphics.Blit(renderTexture2, renderTexture3, material, (int)(1 + settings.kernelSize)); if (this.context.profile.debugViews.IsModeActive(BuiltinDebugViewsModel.Mode.FocusPlane)) { uberMaterial.SetTexture(DepthOfFieldComponent.Uniforms._DepthOfFieldTex, renderTexture); uberMaterial.SetVector(DepthOfFieldComponent.Uniforms._DepthOfFieldParams, new Vector2(num, num3)); uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW"); this.context.Interrupt(); } else { uberMaterial.SetTexture(DepthOfFieldComponent.Uniforms._DepthOfFieldTex, renderTexture3); uberMaterial.EnableKeyword("DEPTH_OF_FIELD"); } if (antialiasCoC) { this.context.renderTextureFactory.Release(renderTexture2); } this.context.renderTextureFactory.Release(renderTexture); source.filterMode = FilterMode.Bilinear; }
public static void Dispose() { GraphicsUtils.Destroy(GraphicsUtils.s_Quad); }
public override void OnDisable() { GraphicsUtils.Destroy(this.m_GrainLookupRT); this.m_GrainLookupRT = null; }
public void Release() { GraphicsUtils.Destroy(this.mesh); this.mesh = null; }
public void Release() { GraphicsUtils.Destroy(mesh); mesh = null; }
public override void OnDisable() { GraphicsUtils.Destroy(this.m_SpectrumLut); this.m_SpectrumLut = null; }
void GenerateLut() { var settings = model.settings; if (!IsLogLutValid(model.bakedLut)) { GraphicsUtils.Destroy(model.bakedLut); model.bakedLut = new RenderTexture(k_InternalLogLutSize * k_InternalLogLutSize, k_InternalLogLutSize, 0, RenderTextureFormat.ARGBHalf) { name = "Color Grading Log LUT", hideFlags = HideFlags.DontSave, filterMode = FilterMode.Bilinear, wrapMode = TextureWrapMode.Clamp, anisoLevel = 0 }; } var lutMaterial = context.materialFactory.Get("Hidden/Post FX/Lut Generator"); lutMaterial.SetVector(Uniforms._LutParams, new Vector4( k_InternalLogLutSize, 0.5f / (k_InternalLogLutSize * k_InternalLogLutSize), 0.5f / k_InternalLogLutSize, k_InternalLogLutSize / (k_InternalLogLutSize - 1f)) ); // Tonemapping lutMaterial.shaderKeywords = null; var tonemapping = settings.tonemapping; switch (tonemapping.tonemapper) { case ColorGradingModel.Tonemapper.Neutral: { lutMaterial.EnableKeyword("TONEMAPPING_NEUTRAL"); const float scaleFactor = 20f; const float scaleFactorHalf = scaleFactor * 0.5f; float inBlack = tonemapping.neutralBlackIn * scaleFactor + 1f; float outBlack = tonemapping.neutralBlackOut * scaleFactorHalf + 1f; float inWhite = tonemapping.neutralWhiteIn / scaleFactor; float outWhite = 1f - tonemapping.neutralWhiteOut / scaleFactor; float blackRatio = inBlack / outBlack; float whiteRatio = inWhite / outWhite; const float a = 0.2f; float b = Mathf.Max(0f, Mathf.LerpUnclamped(0.57f, 0.37f, blackRatio)); float c = Mathf.LerpUnclamped(0.01f, 0.24f, whiteRatio); float d = Mathf.Max(0f, Mathf.LerpUnclamped(0.02f, 0.20f, blackRatio)); const float e = 0.02f; const float f = 0.30f; lutMaterial.SetVector(Uniforms._NeutralTonemapperParams1, new Vector4(a, b, c, d)); lutMaterial.SetVector(Uniforms._NeutralTonemapperParams2, new Vector4(e, f, tonemapping.neutralWhiteLevel, tonemapping.neutralWhiteClip / scaleFactorHalf)); break; } case ColorGradingModel.Tonemapper.ACES: { lutMaterial.EnableKeyword("TONEMAPPING_FILMIC"); break; } } // Color balance & basic grading settings lutMaterial.SetFloat(Uniforms._HueShift, settings.basic.hueShift / 360f); lutMaterial.SetFloat(Uniforms._Saturation, settings.basic.saturation); lutMaterial.SetFloat(Uniforms._Contrast, settings.basic.contrast); lutMaterial.SetVector(Uniforms._Balance, CalculateColorBalance(settings.basic.temperature, settings.basic.tint)); // Lift / Gamma / Gain Vector3 lift, gamma, gain; CalculateLiftGammaGain( settings.colorWheels.linear.lift, settings.colorWheels.linear.gamma, settings.colorWheels.linear.gain, out lift, out gamma, out gain ); lutMaterial.SetVector(Uniforms._Lift, lift); lutMaterial.SetVector(Uniforms._InvGamma, gamma); lutMaterial.SetVector(Uniforms._Gain, gain); // Slope / Power / Offset Vector3 slope, power, offset; CalculateSlopePowerOffset( settings.colorWheels.log.slope, settings.colorWheels.log.power, settings.colorWheels.log.offset, out slope, out power, out offset ); lutMaterial.SetVector(Uniforms._Slope, slope); lutMaterial.SetVector(Uniforms._Power, power); lutMaterial.SetVector(Uniforms._Offset, offset); // Channel mixer lutMaterial.SetVector(Uniforms._ChannelMixerRed, settings.channelMixer.red); lutMaterial.SetVector(Uniforms._ChannelMixerGreen, settings.channelMixer.green); lutMaterial.SetVector(Uniforms._ChannelMixerBlue, settings.channelMixer.blue); // Selective grading & YRGB curves lutMaterial.SetTexture(Uniforms._Curves, GetCurveTexture()); // Generate the lut Graphics.Blit(null, model.bakedLut, lutMaterial, 0); }
public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC) { if (target == null) { target = GameObject.FindGameObjectWithTag("Target").transform; } var settings = model.settings; // Material setup var material = context.materialFactory.Get(k_ShaderString); material.shaderKeywords = null; var s1 = Vector3.Distance(Camera.main.transform.position, target.position);//settings.focusDistance; var f = CalculateFocalLength(); s1 = Mathf.Max(s1, f); material.SetFloat(Uniforms._Distance, s1); Debug.Log(s1); var coeff = f * f / (settings.aperture * (s1 - f) * k_FilmHeight * 2); material.SetFloat(Uniforms._LensCoeff, coeff); var maxCoC = CalculateMaxCoCRadius(source.height); material.SetFloat(Uniforms._MaxCoC, maxCoC); material.SetFloat(Uniforms._RcpMaxCoC, 1f / maxCoC); var rcpAspect = (float)source.height / source.width; material.SetFloat(Uniforms._RcpAspect, rcpAspect); var rt1 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf); source.filterMode = FilterMode.Point; // Pass #1 - Downsampling, prefiltering and CoC calculation if (!antialiasCoC) { Graphics.Blit(source, rt1, material, 0); } else { var initial = m_CoCHistory == null || !m_CoCHistory.IsCreated() || m_CoCHistory.width != context.width / 2 || m_CoCHistory.height != context.height / 2; var tempCoCHistory = RenderTexture.GetTemporary(context.width / 2, context.height / 2, 0, RenderTextureFormat.RHalf); tempCoCHistory.filterMode = FilterMode.Point; tempCoCHistory.name = "CoC History"; m_MRT[0] = rt1.colorBuffer; m_MRT[1] = tempCoCHistory.colorBuffer; material.SetTexture(Uniforms._MainTex, source); material.SetTexture(Uniforms._HistoryCoC, m_CoCHistory); material.SetFloat(Uniforms._HistoryWeight, initial ? 0 : 0.5f); Graphics.SetRenderTarget(m_MRT, rt1.depthBuffer); GraphicsUtils.Blit(material, 1); RenderTexture.ReleaseTemporary(m_CoCHistory); m_CoCHistory = tempCoCHistory; } // Pass #2 - Bokeh simulation var rt2 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf); Graphics.Blit(rt1, rt2, material, 2 + (int)settings.kernelSize); // Pass #3 - Postfilter blur Graphics.Blit(rt2, rt1, material, 6); if (context.profile.debugViews.IsModeActive(DebugMode.FocusPlane)) { uberMaterial.SetVector(Uniforms._DepthOfFieldParams, new Vector2(s1, coeff)); uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW"); context.Interrupt(); } else { uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt1); uberMaterial.EnableKeyword("DEPTH_OF_FIELD"); } context.renderTextureFactory.Release(rt2); source.filterMode = FilterMode.Bilinear; }
// Token: 0x06003AEF RID: 15087 RVA: 0x001C7EB0 File Offset: 0x001C62B0 private void GenerateLut() { ColorGradingModel.Settings settings = base.model.settings; if (!this.IsLogLutValid(base.model.bakedLut)) { GraphicsUtils.Destroy(base.model.bakedLut); base.model.bakedLut = new RenderTexture(1024, 32, 0, RenderTextureFormat.ARGBHalf) { name = "Color Grading Log LUT", hideFlags = HideFlags.DontSave, filterMode = FilterMode.Bilinear, wrapMode = TextureWrapMode.Clamp, anisoLevel = 0 }; } Material material = this.context.materialFactory.Get("Hidden/Post FX/Lut Generator"); material.SetVector(ColorGradingComponent.Uniforms._LutParams, new Vector4(32f, 0.00048828125f, 0.015625f, 1.032258f)); material.shaderKeywords = null; ColorGradingModel.TonemappingSettings tonemapping = settings.tonemapping; ColorGradingModel.Tonemapper tonemapper = tonemapping.tonemapper; if (tonemapper != ColorGradingModel.Tonemapper.Neutral) { if (tonemapper == ColorGradingModel.Tonemapper.ACES) { material.EnableKeyword("TONEMAPPING_FILMIC"); } } else { material.EnableKeyword("TONEMAPPING_NEUTRAL"); float num = tonemapping.neutralBlackIn * 20f + 1f; float num2 = tonemapping.neutralBlackOut * 10f + 1f; float num3 = tonemapping.neutralWhiteIn / 20f; float num4 = 1f - tonemapping.neutralWhiteOut / 20f; float t = num / num2; float t2 = num3 / num4; float y = Mathf.Max(0f, Mathf.LerpUnclamped(0.57f, 0.37f, t)); float z = Mathf.LerpUnclamped(0.01f, 0.24f, t2); float w = Mathf.Max(0f, Mathf.LerpUnclamped(0.02f, 0.2f, t)); material.SetVector(ColorGradingComponent.Uniforms._NeutralTonemapperParams1, new Vector4(0.2f, y, z, w)); material.SetVector(ColorGradingComponent.Uniforms._NeutralTonemapperParams2, new Vector4(0.02f, 0.3f, tonemapping.neutralWhiteLevel, tonemapping.neutralWhiteClip / 10f)); } material.SetFloat(ColorGradingComponent.Uniforms._HueShift, settings.basic.hueShift / 360f); material.SetFloat(ColorGradingComponent.Uniforms._Saturation, settings.basic.saturation); material.SetFloat(ColorGradingComponent.Uniforms._Contrast, settings.basic.contrast); material.SetVector(ColorGradingComponent.Uniforms._Balance, this.CalculateColorBalance(settings.basic.temperature, settings.basic.tint)); Vector3 v; Vector3 v2; Vector3 v3; ColorGradingComponent.CalculateLiftGammaGain(settings.colorWheels.linear.lift, settings.colorWheels.linear.gamma, settings.colorWheels.linear.gain, out v, out v2, out v3); material.SetVector(ColorGradingComponent.Uniforms._Lift, v); material.SetVector(ColorGradingComponent.Uniforms._InvGamma, v2); material.SetVector(ColorGradingComponent.Uniforms._Gain, v3); Vector3 v4; Vector3 v5; Vector3 v6; ColorGradingComponent.CalculateSlopePowerOffset(settings.colorWheels.log.slope, settings.colorWheels.log.power, settings.colorWheels.log.offset, out v4, out v5, out v6); material.SetVector(ColorGradingComponent.Uniforms._Slope, v4); material.SetVector(ColorGradingComponent.Uniforms._Power, v5); material.SetVector(ColorGradingComponent.Uniforms._Offset, v6); material.SetVector(ColorGradingComponent.Uniforms._ChannelMixerRed, settings.channelMixer.red); material.SetVector(ColorGradingComponent.Uniforms._ChannelMixerGreen, settings.channelMixer.green); material.SetVector(ColorGradingComponent.Uniforms._ChannelMixerBlue, settings.channelMixer.blue); material.SetTexture(ColorGradingComponent.Uniforms._Curves, this.GetCurveTexture()); Graphics.Blit(null, base.model.bakedLut, material, 0); }
public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC) { var settings = model.settings; // Material setup var material = context.materialFactory.Get(k_ShaderString); material.shaderKeywords = null; var s1 = settings.focusDistance; var f = CalculateFocalLength(); s1 = Mathf.Max(s1, f); material.SetFloat(Uniforms._Distance, s1); var coeff = f * f / (settings.aperture * (s1 - f) * k_FilmHeight * 2); material.SetFloat(Uniforms._LensCoeff, coeff); var maxCoC = CalculateMaxCoCRadius(source.height); material.SetFloat(Uniforms._MaxCoC, maxCoC); material.SetFloat(Uniforms._RcpMaxCoC, 1f / maxCoC); var rcpAspect = (float)source.height / source.width; material.SetFloat(Uniforms._RcpAspect, rcpAspect); var rt1 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf); source.filterMode = FilterMode.Point; // Pass #1 - Downsampling, prefiltering and CoC calculation Graphics.Blit(source, rt1, material, 0); // Pass #2 - CoC Antialiasing var pass = rt1; if (antialiasCoC) { pass = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf); if (m_CoCHistory == null || !m_CoCHistory.IsCreated() || m_CoCHistory.width != context.width / 2 || m_CoCHistory.height != context.height / 2) { m_CoCHistory = RenderTexture.GetTemporary(context.width / 2, context.height / 2, 0, RenderTextureFormat.RHalf); m_CoCHistory.filterMode = FilterMode.Point; m_CoCHistory.name = "CoC History"; Graphics.Blit(rt1, m_CoCHistory, material, 6); } var tempCoCHistory = RenderTexture.GetTemporary(context.width / 2, context.height / 2, 0, RenderTextureFormat.RHalf); tempCoCHistory.filterMode = FilterMode.Point; tempCoCHistory.name = "CoC History"; m_MRT[0] = pass.colorBuffer; m_MRT[1] = tempCoCHistory.colorBuffer; material.SetTexture(Uniforms._MainTex, rt1); material.SetTexture(Uniforms._HistoryCoC, m_CoCHistory); Graphics.SetRenderTarget(m_MRT, rt1.depthBuffer); GraphicsUtils.Blit(material, 5); RenderTexture.ReleaseTemporary(m_CoCHistory); m_CoCHistory = tempCoCHistory; } // Pass #3 - Bokeh simulation var rt2 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf); Graphics.Blit(pass, rt2, material, 1 + (int)settings.kernelSize); if (context.profile.debugViews.IsModeActive(DebugMode.FocusPlane)) { uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt1); uberMaterial.SetFloat(Uniforms._MaxCoC, maxCoC); uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW"); context.Interrupt(); } else { uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt2); uberMaterial.EnableKeyword("DEPTH_OF_FIELD"); } if (antialiasCoC) { context.renderTextureFactory.Release(pass); } context.renderTextureFactory.Release(rt1); source.filterMode = FilterMode.Bilinear; }