Vertices Engine  v1.9.2.92
A Cross Platform game engine developed by Virtex Edge Design.
Loading...
Searching...
No Matches
VerticesEngine.Graphics.LensFlareComponent Class Reference

Reusable component for drawing a lensflare effect over the top of a 3D scene. More...

Public Member Functions

 LensFlareComponent (vxGameplayScene3D Scene)
 Constructs a new lensflare component.
 
void LoadContent ()
 Loads the content used by the lensflare component.
 
void Draw (GameTime gameTime)
 Draws the lensflare component.
 
void UpdateOcclusion ()
 Mesures how much of the sun is visible, by drawing a small rectangle, centered on the sun, but with the depth set to as far away as possible, and using an occlusion query to measure how many of these very-far-away pixels are not hidden behind the terrain.
 
void DrawGlow ()
 Draws a large circular glow sprite, centered on the sun.
 
void DrawFlares ()
 Draws the lensflare sprites, computing the position of each one based on the current angle of the sun.
 

Public Attributes

Matrix View
 
Matrix Projection
 

Properties

Vector3 LightDir [get, set]
 

Detailed Description

Reusable component for drawing a lensflare effect over the top of a 3D scene.

Member Function Documentation

◆ UpdateOcclusion()

void VerticesEngine.Graphics.LensFlareComponent.UpdateOcclusion ( )

Mesures how much of the sun is visible, by drawing a small rectangle, centered on the sun, but with the depth set to as far away as possible, and using an occlusion query to measure how many of these very-far-away pixels are not hidden behind the terrain.

The problem with occlusion queries is that the graphics card runs in parallel with the CPU. When you issue drawing commands, they are just stored in a buffer, and the graphics card can be as much as a frame delayed in getting around to processing the commands from that buffer. This means that even after we issue our occlusion query, the occlusion results will not be available until later, after the graphics card finishes processing these commands.

It would slow our game down too much if we waited for the graphics card, so instead we delay our occlusion processing by one frame. Each time around the game loop, we read back the occlusion results from the previous frame, then issue a new occlusion query ready for the next frame to read its result. This keeps the data flowing smoothly between the CPU and GPU, but also causes our data to be a frame out of date: we are deciding whether or not to draw our lensflare effect based on whether it was visible in the previous frame, as opposed to the current one! Fortunately, the camera tends to move slowly, and the lensflare fades in and out smoothly as it goes behind the scenery, so this out-by-one-frame error is not too noticeable in practice.


The documentation for this class was generated from the following file: