ImFusion SDK 4.3
OrderIndependentTransparency Class Reference

#include <ImFusion/Core/GL/OrderIndependentTransparency.h>

Helper class to consolidate functionality for implementing order-independent transparency of rendered geometry. More...

Detailed Description

Helper class to consolidate functionality for implementing order-independent transparency of rendered geometry.

Instances of this class hold all OpenGL entities needed for storing a per-pixel lists of semi-transparent fragments that can be correctly blended in a second stage. Multiple actors collaborate in order to implement the functionality:

  1. An entity that hosts and manages the OrderIndependentTransparency instance. At the beginning of the render loop this entity should reset/initialize the data structures by calling reset().
  2. Every entity that renders semi-transparent geometry shall not render its fragments directly but instead add every semi-transparent fragment to the OIT data structures. Therefore, in your GLSL fragment shader must first include the OIT shader include and then call oit_addFragment():
    #pragma include "ImFusionGL/OrderIndependentTransparency.glh"
    [perform regular shading computing output color...]
    if (out_Color.a < 1.0)
    {
    // fully opaque fragments will be written normally so that they participate in the Z test
    // semi-transparent fragments will be discarded after being added to the OIT fragment list
    if (oit_addFragment(out_Color, gl_FragCoord.z))
    discard;
    }
    On the client side, you must setup your shader so that it has access to the OIT data structures. Therefore, call setIncludeArguments() after enabling your shader and before rendering any geometry.
  3. After all geometry has been rendered you need to blend all fragments written to the OIT buffer. You can either do this manually in your own shader after including the OIT shader include or by simply calling renderBlendedFragments(). The OIT shader include provides the following functions for this:
    // Resolve all fragments for the current pixel up to the given depth,
    // sort them and return the number of fragments.
    uint oit_sortFragments(in float maxDepth);
    // Blend all fragments resolved in the previous step and return the final color
    // and depth in the output parameters.
    void oit_blendFragments(out vec4 outColor, out float outDepth);

In the ImFusion view framework, Steps 1 and 3 will be implemented by a GlVolumeView. Step 2 is implemented by selected GlObjects. Since the hosting GlView is passed to GlObject::draw() it can access the view's OrderIndependentTransparency object in order to support order-independent transparency.

Note
OrderIndependentTransparency requires OpenGL 4.4.
See also
GlVolumeView

Public Member Functions

 OrderIndependentTransparency ()
 Instantiate a new OrderIndependentTransparency instance.
 
void reset (const vec2i &viewportSize, bool shrinkToFit=false)
 Initializes and resets all OIT data structures for the given viewport size.
 
void setIncludeArguments (Program &program) const
 Bind all OIT data structures to the given shader so that you can use the OIT shader include.
 
void renderBlendedFragments (const Texture &backgroundColor, const Texture &backgroundDepth)
 Render the correctly blended fragments to the currently attached framebuffer.
 

Static Public Member Functions

static bool isSupported ()
 Checks whether the current platform supports OIT.
 

Constructor & Destructor Documentation

◆ OrderIndependentTransparency()

Instantiate a new OrderIndependentTransparency instance.

Exceptions
std::runtime_errorif no OpenGL 4.4 is available

Member Function Documentation

◆ reset()

void reset ( const vec2i & viewportSize,
bool shrinkToFit = false )

Initializes and resets all OIT data structures for the given viewport size.

This function must be called every time at the beginning of the render loop. To avoid expensive reallocation the internal textures and buffers are only recreated if needed (i.e. viewportSize has increased compared to before). If shrinkToFit is true memory will also be reallocated if the viewport size has decreased.

◆ setIncludeArguments()

void setIncludeArguments ( Program & program) const

Bind all OIT data structures to the given shader so that you can use the OIT shader include.

Note
This function will bind both images and buffers to program. Therefore, you should call Program::unbindImages() and Program::unbindBuffers() after rendering.

◆ renderBlendedFragments()

void renderBlendedFragments ( const Texture & backgroundColor,
const Texture & backgroundDepth )

Render the correctly blended fragments to the currently attached framebuffer.

The pixel data stored in backgroundColor and backgroundDepth will be integrated into the scene. Their size is expected to match the viewport size passed during clear().


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close