using Sandbox.Rendering;
namespace Sandbox;
///
/// Applies a film grain effect to the camera
///
[Title( "FilmGrain" )]
[Category( "Post Processing" )]
[Icon( "grain" )]
public sealed class FilmGrain : BasePostProcess
{
[Range( 0, 1 )]
[Property] public float Intensity { get; set; } = 0.1f;
[Range( 0, 1 )]
[Property] public float Response { get; set; } = 0.5f;
public override void Render()
{
float intensity = GetWeighted( x => x.Intensity );
if ( intensity.AlmostEqual( 0.0f ) ) return;
float response = GetWeighted( x => x.Response, 1 );
Attributes.Set( "intensity", intensity );
Attributes.Set( "response", GetWeighted( x => x.Response, 1 ) );
var blit = BlitMode.WithBackbuffer( Material.FromShader( "shaders/postprocess/pp_filmgrain.shader" ), Stage.AfterPostProcess, 200, false );
Blit( blit, "FilmGrain" );
}
}