2.22
Forward rendering (Translucency)

- 2.22.1. Overview
- 2.22.2. Instances
- 2.22.3. Blending
- 2.22.4. Culling
- 2.22.5. Ordering
- 2.22.6. Types
- 2.22.7. Provided Shaders

2.22.1
Overview
1
Because the deferred renderer in the r2 package is incapable of rendering translucent instances, a separate forward renderer is provided. A translucent instance is an instance that, when rendered, is simply blended with the current image. This is used to implement visual effects such as glass, water, smoke, fire, etc.
2.22.2
Instances
1
The r2 package provides a slightly different abstraction for translucent instances. Because of the strict ordering requirements when rendering translucent instances, it is simply not possible to batch translucent instances by material and shaders for performance reasons as is done with opaque instances. The r2 package therefore simply has users submit a list of values of type R2TranslucentType in draw order. Each translucent value contains a blending and culling configuration, along with an instance, and a shader for rendering the instance.
2.22.3
Blending
1
Each translucent instance provides a blending configuration that states how the rendered instance is blended with the contents of the current framebuffer.
2.22.4
Culling
1
Typically, it is not desirable to render the back faces of opaque instances as they are by definition invisible. However, translucent instances are by definition translucent and therefore the back faces of the instances may be visible. A translucent instance therefore contains a value that specifies whether front faces, back faces, or both should be rendered.
2.22.5
Ordering
1
Unlike opaque instances which can be rendered in any order due to depth testing, translucent instances must be rendered in strict furthest-to-nearest order. The r2 package simply delegates the responsibility of submitting instances in the correct order to the user. This frees the package from having to know anything about the spatial properties of the scene being rendered.
2.22.6
Types
1
In the r2 package, translucent instances are rendered via implementations of the R2TranslucentRendererType interface.
2
Shaders for rendering translucent instances are of type R2ShaderTranslucentType.
2.22.7
Provided Shaders
1
Because translucent surface can have a massive range of appearances, the r2 package makes no attempt to provide a wide range of shaders for translucent surfaces.
2.22.7.2 Provided instance shaders

Shader | Description
--- | ---
R2TranslucentShaderBasicPremultipliedSingle | Basic textured surface without lighting, with distance fading, producing premultiplied alpha output.