SlideShare a Scribd company logo
1 of 69
Around the World in 80 Shaders
Stephen McAuley
Bizarre Creations
stephen.mcauley@bizarrecreations.com
Overview
• Introduction:
– The FX system
• Around the world tour:
– Default
– Skin
– MPEG corruption
– Refraction mapping
– Shallow water
– Aquarium
FX System: Problem
• After finishing PGR4 and The Club we needed
a new solution to handling shaders.
– Two different systems.
– Extremely complicated to add new shaders.
• Have to add new vertex declarations, new exporter
code and new rendering code as well.
– Not data driven.
• Shaders treated as code not data.
• Could never run on an SPU.
– No Maya previewing for artists.
FX System: Solution
• Our solution was the FX system:
– Based on .fx files.
– Entirely data driven.
– Automatic Maya previews for artists.
– All rendering code now runs on the SPUs.
FX System: Maya and XSI
• Compile Maya and XSI shaders alongside PC
shaders.
• Annotations control how the parameters
appear to the artists:
• Artists can “expose” parameters they want to
be set within game.
texture2D g_tAlbedo < string SasUiLabel = “Colour”; >;
float g_fScale < string SasUiLabel = “Scale”; > = 0.0;
FX System: Exporting
• Scene converter:
– Reads vertex input structure
• With the help of annotations.
– Exports relevant vertex data in the correct format.
struct C_VertexInput
{
float3 m_vPosition : POSITION;
float3 m_vNormal : NORMAL;
float4 m_vTexCoord : TEXCOORD0
annotation(xy(uv:0) | zw(uv:luxlightmap) | format(F16_4));
};
FX System: Exporting
• Lua script within each shader helps build shader
permutations:
• If a bumpmap is present, game will search for
ShaderB.fx instead of Shader.fx.
• Make sure you have compiled that permutation!
texture2D g_tBumpmap < string SasUiLabel = “Bumpmap”; >;
#if defined(FXFILE_PARSER)
if (g_tBumpmap) then append(“B”, 10) end
#endif
FX System: In Game
• Game sets exposed and shared parameters.
• Techniques are changed dynamically:
• e.g. shadow mapping technique, prepass technique…
• Shader parameters can be overridden via our
debugging tool:
– Currently only on all instances of a shader.
Default
Athens
Default Shader
• This is our base material for everything in
game.
• Applied when artists use the Lambert shader
in Maya.
– Easy to set up.
– Artists just set an albedo texture.
– Other textures are picked up in the exporter using
a naming convention.
Default Shader: Material
• The following material options are supported:
– Albedo (_DIFF)
– Normal (_NORM)
– Specular (_IPR0)
– Emissive (_NEON)
• These are all controlled by textures.
Default Shader: Lighting
• We support these lighting methods:
– Light maps
– Vertex lighting
– Vertex PRT
– SH lighting
• In Blood Stone, they contained the following
information:
– Colour, sun occlusion and ambient occlusion
Default Shader: Lighting
Our BRDF for sun lighting:
𝜌 =
𝑅 𝑑
𝜋
1 − 𝐼𝐹 𝐹0 + 𝐼𝐹(𝐹0)
𝑛 + 2
2𝜋
(𝑅. 𝑉) 𝑛
(𝑁. 𝐿)
where 𝑅 𝑑 is the surface albedo and 𝐹(𝐹0) is
Schlick’s fresnel approximation:
𝐹(𝐹0) = 𝐹0 + (1 − 𝐹0)(𝑁. 𝑉)5
Default Shader: Specular
We have three parameters controlling specular:
𝜌 =
𝑅 𝑑
𝜋
1 − 𝐼𝐹 𝐹0 + 𝐼𝐹(𝐹0)
𝑛 + 2
2𝜋
(𝑅. 𝑉) 𝑛
(𝑁. 𝐿)
• 𝐼 is the specular intensity
• 𝑛 is the specular power
• 𝐹0 is the normal specular reflectance
Default Shader: Specular
• These three specular properties come from
our specular texture:
– Red channel: Intensity (𝐼)
– Green channel: Power (𝑛)
• 𝑛 = 4 + 8188𝑔2
• 𝑚𝑖𝑝𝑀𝑎𝑝𝐿𝑜𝑑 = 7(1 − 𝑔)
– Blue channel: Reflectance (𝐹0)
Skin
Istanbul
Skin
• Standard diffuse lighting gives unrealistic
results when applied to skin.
• It looks hard and dry compared to skin’s soft
appearance.
• To achieve this look, we need to model
subsurface scattering.
Skin
• The best approach is described by Eugene
d’Eon and David Luebke in [1]:
– Observed that red light scatters in skin more than
green and blue.
– Simulate subsurface scattering by lighting in
texture space, then performing separate gaussian
blurs for red, green and blue channels.
• This is expensive and intrusive. Are there any
cheaper ways?
Skin: Approximations
• Standard diffuse lighting:
D = N.L
• Wrapped diffuse lighting:
D = N.L * w + (1 – w)
• i.e. D = N.L * 0.5 + 0.5
• What if we wrap different colours by different
amounts?
Skin: Our solution
• Coloured wrapped diffuse lighting:
D = N.L * W + (1 – W)
• i.e. D = N.L * { 0.5, 0.8, 0.9 } + { 0.5, 0.2, 0.1 }
• Simulates subsurface scattering by giving skin
a softer look.
• Simulates red light scattering further in skin.
• Cheap and easy to implement.
Standard Diffuse
Wrapped Diffuse
Coloured Wrapped
Diffuse
MPEG
Corruption
Monaco
MPEG Corruption
• For the AR phone, we wanted an effect that
simulated MPEG corruption.
• “Blocks” in the image don’t update and
remain from the previous frame.
MPEG Corruption
• Algorithm:
– For each pixel, point sample a noise texture.
• Scaled so each texel is the size of a “block”.
– If sample is less than a threshold, take pixel from
previous frame buffer.
• Instead of the previous frame buffer, use a scaled and
offset version of the current frame.
– Else, take pixel from current frame buffer.
MPEG Corruption
half2 vRUV = vUV * g_vCorruptionBlockSize;
vRUV += half2(g_fCorruptionAmount * 7.123h, 0.0h);
half fRand = h4tex2D(g_tNoise, vRUV).r;
if(fRand < g_fCorruptionAmount)
{
real2 vDUV = input.m_TexCoord * g_vCorruptionUVScale;
vDUV += g_vCorruptionUVOffset;
vColour = h4tex2D(g_tBackbuffer, vDUV).rgb;
vColour *= (1.0h + fRand - 0.5h * g_fCorruptionAmount);
}
else
{
vColour = h4tex2D(g_tBackbuffer, vUV).rgb;
}
Refraction
Mapping
Siberia
Refraction Mapping
• We wanted to simulate surfaces that are
coated in a layer of ice.
• Requirements:
– These surfaces have two layers:
• Ice layer
• Base layer
– The base layer is refracted by the ice layer.
Refraction Mapping
• Our in-game materials use three textures:
– albedo
– normal
– specular
• We split these textures across the two layers.
Ice layer:
• normal
• specular
Base layer:
• albedo
uv
refracted uv
Refraction Mapping
• Calculate the refracted texture coordinate:
• Albedo texture uses vRefractUV.
• Normal and specular maps use vUV.
half3 vRefract = refract(vTangentView, vTangentNormal,
1.0f / g_fRefractiveIndex);
float2 vUVOffset = g_fDisplacement * vRefract.xy / vRefract.z;
float2 vRefractUV = vUV + vUVOffset;
Default
Displacement
Refraction
Refraction Mapping: Extensions
• Vary the displacement across the surface:
– Height map.
– Vertex colours.
• Add a frost layer in between the top layer and
the base layer.
Default
Refraction
Frost
Refraction Mapping: Problems
• Make sure your tangent space is correct!
– Any errors will very quickly become apparent.
• Displacement breaks as you look at the
surface edge on.
Shallow
Water
Burma
Shallow water
Deep water
Shallow Water
• Why does shallow water appear more
transparent than deep water?
– Water molecules absorb and scatter light.
– The further light travels, the higher probability it is
absorbed or scattered.
– Absorption and scattering are dependent on
wavelength:
• e.g. red light is absorbed more than green or blue,
giving water its characteristic colour.
Shallow Water
• Premoze and Ashikhmin suggested the
following model for the absorption and
scattering of light in water [2]:
𝐿 0, 𝜃, 𝜑 = 𝐿 𝑍, 𝜃, 𝜑 𝑒−𝑐𝑅 + 𝐿 𝑑𝑓 0 1 − 𝑒 −𝑐+𝐾 𝑑 𝑐𝑜𝑠𝜃 𝑅
Shallow Water
𝐿 = 𝐿 𝑧 𝑒−𝑐𝑅
+ 𝐿0(1 − 𝑒−𝑐𝑅
𝑒−𝐾 𝑑 𝐻
)
R
H
LZ
L0
extinction inscattering
c and Kd are wavelength dependent absorption
and scattering coefficients
Shallow Water
𝐿 = 𝐿 𝑧 𝑒−𝑐𝑅
+ 𝐿0 1 − 𝑒−𝑐𝑅
𝑒−𝐾 𝑑 𝐻
• Optimisation:
– Remove the 𝑒−𝐾 𝑑 𝐻term.
– Only changes the falloff of the inscattering, not
the intensity.
Shallow Water
𝐿 = 𝐿 𝑧 𝑒−𝑐𝑅
+ 𝐿0 1 − 𝑒−𝑐𝑅
• Optimisation:
– Remove the 𝑒−𝐾 𝑑 𝐻term.
– Only changes the falloff of the inscattering, not
the intensity.
Shallow Water
𝐿 = 𝐿 𝑧 𝑒−𝑐𝑅
+ 𝐿0 1 − 𝑒−𝑐𝑅
• Optimisation:
– Remove the 𝑒−𝐾 𝑑 𝐻term.
– Only changes the falloff of the inscattering, not
the intensity.
• Visual artefact:
– Very shallow water is slightly darker.
Shallow Water
• The final equation is a lerp between the water
colour and the underwater colour, based on
the extinction:
𝐿 = lerp(𝐿0, 𝐿 𝑧, 𝑒−𝑐𝑅
)
• Final shader code:
half3 vExtinction = exp(-g_vExtinctionCoeffs * fDistUnderwater);
half3 vDiffuse = lerp(vSceneColour, vWaterColour, vExtinction);
No extinction
Red extinction
Green/blue extinction
Aquarium
Bangkok
Aquarium
• Is an aquarium tank equivalent to shallow
water?
R
LZ
L0
With Extinction
Image courtesy Jon Rawlinson
jonrawlinson.com
Aquarium
• Simulate a light positioned directly above the
tank.
• This is our new inscattering term.
R LZ
L0
M0
H
MZ
Aquarium
• Inscattering equation:
𝐼 = 𝑀0 𝑒−𝑐1 𝐻
(1 − 𝑒−𝑐0 𝑅
)
• Light colour, 𝑀0, should be the colour of the
light as it hits the surface of the water.
– i.e. light colour modulated by water colour
• Use a different attenuation coefficient to the
extinction.
– Allows for more interesting hue shifts.
Aquarium
• Shader code:
half3 vExtinction = exp(-g_vExtinctionCoeffs *
fDistanceThroughWater);
half3 vInscattering = exp(-g_vInscatteringCoeffs *
fDistanceUnderWater);
vInscattering *= g_vLightColour.rgb;
half3 vDiffuse = lerp(vSceneColour, vInscattering, vExtinction);
Aquarium
• For the final touch, add light shafts:
– Project two scrolling textures in the world x-z
plane.
• Sample each texture at a fixed distance behind the
glass front of the aquarium tank.
– Combine texture samples into light shaft term, 𝑘.
– Modify inscattering term:
inscattering = 𝑀0 𝑒−𝑐1 𝐻(1−𝑘)
(1 − 𝑒−𝑐0 𝑅
)
With Light
With Light Shafts
References
• [1] Advanced Techniques for Real-Time Skin
Rendering, Eugene d’Eon and David Luebke,
GPU Gems 3, 2008
• [2] Rendering Natural Waters, Simon Premoze
& Michael Ashikhmin, 2001
Credits
• For working on the technology described in
this presentation:
– Paul Malin
– Jan van Valburg
– David Hampson

More Related Content

What's hot

A Bit More Deferred Cry Engine3
A Bit More Deferred   Cry Engine3A Bit More Deferred   Cry Engine3
A Bit More Deferred Cry Engine3guest11b095
 
Rendering AAA-Quality Characters of Project A1
Rendering AAA-Quality Characters of Project A1Rendering AAA-Quality Characters of Project A1
Rendering AAA-Quality Characters of Project A1Ki Hyunwoo
 
SIGGRAPH 2010 - Style and Gameplay in the Mirror's Edge
SIGGRAPH 2010 - Style and Gameplay in the Mirror's EdgeSIGGRAPH 2010 - Style and Gameplay in the Mirror's Edge
SIGGRAPH 2010 - Style and Gameplay in the Mirror's EdgeElectronic Arts / DICE
 
Lighting Shading by John Hable
Lighting Shading by John HableLighting Shading by John Hable
Lighting Shading by John HableNaughty Dog
 
An introduction to Realistic Ocean Rendering through FFT - Fabio Suriano - Co...
An introduction to Realistic Ocean Rendering through FFT - Fabio Suriano - Co...An introduction to Realistic Ocean Rendering through FFT - Fabio Suriano - Co...
An introduction to Realistic Ocean Rendering through FFT - Fabio Suriano - Co...Codemotion
 
Massive Point Light Soft Shadows
Massive Point Light Soft ShadowsMassive Point Light Soft Shadows
Massive Point Light Soft ShadowsWolfgang Engel
 
Deferred shading
Deferred shadingDeferred shading
Deferred shadingFrank Chao
 
More Performance! Five Rendering Ideas From Battlefield 3 and Need For Speed:...
More Performance! Five Rendering Ideas From Battlefield 3 and Need For Speed:...More Performance! Five Rendering Ideas From Battlefield 3 and Need For Speed:...
More Performance! Five Rendering Ideas From Battlefield 3 and Need For Speed:...Colin Barré-Brisebois
 
Shiny Pixels and Beyond: Real-Time Raytracing at SEED
Shiny Pixels and Beyond: Real-Time Raytracing at SEEDShiny Pixels and Beyond: Real-Time Raytracing at SEED
Shiny Pixels and Beyond: Real-Time Raytracing at SEEDElectronic Arts / DICE
 
Paris Master Class 2011 - 01 Deferred Lighting, MSAA
Paris Master Class 2011 - 01 Deferred Lighting, MSAAParis Master Class 2011 - 01 Deferred Lighting, MSAA
Paris Master Class 2011 - 01 Deferred Lighting, MSAAWolfgang Engel
 
Deferred Rendering in Killzone 2
Deferred Rendering in Killzone 2Deferred Rendering in Killzone 2
Deferred Rendering in Killzone 2ozlael ozlael
 
A new Post-Processing Pipeline
A new Post-Processing PipelineA new Post-Processing Pipeline
A new Post-Processing PipelineWolfgang Engel
 
Paris Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsParis Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsWolfgang Engel
 
Paris Master Class 2011 - 05 Post-Processing Pipeline
Paris Master Class 2011 - 05 Post-Processing PipelineParis Master Class 2011 - 05 Post-Processing Pipeline
Paris Master Class 2011 - 05 Post-Processing PipelineWolfgang Engel
 
Five Rendering Ideas from Battlefield 3 & Need For Speed: The Run
Five Rendering Ideas from Battlefield 3 & Need For Speed: The RunFive Rendering Ideas from Battlefield 3 & Need For Speed: The Run
Five Rendering Ideas from Battlefield 3 & Need For Speed: The RunElectronic Arts / DICE
 

What's hot (20)

A Bit More Deferred Cry Engine3
A Bit More Deferred   Cry Engine3A Bit More Deferred   Cry Engine3
A Bit More Deferred Cry Engine3
 
Rendering AAA-Quality Characters of Project A1
Rendering AAA-Quality Characters of Project A1Rendering AAA-Quality Characters of Project A1
Rendering AAA-Quality Characters of Project A1
 
SIGGRAPH 2010 - Style and Gameplay in the Mirror's Edge
SIGGRAPH 2010 - Style and Gameplay in the Mirror's EdgeSIGGRAPH 2010 - Style and Gameplay in the Mirror's Edge
SIGGRAPH 2010 - Style and Gameplay in the Mirror's Edge
 
Lighting Shading by John Hable
Lighting Shading by John HableLighting Shading by John Hable
Lighting Shading by John Hable
 
An introduction to Realistic Ocean Rendering through FFT - Fabio Suriano - Co...
An introduction to Realistic Ocean Rendering through FFT - Fabio Suriano - Co...An introduction to Realistic Ocean Rendering through FFT - Fabio Suriano - Co...
An introduction to Realistic Ocean Rendering through FFT - Fabio Suriano - Co...
 
Massive Point Light Soft Shadows
Massive Point Light Soft ShadowsMassive Point Light Soft Shadows
Massive Point Light Soft Shadows
 
Deferred shading
Deferred shadingDeferred shading
Deferred shading
 
DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3
 
More Performance! Five Rendering Ideas From Battlefield 3 and Need For Speed:...
More Performance! Five Rendering Ideas From Battlefield 3 and Need For Speed:...More Performance! Five Rendering Ideas From Battlefield 3 and Need For Speed:...
More Performance! Five Rendering Ideas From Battlefield 3 and Need For Speed:...
 
Lighting you up in Battlefield 3
Lighting you up in Battlefield 3Lighting you up in Battlefield 3
Lighting you up in Battlefield 3
 
Light prepass
Light prepassLight prepass
Light prepass
 
Shiny Pixels and Beyond: Real-Time Raytracing at SEED
Shiny Pixels and Beyond: Real-Time Raytracing at SEEDShiny Pixels and Beyond: Real-Time Raytracing at SEED
Shiny Pixels and Beyond: Real-Time Raytracing at SEED
 
Paris Master Class 2011 - 01 Deferred Lighting, MSAA
Paris Master Class 2011 - 01 Deferred Lighting, MSAAParis Master Class 2011 - 01 Deferred Lighting, MSAA
Paris Master Class 2011 - 01 Deferred Lighting, MSAA
 
Deferred Rendering in Killzone 2
Deferred Rendering in Killzone 2Deferred Rendering in Killzone 2
Deferred Rendering in Killzone 2
 
Shiny PC Graphics in Battlefield 3
Shiny PC Graphics in Battlefield 3Shiny PC Graphics in Battlefield 3
Shiny PC Graphics in Battlefield 3
 
A new Post-Processing Pipeline
A new Post-Processing PipelineA new Post-Processing Pipeline
A new Post-Processing Pipeline
 
Paris Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsParis Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow Maps
 
Lighting the City of Glass
Lighting the City of GlassLighting the City of Glass
Lighting the City of Glass
 
Paris Master Class 2011 - 05 Post-Processing Pipeline
Paris Master Class 2011 - 05 Post-Processing PipelineParis Master Class 2011 - 05 Post-Processing Pipeline
Paris Master Class 2011 - 05 Post-Processing Pipeline
 
Five Rendering Ideas from Battlefield 3 & Need For Speed: The Run
Five Rendering Ideas from Battlefield 3 & Need For Speed: The RunFive Rendering Ideas from Battlefield 3 & Need For Speed: The Run
Five Rendering Ideas from Battlefield 3 & Need For Speed: The Run
 

Similar to Around the World in 80 Shaders

Rendering basics
Rendering basicsRendering basics
Rendering basicsicedmaster
 
Spatial Filtering in intro image processingr
Spatial Filtering in intro image processingrSpatial Filtering in intro image processingr
Spatial Filtering in intro image processingrkumarankit06875
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithmKKARUNKARTHIK
 
Volume Rendering in Unity3D
Volume Rendering in Unity3DVolume Rendering in Unity3D
Volume Rendering in Unity3DMatias Lavik
 
smallpt: Global Illumination in 99 lines of C++
smallpt:  Global Illumination in 99 lines of C++smallpt:  Global Illumination in 99 lines of C++
smallpt: Global Illumination in 99 lines of C++鍾誠 陳鍾誠
 
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)Mark Kilgard
 
4 image enhancement in spatial domain
4 image enhancement in spatial domain4 image enhancement in spatial domain
4 image enhancement in spatial domainPrakash Velayudham V
 
DeepLab V3+: Encoder-Decoder with Atrous Separable Convolution for Semantic I...
DeepLab V3+: Encoder-Decoder with Atrous Separable Convolution for Semantic I...DeepLab V3+: Encoder-Decoder with Atrous Separable Convolution for Semantic I...
DeepLab V3+: Encoder-Decoder with Atrous Separable Convolution for Semantic I...Joonhyung Lee
 
Clustering of graphs and search of assemblages
Clustering of graphs and search of assemblagesClustering of graphs and search of assemblages
Clustering of graphs and search of assemblagesData-Centric_Alliance
 
A modern Post-Processing Pipeline
A modern Post-Processing PipelineA modern Post-Processing Pipeline
A modern Post-Processing PipelineWolfgang Engel
 
Applied Deep Learning 11/03 Convolutional Neural Networks
Applied Deep Learning 11/03 Convolutional Neural NetworksApplied Deep Learning 11/03 Convolutional Neural Networks
Applied Deep Learning 11/03 Convolutional Neural NetworksMark Chang
 
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" DemoThe Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demodrandom
 

Similar to Around the World in 80 Shaders (20)

Real-time lightmap baking
Real-time lightmap bakingReal-time lightmap baking
Real-time lightmap baking
 
Rendering basics
Rendering basicsRendering basics
Rendering basics
 
Deferred shading
Deferred shadingDeferred shading
Deferred shading
 
Spatial Filtering in intro image processingr
Spatial Filtering in intro image processingrSpatial Filtering in intro image processingr
Spatial Filtering in intro image processingr
 
Hidden surface removal algorithm
Hidden surface removal algorithmHidden surface removal algorithm
Hidden surface removal algorithm
 
Volume Rendering in Unity3D
Volume Rendering in Unity3DVolume Rendering in Unity3D
Volume Rendering in Unity3D
 
smallpt: Global Illumination in 99 lines of C++
smallpt:  Global Illumination in 99 lines of C++smallpt:  Global Illumination in 99 lines of C++
smallpt: Global Illumination in 99 lines of C++
 
Lighting and shading
Lighting and shadingLighting and shading
Lighting and shading
 
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
A Practical and Robust Bump-mapping Technique for Today’s GPUs (slides)
 
4 image enhancement in spatial domain
4 image enhancement in spatial domain4 image enhancement in spatial domain
4 image enhancement in spatial domain
 
november6.ppt
november6.pptnovember6.ppt
november6.ppt
 
lec06-resampling2.pptx
lec06-resampling2.pptxlec06-resampling2.pptx
lec06-resampling2.pptx
 
DeepLab V3+: Encoder-Decoder with Atrous Separable Convolution for Semantic I...
DeepLab V3+: Encoder-Decoder with Atrous Separable Convolution for Semantic I...DeepLab V3+: Encoder-Decoder with Atrous Separable Convolution for Semantic I...
DeepLab V3+: Encoder-Decoder with Atrous Separable Convolution for Semantic I...
 
Clustering of graphs and search of assemblages
Clustering of graphs and search of assemblagesClustering of graphs and search of assemblages
Clustering of graphs and search of assemblages
 
2. filtering basics
2. filtering basics2. filtering basics
2. filtering basics
 
A modern Post-Processing Pipeline
A modern Post-Processing PipelineA modern Post-Processing Pipeline
A modern Post-Processing Pipeline
 
Color
ColorColor
Color
 
Applied Deep Learning 11/03 Convolutional Neural Networks
Applied Deep Learning 11/03 Convolutional Neural NetworksApplied Deep Learning 11/03 Convolutional Neural Networks
Applied Deep Learning 11/03 Convolutional Neural Networks
 
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" DemoThe Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
The Technology Behind the DirectX 11 Unreal Engine"Samaritan" Demo
 
Ch2
Ch2Ch2
Ch2
 

Recently uploaded

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 

Around the World in 80 Shaders

  • 1.
  • 2. Around the World in 80 Shaders Stephen McAuley Bizarre Creations stephen.mcauley@bizarrecreations.com
  • 3. Overview • Introduction: – The FX system • Around the world tour: – Default – Skin – MPEG corruption – Refraction mapping – Shallow water – Aquarium
  • 4. FX System: Problem • After finishing PGR4 and The Club we needed a new solution to handling shaders. – Two different systems. – Extremely complicated to add new shaders. • Have to add new vertex declarations, new exporter code and new rendering code as well. – Not data driven. • Shaders treated as code not data. • Could never run on an SPU. – No Maya previewing for artists.
  • 5. FX System: Solution • Our solution was the FX system: – Based on .fx files. – Entirely data driven. – Automatic Maya previews for artists. – All rendering code now runs on the SPUs.
  • 6. FX System: Maya and XSI • Compile Maya and XSI shaders alongside PC shaders. • Annotations control how the parameters appear to the artists: • Artists can “expose” parameters they want to be set within game. texture2D g_tAlbedo < string SasUiLabel = “Colour”; >; float g_fScale < string SasUiLabel = “Scale”; > = 0.0;
  • 7. FX System: Exporting • Scene converter: – Reads vertex input structure • With the help of annotations. – Exports relevant vertex data in the correct format. struct C_VertexInput { float3 m_vPosition : POSITION; float3 m_vNormal : NORMAL; float4 m_vTexCoord : TEXCOORD0 annotation(xy(uv:0) | zw(uv:luxlightmap) | format(F16_4)); };
  • 8. FX System: Exporting • Lua script within each shader helps build shader permutations: • If a bumpmap is present, game will search for ShaderB.fx instead of Shader.fx. • Make sure you have compiled that permutation! texture2D g_tBumpmap < string SasUiLabel = “Bumpmap”; >; #if defined(FXFILE_PARSER) if (g_tBumpmap) then append(“B”, 10) end #endif
  • 9. FX System: In Game • Game sets exposed and shared parameters. • Techniques are changed dynamically: • e.g. shadow mapping technique, prepass technique… • Shader parameters can be overridden via our debugging tool: – Currently only on all instances of a shader.
  • 10.
  • 12. Default Shader • This is our base material for everything in game. • Applied when artists use the Lambert shader in Maya. – Easy to set up. – Artists just set an albedo texture. – Other textures are picked up in the exporter using a naming convention.
  • 13. Default Shader: Material • The following material options are supported: – Albedo (_DIFF) – Normal (_NORM) – Specular (_IPR0) – Emissive (_NEON) • These are all controlled by textures.
  • 14. Default Shader: Lighting • We support these lighting methods: – Light maps – Vertex lighting – Vertex PRT – SH lighting • In Blood Stone, they contained the following information: – Colour, sun occlusion and ambient occlusion
  • 15. Default Shader: Lighting Our BRDF for sun lighting: 𝜌 = 𝑅 𝑑 𝜋 1 − 𝐼𝐹 𝐹0 + 𝐼𝐹(𝐹0) 𝑛 + 2 2𝜋 (𝑅. 𝑉) 𝑛 (𝑁. 𝐿) where 𝑅 𝑑 is the surface albedo and 𝐹(𝐹0) is Schlick’s fresnel approximation: 𝐹(𝐹0) = 𝐹0 + (1 − 𝐹0)(𝑁. 𝑉)5
  • 16. Default Shader: Specular We have three parameters controlling specular: 𝜌 = 𝑅 𝑑 𝜋 1 − 𝐼𝐹 𝐹0 + 𝐼𝐹(𝐹0) 𝑛 + 2 2𝜋 (𝑅. 𝑉) 𝑛 (𝑁. 𝐿) • 𝐼 is the specular intensity • 𝑛 is the specular power • 𝐹0 is the normal specular reflectance
  • 17. Default Shader: Specular • These three specular properties come from our specular texture: – Red channel: Intensity (𝐼) – Green channel: Power (𝑛) • 𝑛 = 4 + 8188𝑔2 • 𝑚𝑖𝑝𝑀𝑎𝑝𝐿𝑜𝑑 = 7(1 − 𝑔) – Blue channel: Reflectance (𝐹0)
  • 18.
  • 20. Skin • Standard diffuse lighting gives unrealistic results when applied to skin. • It looks hard and dry compared to skin’s soft appearance. • To achieve this look, we need to model subsurface scattering.
  • 21. Skin • The best approach is described by Eugene d’Eon and David Luebke in [1]: – Observed that red light scatters in skin more than green and blue. – Simulate subsurface scattering by lighting in texture space, then performing separate gaussian blurs for red, green and blue channels. • This is expensive and intrusive. Are there any cheaper ways?
  • 22. Skin: Approximations • Standard diffuse lighting: D = N.L • Wrapped diffuse lighting: D = N.L * w + (1 – w) • i.e. D = N.L * 0.5 + 0.5 • What if we wrap different colours by different amounts?
  • 23. Skin: Our solution • Coloured wrapped diffuse lighting: D = N.L * W + (1 – W) • i.e. D = N.L * { 0.5, 0.8, 0.9 } + { 0.5, 0.2, 0.1 } • Simulates subsurface scattering by giving skin a softer look. • Simulates red light scattering further in skin. • Cheap and easy to implement.
  • 28. MPEG Corruption • For the AR phone, we wanted an effect that simulated MPEG corruption. • “Blocks” in the image don’t update and remain from the previous frame.
  • 29. MPEG Corruption • Algorithm: – For each pixel, point sample a noise texture. • Scaled so each texel is the size of a “block”. – If sample is less than a threshold, take pixel from previous frame buffer. • Instead of the previous frame buffer, use a scaled and offset version of the current frame. – Else, take pixel from current frame buffer.
  • 30. MPEG Corruption half2 vRUV = vUV * g_vCorruptionBlockSize; vRUV += half2(g_fCorruptionAmount * 7.123h, 0.0h); half fRand = h4tex2D(g_tNoise, vRUV).r; if(fRand < g_fCorruptionAmount) { real2 vDUV = input.m_TexCoord * g_vCorruptionUVScale; vDUV += g_vCorruptionUVOffset; vColour = h4tex2D(g_tBackbuffer, vDUV).rgb; vColour *= (1.0h + fRand - 0.5h * g_fCorruptionAmount); } else { vColour = h4tex2D(g_tBackbuffer, vUV).rgb; }
  • 31.
  • 32.
  • 33.
  • 35. Refraction Mapping • We wanted to simulate surfaces that are coated in a layer of ice. • Requirements: – These surfaces have two layers: • Ice layer • Base layer – The base layer is refracted by the ice layer.
  • 36. Refraction Mapping • Our in-game materials use three textures: – albedo – normal – specular • We split these textures across the two layers. Ice layer: • normal • specular Base layer: • albedo uv refracted uv
  • 37. Refraction Mapping • Calculate the refracted texture coordinate: • Albedo texture uses vRefractUV. • Normal and specular maps use vUV. half3 vRefract = refract(vTangentView, vTangentNormal, 1.0f / g_fRefractiveIndex); float2 vUVOffset = g_fDisplacement * vRefract.xy / vRefract.z; float2 vRefractUV = vUV + vUVOffset;
  • 41. Refraction Mapping: Extensions • Vary the displacement across the surface: – Height map. – Vertex colours. • Add a frost layer in between the top layer and the base layer.
  • 44. Frost
  • 45. Refraction Mapping: Problems • Make sure your tangent space is correct! – Any errors will very quickly become apparent. • Displacement breaks as you look at the surface edge on.
  • 48. Shallow Water • Why does shallow water appear more transparent than deep water? – Water molecules absorb and scatter light. – The further light travels, the higher probability it is absorbed or scattered. – Absorption and scattering are dependent on wavelength: • e.g. red light is absorbed more than green or blue, giving water its characteristic colour.
  • 49. Shallow Water • Premoze and Ashikhmin suggested the following model for the absorption and scattering of light in water [2]: 𝐿 0, 𝜃, 𝜑 = 𝐿 𝑍, 𝜃, 𝜑 𝑒−𝑐𝑅 + 𝐿 𝑑𝑓 0 1 − 𝑒 −𝑐+𝐾 𝑑 𝑐𝑜𝑠𝜃 𝑅
  • 50. Shallow Water 𝐿 = 𝐿 𝑧 𝑒−𝑐𝑅 + 𝐿0(1 − 𝑒−𝑐𝑅 𝑒−𝐾 𝑑 𝐻 ) R H LZ L0 extinction inscattering c and Kd are wavelength dependent absorption and scattering coefficients
  • 51. Shallow Water 𝐿 = 𝐿 𝑧 𝑒−𝑐𝑅 + 𝐿0 1 − 𝑒−𝑐𝑅 𝑒−𝐾 𝑑 𝐻 • Optimisation: – Remove the 𝑒−𝐾 𝑑 𝐻term. – Only changes the falloff of the inscattering, not the intensity.
  • 52. Shallow Water 𝐿 = 𝐿 𝑧 𝑒−𝑐𝑅 + 𝐿0 1 − 𝑒−𝑐𝑅 • Optimisation: – Remove the 𝑒−𝐾 𝑑 𝐻term. – Only changes the falloff of the inscattering, not the intensity.
  • 53. Shallow Water 𝐿 = 𝐿 𝑧 𝑒−𝑐𝑅 + 𝐿0 1 − 𝑒−𝑐𝑅 • Optimisation: – Remove the 𝑒−𝐾 𝑑 𝐻term. – Only changes the falloff of the inscattering, not the intensity. • Visual artefact: – Very shallow water is slightly darker.
  • 54. Shallow Water • The final equation is a lerp between the water colour and the underwater colour, based on the extinction: 𝐿 = lerp(𝐿0, 𝐿 𝑧, 𝑒−𝑐𝑅 ) • Final shader code: half3 vExtinction = exp(-g_vExtinctionCoeffs * fDistUnderwater); half3 vDiffuse = lerp(vSceneColour, vWaterColour, vExtinction);
  • 59. Aquarium • Is an aquarium tank equivalent to shallow water? R LZ L0
  • 61. Image courtesy Jon Rawlinson jonrawlinson.com
  • 62. Aquarium • Simulate a light positioned directly above the tank. • This is our new inscattering term. R LZ L0 M0 H MZ
  • 63. Aquarium • Inscattering equation: 𝐼 = 𝑀0 𝑒−𝑐1 𝐻 (1 − 𝑒−𝑐0 𝑅 ) • Light colour, 𝑀0, should be the colour of the light as it hits the surface of the water. – i.e. light colour modulated by water colour • Use a different attenuation coefficient to the extinction. – Allows for more interesting hue shifts.
  • 64. Aquarium • Shader code: half3 vExtinction = exp(-g_vExtinctionCoeffs * fDistanceThroughWater); half3 vInscattering = exp(-g_vInscatteringCoeffs * fDistanceUnderWater); vInscattering *= g_vLightColour.rgb; half3 vDiffuse = lerp(vSceneColour, vInscattering, vExtinction);
  • 65. Aquarium • For the final touch, add light shafts: – Project two scrolling textures in the world x-z plane. • Sample each texture at a fixed distance behind the glass front of the aquarium tank. – Combine texture samples into light shaft term, 𝑘. – Modify inscattering term: inscattering = 𝑀0 𝑒−𝑐1 𝐻(1−𝑘) (1 − 𝑒−𝑐0 𝑅 )
  • 68. References • [1] Advanced Techniques for Real-Time Skin Rendering, Eugene d’Eon and David Luebke, GPU Gems 3, 2008 • [2] Rendering Natural Waters, Simon Premoze & Michael Ashikhmin, 2001
  • 69. Credits • For working on the technology described in this presentation: – Paul Malin – Jan van Valburg – David Hampson

Editor's Notes

  1. At Bizarre, our environment and character artists primarily work in Maya whereas our vehicle team use XSI. For example, in our Bangkok levels in Blood Stone we had a dynamically generated ripple texture used as a normal map on puddles. The artist exposed the normal map parameter on that shader with the name “Ripple” and we were then able to set the ripple texture to that exposed parameter.
  2. Semantics such as POSITION and NORMAL have default settings so there is no need to annotate them. As for the texture coordinate, we are telling it to use a format of four F16s, put UV set 0 into the xy coordinates and put our lightmap UV set into the zw coordinates. (Lux is our lighting tool.) Vertex declarations are now therefore fully data driven.
  3. This Lua script is run per polygon, which although is slow, isn’t as slow as you think. There are so many ways we can use this functionality. For example, for shaders where the vertex colours are used to blend between two textures, we could read the vertex colours in script, detect where no blending is taking place and fallback to a permutation with only one texture instead of two. Or where vertex alpha is used to alpha fade, we could move any polygons with a vertex alpha of 1 into the solid render pass.
  4. F0 should never be zero, the minimum real world value is 0.02.
  5. We call our specular texture IPR (just look at the initials). We don’t just have sun highlights for specular, we also have an environment map. We specify the mip map level we look up with the green channel. Make sure that the blurriness of the cube map and the size of the specular highlight match! (My advice on doing this is to avoid changing the equations, as they’re simple and you don’t want to complicate things. Instead, adjust the blurriness of the cube map mip levels when you generate it. CubeMapGen is great for this. We realised that we needed to blur each mip level a little bit more than normal – if you just downsize to create the mips, you’re left with an ugly blocky reflection instead of a blurry reflection.)
  6. Almost everything on this shot is using just the default shader, including the car! As you can see, it’s really powerful and easy for the artists to set up.
  7. Some other approximations are described by John Hable in his talk on Uncharted 2 Character Lighting and Shading in the Advances in Real-Time Rendering in 3D Graphics and Games course at SIGGRAPH 2010.
  8. This is the reference photo our art director gave me!
  9. Note: We offset the lookup into the noise texture by the corruption amount, so that as the corruption blends in and out it animates. We also brighten and darken the colour of each block by a small amount, to give more variation in the effect.
  10. The normal and specular textures are sampled with the standard uv, whereas the albedo is sampled with the newly calculated refracted uv.
  11. We calculate the tangent view vector (the view vector in tangent space) in the vertex shader and upload via an interpolator to the pixel shader.
  12. Had to dig around in the holiday albums for these… the picture on the left is from a little stream in the Forest of Bowland (I fell into this at one point…), whereas on the right is Lake Michigan, as seen from Muskegon. The deep water on the right looks opaque, whereas on the left you can see the rocks underneath the water.
  13. This is for diffuse lighting only. We simulate specular with a standard physically-correct Blinn-Phong model. Remember that the normal specular reflectance of water is 0.02.
  14. L0 is the colour at the surface at the water, the water surface colour modulated by the diffuse lighting. LZ is the colour underneath the water, you’ll need to look this up from either your frame buffer or a specifically generated refraction texture. I’m using L to denote that both these points have already been lit before being fed into this equation.
  15. The original equation has two exponentials in it, which given that they are scalar instructions and we need to operate on a vector, amounts to six whole scalar instructions. That’s really going to block up your scalar pipe, so minimising the exponentials is really key. Observe that 1 – exp(-cR)exp(-KH) is always between 0 and 1 (given that c, K, R and H are all positive, so exp(-cR) and exp(-KH) are both between 0 and 1) and when H is large, R is large (although the reverse isn’t necessarily true), which takes the exponential terms to 0.
  16. This now falls out into a lerp!
  17. Although you can notice the visual difference by removing this term, this is enough of an approximation anyway that it would be hard for you to say that one looks more realistic than the other. So for performance reasons, it’s best to remove it.
  18. Having a real-time reflection really helps!
  19. Can we treat the aquarium tank in the same way we treat shallow water? Rather than having a horizontal water plane, now we just have a vertical one.
  20. The answer is no, because the aquarium tank just looks far too dark.
  21. If we look at real aquarium tanks (here’s a huge one in Okinawa, Japan), they clearly have light filtering down from the top of the tank. They’re definitely not as dark as the implementation I just showed!
  22. Can we treat the aquarium tank in the same way we treat shallow water? Rather than having a horizontal water plane, now we just have a vertical one.
  23. To calculate the distance under the water, you do need to have the height of the light (i.e. the world space position of the top of the aquarium tank) passed up as a shader constant.