A post-processing component that renders anamorphic lens flares. It exposes adjustable properties (threshold, intensity, streak length, falloff, tint, horizontal/vertical toggles), sets shader parameters, loads a shader material, and issues a blit after post-processing.
using Sandbox;
using System;
using Sandbox;
using Sandbox.Rendering;
[Title( "Anamorphic Flares" )]
[Category( "Post Processing" )]
[Icon( "align_horizontal_center" )]
public sealed class CCSAnamorphicFlares : BasePostProcess<CCSAnamorphicFlares>
{
[Property, Title("Threshold"), Range(0.0f, 1.0f)]
public float Threshold { get; set; } = 0.6f;
[Property, Title("Intensity"), Range(0.0f, 10.0f)]
public float Intensity { get; set; } = 3.0f;
[Property, Title("Streak Length"), Range(10.0f, 256.0f)]
public float StreakLength { get; set; } = 100.0f;
/// <summary>
/// Exponential falloff factor. Higher = thinner streaks.
/// Works as fractional value: Falloff / 100.0
/// </summary>
[Property, Title("Falloff"), Range(0.1f, 20.0f)]
public float Falloff { get; set; } = 5.0f;
[Property, Title("Streak Color")]
public Color Tint { get; set; } = new Color(0.5f, 0.7f, 1.0f, 1.0f);
[Property, Title("Horizontal Streaks")]
public bool Horizontal { get; set; } = true;
[Property, Title("Vertical Streaks")]
public bool Vertical { get; set; } = false;
public override void Render()
{
Attributes.Set("Threshold", Threshold);
Attributes.Set("Intensity", Intensity);
Attributes.Set("StreakLength", StreakLength);
Attributes.Set("Falloff", Falloff);
Attributes.Set("Tint", new Vector3(Tint.r, Tint.g, Tint.b));
Attributes.Set("Horizontal", Horizontal ? 1 : 0);
Attributes.Set("Vertical", Vertical ? 1 : 0);
var material = Material.FromShader("postprocess/ccs_anamorphicflare.shader");
if (material == null)
{
Log.Error("CCSAnamorphicFlares: Shader not found!");
return;
}
var blit = BlitMode.WithBackbuffer(material, Stage.AfterPostProcess, 4000, false);
Blit(blit, "CCSAnamorphicFlares");
}
}