10: The OpenGL Pipeline
09: Compositing Tricks
COMP5822M: High Performance Graphics
Compositing
General term for combining images
Was done in specialised frame buffers
Now moved into the pipeline
Using multipass rendering
Each pass builds up part of image
Final pass combines the parts
Or image transformations in framebuffer
COMP5822M: High Performance Graphics
Some Examples
Anti-aliasing
Motion Blur
Depth of Field
COMP5822M: High Performance Graphics
Aliasing & Anti-aliasing
Aliasing is a discrete quantisation problem
Solution always involves more samples
Aliased
Anti-aliased
Far away
COMP5822M: High Performance Graphics
Example
COMP5822M: High Performance Graphics
Approaches
Get a 4K, 5K, 8K monitor
Which means more samples anyway
And helps less than you think
Render higher resolution
Then average the pixels
Render standard resolution
Resample pixels in frame buffer
COMP5822M: High Performance Graphics
Super-Sampling
Render twice the resolution
At 2h x 2w
Then down-sample image
to h x w
COMP5822M: High Performance Graphics
Super-Sampling Choices
Many variations
But just a filter
So we abstract it
COMP5822M: High Performance Graphics
Screen-based Antialiasing
Operates on output samples of pipeline
No a priori knowledge of objects rendered
Simply filters the output image
General formula:
is the weight of each sample
is the sample (chosen somehow)
COMP5822M: High Performance Graphics
Result
COMP5822M: High Performance Graphics
Multi-Sample AA (MSAA)
Multiple sample locations per fragment
Some may be inside / outside triangle
Typically at edges where depth changes
Rasteriser generates fragment if any inside
Based on a bitwise coverage mask
And passes the mask information onwards
So it can be used in the fragment shader
COMP5822M: High Performance Graphics
MSAA Sample Pattern
4 samples, not 1
Many patterns
Much argument
Same basic idea
COMP5822M: High Performance Graphics
Coverage Test
Coverage
(Original Pixels)
Coverage
(MSAA 4x)
COMP5822M: High Performance Graphics
Fragment Shader
Samples are in known locations
So fragment shader loops through them
Interpolates same texture value for entire pixel
And same lighting
But keeps each subpixel separately
So buffer stores subpixel colour & depth
And tests depth, &c. for each one
COMP5822M: High Performance Graphics
MSAA Resolve
When it’s done, down-sample
COMP5822M: High Performance Graphics
Morphological AA (MLAA)
Computed in post-processing
Detect pixels that differ from neighbours
Approximate silhouettes
Filter colours around them
COMP5822M: High Performance Graphics
MLAA Example
COMP5822M: High Performance Graphics
GPU-based MLAA
Pass I: Edge Detection
Pass II: Revectorise edges with blurring
Pass III: Blend pixels with blending texture
Original
Edges
Blended
Result
From http://www.iryoku.com/aacourse/
COMP5822M: High Performance Graphics
Temporal AA
What if object motion is the problem
Too fast (Motion blur)
Multiple pixels per frame
Too slow (Aliased motion)
Multiple frames per pixel
Temporal AA (TXAA)
COMP5822M: High Performance Graphics
Aliased Motion
COMP5822M: High Performance Graphics
Aliased Motion
Object moves 2 pixels in 4 time steps
But it looks like it speeds up in the middle
Really just aliasing
COMP5822M: High Performance Graphics
Temporal AA (TXAA)
COMP5822M: High Performance Graphics
Fast Motion
Motion is too fast
Object moves multiple pixels per frame
COMP5822M: High Performance Graphics
Motion Blur
Add extra samples between frames
Pixels integrate over time
COMP5822M: High Performance Graphics
Basic Solution
Render multiple frames then average
COMP5822M: High Performance Graphics
Improvement
This is expensive
Especially if we are tracking motion
I.e. the background blurs, the object doesn’t
Instead, we post-process in the frame buffer
Depth buffer used to compute velocity
Velocity then used to generate blur
Faster, just as good in practice
COMP5822M: High Performance Graphics
Depth Buffer Motion Blur
Without
With
We need to know each pixel’s velocity
Reverses optical flow from image processing
Use previous frame’s projection matrix
COMP5822M: High Performance Graphics
I. Compute World Coords
Computed in NDCS
Per pixel, we know x, y, set w=1, z = depth
Apply unprojection by reversing matrices
And we’re back to world coordinates
COMP5822M: High Performance Graphics
II. Compute 2D Velocity
Compute previous frame’s position, reconvert
Convert to texture coords (0..1)
Now compute velocity
COMP5822M: High Performance Graphics
III. Sample Along Vector
We know where the pixel came from
We generate intermediate samples
And average them into the colour buffer
Net result: motion blur
But without rendering multiple images
COMP5822M: High Performance Graphics
Shader Code
COMP5822M: High Performance Graphics
Depth of Focus
COMP5822M: High Performance Graphics
Solution: Jitter Viewpoint
COMP5822M: High Performance Graphics
Result
COMP5822M: High Performance Graphics
COMP 30020: Intro Computer Graphics
Dr. Hamish Carr, Spring 2009
Red Book Example
Aliased Anti-Aliased
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled
Untitled