CCSColorCorrection.cs

A post-processing component that applies a color correction LUT. It exposes a LUT texture and an opacity property, sets shader attributes, loads a material by shader path, and blits the effect to the backbuffer.

Native Interop
using Sandbox;
using System;


using Sandbox;
using Sandbox.Rendering;

/// <summary>
/// Uses the same "Neutral" LUT type as OBS, low quality but good for FX
/// </summary>
[Title( "Color Correction LUT" )]
[Category( "Post Processing" )]
[Icon( "filter_center_focus" )]
public sealed class CCSColorCorrection : BasePostProcess<CCSColorCorrection>
{
	/// <summary>
	/// Make sure you set it to RGBA8888 not DXT for best quality.
	/// </summary>
	[Property]
	public Texture lut_texture { get; set; }

	/// <summary>
	/// Blend the corrected image with the original.
	/// </summary>
	[Property, Title("Opacity"), Range(0.00f, 1.0f, 0, true)]
	public float fOpacity { get; set; } = 1.0f;

	public override void Render()
	{
		// Защита от отсутствия LUT-текстуры — без неё шейдер не сможет работать корректно
		if (lut_texture == null)
			return;

		// Числовое значение через GetWeighted — поддерживает блендинг в PostProcess Volume
		float fOpacityW = GetWeighted(x => x.fOpacity);

		// Texture передаем напрямую — GetWeighted с Texture не работает
		Attributes.Set("lut_texture", lut_texture);
		Attributes.Set("fOpacity", fOpacityW);

		// Загружаем материал с проверкой на null
		var material = Material.FromShader("postprocess/ccs_colorcorrection.shader");
		if (material == null)
		{
			Log.Warning("CCSColorCorrection: Material 'materials/postprocess/ccs_colorcorrection.vmat' not found!");
			return;
		}

		// Применяем эффект через современный Blit API
		// Приоритет 2001 перенесен из оригинального кода
		var blit = BlitMode.WithBackbuffer(material, Stage.AfterPostProcess, 2001, true);
		Blit(blit, "CCSColorCorrection");
	}
}