a bit more deferred - cryengine 3 martin mittring – lead graphics programmer triangle game...

27
“A bit more Deferred” - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Upload: haley-riley

Post on 26-Mar-2015

259 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

“A bit more Deferred” - CryEngine 3

Martin Mittring – Lead Graphics Programmer

Triangle Game Conference 2009

Page 2: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Crytek

• Main office:Germany Frankfurt

• More studios: Kiev, Budapest, Sofia, Nottingham, Seoul

• English as company language• 30+ nationalities• CryEngine 1: PC only (Far Cry …)• CryEngine 2: PC only (Crysis …)• CryEngine 3: PC, XBox360, PS3

(announced GDC09)

Page 3: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

• 32/64 Bit, WinXP/Vista, DX9/10, Multi CPU/GPU• WYSIWYP• ResourceCompiler

Source asset -> Platform specific

• Direct Light: Shadow mapping• Indirect Light (AO): SSAO / RAM / ...• No precomputed lighting

Production time saver, Memory, Consistency, Dynamic content

• Übershaders[Mittring07]

Page 4: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Goals after CryEngine 2

• PS3 / XBox360GPU, CPU, memory

• Improve streaming

• Improve multithreading

• Improve lighting

• More predictable performance

• Tackle the shader combination issue

Page 5: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

What is the shadercombination issue?

• Übershader is one shader with many features (e.g. 0..4 lights, light types, CM reflection, fog, detail texture, normalmap, specular texture)

• Compiling all possible permutations is a memory, production and performance problem

• Usual solutions:– dynamic branching / separating into multiple passes / reducing

combinations and accepting less functionality and less performance

– Asynchronous shader compiling– Distributed Job System to compile the shader cache

Page 6: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Why Deferred Rendering?

• Rendering is a multi-dimensional query:View x Geometry x Material x Light

• Classic Forward Rendering: for each light render geometry from scene query with shader

• Classic Deferred Rendering:render geometry from scene query outputting GBufferrender each light from scene query and shade with GBuffer

=> Decouples geometric complexity from lighting and shading => Helps on shader combination issue and predictable performance

Page 7: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

GBuffer in CryEngine 2

• Minimal GBuffer (depth)• Slower Early Z pass when outputting linear depth• Formats:

– R16– R16G16– R32

• Proved to be very useful

Z

Page 8: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Deferred in CryEngine 2

• Main use:Deferred shadows, Per pixel fog

• Additionally:Soft Z clipped Particles, Motion Blur, Beach/Ocean, EdgeAA,Sun Rays, SSAO, Fake lights, 2.5D TerrainAO

SSAO ShadowMask

Page 9: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Deferred Lighting in CryEngine 3

• Passes:1) Forward GBuffer generation2) Deferred light accumulation into texture (Phong)3) Forward shading with light accumulation texture => No deferred shading

• Deferred Lighting* + Multiple light primitives are possible+ even Image Based Lighting (IBL)+ easy to extend

• Compared to Deferred Shading+ Less bandwidth and memory problems (10MB EDRAM XBox360)+ More flexibility on shading (besides Phong)

Z (native) Normal Specular Power

* [Geldreich09] aka Light Pre-Pass Renderer [Engel08]

Page 10: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Options for the light accumulation texture

• 6 channels: Diffuse and Specular two 7e3 7e3 7e3, A16R16G16B16f or A8R8G8B8*

• 4 channels: Diffuse and Specular strengtha single A16R16G16B16f or A8R8G8B8*

(specular approximated by diffuse*strength)

The following pictures show lighting with two differently coloured lights:

6 channels (correct) 4 channels (fast)

* sRGB helps to distribute more details in dark areas

Page 11: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Light accumulation texture in IBL

• Diffuse RGBSpecular RGBHigh Quality(left)

• Diffuse RGBSpecular StrengthFast Rendering(right)

• Difference often neglectable (depends on environment)

The following pictures show lighting with Diffuse and Specular Cubemaps:

Page 12: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Storing normals in the GBuffer

• XYZ world space8 bit: problematic with extreme reflections/specular10 bit: good, but what about specular power and PS3

• Solving Quantization ArtefactsDetail Normalmaps, Noise, Dither

• XY view space (Z reconstruct)8/10/16 bit, negate Z bit (perspective and normal mapping)

[Lee09] [Lob09]

=> Problematic

Page 13: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Alternative: VS Normal in 2 scalars-1..1 => -1..1

Normal to GBufffer:

G=normalize(N.xy)*sqrt(N.z*0.5+0.5)

GBuffer to Normal:

N.z=length2(G.xy)*2-1N.xy=normalize(G.xy)*sqrt(1-N.z*N.z)

+ more precision where it matters (bright part)+ framebuffer blending friendly+ no z reconstruction issues- wasted area - more ALU than WS

=> still, WS normals are faster

Page 14: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Improved SSAO (with normals)

Page 15: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Light rasterization in2D (Rectangle) or 3D (Convex Object)

• 2D+ cheap WS position reconstruction (Interpolator+MAD)

+ Combining multiple lights- Stencil prepass (if not fullscreen)- Coarse blocks can be rejected based on z min/max

• 3D+ Z buffer

+ tighter bounding object (less pixels to process)

• Depth bounds test (only on some HW)

Page 16: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Deferred Light Types 1/3:

• Directional lightoptional with cloud shadows, multiple shadowmaps

• Point/Projector lightsoptional with projector texture

• Procedural Caustics(before this was multi-pass, one drawcall for each object under water including terrain)

• Interleaved Shadowmap lookupsno extra memoryless bandwidth neededno limits on shadow mask channel count

Page 17: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Deferred Light Types 2/3:Image Based Lighting (IBL)

• Light Probes are the high quality solution for distant light• Cubemaps allow efficient HDR lighting in real-time• Diffuse CM can be computed from specular CM• Mip adjusted lookup allows different specular power values• Improves shading in ambient lighting condition

by adding normal dependent and specular lighting• Light Probes can be generated at specified level positions• Deferred Lighting allows blending of localized Light Probes• Looks even better with SSAO

Page 18: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Ambient without SSAO

with hemispherical lighting

Page 19: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Bright ambient SSAO

Black ambient Shadow casting light source

SSAO

Grey ambient (hemispherical)Shadow casting light source

SSAO

IBL ambient (Specular and Diffuse)Shadow casting light source

SSAO

Page 20: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

IBL ambient (Specular and Diffuse)

SSAO

* brightened up for better display

Page 21: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Deferred Light Types 3/3:Real-time Dynamic Global Illumination

• Details will be presented at upcomingSiggraph 2009 by Anton Kaplanyanwho developed that at Crytek

• Implemented and fast on XBox360, PS3 and PC• No precomputation• Fully dynamic (geometry, materials and lights)

• Unified for static and dynamic objects

Page 22: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

black ambient

(to emphasize where GI

affects the image)

color bleeding

bump without light

fully dynamic

real-time

Global Illumination off

Global Illumination on

Page 23: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

* brightened up for better display

Global Illumination

Page 24: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

Something missing?

Transparency => falling back to well known techniques:– Per pixel global fog and fog volumes (deferred)– Back to front sorted alpha transparent objects– Volume texture clouds, Imposter clouds, Distance clouds– Particle systems avoiding per particle sorting

Anti-aliasing => Nasty but possible– EdgeAA, …

... we work on it

Page 25: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009

References

• [Mittring07] “Finding Next Gen CryEngine2“Siggraph 2007, Martin Mittringhttp://ati.amd.com/developer/gdc/2007/mittring-finding_nextgen_cryengine2(siggraph07).pdf

• [Engel08] “The Light Pre-Pass Renderer“ShaderX7, Wolfgang Engelhttp://diaryofagraphicsprogrammer.blogspot.com/2008/03/light-pre-pass-renderer.html

• [Lee09a] “Prelighting“Mark Leehttp://www.insomniacgames.com/tech/articles/0209/files/prelighting.pdf

• [Lee09b] “Pre-lighting in Resistance 2“GDC 2009, Mark Leehttp://www.gdconf.com/conference/Tutorial%20Handouts/200_insomniac/gdc09_insomniac_prelighting.pdf

• [Geldreich09] ”Deferred Lighting and Shading”GDC 2009, Rich Geldreich, Matt Pritchard, John Brookshttp://archive.gdconf.com/gdc_2004/pritchard_matt.ppt

• [Shish05] “Deferred Shading in S.T.A.L.K.E.R.“GPU Gems 2, Oles Shishkovtsov http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter09.html

• [Lob09] S.T.A.L.K.E.R : Clear Sky – a showcase for Direct3D 10.0/1GDC 2009, Igor A. Lobanchikov, Holger Gruenhttp://www.gdconf.com/conference/Tutorial%20Handouts/100_Advanced%20Visual%20Effects%20with%20Direct3D/100_Handout%202.pdf

• [Valient07] “Deferred Rendering in Killzone 2“Develop Conference 2007, Michal Valienthttp://www.guerrilla-games.com/publications/dr_kz2_rsx_dev07.pdf

Slides should be soon at http://www.crytek.com/technology/presentations

Special thanks to all the passionate people at Crytek

Page 26: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009
Page 27: A bit more Deferred - CryEngine 3 Martin Mittring – Lead Graphics Programmer Triangle Game Conference 2009