RetroScreenPostProcess.cs

A post-processing component that hooks into a CameraComponent to run a custom retro screen effect. It grabs the color and depth frame textures, sets a few render attributes (vertex snap and dithered flag) and blits a material (materials/postprocessing/post_processing.vmat) before the overlay.

Native Interop
using System;
using Sandbox;

[Title( "Retro Camera Post Process" )]
[Category( "Post Processing" )]
[Icon( "apps" )]
public class RetroScreenPostProcess : Component, Component.ExecuteInEditor
{
	IDisposable renderHook;

	[ConVar( "op_postprocess" )]
	public static bool PostProcessEnabled { get; set; } = true;

	protected override void OnEnabled()
	{
		renderHook?.Dispose();

		var cc = Components.Get<CameraComponent>( FindMode.EnabledInSelfAndChildren );
		renderHook = cc.AddHookBeforeOverlay( "DDDownscaler", 500, RenderEffect );
	}

	protected override void OnDisabled()
	{
		renderHook?.Dispose();
		renderHook = null;
	}

	RenderAttributes attributes = new RenderAttributes();
	static Material effectMaterial = Material.Load( "materials/postprocessing/post_processing.vmat" );
	public void RenderEffect( SceneCamera camera )
	{
		camera.Attributes.SetCombo( "D_VERTEX_SNAP", true );

		//if ( !PostProcessEnabled )
			//return;

		Graphics.GrabFrameTexture( "ColorBuffer", attributes );
		Graphics.GrabDepthTexture( "DepthBuffer", attributes );
		//Set if you want to use the dithered effect. TONY! DEFAULT TO TRUE!
		attributes.Set( "Dithered", true );
		Graphics.Blit( effectMaterial, attributes );
	}
}