![Page 1: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/1.jpg)
![Page 2: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/2.jpg)
Building a Dynamic Lighting Engine for
Velvet Assassin
Christian Schüler
![Page 3: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/3.jpg)
Velvet Assassin
3rd person stealth game Formerly known as “Sabotage
1943” First concepts: late 2000 Release: April 2009 Platforms PC, X360
My role: tech. dir. plus lead engine programmer
![Page 4: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/4.jpg)
Engine Goals
Must look great! (of course)
Everything is dynamically lit Cannot use Lightmaps
Lighting is part of gameplay If it looks dark, the player should be
hidden! Light sources become game entites.
![Page 5: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/5.jpg)
Engine Goals?
So, what about ... … scene visibility … light influence … indirect lighting (like radiosity)
… if every object can possibly move,even light sources?
![Page 6: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/6.jpg)
First Engine (2003)
![Page 7: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/7.jpg)
Axioms (2003)
World is a loose octree of objects Objects are OBB trees of triangles Multi-pass lighting with stencil
shadows Occlusion culling for visibility Indirect illumination via bounce
lights
![Page 8: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/8.jpg)
Shipping Engine (2009)
![Page 9: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/9.jpg)
Axioms (2009)
World is a loose octree of objects Objects are OBB trees of triangles Hybrid single/multi-pass lighting
with shadow maps Portals for visibility Indirect illumination via bounce
lights
+ XBox 360 specific optimizations
![Page 10: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/10.jpg)
Loose Octrees
Thatcher Ulrich (2001): Cells are overlapping (loose) Insertion is efficient
No need to rebuild the whole octree if an element moves!
Perfect as spatial index of a dynamic scene!
![Page 11: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/11.jpg)
Loose Octrees contd.
Base cell
Extended volume
![Page 12: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/12.jpg)
Loose Octrees contd.
Object inserted if inside extended volume
O(1) insertion
![Page 13: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/13.jpg)
Loose Octrees contd.
Used in finding out
Objects in a view frustum Objects influenced by a light Lights influencing an object Broad phase for ray tests Gameplay objects in range
And everything can be dynamic!
![Page 14: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/14.jpg)
OBB Trees
Oriented Bounding Box TreeS. Gottschalk et al (1995)
Used on the polygon level Build as a pre-process over mesh
data Allows efficient ray-mesh and
mesh-mesh interference tests
![Page 15: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/15.jpg)
OBB Trees contd.
Axis aligned …
… vs oriented!
![Page 16: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/16.jpg)
OBB Trees contd.
Construction:
• Principal axes (gaussian point distribution)*
• Minimize Box volume(possibly iterative)
*eigenvectors of covariance matrix
![Page 17: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/17.jpg)
Hybrid Lighting
A hybrid between multi-passand single-pass forward renderer:
One pass for each primary light
One pass for all secondary lights combined
![Page 18: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/18.jpg)
Hybrid Lighting contd.
Primary lights
Classic multi-pass (Doom 3 style) One pass per primary light Can cast shadows The light queries for surrounding
geometry
![Page 19: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/19.jpg)
Hybrid Lighting contd.
Secondary lights
Classic single-pass (HL2 style) Lights collected into one pass
(shader variation based on count) Can not cast shadows The geometry queries for
surrounding lights (up to a maximum amount)
![Page 20: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/20.jpg)
Hybrid Lighting contd.
primary spotsecondarypoints
![Page 21: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/21.jpg)
Hybrid Lighting contd.
primary directional
secondarypoints
![Page 22: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/22.jpg)
Bounce Light
axis
N
L
(N•L) · f(axis•L)
Gives appearance of first bounce indirect light from a surface.
Must not illuminate the surface it is placed on.
Has a half-sphere influence radius determined by axis.
![Page 23: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/23.jpg)
Bounce Light contd.
primary spot
secondarybounce
![Page 24: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/24.jpg)
Bounce Light contd.
primaryspot
2 secondaryambients
![Page 25: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/25.jpg)
Bounce Light contd.
... and even back in 2003
(it‘s not rocket science)
![Page 26: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/26.jpg)
So, for each frame …1. Get all primary lights in view2. Distribute shadow map pool3. Render shadow maps, for each:
Render all objects contained in light frustum Get all objects in view Render base pass
For each object, collect nearest N secondary lights (sorted by importance) for the shader
Render additive passes for each … … primary light: for each object that is in the
view and also in the light frustum.
That is why you need an efficient spatialindex data structure.
![Page 27: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/27.jpg)
Fog Zones
A.k.a.: There has to be at leastone benefit for manualportalization!
Here it is: Fog Zones!
![Page 28: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/28.jpg)
Fog Zones contd.
portalseparates fog environments
![Page 29: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/29.jpg)
Fog Zones contd.
… from the other side
![Page 30: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/30.jpg)
Fog Zones contd.
Multiply-Add is your friend!(instead of lerping against a constant fog color)
C = C0 ∙ T + S
C0 original color
T fog transmittanceS fog in-scatter
= (1−T) ∙ CFog traditionally
![Page 31: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/31.jpg)
Fog Zones contd.
C = ( C0 ∙ TB + SB ) ∙ TA + SA
A B
portal
C = C0 ∙ ( TB ∙ TA ) + ( SB ∙ TA + SA )
![Page 32: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/32.jpg)
Fog Zones contd.
Modify T and S of the new environment with T and S from the portal polygon
Calculate fog from the distance of the portal
Repeat recusively
![Page 33: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/33.jpg)
Fill Optimization
Only done for XBox 360
Selected particle effects rendered into off-screen render target at half resolution to save fill rate (against half resolution depth buffer)
Composited over the final image
![Page 34: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/34.jpg)
Fill Optimization contd.
![Page 35: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/35.jpg)
Fill Optimization contd.Again, multiply-add solves the math
(in the form of pre-multiplied alpha)
Off-screen target:CTarget’ = (1−AParticle) · CTarget + CParticle
ATarget’ = (1−AParticle) · ATarget + AParticle
Compositing:CFrame’ = (1−ATarget) · CFrame + CTarget
![Page 36: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/36.jpg)
Multi-threading
XBox 360 needed it; a dual-core PC at least benefits
First thread performs all spatial queries and compiles a “drawlist”
Second thread sets shader registers, render states and submits batches
Most scenes from 300 to 1200 batches/frame
![Page 37: Building a Dynamic Lighting Engine for Velvet Assassin Christian Schüler](https://reader035.vdocument.in/reader035/viewer/2022062322/56649cd85503460f949a16fc/html5/thumbnails/37.jpg)
The End
Questions?