-
-
Notifications
You must be signed in to change notification settings - Fork 234
Effect Merging
The Effect framework defines a simple shader format for easy merging. The merging process gathers and prefixes functions, varyings, uniforms and macros to produce a single compound shader. This shader processes texels from an input buffer which usually contains the rendered scene colors. As each texel passes through the effect function chain, 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 for you 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 |
---|---|---|
![]() |
![]() |
![]() |
Pixelation transforms texture coordinates for individual fragments. SMAA then uses these coordinates but calculates its own offsets to blend texels with neighbors. As a result, the antialiased lines show up in the final image. The image on the right shows the extreme case where the pixelation reduces the scene into a single pixel.