程序代写代做代考 10: The OpenGL Pipeline

10: The OpenGL Pipeline

14: Real-Time Lighting

COMP5822M: High Performance Graphics
Real Time Lighting
Recall the rendering equation:

But we know that this is expensive
How do we approximate it real-time?

COMP5822M: High Performance Graphics

Common Shading Approaches
Direct Lighting only
Indirect Lighting via Ambient Term
Indirect Lighting (no visibility computation)
Indirect Lighting (semi static scenes)
Indirect Lighting (single bounce)
Deferred Rendering

COMP5822M: High Performance Graphics
Basic Approach
For each fragment
For each light source
Compute light direction & contribution
Evaluate BRDF / texture
May have multiple textures involved
Apply Blinn-Phong equations
Sum contributions over all light sources

COMP5822M: High Performance Graphics

Problems
Lots of light/material combos
Half-Life 2 has 1920 fragment shader combos
Inefficient
Dynamic branch prediction fails a lot

COMP5822M: High Performance Graphics
Multipass Lighting
Surfaces see few lights
So each light is separate pass
Relevant surfaces only
Moves control outside the fragment loop
i.e. up to CPU
Also, attenuate lighting by distance
Reduces # of light sources more

COMP5822M: High Performance Graphics
Multipass Downsides
Multiple blending passes burn bandwidth
Mesh is processed multiple times
And geometry transforms are not cheap
Fragment computations are repeated
Eg texture blending, relief mapping
So no longer the preferred method

COMP5822M: High Performance Graphics
Screen Space Techniques
Decouple visibility from lighting calculation
First pass computes visibility
Store depth, position &c. in texture
Second pass computes lighting

COMP5822M: High Performance Graphics
Deferred Shading

General SS technique
Compute visibility first
Render attributes to pixel buffer
Second pass uses attributes
Computes full lighting
One quad for entire image

COMP5822M: High Performance Graphics
Ambient Occlusion
Approximation of local illumination
Convex surfaces tend to be heavily shadowed
So attenuate ambient based on occlusion

COMP5822M: High Performance Graphics
Local Occlusion
Most of the shadowing is from nearby features
So approximate this reduction
By sampling the mesh neighbourhood

COMP5822M: High Performance Graphics
Occlusion Function
The original integral:

Separate out occlusion function:

Rewrite integral:

Now we can approximate !

COMP5822M: High Performance Graphics
Screen-Space Ambient Occlusion
Used in Crysis:Mittring, https://dl.acm.org/citation.cfm?id=1281671
Generate a number of points near pixel
Compare with Z-buffer
50% samples pass => 100% lighting (
Weight samples by distance from pixel

COMP5822M: High Performance Graphics
SSAO Performance
No more than 16 samples per pixel
But >200 needed for good visual quality
Change sample pattern at each pixel
Then blur in post-processing

COMP5822M: High Performance Graphics
SSAO Variations
Horizon-based AO
See nvidia.com
Z-buffer is height field
Trace local rays from fragment
Into oriented hemisphere
Higher quality, more expensive
Still needs post-process blur

COMP5822M: High Performance Graphics
SS Directional Occlusion
SSAO ignores direction of light
Surface at the point should have greenish light
So we want to compensate for this

COMP5822M: High Performance Graphics
SSDO
Account for light sources during loop
Actually integrate the radiance as well
https://people.mpi-inf.mpg.de/~ritschel/Papers/SSDO.pdf

*

COMP5822M: High Performance Graphics
SSDO Visibility Test
Compute N samples for P
All in upper hemisphere
User-defined radius
Backproject sample to image
Look up surface position
Test z-buffer for occlusion
Add radiance if passes

COMP5822M: High Performance Graphics
SSDO Comparison

COMP5822M: High Performance Graphics
Indirect Illumination
Every pixel is a surface patch
Oriented by pixel normal
Reflecting Light
Computed from direct light
Accumulate neighbours
Allows one indirect bounce

COMP5822M: High Performance Graphics
Indirect Illumination

COMP5822M: High Performance Graphics
SSDO Limitations
Only approximation
Wrong visibility
Can generate halos
Nearby geometry only
Ignores distant occluders

COMP5822M: High Performance Graphics
Precomputed AO
AO can be precomputed and stored
Treated as attribute of surface
Note: you can do many samples this way
Doesn’t work as well for SSDO
Except for static surfaces / lights

COMP5822M: High Performance Graphics
Precomputed DO
Directional Occlusion can be precomputed
Under tight assumptions on lighting
Most useful for terrains
Which don’t change lighting too fast

COMP5822M: High Performance Graphics