Skip to content

Using the VignettePass function

theproadam edited this page May 3, 2020 · 1 revision

To prevent recalculation of the same vignette values for each pixel, renderXF allows for the creation of a vignette buffer that contains the precomputed vignette values. This trick saves valuable frametime during rendering.

Initializing the Vignette Buffer

To initialize the vignette buffer, the renderX instance requires a delegate method.

GL.InitializeVignetteBuffer(VignetteShader);

This function requires a vignette shader. Here is an example of a possible vignette shader:

unsafe void VignetteShader(float* Opacity, int posX, int posY)
{
    float X = (2f * posX / GL.RenderWidth) - 1f;
    float Y = (2f * posY / GL.RenderHeight) - 1f;

    X = 1f - 0.5f * X * X;
    Y = 1f - 0.5f * Y * Y;

    *Opacity = Y * X;
}

This method will be called whenever the vignette buffer is initailized, the viewport is resized via the SetViewportSize() function OR when the Vignette Buffer is manually rebuilt via the RebuildVignetteBuffer() function:

//Rebuilds the vignette buffer manually
GL.RebuildVignetteBuffer();

//Rebuilds the vignette buffer on resolution change
GL.SetViewportSize(width, height);

The vignette shader can also be swapped to another method via the SwapVignetteMethod() function:

GL.SwapVignetteMethod(newMethod);

Finally, the vignette buffer can be deinitiallized via the DeinitializeVignetteBuffer() method:

GL.DeinitializeVignetteBuffer();

Using the Vignette shader

To use the vignette shader, just call the VignettePass() method:

GL.VignettePass();
At 1024x768 this method should take ~1ms, at 1920x1017 it should take ~2ms.