-
Notifications
You must be signed in to change notification settings - Fork 4
Using the VignettePass function
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.
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();
To use the vignette shader, just call the VignettePass()
method:
GL.VignettePass();
- Initializing the renderer
- Setting the transform data
- Blitting and clearing the viewport
- Initializing a vertex buffer
- Creating a shader
- Drawing an object
- Screen space shaders
- Blitting bitmaps
- Loading a texture
- Creating a framebuffer
- Displaying a texture