@@ -171,6 +171,14 @@ public BaseLightLoop lightLoop
171
171
// 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 ?
172
172
Lit . RenderLoop m_LitRenderLoop = new Lit . RenderLoop ( ) ;
173
173
174
+ public struct HDCamera
175
+ {
176
+ public Camera camera ;
177
+ public Vector4 screenSize ;
178
+ public Matrix4x4 viewProjectionMatrix ;
179
+ public Matrix4x4 invViewProjectionMatrix ;
180
+ }
181
+
174
182
public override void Build ( )
175
183
{
176
184
#if UNITY_EDITOR
@@ -374,7 +382,7 @@ void RenderForwardOnlyDepthPrepass(CullResults cull, Camera camera, RenderLoop r
374
382
}
375
383
}
376
384
377
- void RenderDebugViewMaterial ( CullResults cull , Camera camera , RenderLoop renderLoop )
385
+ void RenderDebugViewMaterial ( CullResults cull , HDCamera hdCamera , RenderLoop renderLoop )
378
386
{
379
387
using ( new Utilities . ProfilingSample ( "DebugView Material Mode Pass" , renderLoop ) )
380
388
// Render Opaque forward
@@ -383,17 +391,14 @@ void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderL
383
391
384
392
Shader . SetGlobalInt ( "_DebugViewMaterial" , ( int ) debugParameters . debugViewMaterial ) ;
385
393
386
- RenderOpaqueRenderList ( cull , camera , renderLoop , "DebugViewMaterial" ) ;
394
+ RenderOpaqueRenderList ( cull , hdCamera . camera , renderLoop , "DebugViewMaterial" ) ;
387
395
}
388
396
389
397
// Render GBuffer opaque
390
398
if ( ! debugParameters . useForwardRenderingOnly )
391
399
{
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 ) ;
395
401
m_DebugViewMaterialGBuffer . SetFloat ( "_DebugViewMaterial" , ( float ) debugParameters . debugViewMaterial ) ;
396
- m_DebugViewMaterialGBuffer . SetMatrix ( "_InvViewProjMatrix" , invViewProj ) ;
397
402
398
403
// m_gbufferManager.BindBuffers(m_DebugViewMaterialGBuffer);
399
404
// TODO: Bind depth textures
@@ -405,7 +410,7 @@ void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderL
405
410
406
411
// Render forward transparent
407
412
{
408
- RenderTransparentRenderList ( cull , camera , renderLoop , "DebugViewMaterial" ) ;
413
+ RenderTransparentRenderList ( cull , hdCamera . camera , renderLoop , "DebugViewMaterial" ) ;
409
414
}
410
415
411
416
// Last blit
@@ -417,7 +422,7 @@ void RenderDebugViewMaterial(CullResults cull, Camera camera, RenderLoop renderL
417
422
}
418
423
}
419
424
420
- void RenderDeferredLighting ( Camera camera , RenderLoop renderLoop )
425
+ void RenderDeferredLighting ( HDCamera hdCamera , RenderLoop renderLoop )
421
426
{
422
427
if ( debugParameters . useForwardRenderingOnly )
423
428
{
@@ -426,12 +431,12 @@ void RenderDeferredLighting(Camera camera, RenderLoop renderLoop)
426
431
427
432
// Bind material data
428
433
m_LitRenderLoop . Bind ( ) ;
429
- m_lightLoop . RenderDeferredLighting ( camera , renderLoop , m_CameraColorBuffer ) ;
434
+ m_lightLoop . RenderDeferredLighting ( hdCamera , renderLoop , m_CameraColorBuffer ) ;
430
435
}
431
436
432
- void RenderSky ( Camera camera , RenderLoop renderLoop )
437
+ void RenderSky ( HDCamera hdCamera , RenderLoop renderLoop )
433
438
{
434
- m_SkyRenderer . RenderSky ( camera , m_SkyParameters , m_CameraColorBufferRT , m_CameraDepthBufferRT , renderLoop ) ;
439
+ m_SkyRenderer . RenderSky ( hdCamera , m_SkyParameters , m_CameraColorBufferRT , m_CameraDepthBufferRT , renderLoop ) ;
435
440
}
436
441
437
442
void RenderForward ( CullResults cullResults , Camera camera , RenderLoop renderLoop , bool renderOpaque )
@@ -606,7 +611,7 @@ void Resize(Camera camera)
606
611
}
607
612
}
608
613
609
- public void PushGlobalParams ( Camera camera , RenderLoop renderLoop )
614
+ public void PushGlobalParams ( HDCamera hdCamera , RenderLoop renderLoop )
610
615
{
611
616
if ( m_SkyRenderer . IsSkyValid ( m_SkyParameters ) )
612
617
{
@@ -618,18 +623,16 @@ public void PushGlobalParams(Camera camera, RenderLoop renderLoop)
618
623
Shader . SetGlobalInt ( "_EnvLightSkyEnabled" , 0 ) ;
619
624
}
620
625
621
- var invViewProj = Utilities . GetViewProjectionMatrix ( camera ) . inverse ;
622
- var screenSize = Utilities . ComputeScreenSize ( camera ) ;
623
-
624
626
var cmd = new CommandBuffer { name = "Push Global Parameters" } ;
625
627
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 ) ;
628
631
629
632
renderLoop . ExecuteCommandBuffer ( cmd ) ;
630
633
cmd . Dispose ( ) ;
631
634
632
- m_lightLoop . PushGlobalParams ( camera , renderLoop ) ;
635
+ m_lightLoop . PushGlobalParams ( hdCamera . camera , renderLoop ) ;
633
636
}
634
637
635
638
public override void Render ( Camera [ ] cameras , RenderLoop renderLoop )
@@ -662,6 +665,8 @@ public override void Render(Camera[] cameras, RenderLoop renderLoop)
662
665
663
666
renderLoop . SetupCameraProperties ( camera ) ;
664
667
668
+ HDCamera hdCamera = Utilities . GetHDCamera ( camera ) ;
669
+
665
670
InitAndClearBuffer ( camera , renderLoop ) ;
666
671
667
672
RenderDepthPrepass ( cullResults , camera , renderLoop ) ;
@@ -674,7 +679,7 @@ public override void Render(Camera[] cameras, RenderLoop renderLoop)
674
679
675
680
if ( debugParameters . debugViewMaterial != 0 )
676
681
{
677
- RenderDebugViewMaterial ( cullResults , camera , renderLoop ) ;
682
+ RenderDebugViewMaterial ( cullResults , hdCamera , renderLoop ) ;
678
683
}
679
684
else
680
685
{
@@ -691,14 +696,14 @@ public override void Render(Camera[] cameras, RenderLoop renderLoop)
691
696
m_lightLoop . PrepareLightsForGPU ( cullResults , camera , ref shadows ) ;
692
697
m_lightLoop . BuildGPULightLists ( camera , renderLoop , m_CameraDepthBufferRT ) ;
693
698
694
- PushGlobalParams ( camera , renderLoop ) ;
699
+ PushGlobalParams ( hdCamera , renderLoop ) ;
695
700
}
696
- RenderDeferredLighting ( camera , renderLoop ) ;
701
+ RenderDeferredLighting ( hdCamera , renderLoop ) ;
697
702
698
703
RenderForward ( cullResults , camera , renderLoop , true ) ;
699
704
RenderForwardOnly ( cullResults , camera , renderLoop ) ;
700
705
701
- RenderSky ( camera , renderLoop ) ;
706
+ RenderSky ( hdCamera , renderLoop ) ;
702
707
703
708
RenderForward ( cullResults , camera , renderLoop , false ) ;
704
709
0 commit comments