Mitchell ShadingInValvesSourceEngine
Mitchell ShadingInValvesSourceEngine
SIGGRAPH 2006
Jason Mitchell
Valve
Introduction
¾ World Lighting
• Radiosity Normal Mapping
• Specular Lighting
¾ Model lighting
• Irradiance Volume
• Half-Lambert
• Phong terms
¾ High Dynamic Range Rendering
• Tone mapping
• Autoexposure
¾ Color Correction
Timeline
¾ Realism
¾ More forgiving than direct lighting only
• Avoids harsh lighting situations
• Less micro-management of light sources for content
production
• Can’t tune lights shot-by-shot like movies. Don’t
know what the shots are, and don’t want to take the
production time to do this
Direct lighting only
Radiosity lighting
Normal Mapping
1 1 1
− , ,
6 2 3
1 1 1 3 1
− ,− , ,0 ,
6 2 3 2 3
Computing Light map Values
+ + =
+ + =
Diffuse
Diffuse 11
*
Albedo
Albedo
Final
Final
Diffuse
Diffuse +
+
Diffuse
Diffuse 22 Total
Total
Diffuse
Diffuse
Phong
Phong Mask
Mask
Light
Light
source
source
parameters
parameters Final Lighting
Ambient
Ambient
Cube
Cube *
Specular
Specular
Raw
Raw Phong
Phong Term
Term
Phong
Phong
Exponent
Exponent
Fresnel
Fresnel
High Dynamic Range
Rendering in the
Source Engine
High Dynamic Range
LDR HDR
Tone Mapping
¾ Very careful with linear versus gamma color spaces
¾ All shaders in our DirectX 9 code path are single-pass
¾ As a result, tone mapping can be performed during
normal rendering
• Simple subroutine added to the end of all pixel shaders
¾ This allows us to use 32-bit RGBA render targets
• No increase in render target memory footprint
• MSAA supported
• 60% of our total users see HDR rendering
• 82% of those who have played Episode One so far!
Auto Exposure
¾ Running luminance histogram of post-tonemapped frame
• Update one bucket per frame
• More histogram buckets for low luminance values
¾ Each frame, we determine which output pixels fall within a
given range, tagging such pixels in the stencil buffer
¾ Use an asynchronous occlusion query to count pixels in range
¾ Full running histogram (not just a single average luminance) is
available to the CPU with no stalls
¾ Time averaging is used smooth out auto exposure adjustments
¾ Designers can also modify auto exposure and bloom across
different areas of a level or in connection with game events
A single bucket from the running histogram (shown in red)
Another bucket from the running histogram (shown in red)
Implemented Multiple HDR Paths
¾ Floating point
• HDR textures and render targets are fp16
• Shipped this path, but it is not the one typically used
¾ Integer
• Render to 32 bit RGBA integer frame buffer
• Store HDR textures in fp16 (linear color space) when filtered
fp16 textures are supported.
• Store HDR textures in 4.12 linear color space otherwise.
• Had to implement this version along with floating point
version to support more hardware
Float vs. Integer HDR Tradeoffs
¾ Floating Point
+ Pre-tone-mapping data available for blooming
+ General refraction mapping techniques preserve HDR information
- Requires floating-point alpha blending
- Hardware lacks precision to perform fixed function pixel fog
¾ Integer
+ Compatible with Multisample Antialiasing (MSAA)
+ Works on all DirectX 9 hardware (runs well even on ATI RADEON 9600)
+ Small performance hit relative to LDR
Half Life 2: Episode 1
Half Life 2: Episode 1
Half Life 2: Episode 1
Team Fortress 2: NPR + HDR!
Team Fortress 2: NPR + HDR!
Team Fortress 2: NPR + HDR!
Lost Coast
Demo
Color Correction
¾ Color has been used in visual arts to evoke particular emotional
responses for millennia, and we can do the same in video games
¾ It is very natural to apply color correction to rendered images as a
post process, since we’re doing lots of image processing already
• Simply define a mapping from a one set of RGB triples to another
• We do this with a 323 volume texture lookup (sometimes several)
¾ Decouples color correction from the art or lighting of a given setting
¾ Useful for a variety of purposes
• Stylization
• Day for night
• Gameplay
Color Correction in Source
¾ Improvements to
irradiance volume
sampling
¾ Shadow Mapping
¾ Foliage Rendering
¾ Soft Particles
¾ Non-Photorealistic
rendering in Team
Fortress 2
Conclusion
¾ World Lighting
• Radiosity Normal Mapping
• Specular Lighting
¾ Model lighting
• Irradiance Volume
• Half-Lambert
• Phong terms
¾ High Dynamic Range Rendering
• Tone mapping
• Autoexposure
¾ Color Correction
SDK & Academic Licensing
¾ Publicly available SDK
¾ Academic licenses provide
• Access to Valve games
• Source code
• HLSL shaders, Radiosity and visibility calculations
• AI system, path finding
• Animation system, acting system, inverse kinematics
• Production quality art and sound assets
• Useful level and modeling tools
• Hammer level editor, Faceposer, Model viewing utilities
[email protected]
Acknowledgements
Valve is Hiring!