using Sandbox.Rendering;
namespace Sandbox;
///
/// Applies a chromatic aberration effect to the camera
///
[Title( "Chromatic Aberration" )]
[Category( "Post Processing" )]
[Icon( "zoom_out_map" )]
public sealed class ChromaticAberration : BasePostProcess
{
///
/// Enable chromatic aberration
///
[Property, Range( 0, 1 )] public float Scale { get; set; } = 0.33f;
///
/// The pixel offset for each color channel. These values should
/// be very small as it's in UV space. (0.004 for example)
/// X = Red
/// Y = Green
/// Z = Blue
///
[Property] public Vector3 Offset { get; set; } = new Vector3( 6f, 2f, 4.0f );
public override void Render()
{
float scale = GetWeighted( x => x.Scale );
Vector3 offset = GetWeighted( x => x.Offset );
if ( scale <= 0f )
return;
Attributes.Set( "scale", scale );
Attributes.Set( "amount", offset / 1000.0f );
var blit = BlitMode.WithBackbuffer( Material.FromShader( "shaders/postprocess/pp_chromaticaberration.shader" ), Stage.AfterPostProcess, 1000, false );
Blit( blit, "ChromaticAberration" );
}
}