public override void OnDisable() { GraphicsUtils.Destroy(m_GradingCurves); GraphicsUtils.Destroy(model.bakedLut); m_GradingCurves = null; model.bakedLut = null; }
public void Dispose() { var enumerator = m_Materials.GetEnumerator(); while (enumerator.MoveNext()) { var material = enumerator.Current.Value; GraphicsUtils.Destroy(material); } m_Materials.Clear(); }
public override void Prepare(Material uberMaterial) { var settings = model.settings; uberMaterial.EnableKeyword("GRAIN"); float rndOffsetX; float rndOffsetY; #if POSTFX_DEBUG_STATIC_GRAIN // Chosen by a fair dice roll float time = 4f; rndOffsetX = 0f; rndOffsetY = 0f; #else float time = Time.realtimeSinceStartup; rndOffsetX = Random.value; rndOffsetY = Random.value; #endif // Generate the grain lut for the current frame first if (m_GrainLookupRT == null || !m_GrainLookupRT.IsCreated()) { GraphicsUtils.Destroy(m_GrainLookupRT); m_GrainLookupRT = new RenderTexture(192, 192, 0, RenderTextureFormat.ARGBHalf) { filterMode = FilterMode.Bilinear, wrapMode = TextureWrapMode.Repeat, anisoLevel = 0, name = "Grain Lookup Texture" }; m_GrainLookupRT.Create(); } var grainMaterial = context.materialFactory.Get("Hidden/Post FX/Grain Generator"); grainMaterial.SetFloat(Uniforms._Phase, time / 20f); Graphics.Blit((Texture)null, m_GrainLookupRT, grainMaterial, settings.colored ? 1 : 0); // Send everything to the uber shader uberMaterial.SetTexture(Uniforms._GrainTex, m_GrainLookupRT); uberMaterial.SetVector(Uniforms._Grain_Params1, new Vector2(settings.luminanceContribution, settings.intensity * 20f)); uberMaterial.SetVector(Uniforms._Grain_Params2, new Vector4((float)context.width / (float)m_GrainLookupRT.width / settings.size, (float)context.height / (float)m_GrainLookupRT.height / settings.size, rndOffsetX, rndOffsetY)); }
public override void OnDisable() { foreach (var rt in m_AutoExposurePool) { GraphicsUtils.Destroy(rt); } if (m_HistogramBuffer != null) { m_HistogramBuffer.Release(); } m_HistogramBuffer = null; if (m_DebugHistogram != null) { m_DebugHistogram.Release(); } m_DebugHistogram = 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, GetLutFormat()) { 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 Release() { GraphicsUtils.Destroy(mesh); mesh = null; }
public override void OnDisable() { GraphicsUtils.Destroy(m_SpectrumLut); m_SpectrumLut = null; }
public override void OnDisable() { GraphicsUtils.Destroy(m_GrainLookupRT); m_GrainLookupRT = null; }