Color legend plain property method
The two screen-sized targets a traced pass starts from: the linear depth and the normal of the nearest surface at every pixel.
A sealed class that implements IDisposable. Your prepass fills it, between BindAndClear and Unbind, in the encoding GBuffer.fxh reads back. The G-buffer page shows it in context, with code.
Names are colored by what they are: a property or a method; values and fields keep the plain color.
Properties
ContentVersion →
int · Read-only. Moves at every Unbind that ends a prepass, and not at a ConfirmCurrent: a pass tells new surfaces from the same ones by it.
Depth →
RenderTarget2D? · Read-only. The nearest surface’s distance in front of the camera, -PositionVS.z, as a 32-bit float, SurfaceFormat.Single; 0 where nothing was drawn. It has a 24-bit depth buffer for the prepass’s depth test, and keeps its contents when bound. null until the first Resize.
Height →
int · Read-only. The targets’ height in pixels; 0 before the first Resize.
IsCurrent →
bool · Read-only. The targets hold this frame’s surfaces: the prepass drew them, or ConfirmCurrent said they already did. False after a resize to a new size, after Invalidate and after Dispose. Gate every pass that reads the G-buffer on it, not on IsReady.
IsDisposed →
bool · Read-only. Dispose has been called.
IsReady →
bool · Read-only. The targets exist. Says nothing of what is in them: see IsCurrent.
Normal →
RenderTarget2D? · Read-only. The nearest surface’s view-space normal packed into 0..1, normal * 0.5 + 0.5, 8 bits a channel, SurfaceFormat.Color. No depth buffer of its own. null until the first Resize.
Width →
int · Read-only. The targets’ width in pixels; 0 before the first Resize.
Methods
GBuffer() →
GBuffer(GraphicsDevice graphicsDevice) · A G-buffer on the device, with no targets until the first Resize.
| Parameter | Type | Description |
|---|---|---|
graphicsDevice |
GraphicsDevice |
The device the targets are made on. |
BindAndClear() →
BindAndClear() · Binds both targets and clears them: the distance and the normal to 0, “nothing here”, and the depth buffer to 1. Throws InvalidOperationException before the first Resize: with no targets bound, the clear would wipe the back buffer.
ConfirmCurrent() →
ConfirmCurrent() · The targets already hold this frame’s surfaces, and weren’t redrawn: makes the G-buffer current, if it has targets, without moving ContentVersion.
Dispose() →
Dispose() · Frees both targets; the G-buffer is no longer current. A second call does nothing.
Invalidate() →
Invalidate() · This frame’s surfaces couldn’t be drawn, the prepass’s effect missing say: the G-buffer isn’t current, and the passes that gate on it skip the frame.
Resize() →
Resize(int width, int height) · Makes the targets at this size, or new ones at a new size, and does nothing when they already have it: hand it the viewport’s size every frame. New targets aren’t current until the next prepass.
| Parameter | Type | Description |
|---|---|---|
width |
int |
The width in pixels. Less than 1 counts as 1. |
height |
int |
The height in pixels. Less than 1 counts as 1. |
Unbind() →
Unbind() · Binds the back buffer. What was drawn since BindAndClear is this frame’s G-buffer: it is current, and ContentVersion moves. With no targets, it isn’t current and nothing moves. A game that draws into a render target of its own sets it again after.