Practical 3 Introduction Paul Scharf Tom Rijnbeek Practical 3 - - PowerPoint PPT Presentation
Practical 3 Introduction Paul Scharf Tom Rijnbeek Practical 3 - - PowerPoint PPT Presentation
Practical 3 Introduction Paul Scharf Tom Rijnbeek Practical 3 Advanced Shader Programming 18 tasks: 6 easy; 7 medium; 5 hard Easy exercises: choose 4 out of 6 Maximum grade: 8 Two more points by doing either: Two medium tasks
Practical 3
- 18 tasks: 6 easy; 7 medium; 5 hard
- Easy exercises: choose 4 out of 6
– Maximum grade: 8
- Two more points by doing either:
– Two medium tasks – One hard task
- Deadline: Thursday June 26, 23:59
Advanced Shader Programming
EASY TASKS
[E1] Multiple light sources
- Repeat light calculations for every source
[E2] Spotlight
[E3] Cel shading
- Discretised shading
smooth
[E3] Cel shading
- Easy solution: use texture for spectrum
- More complicated:
– Discretise mathematically – Use gradients for smoothing
[E4] Frustrum culling
- Only draw visible models
- Calculated on the CPU
[E4] Frustrum culling
- Frustrum bounded by six planes
- Don’t draw models on the wrong side of
planes
- Or use XNA’s BoundingFrustrum class...
Post-processing basics
- 1. Render scene to texture (rendertarget)
- 2. Render screen-filling quad sampling from
texture in pixel shader
- XNA: draw texture with Spritebatch
using pixel shader
[E5] Simple colour filter
- Apply grey-scale filter to every pixel
- Use weighted sum:
𝑍 = 0.3𝑆 + 0.59𝐻 + 0.11𝐶
[E6] Gaussian blur
- Box blur: average pixels in a square area
around target pixel
- Calculate by applying a convolution kernel
- n the image
1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9 1/9
[E6] Gaussian blur
- Gaussian blur: average pixels in a
(roughly) circular area around target pixel
- Use normal distribution to build kernel
[E6] Gaussian blur
0.00000067 0.00002292 0.00019117 0.00038771 0.00019117 0.00002292 0.00000067 0.00002292 0.00078633 0.00655965 0.01330373 0.00655965 0.00078633 0.00002292 0.00019117 0.00655965 0.05472157 0.11098164 0.05472157 0.00655965 0.00019117 0.00038771 0.01330373 0.11098164 0.22508352 0.11098164 0.01330373 0.00038771 0.00019117 0.00655965 0.05472157 0.11098164 0.05472157 0.00655965 0.00019117 0.00002292 0.00078633 0.00655965 0.01330373 0.00655965 0.00078633 0.00002292 0.00000067 0.00002292 0.00019117 0.00038771 0.00019117 0.00002292 0.00000067
[E6] Gaussian blur
- Convolution can be heavily optimised
- Split in vertical and horizontal pass
1 3 1 3 1 3 ∗ 1 3 1 3 1 3 = 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9
MEDIUM TASKS
[M1] Textured light
- Create view & projection matrix for light
- Transform vertex position twice
[M2] Shadow mapping
- Render depth texture from light
- Render scene normally
– Compare pixel’s distance to light with value from depth texture
[M2] Shadow mapping
depth from light from camera compare
distance to light pictures from: http://en.wikipedia.org/wiki/Shadow_mapping
[M3] Reflection
- Render scene from reflected camera
- Render to texture
– Render mirror with texture
- Or: use stencil buffer
– Mask mirror pixels, to only render reflection there
[M4] Cube mapping
- Cube map: texture
represting lighting from all directions
[M4] Cube mapping
- Calculate reflection vector
- Use cube texture lookup to find reflected
colour
[H5] Advanced cube mapping
- Precomputed diffuse light map
- Stronger reflections at shallow
reflection angles
[M5] Transparency
- Render transparent objects after opaque
- nes
- Sort transparent objects back-to-front
[M6] Post-processing: Bloom
- Render scene
- Threshold bright pixels
- Downscale and blur repeatedly
- Add up all scales
[M6] Post-processing: Bloom
threshold scale down and blur all added up
[M7] Post-processing: God rays
- Volumetric light scattering through
dust/mist
- Approximate in screen-space
HARD TASKS
[H1] HDR Lighting & Tone Mapping
- Simulate adaption of human eye to
changing brightness
- LDR vs. HDR
– LDR [0, 1] – HDR [0, ∞)
- Tone Mapping: HDR LDR
[H2] Deferred Shading
- Earlier lighting methods inefficient with
many lights
- Render geometry information to multiple
rendertargets (G-buffers)
- Calculate lighting per light for affected
pixels
[H2] Deferred Shading
Diffuse Colour Depth/Position Normal Tons of lights
[H3] Parallax Mapping
- Use height map to
displace diffuse texture
[H4] Post-processing: SSAO
[H4] Post-processing: SSAO
- Crude approximation of
full global illumination
- Calculate in screen-
space
- First real-time
implementation: Crysis
Final words
- Try focusing on doing few tasks well rather
than lots of exercises poorly
- Finish the easy tasks first
- Start in time!
Recap
- Finish 4 easy tasks for an 8
- Finish 2 medium tasks or 1 hard task for 2
points
- Additional tasks don’t improve grade
- Start in time!