mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-27 15:50:36 -05:00
* Make SpriteBatchSceneObject shaders static, so we don't create them per instance * Avoid per frame shader/material creation in PostProcessing * Avoid per frame shader/material creation in HudPainter * Move a few more compute shaders into static members * Reduce allocations in NormalizeFilename * Reduce string allocations in Material.FromShader
36 lines
935 B
C#
36 lines
935 B
C#
using Sandbox.Rendering;
|
|
|
|
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// Applies a film grain effect to the camera
|
|
/// </summary>
|
|
[Title( "FilmGrain" )]
|
|
[Category( "Post Processing" )]
|
|
[Icon( "grain" )]
|
|
public sealed class FilmGrain : BasePostProcess<FilmGrain>
|
|
{
|
|
[Range( 0, 1 )]
|
|
[Property] public float Intensity { get; set; } = 0.1f;
|
|
|
|
[Range( 0, 1 )]
|
|
[Property] public float Response { get; set; } = 0.5f;
|
|
|
|
private static readonly Material Shader = Material.FromShader( "shaders/postprocess/pp_filmgrain.shader" );
|
|
|
|
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( Shader, Stage.AfterPostProcess, 200, false );
|
|
Blit( blit, "FilmGrain" );
|
|
}
|
|
|
|
}
|