A post-process effect class for s&box that applies a colorful glitch/JPEG corruption look. It exposes two properties, levels and freq, reads a material shader, sets shader attributes, and performs a blit to apply the effect.
using Sandbox;
using System;
using Sandbox;
using Sandbox.Rendering;
/// <summary>
/// Make everything look horrid (VERY FLASHY COLORS!)
/// </summary>
[Title( "Wacky Screen" )]
[Category( "Post Processing" )]
[Icon( "coronavirus" )]
public sealed class CCSJGlitch_bad : BasePostProcess<CCSJGlitch_bad>
{
/// <summary>
/// Higher = more messed up.
/// </summary>
// ИСПРАВЛЕНО: Убраны лишние аргументы из Range (1, true), чтобы избежать NullReferenceException
[Property, Title("Goofyness"), Range(1, 99)]
public int levels { get; set; } = 75;
/// <summary>
/// Sorta zooms in on the image.
/// </summary>
[Property, Title("Zoomyness"), Range(1, 20)]
public int freq { get; set; } = 3;
public override void Render()
{
// Числовые значения через GetWeighted — поддерживает блендинг в PostProcess Volume
int levelsW = GetWeighted(x => x.levels);
int freqW = GetWeighted(x => x.freq);
// Загружаем материал с проверкой на null
var material = Material.FromShader("postprocess/ccs_jpeg_bad.shader");
if (material == null)
{
Log.Warning("CCSJGlitch_bad: Material 'materials/postprocess/ccs_jpeg_bad.vmat' not found!");
return;
}
// Передаем значения в шейдер
Attributes.Set("levels", levelsW);
Attributes.Set("freq", freqW);
// Применяем эффект через современный Blit API
// Приоритет 5001 перенесен из оригинального кода
var blit = BlitMode.WithBackbuffer(material, Stage.AfterPostProcess, 5001, true);
Blit(blit, "CCSJGlitch_bad");
}
}