A post-processing effect class that applies an ordered-dithering full-screen shader. It creates a CommandList, grabs the current frame into a texture named "FrameTexture", blits with shaders/dithering_postprocess.shader, and inserts the list at Stage.AfterUI.
using Sandbox;
using Sandbox.Rendering;
namespace BrickJam;
/// <summary>
/// Full-screen ordered-dithering post effect. Scene-System port of the legacy
/// <c>DitheringEffect : RenderHook</c>. Uses the same unchanged <c>shaders/dithering_postprocess.shader</c>
/// (which samples the <c>"FrameTexture"</c> attribute). The legacy ran
/// <c>Graphics.GrabFrameTexture + Graphics.Blit</c> at <c>Stage.AfterUI</c>; here we build the same
/// command list and insert it via <see cref="BasePostProcess{T}"/>.
/// </summary>
[Title( "Dithering" )]
[Category( "Post Processing" )]
[Icon( "grain" )]
public sealed class DitheringEffect : BasePostProcess<DitheringEffect>
{
private static readonly Material Shader = Material.FromShader( "shaders/dithering_postprocess.shader" );
public override void Render()
{
if ( !Shader.IsValid() )
return;
var cl = new CommandList( "Dithering" );
cl.Attributes.GrabFrameTexture( "FrameTexture" );
cl.Blit( Shader, Attributes );
InsertCommandList( cl, Stage.AfterUI, 5000, "Dithering" );
}
}