mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-18 03:09:45 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
34 lines
883 B
C#
34 lines
883 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;
|
|
|
|
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" );
|
|
}
|
|
|
|
}
|