A post-processing component that applies a directional motion-blur effect. It exposes editable properties for angle, length, sample count and strength, sets them as shader attributes, loads a shader material and performs a blit after post processing.
using Sandbox;
using Sandbox.Rendering;
/// <summary>
/// Directional blur - motion blur effect along specific angle
/// </summary>
[Title( "Directional Blur" )]
[Category( "Post Processing" )]
[Icon( "blur_on" )]
public sealed class CCSDirectionalBlur : BasePostProcess<CCSDirectionalBlur>
{
/// <summary>
/// Direction angle in degrees (0 = right, 90 = up, 180 = left, 270 = down)
/// </summary>
[Property, Title("Angle"), Range(0.0f, 360.0f)]
public float Angle { get; set; } = 0.0f;
/// <summary>
/// Blur length in pixels
/// </summary>
[Property, Title("Length"), Range(0.0f, 50.0f)]
public float Length { get; set; } = 10.0f;
/// <summary>
/// Number of samples (higher = better quality, slower)
/// </summary>
[Property, Title("Samples"), Range(1, 32)]
public int Samples { get; set; } = 8;
/// <summary>
/// Effect strength (0 = original, 1 = full blur)
/// </summary>
[Property, Title("Strength"), Range(0.0f, 1.0f)]
public float Strength { get; set; } = 1.0f;
public override void Render()
{
Attributes.Set("Angle", Angle);
Attributes.Set("Length", Length);
Attributes.Set("Samples", Samples);
Attributes.Set("Strength", Strength);
var material = Material.FromShader("postprocess/fl4_directionalblur.shader");
if (material == null)
{
Log.Error("CCSDirectionalBlur: Shader not found!");
return;
}
var blit = BlitMode.WithBackbuffer(material, Stage.AfterPostProcess, 4000, false);
Blit(blit, "CCSDirectionalBlur");
}
}