Files
sbox-public/engine/Sandbox.Engine/Scene/Components/PostProcessing/Effects/Pixelate.cs
Lorenz Junglas 12affe5ccb Reduce material creations/allocations (#3766)
* 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
2026-01-14 08:40:37 +01:00

29 lines
708 B
C#

using Sandbox.Rendering;
namespace Sandbox;
/// <summary>
/// Applies a pixelate effect to the camera
/// </summary>
[Title( "Pixelate" )]
[Category( "Post Processing" )]
[Icon( "apps" )]
public sealed class Pixelate : BasePostProcess<Pixelate>
{
[Range( 0, 1 )]
[Property] public float Scale { get; set; } = 0.25f;
private static readonly Material Shader = Material.FromShader( "shaders/postprocess/pp_pixelate.shader" );
public override void Render()
{
float scale = GetWeighted( x => x.Scale );
if ( scale.AlmostEqual( 0.0f ) ) return;
Attributes.Set( "scale", scale );
var blit = BlitMode.WithBackbuffer( Shader, Stage.AfterPostProcess, 10000, true );
Blit( blit, "Pixelate" );
}
}