public override void OnDisable() { GraphicsUtils.Destroy(m_GradingCurves); GraphicsUtils.Destroy(model.bakedLut); m_GradingCurves = null; model.bakedLut = null; }
private void ComputeWaveform(RenderTexture source) { if (m_Buffer == null) { CreateBuffer(source.width, source.height); } else if (m_Buffer.count != source.width * source.height) { m_Buffer.Release(); CreateBuffer(source.width, source.height); } var channels = m_MonitorSettings.waveformY ? new Vector4(0f, 0f, 0f, 1f) : new Vector4(m_MonitorSettings.waveformR ? 1f : 0f, m_MonitorSettings.waveformG ? 1f : 0f, m_MonitorSettings.waveformB ? 1f : 0f, 0f); var cs = m_ComputeShader; var kernel = cs.FindKernel("KWaveformClear"); cs.SetBuffer(kernel, "_Waveform", m_Buffer); cs.Dispatch(kernel, source.width, 1, 1); kernel = cs.FindKernel("KWaveform"); cs.SetBuffer(kernel, "_Waveform", m_Buffer); cs.SetTexture(kernel, "_Source", source); cs.SetInt("_IsLinear", GraphicsUtils.isLinearColorSpace ? 1 : 0); cs.SetVector("_Channels", channels); cs.Dispatch(kernel, source.width, 1, 1); if (m_WaveformTexture == null || m_WaveformTexture.width != source.width * 3 || m_WaveformTexture.height != source.height) { GraphicsUtils.Destroy(m_WaveformTexture); m_WaveformTexture = new RenderTexture(source.width * 3, source.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear) { hideFlags = HideFlags.DontSave, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; } if (m_Material == null) { m_Material = new Material(Shader.Find("Hidden/Post FX/Monitors/Parade Render")) { hideFlags = HideFlags.DontSave } } ; m_Material.SetBuffer("_Waveform", m_Buffer); m_Material.SetVector("_Size", new Vector2(m_WaveformTexture.width, m_WaveformTexture.height)); m_Material.SetVector("_Channels", channels); } }
public override void Prepare(Material uberMaterial) { var settings = model.settings; uberMaterial.EnableKeyword("GRAIN"); #if POSTFX_DEBUG_STATIC_GRAIN // Chosen by a fair dice roll float time = 4f; float rndXOffset = 0f; float rndYOffset = 0f; #else float time = Time.realtimeSinceStartup; float rndXOffset = Random.value; float rndYOffset = Random.value; #endif // Used for sample rotation in Filmic mode and position offset in Fast mode const float kRotationOffset = 1.425f; float c = Mathf.Cos(time + kRotationOffset); float s = Mathf.Sin(time + kRotationOffset); 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.SetVector(Uniforms._Params, new Vector4(settings.size, time / 20f, c, s)); Graphics.Blit((Texture)null, m_GrainLookupRT, grainMaterial, settings.colored ? 1 : 0); uberMaterial.SetTexture(Uniforms._GrainTex, m_GrainLookupRT); float intensity = settings.intensity * 0.25f; if (!settings.colored) { uberMaterial.SetVector(Uniforms._Grain_Params1, new Vector4(settings.luminanceContribution, intensity, intensity, intensity)); } else { uberMaterial.SetVector(Uniforms._Grain_Params1, new Vector4(settings.luminanceContribution, settings.weightR * intensity, settings.weightG * intensity, settings.weightB * intensity)); } uberMaterial.SetVector(Uniforms._Grain_Params2, new Vector4((float)context.width / (float)m_GrainLookupRT.width, (float)context.height / (float)m_GrainLookupRT.height, rndXOffset, rndYOffset)); }
private void ComputeVectorscope(RenderTexture source) { if (m_Buffer == null) { CreateBuffer(source.width, source.height); } else if (m_Buffer.count != source.width * source.height) { m_Buffer.Release(); CreateBuffer(source.width, source.height); } var cs = m_ComputeShader; var kernel = cs.FindKernel("KVectorscopeClear"); cs.SetBuffer(kernel, "_Vectorscope", m_Buffer); cs.SetVector("_Res", new Vector4(source.width, source.height, 0f, 0f)); cs.Dispatch(kernel, Mathf.CeilToInt(source.width / 32f), Mathf.CeilToInt(source.height / 32f), 1); kernel = cs.FindKernel("KVectorscope"); cs.SetBuffer(kernel, "_Vectorscope", m_Buffer); cs.SetTexture(kernel, "_Source", source); cs.SetInt("_IsLinear", GraphicsUtils.isLinearColorSpace ? 1 : 0); cs.SetVector("_Res", new Vector4(source.width, source.height, 0f, 0f)); cs.Dispatch(kernel, Mathf.CeilToInt(source.width / 32f), Mathf.CeilToInt(source.height / 32f), 1); if (m_VectorscopeTexture == null || m_VectorscopeTexture.width != source.width || m_VectorscopeTexture.height != source.height) { GraphicsUtils.Destroy(m_VectorscopeTexture); m_VectorscopeTexture = new RenderTexture(source.width, source.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear) { hideFlags = HideFlags.DontSave, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; } if (m_Material == null) { m_Material = new Material(Shader.Find("Hidden/Post FX/Monitors/Vectorscope Render")) { hideFlags = HideFlags.DontSave } } ; m_Material.SetBuffer("_Vectorscope", m_Buffer); m_Material.SetVector("_Size", new Vector2(m_VectorscopeTexture.width, m_VectorscopeTexture.height)); } }
public override void Dispose() { GraphicsUtils.Destroy(m_Material): GraphicsUtils.Destroy(m_HistogramTexture): if (m_Buffer != null) m_Buffer.Release(): m_Material = null: m_HistogramTexture = null: m_Buffer = null: }
public override void Dispose() { GraphicsUtils.Destroy(m_Material); GraphicsUtils.Destroy(m_VectorscopeTexture); if (m_Buffer != null) { m_Buffer.Release(); } m_Material = null; m_VectorscopeTexture = null; m_Buffer = null; }
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 var 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(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(context.width / (float)m_GrainLookupRT.width / settings.size, 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 ComputeHistogram(RenderTexture source) { if (m_Buffer == null) { CreateBuffer(256, 1); } else if (m_Buffer.count != 256) { m_Buffer.Release(); CreateBuffer(256, 1); } if (m_Material == null) { m_Material = new Material(Shader.Find("Hidden/Post FX/Monitors/Histogram Render")) { hideFlags = HideFlags.DontSave }; } var channels = Vector4.zero; switch (m_MonitorSettings.histogramMode) { case HistogramMode.Red: channels.x = 1f; break; case HistogramMode.Green: channels.y = 1f; break; case HistogramMode.Blue: channels.z = 1f; break; case HistogramMode.Luminance: channels.w = 1f; break; default: channels = new Vector4(1f, 1f, 1f, 0f); break; } var cs = m_ComputeShader; int kernel = cs.FindKernel("KHistogramClear"); cs.SetBuffer(kernel, "_Histogram", m_Buffer); cs.Dispatch(kernel, 1, 1, 1); kernel = cs.FindKernel("KHistogramGather"); cs.SetBuffer(kernel, "_Histogram", m_Buffer); cs.SetTexture(kernel, "_Source", source); cs.SetInt("_IsLinear", GraphicsUtils.isLinearColorSpace ? 1 : 0); cs.SetVector("_Res", new Vector4(source.width, source.height, 0f, 0f)); cs.SetVector("_Channels", channels); cs.Dispatch(kernel, Mathf.CeilToInt(source.width / 16f), Mathf.CeilToInt(source.height / 16f), 1); kernel = cs.FindKernel("KHistogramScale"); cs.SetBuffer(kernel, "_Histogram", m_Buffer); cs.Dispatch(kernel, 1, 1, 1); if (m_HistogramTexture == null || m_HistogramTexture.width != source.width || m_HistogramTexture.height != source.height) { GraphicsUtils.Destroy(m_HistogramTexture); m_HistogramTexture = new RenderTexture(source.width, source.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear) { hideFlags = HideFlags.DontSave, wrapMode = TextureWrapMode.Clamp, filterMode = FilterMode.Bilinear }; } m_Material.SetBuffer("_Histogram", m_Buffer); m_Material.SetVector("_Size", new Vector2(m_HistogramTexture.width, m_HistogramTexture.height)); m_Material.SetColor("_ColorR", new Color(1f, 0f, 0f, 1f)); m_Material.SetColor("_ColorG", new Color(0f, 1f, 0f, 1f)); m_Material.SetColor("_ColorB", new Color(0f, 0f, 1f, 1f)); m_Material.SetColor("_ColorL", new Color(1f, 1f, 1f, 1f)); m_Material.SetInt("_Channel", (int)m_MonitorSettings.histogramMode); int pass = 0; if (m_MonitorSettings.histogramMode == HistogramMode.RGBMerged) { pass = 1; } else if (m_MonitorSettings.histogramMode == HistogramMode.RGBSplit) { pass = 2; } Graphics.Blit(null, m_HistogramTexture, m_Material, pass); }
public override void OnDisable() { GraphicsUtils.Destroy(m_GrainLookupRT); m_GrainLookupRT = null; }
public override void OnDisable() { GraphicsUtils.Destroy(m_SpectrumLut); m_SpectrumLut = null; }
public void Release() { GraphicsUtils.Destroy(mesh); mesh = 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); }