Skip to main content

PostProcessor

PostProcessors apply a shader effect to the entire screen at the end of the frame.

Implement PostProcessor.process: the current (MSAA-resolved) screen arrives as source and the result must be rendered into destination — typically with a ShaderPass or ShaderPipeline. Because the shape matches ShaderPipelineLike, effect objects like BloomEffect or BlurEffect can be added as post processors directly:

game.graphicsContext.addPostProcessor(new ex.BloomEffect({ graphicsContext }));

Use ShaderPipelinePostProcessor to build one from a list of fragment sources.

Fragment shaders in a ShaderPass/ShaderPipeline get these built-ins:

  • uniform sampler2D u_image - the current screen (or previous pass output)
  • uniform vec2 u_resolution - the destination resolution (in pixels)
  • uniform vec2 u_texelSize - 1.0 / source resolution
  • uniform float u_time_ms - total time in milliseconds
  • uniform float u_elapsed_ms - elapsed milliseconds since the last frame
  • in vec2 v_uv - 0-1 UV over the screen

The deprecated single-pass path receives u_image at slot 0 plus u_time_ms, u_elapsed_ms, and u_resolution when declared; custom uniforms can be updated in PostProcessor.onUpdate.

Implemented by

Index

Methods

optionalgetLayout

optionalgetShader

  • @deprecated

    implement PostProcessor.process instead, the single-pass shader/layout path will be removed in v1. The screen texture is bound to slot 0 as uniform sampler2D u_image and default uniforms (u_time_ms, u_elapsed_ms, u_resolution) are set when declared.


    Returns Shader

optionalinitialize

optionalonDraw

  • onDraw(): void
  • Use the onDraw hook to upload any textures or command that need to run right before draw


    Returns void

optionalonUpdate

  • onUpdate(elapsed: number): void
  • Use the onUpdate hook to update any uniforms in the postprocessors shader

    The shader has already been bound so there is no need to call shader.use();


    Parameters

    • elapsed: number

    Returns void

optionalprocess