Files
sbox-public/engine/Sandbox.Engine/Scene/Components/PostProcessing/Effects/ChromaticAberration.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

42 lines
1.1 KiB
C#

using Sandbox.Rendering;
namespace Sandbox;
/// <summary>
/// Applies a chromatic aberration effect to the camera
/// </summary>
[Title( "Chromatic Aberration" )]
[Category( "Post Processing" )]
[Icon( "zoom_out_map" )]
public sealed class ChromaticAberration : BasePostProcess<ChromaticAberration>
{
/// <summary>
/// Enable chromatic aberration
/// </summary>
[Property, Range( 0, 1 )] public float Scale { get; set; } = 0.33f;
/// <summary>
/// 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
/// </summary>
[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" );
}
}