@@ -171,6 +171,14 @@ public BaseLightLoop lightLoop
171171 // TODO TO CHECK: SebL I move allocation from Build() to here, but there was a comment "// Our object can be garbage collected, so need to be allocate here", it is still true ?
172172 Lit . RenderLoop m_LitRenderLoop = new Lit . RenderLoop ( ) ;
173173
174+ public struct HDCamera
175+ {
176+ public Camera camera ;
177+ public Vector4 screenSize ;
178+ public Matrix4x4 viewProjectionMatrix ;
179+ public Matrix4x4 invViewProjectionMatrix ;
180+ }
181+
174182 public override void Build ( )
175183 {
176184#if UNITY_EDITOR
@@ -374,7 +382,7 @@ void RenderForwardOnlyDepthPrepass(CullResults cull, Camera camera, RenderLoop r
374382 }
375383 }
376384
377- void RenderDebugViewMaterial ( CullResults cull , Camera camera , RenderLoop renderLoop )
385+ void RenderDebugViewMaterial ( CullResults cull , HDCamera hdCamera , RenderLoop renderLoop )
378386 {
379387 using ( new Utilities . ProfilingSample ( "DebugView Material Mode Pass" , renderLoop ) )
380388 // Render Opaque forward
@@ -383,17 +391,14 @@ void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderL
383391
384392 Shader . SetGlobalInt ( "_DebugViewMaterial" , ( int ) debugParameters . debugViewMaterial ) ;
385393
386- RenderOpaqueRenderList ( cull , camera , renderLoop , "DebugViewMaterial" ) ;
394+ RenderOpaqueRenderList ( cull , hdCamera . camera , renderLoop , "DebugViewMaterial" ) ;
387395 }
388396
389397 // Render GBuffer opaque
390398 if ( ! debugParameters . useForwardRenderingOnly )
391399 {
392- var invViewProj = Utilities . GetViewProjectionMatrix ( camera ) . inverse ;
393- var screenSize = Utilities . ComputeScreenSize ( camera ) ;
394- m_DebugViewMaterialGBuffer . SetVector ( "_ScreenSize" , screenSize ) ;
400+ Utilities . SetupMaterialHDCamera ( hdCamera , m_DebugViewMaterialGBuffer ) ;
395401 m_DebugViewMaterialGBuffer . SetFloat ( "_DebugViewMaterial" , ( float ) debugParameters . debugViewMaterial ) ;
396- m_DebugViewMaterialGBuffer . SetMatrix ( "_InvViewProjMatrix" , invViewProj ) ;
397402
398403 // m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
399404 // TODO: Bind depth textures
@@ -405,7 +410,7 @@ void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderL
405410
406411 // Render forward transparent
407412 {
408- RenderTransparentRenderList ( cull , camera , renderLoop , "DebugViewMaterial" ) ;
413+ RenderTransparentRenderList ( cull , hdCamera . camera , renderLoop , "DebugViewMaterial" ) ;
409414 }
410415
411416 // Last blit
@@ -417,7 +422,7 @@ void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderL
417422 }
418423 }
419424
420- void RenderDeferredLighting ( Camera camera , RenderLoop renderLoop )
425+ void RenderDeferredLighting ( HDCamera hdCamera , RenderLoop renderLoop )
421426 {
422427 if ( debugParameters . useForwardRenderingOnly )
423428 {
@@ -426,12 +431,12 @@ void RenderDeferredLighting(Camera camera, RenderLoop renderLoop)
426431
427432 // Bind material data
428433 m_LitRenderLoop . Bind ( ) ;
429- m_lightLoop . RenderDeferredLighting ( camera , renderLoop , m_CameraColorBuffer ) ;
434+ m_lightLoop . RenderDeferredLighting ( hdCamera , renderLoop , m_CameraColorBuffer ) ;
430435 }
431436
432- void RenderSky ( Camera camera , RenderLoop renderLoop )
437+ void RenderSky ( HDCamera hdCamera , RenderLoop renderLoop )
433438 {
434- m_SkyRenderer . RenderSky ( camera , m_SkyParameters , m_CameraColorBufferRT , m_CameraDepthBufferRT , renderLoop ) ;
439+ m_SkyRenderer . RenderSky ( hdCamera , m_SkyParameters , m_CameraColorBufferRT , m_CameraDepthBufferRT , renderLoop ) ;
435440 }
436441
437442 void RenderForward ( CullResults cullResults , Camera camera , RenderLoop renderLoop , bool renderOpaque )
@@ -606,7 +611,7 @@ void Resize(Camera camera)
606611 }
607612 }
608613
609- public void PushGlobalParams ( Camera camera , RenderLoop renderLoop )
614+ public void PushGlobalParams ( HDCamera hdCamera , RenderLoop renderLoop )
610615 {
611616 if ( m_SkyRenderer . IsSkyValid ( m_SkyParameters ) )
612617 {
@@ -618,18 +623,16 @@ public void PushGlobalParams(Camera camera, RenderLoop renderLoop)
618623 Shader . SetGlobalInt ( "_EnvLightSkyEnabled" , 0 ) ;
619624 }
620625
621- var invViewProj = Utilities . GetViewProjectionMatrix ( camera ) . inverse ;
622- var screenSize = Utilities . ComputeScreenSize ( camera ) ;
623-
624626 var cmd = new CommandBuffer { name = "Push Global Parameters" } ;
625627
626- cmd . SetGlobalVector ( "_ScreenSize" , screenSize ) ;
627- cmd . SetGlobalMatrix ( "_InvViewProjMatrix" , invViewProj ) ;
628+ cmd . SetGlobalVector ( "_ScreenSize" , hdCamera . screenSize ) ;
629+ cmd . SetGlobalMatrix ( "_ViewProjMatrix" , hdCamera . viewProjectionMatrix ) ;
630+ cmd . SetGlobalMatrix ( "_InvViewProjMatrix" , hdCamera . invViewProjectionMatrix ) ;
628631
629632 renderLoop . ExecuteCommandBuffer ( cmd ) ;
630633 cmd . Dispose ( ) ;
631634
632- m_lightLoop . PushGlobalParams ( camera , renderLoop ) ;
635+ m_lightLoop . PushGlobalParams ( hdCamera . camera , renderLoop ) ;
633636 }
634637
635638 public override void Render ( Camera [ ] cameras , RenderLoop renderLoop )
@@ -662,6 +665,8 @@ public override void Render(Camera[] cameras, RenderLoop renderLoop)
662665
663666 renderLoop . SetupCameraProperties ( camera ) ;
664667
668+ HDCamera hdCamera = Utilities . GetHDCamera ( camera ) ;
669+
665670 InitAndClearBuffer ( camera , renderLoop ) ;
666671
667672 RenderDepthPrepass ( cullResults , camera , renderLoop ) ;
@@ -674,7 +679,7 @@ public override void Render(Camera[] cameras, RenderLoop renderLoop)
674679
675680 if ( debugParameters . debugViewMaterial != 0 )
676681 {
677- RenderDebugViewMaterial ( cullResults , camera , renderLoop ) ;
682+ RenderDebugViewMaterial ( cullResults , hdCamera , renderLoop ) ;
678683 }
679684 else
680685 {
@@ -691,14 +696,14 @@ public override void Render(Camera[] cameras, RenderLoop renderLoop)
691696 m_lightLoop . PrepareLightsForGPU ( cullResults , camera , ref shadows ) ;
692697 m_lightLoop . BuildGPULightLists ( camera , renderLoop , m_CameraDepthBufferRT ) ;
693698
694- PushGlobalParams ( camera , renderLoop ) ;
699+ PushGlobalParams ( hdCamera , renderLoop ) ;
695700 }
696- RenderDeferredLighting ( camera , renderLoop ) ;
701+ RenderDeferredLighting ( hdCamera , renderLoop ) ;
697702
698703 RenderForward ( cullResults , camera , renderLoop , true ) ;
699704 RenderForwardOnly ( cullResults , camera , renderLoop ) ;
700705
701- RenderSky ( camera , renderLoop ) ;
706+ RenderSky ( hdCamera , renderLoop ) ;
702707
703708 RenderForward ( cullResults , camera , renderLoop , false ) ;
704709
0 commit comments