-
-
Notifications
You must be signed in to change notification settings - Fork 230
Effect Merging
The Effect framework defines a simple shader format for easy merging. Effects are merged into a single compound shader by gathering and prefixing functions, varyings, uniforms and macros. This shader is then used to process texels from an input buffer which usually contains the rendered scene colors. Texels pass through the effect function chain and intermediate results are blended with previous results. The final result is written to an output buffer or to screen.
Effect merging can drastically increase pixel throughput as it reduces the amount of fullscreen render operations per frame. This, however, is still just a tool to improve performance. Sometimes, you'll need to split effects into separate passes to achieve the best results. For instance, SMAA should usually be applied first to avoid conflicts with other effects, but some effects may introduce new aliasing artifacts further down the line. If that's the case, it can be a better option to run these effects in a separate pass before SMAA.
The EffectPass
sorts effects based on whether or not they read data from the input buffer or rely on depth. Other effects will be rendered in the order in which they were added. The recommended order for common effects is as follows:
- SMAA
- SSR (NYI)
- SSAO
- DoF
- Motion Blur (NYI)
- Chromatic Aberration
- Bloom
- God Rays
- Vignette
- Tone Mapping
- LUT / Color Grading
- Noise / Film Grain
The
EffectPass
prevents bad combinations of effects and informs the user about potential issues.
Convolution effects and effects that transform texture coordinates inside the fragment shader cannot be merged with each other. To use such effects together, you'll need to use multiple EffectPass
instances. While it's technically possible to merge all effects, some combinations will produce undesired results in the form of visual discontinuities and artifacts. The following example shows a combination of a PixelationEffect
and an SMAAEffect
:
SMAA | With Pixelation | Extreme Pixelation |
---|---|---|
![]() |
![]() |
![]() |
The PixelationEffect
transforms texture coordinates in the fragment shader. The transformed UV coordinates are then passed to the SMAAEffect
which calculates its own coordinate offsets to blend texels with neighbors from the input buffer. As a result, the antialiased lines show up in the final image. The image on the right shows an extreme case where the PixelationEffect
reduces the scene into a single grey pixel to better highlight the artifacts.