@@ -37,18 +37,12 @@ public class LightDefinitions
37
37
public static int DIRECTIONAL_LIGHT = 3 ;
38
38
39
39
// direct lights and reflection probes for now
40
- public static int NR_LIGHT_MODELS = 2 ;
40
+ public static int NR_LIGHT_MODELS = 3 ;
41
41
public static int DIRECT_LIGHT = 0 ;
42
42
public static int REFLECTION_LIGHT = 1 ;
43
+ public static int AREA_LIGHT = 2 ;
43
44
}
44
45
45
- [ GenerateHLSL ]
46
- public enum DebugViewTilesFlags
47
- {
48
- DirectLighting = 1 ,
49
- Reflection = 2
50
- } ;
51
-
52
46
[ GenerateHLSL ]
53
47
public struct SFiniteLightBound
54
48
{
@@ -76,7 +70,7 @@ public struct LightShapeData
76
70
public float cotan ;
77
71
78
72
public Vector3 boxInnerDist ;
79
- public uint lightCategory ; // DIRECT_LIGHT=0, REFLECTION_LIGHT=1
73
+ public uint lightCategory ; // DIRECT_LIGHT=0, REFLECTION_LIGHT=1, AREA_LIGHT=2
80
74
81
75
public Vector3 boxInvRange ;
82
76
public float unused2 ;
@@ -111,7 +105,7 @@ string GetKeyword()
111
105
private static int s_GenListPerBigTileKernel ;
112
106
113
107
// clustered light list specific buffers and data begin
114
- public DebugViewTilesFlags debugViewTilesFlags = 0 ;
108
+ public int debugViewTilesFlags = 0 ;
115
109
public bool enableClustered = false ;
116
110
public bool disableFptlWhenClustered = true ; // still useful on opaques. Should be false by default to force tile on opaque.
117
111
public bool enableBigTilePrepass = true ;
@@ -348,7 +342,6 @@ public void PrepareLightsForGPU(CullResults cullResults, Camera camera, HDRender
348
342
// Use for the second pass (fine pruning)
349
343
var numEntries2nd = new int [ numModels , numVolTypes ] ;
350
344
351
- // TODO manage area lights
352
345
foreach ( var punctualLight in lightList . punctualLights )
353
346
{
354
347
var volType = punctualLight . lightType == GPULightType . Spot ? LightDefinitions . SPOT_LIGHT : ( punctualLight . lightType == GPULightType . Point ? LightDefinitions . SPHERE_LIGHT : - 1 ) ;
@@ -361,8 +354,15 @@ public void PrepareLightsForGPU(CullResults cullResults, Camera camera, HDRender
361
354
{
362
355
var volType = LightDefinitions . BOX_LIGHT ; // always a box for now
363
356
++ numEntries [ LightDefinitions . REFLECTION_LIGHT , volType ] ;
357
+ }
358
+
359
+ foreach ( var areaLight in lightList . areaLights )
360
+ {
361
+ var volType = LightDefinitions . BOX_LIGHT ;
362
+ ++ numEntries [ LightDefinitions . AREA_LIGHT , volType ] ;
364
363
}
365
364
365
+
366
366
// add decals here too similar to the above
367
367
368
368
// establish offsets
@@ -508,7 +508,7 @@ public void PrepareLightsForGPU(CullResults cullResults, Camera camera, HDRender
508
508
//Vector3 C = bnds.center; // P + boxOffset;
509
509
var C = mat . MultiplyPoint ( boxOffset ) ; // same as commented out line above when rot is identity
510
510
511
- var combinedExtent = e + new Vector3 ( blendDistance , blendDistance , blendDistance ) ;
511
+ var combinedExtent = e + new Vector3 ( blendDistance , blendDistance , blendDistance ) ;
512
512
513
513
Vector3 vx = mat . GetColumn ( 0 ) ;
514
514
Vector3 vy = mat . GetColumn ( 1 ) ;
@@ -547,6 +547,86 @@ public void PrepareLightsForGPU(CullResults cullResults, Camera camera, HDRender
547
547
m_lightShapeData [ index ] = lightShapeData ;
548
548
}
549
549
550
+ for ( int areaLightIndex = 0 ; areaLightIndex < lightList . areaLights . Count ; areaLightIndex ++ )
551
+ {
552
+ LightData areaLightData = lightList . areaLights [ areaLightIndex ] ;
553
+ VisibleLight light = cullResults . visibleLights [ lightList . areaCullIndices [ areaLightIndex ] ] ;
554
+
555
+ // Fill bounds
556
+ var bound = new SFiniteLightBound ( ) ;
557
+ var lightShapeData = new LightShapeData ( ) ;
558
+
559
+ lightShapeData . lightType = ( uint ) LightDefinitions . BOX_LIGHT ;
560
+ lightShapeData . lightCategory = ( uint ) LightDefinitions . AREA_LIGHT ;
561
+ lightShapeData . lightIndex = ( uint ) areaLightIndex ;
562
+
563
+
564
+ if ( areaLightData . lightType == GPULightType . Rectangle )
565
+ {
566
+ Vector3 centerVS = worldToView . MultiplyPoint ( areaLightData . positionWS ) ;
567
+ Vector3 xAxisVS = worldToView . MultiplyVector ( areaLightData . right ) ;
568
+ Vector3 yAxisVS = worldToView . MultiplyVector ( areaLightData . up ) ;
569
+ Vector3 zAxisVS = worldToView . MultiplyVector ( areaLightData . forward ) ;
570
+ float radius = 1.0f / Mathf . Sqrt ( areaLightData . invSqrAttenuationRadius ) ;
571
+
572
+ Vector3 dimensions = new Vector3 ( areaLightData . size . x * 0.5f + radius , areaLightData . size . y * 0.5f + radius , radius ) ;
573
+
574
+ if ( ! areaLightData . twoSided )
575
+ {
576
+ centerVS -= zAxisVS * radius * 0.5f ;
577
+ dimensions . z *= 0.5f ;
578
+ }
579
+
580
+ bound . center = centerVS ;
581
+ bound . boxAxisX = dimensions . x * xAxisVS ;
582
+ bound . boxAxisY = dimensions . y * yAxisVS ;
583
+ bound . boxAxisZ = dimensions . z * zAxisVS ;
584
+ bound . scaleXY . Set ( 1.0f , 1.0f ) ;
585
+ bound . radius = dimensions . magnitude ;
586
+
587
+ lightShapeData . lightPos = centerVS ;
588
+ lightShapeData . lightAxisX = xAxisVS ;
589
+ lightShapeData . lightAxisY = yAxisVS ;
590
+ lightShapeData . lightAxisZ = zAxisVS ;
591
+ lightShapeData . boxInnerDist = dimensions ;
592
+ lightShapeData . boxInvRange . Set ( 1e5f , 1e5f , 1e5f ) ;
593
+ }
594
+ else if ( areaLightData . lightType == GPULightType . Line )
595
+ {
596
+ Vector3 centerVS = worldToView . MultiplyPoint ( areaLightData . positionWS ) ;
597
+ Vector3 xAxisVS = worldToView . MultiplyVector ( areaLightData . right ) ;
598
+ Vector3 yAxisVS = worldToView . MultiplyVector ( areaLightData . up ) ;
599
+ Vector3 zAxisVS = worldToView . MultiplyVector ( areaLightData . forward ) ;
600
+ float radius = 1.0f / Mathf . Sqrt ( areaLightData . invSqrAttenuationRadius ) ;
601
+
602
+ Vector3 dimensions = new Vector3 ( areaLightData . size . x * 0.5f + radius , radius , radius ) ;
603
+
604
+ bound . center = centerVS ;
605
+ bound . boxAxisX = dimensions . x * xAxisVS ;
606
+ bound . boxAxisY = dimensions . y * yAxisVS ;
607
+ bound . boxAxisZ = dimensions . z * zAxisVS ;
608
+ bound . scaleXY . Set ( 1.0f , 1.0f ) ;
609
+ bound . radius = dimensions . magnitude ;
610
+
611
+ lightShapeData . lightPos = centerVS ;
612
+ lightShapeData . lightAxisX = xAxisVS ;
613
+ lightShapeData . lightAxisY = yAxisVS ;
614
+ lightShapeData . lightAxisZ = zAxisVS ;
615
+ lightShapeData . boxInnerDist = new Vector3 ( areaLightData . size . x * 0.5f , 0.01f , 0.01f ) ;
616
+ lightShapeData . boxInvRange . Set ( 1.0f / radius , 1.0f / radius , 1.0f / radius ) ;
617
+ }
618
+ else
619
+ {
620
+ Debug . Assert ( false ) ;
621
+ }
622
+
623
+ int i = LightDefinitions . AREA_LIGHT , j = LightDefinitions . BOX_LIGHT ;
624
+ int index = numEntries2nd [ i , j ] + offsets [ i , j ] ; ++ numEntries2nd [ i , j ] ;
625
+
626
+ m_boundData [ index ] = bound ;
627
+ m_lightShapeData [ index ] = lightShapeData ;
628
+ }
629
+
550
630
// Sanity check
551
631
for ( var m = 0 ; m < numModels ; m ++ )
552
632
{
@@ -556,7 +636,7 @@ public void PrepareLightsForGPU(CullResults cullResults, Camera camera, HDRender
556
636
}
557
637
}
558
638
559
- m_lightCount = lightList . punctualLights . Count + lightList . envLights . Count ;
639
+ m_lightCount = lightList . punctualLights . Count + lightList . envLights . Count + lightList . areaLights . Count ;
560
640
s_ConvexBoundsBuffer . SetData ( m_boundData ) ; // TODO: check with Vlad what is happening here, do we copy 1024 element always ? Could we setup the size we want to copy ?
561
641
s_LightShapeDataBuffer . SetData ( m_lightShapeData ) ;
562
642
}
@@ -757,7 +837,7 @@ public void RenderDeferredLighting(Camera camera, RenderLoop renderLoop, RenderT
757
837
758
838
m_DebugViewTilesMaterial . SetMatrix ( "_InvViewProjMatrix" , invViewProj ) ;
759
839
m_DebugViewTilesMaterial . SetVector ( "_ScreenSize" , screenSize ) ;
760
- m_DebugViewTilesMaterial . SetInt ( "_ViewTilesFlags" , ( int ) debugViewTilesFlags ) ;
840
+ m_DebugViewTilesMaterial . SetInt ( "_ViewTilesFlags" , debugViewTilesFlags ) ;
761
841
m_DebugViewTilesMaterial . EnableKeyword ( bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST" ) ;
762
842
m_DebugViewTilesMaterial . DisableKeyword ( ! bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST" ) ;
763
843
0 commit comments