using Sandbox.Rendering; namespace Sandbox; /// /// Applies a vignette to the camera /// [Title( "Vignette" )] [Category( "Post Processing" )] [Icon( "vignette" )] public sealed class Vignette : BasePostProcess { /// /// The color of the vignette or the "border" /// [Property] public Color Color { get; set; } = Color.Black; /// /// How strong the vignette is. This is a value between 0 -> 1 /// [Property, Range( 0, 1 )] public float Intensity { get; set; } = 1.0f; /// /// How much fall off or how blurry the vignette is /// [Property, Range( 0, 1 )] public float Smoothness { get; set; } = 1.0f; /// /// How circular or round the vignette is /// [Property, Range( 0, 1 )] public float Roundness { get; set; } = 1.0f; /// /// The center of the vignette in relation to UV space. This means /// a value of {0.5, 0.5} is the center of the screen /// [Property] public Vector2 Center { get; set; } = new Vector2( 0.5f, 0.5f ); public override void Render() { var shader = Material.FromShader( "shaders/postprocess/pp_vignette.shader" ); float intensity = GetWeighted( x => x.Intensity ); if ( intensity.AlmostEqual( 0.0f ) ) return; var color = GetWeighted( x => x.Color ); if ( color.a.AlmostEqual( 0.0f ) ) return; Attributes.Set( "color", color ); Attributes.Set( "intensity", intensity ); Attributes.Set( "smoothness", GetWeighted( x => x.Smoothness, onlyLerpBetweenVolumes: true ) ); Attributes.Set( "roundness", GetWeighted( x => x.Roundness, onlyLerpBetweenVolumes: true ) ); Attributes.Set( "center", GetWeighted( x => x.Center, onlyLerpBetweenVolumes: true ) ); var blit = BlitMode.Simple( shader, Stage.BeforePostProcess, 5000 ); Blit( blit, "Vignette" ); } }