menu_bookDocumentation
Creating Post-Process Effects: BasePostProcess with Volume Blending and Shaders
Create custom post-processing effects in s&box by deriving from BasePostProcess<T>. This enables volume-based blending and custom shader rendering.
The Component
CSHARP
public sealed class MyBrightnessEffect : BasePostProcess<MyBrightnessEffect>
{
[Property, Range( -1, 1 )]
public float Brightness { get; set; } = 0.0f;
public override void Render()
{
float brightness = GetWeighted( x => x.Brightness );
if ( brightness.AlmostEqual( 0.0f ) ) return;
Attributes.Set( "brightness", 1 + brightness );
var shader = Material.FromShader( "shaders/postprocess/brightness.shader" );
var blit = BlitMode.WithBackbuffer( shader, Stage.AfterPostProcess, 200, false );
Blit( blit, "Brightness" );
}
}Key Methods
- GetWeighted — gets a blended value from all active PostProcessVolumes based on camera position
- Blit — creates a CommandList for rendering. Specify render stage, order, and whether you need the backbuffer (passed as ColorBuffer to shader)
Shader Example
CPP
PS
{
Texture2D colorBuffer < Attribute( "ColorBuffer" ); SrgbRead( true ); >;
float brightness < Attribute("brightness"); >;
float4 MainPs( PixelInput i ) : SV_Target0
{
float2 uv = CalculateViewportUv( i.uv.xy );
float4 color = colorBuffer.SampleLevel( g_sBilinearMirror, uv, 0 );
color.rgb *= brightness;
return color;
}
}Include postprocess/shared.hlsl in COMMON and postprocess/common.hlsl + postprocess/functions.hlsl in PS.
Was this helpful?