Light in screen_space(Light Pre Pass)

  • Published on
    24-May-2015

  • View
    1.599

  • Download
    2

Embed Size (px)

DESCRIPTION

Light Pre Pass

Transcript

<ul><li> 1. Lighting In Screen Space (Light Pre-Pass)</li></ul> <p> 2. Light Pre-Pass Light Pre-Pass Deferred ShadingGBuffer Light Buffer 3. Deferred Shading / Rendering Z Pre Pass Rendering John D. Carmack II, Doom3Light Pre Pass Saito &amp; Takahashi 1990Wolfgang Engel 2008Inferred Lighting SIGGRAPH2009 Scott Kircher,Alan Lawrance 4. Z Pre Pass Rendering Doom3 Depth Light 5. Deferred Shading , O(1) . Lighting Scene . Killzone 2s G-Buffer Layout (courtesy of Michal Valient) 6. Deferred Shading MRT (Shader 3.0)NormalsSpecularAlbedo / ShadowDepth Buffer Motion VecDeferred Lighting Forward Rendering 7. Deferred Shading G-Buffer Material Property G-Buffer ( 4) Material Lighting RenderTarget 4 Forward Rendering frame buffer anti-aliasing 8. Light Pre Pass 9. Light Pre-Pass MRT 2Pass MSAA 2Pass Render Target Shader 2.0 ( )Deferred Shading Material 2Pass 10. Light Pre-Pass1Pass NormalsDepth Buffer Light BufferForward RenderingForward Rendering 2Pass 11. Light Pre-Pass Deferred Shading , 1 MRT G-Buffer Light Pre-Pass 2Pass light specular (GameDev.net) Specular 12. Light Pre-Pass S.T.A.L.K.E.R: Clear Skies 13. Light Pre-Pass BlurTM in-game screenshot 14. Light Pre-Pass UnchartedTM in-game screenshot 15. Light Pre Pass 16. G Buffer (1Pass) Depth + Normal NORMAL Normal RG : normal B : Depth A : Alpha TestA16FR16FG16FB16 17. G Buffer (1Pass) Gbuffer_VS { float4 position = float4( vertex.position , 1.0f ); Out.PosClip = mul(position, WORLDVIEWPROJ); Out.PosView = mul(position, WORLDVIEW); float3 N = vertex.normal; float3 T = vertex.tangent.xyz; float3 B = cross(N,T) * vertex.tangent.w; Out.TangentToView1 = mul( T, (float3x3)WORLDVIEW ); Out.TangentToView2 = mul( B, (float3x3)WORLDVIEW ); Out.TangentToView3 = mul( N, (float3x3)WORLDVIEW ); } 18. G Buffer (1Pass) Gbuffer_PS { float4 texcolor float depth= tex2D( diffuseSampler , Input.TexCoords.xy ); = Input.PosView.z / CAMERAFAR;float3 tangentSpaceNormal.xyz = tex2D( bumpSampler, Input.TexCoords.xy ).xyz * 2 - 1; float3x3 mtxRot; mtxRot[0] = normalize( Input.TangentToView1 ); mtxRot[1] = normalize( Input.TangentToView2 ); mtxRot[2] = normalize( Input.TangentToView3 ); tangentSpaceNormal = normalize( mul( tangentSpaceNormal, mtxRot ) ); float4 packColor = PackDepthNormal(depth, tangentSpaceNormal); packColor.a = texcolor.a; return packColor; } 19. Compact Normal Storage store X&amp;Y, reconstruct Z half4 encode (half3 n, float3 view) { return half4(n.xy*0.5+0.5,0,0); } half3 decode (half2 enc, float3 view) { half3 n; n.xy = enc*2-1; n.z = sqrt(1-dot(n.xy, n.xy)); return n; }Compact Normal Storage for small G-Buffers http://aras-p.info/texts/CompactNormalStorage.html 20. Compact Normal Storage Spheremap Transform half2 encode (half3 n, float3 view) { half f = sqrt(8*n.z+8); return n.xy / f + 0.5; } half3 decode (half4 enc, float3 view) { half2 fenc = enc*4-2; half f = dot(fenc,fenc); half g = sqrt(1-f/4); half3 n; n.xy = fenc*g; n.z = 1-f/2; return n; }Compact Normal Storage for small G-Buffers http://aras-p.info/texts/CompactNormalStorage.html 21. Gbuffer(Depth) 22. Gbuffer(Normal) 23. Light Buffer Pass Screen Space Gbuffer Light Light Light ViewSpace Depth Speculer Point Light Light A16FR16FG16FB16F Light buffer layout R : LightColor.r * N.L * Att G : LightColor.g * N.L * Att B : LightColor.b * N.L * Att A : R.V^n * N.L * Att (Speculer) 24. Light Buffer Pass 2Pass 25. Light Buffer PassSpeculer Color Speculer Color CryEngine 3 26. depth buffer Inverse Projection matrix Depth WVP z/w WV Z Linear floating Zfar ,,, far clip rayVS PS ray( ) SSAO , Motion blur(depth based), DOFFrustumCorner = Vector3(0,0,Far) FrustumCorner.y = tan( FOV / 2 ) * Far FrustumCorner.x = FrustumCorner.y * Aspect 27. Light Buffer Pass pos_vs { Out.Position = Input.Position; Out.TexCoords = Input.TexCoords.xy; Out.View = float3(FRUSTUMCORNER.x * Input.Position.x, FRUSTUMCORNER.y * Input.Position.y, FRUSTUMCORNER.z); }directional_ps { float fvDepth; float3 fvViewSpaceNormal; UnpackDepthNormal( normalDepthSampler , In.TexCoords, fvDepth, fvViewSpaceNormal ); float3 fvViewSpacePos = fvDepth * In.View;float diffuseLight = saturate( dot( fvViewSpaceNormal, DIRLIGHT) + AMBIENT; float3 eyeVec = -normalize( fvViewSpacePos ); float3 halfVec = normalize( eyeVec + DIRLIGHT ); float specular = pow( saturate( dot( fvViewSpaceNormal, halfVec) SHININESS ) return float4(diffuseLight , specular * NdotL); } 28. Light Buffer( Light ) 29. Light Buffer( Speculer ) 30. (?) Ambient Cube ( Valves ) 6 irradiance Cube 6 (indirect illumination) Shading in Valve's Source Engine float3 AmbientLight( const float3 worldNormal ) { float3 nSquared = worldNormal * worldNormal; int3 isNegative = ( worldNormal &lt; 0.0 ); float3 linearColor; linearColor = nSquared.x * cAmbientCube[isNegative.x] + nSquared.y * cAmbientCube[isNegative.y+2] + nSquared.z * cAmbientCube[isNegative.z+4]; return linearColor; } 31. Light Buffer( Light + AmbientCube) 32. Light Buffer( Light )Ambient Cube Ambient 33. 2Pass Pass ZBuffer ZCull(EalryZ) z-culling Render depth only, 1Pass Render with full shaders, 2Pass Early-Z (and Z-Cull) ZWRITEENABLE = FALSE, ZFUNC = EQUALDiffuse ZWRITEENABLE = TRUE, ZFUNC = LESSEQUALDiffuse * LightBuffer 34. Light Pre Pass Gbuffer Pass ( 1Pass ) Light Pass Accumulate Light Info2Pass , view normal view depth Diffuse * LightBuffer 35. Light-Pre-Pass Final 36. , , , (DOF, SSAO, HDR) G-Buffer . 37. References [Hargreaves] Shawn Hargreaves, Deferred Shading, http://www.talula.demon.co.uk/DeferredShading.pdf [Lobanchikov] Igor A. Lobanchikov, GSC Game Worlds S.T.A.L.K.E.R : Clear Sky a showcase for Direct3D 10.0/1, http://developer.amd.com/gpu_assets/01GDC09AD3DDStalkerClearSky210309.ppt [Mittring] Martin Mittring, A bit more Deferred Cry Engine 3, http://www.slideshare.net/guest11b095/a-bit-more-deferred-cryengine3 [Lee] Mark Lee, Resistance 2 Prelighting, http://www.insomniacgames.com/tech/articles/0409/files/GDC09_Lee_Prelighting.pdf [Lengyel] Eric Lengyel, Advanced Light and Shadow Culling Methods, http://www.terathon.com/lengyel/#slides [Placeres] Frank Puig Placeres, Overcoming Deferred Shading Drawbacks, pp. 115 130, ShaderX5 [Shishkovtsov] Oles Shishkovtsov, Making some use out of hardware multisampling; http://olesrants.blogspot.com/2008/08/making-some-use-out-of-hardware.html [Swoboda] Matt Swoboda, Deferred Lighting and Post Processing on PLAYSTATION3, http://research.scee.net/presentations [Tovey] Steven J. Tovey, Stephen McAuley, Parallelized Light Pre-Pass Rendering with the Cell Broadband EngineTM, to appear in GPU Pro [Thibieroz04] Nick Thibieroz, Deferred Shading with Multiple-Render-Targets, pp. 251 269, ShaderX2 [Thibieroz] Nick Thibieroz, Deferred Shading with Multisampling Anti-Aliasing in DirectX 10 , ShaderX7 [Valient] Michael Valient, Deferred Rendering in Killzone 2, www.guerillagames.com/publications/dr_kz2_rsx_dev07.pdf [Wolfgang Engel] Wolfgang Engel, Light Pre-Pass Deferred Lighting: Latest Development- August 3rd, 2009 [] Rendering C9 kgc2009 [] Kasa Light-Pre-Pass 2009-07-04[] [] Deferred Shading ( ) [ ] http://ozlael.egloos.com/2374651 [ ] http://ozlael.egloos.com/2876211 Z-culling http://codevania.springnote.com/pages/3936893.xhtml Compact Normal Storage for small G-Buffers http://aras-p.info/texts/CompactNormalStorage.html</p>