@@ -82,11 +82,11 @@ public struct LightVolumeData
82
82
83
83
public class LightLoop : BaseLightLoop
84
84
{
85
- public const int k_MaxDirectionalLightsOnSCreen = 10 ;
86
- public const int k_MaxPunctualLightsOnSCreen = 512 ;
85
+ public const int k_MaxDirectionalLightsOnScreen = 10 ;
86
+ public const int k_MaxPunctualLightsOnScreen = 512 ;
87
87
public const int k_MaxAreaLightsOnSCreen = 128 ;
88
- public const int k_MaxLightsOnSCreen = k_MaxDirectionalLightsOnSCreen + k_MaxPunctualLightsOnSCreen + k_MaxAreaLightsOnSCreen ;
89
- public const int k_MaxEnvLightsOnSCreen = 64 ;
88
+ public const int k_MaxLightsOnScreen = k_MaxDirectionalLightsOnScreen + k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnSCreen ;
89
+ public const int k_MaxEnvLightsOnScreen = 64 ;
90
90
public const int k_MaxShadowOnScreen = 16 ;
91
91
public const int k_MaxCascadeCount = 4 ; //Should be not less than m_Settings.directionalLightCascadeCount;
92
92
@@ -214,9 +214,9 @@ public override void Build(TextureSettings textureSettings)
214
214
m_lightList = new LightList ( ) ;
215
215
m_lightList . Allocate ( ) ;
216
216
217
- s_DirectionalLightDatas = new ComputeBuffer ( k_MaxDirectionalLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( DirectionalLightData ) ) ) ;
218
- s_LightDatas = new ComputeBuffer ( k_MaxPunctualLightsOnSCreen + k_MaxAreaLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightData ) ) ) ;
219
- s_EnvLightDatas = new ComputeBuffer ( k_MaxEnvLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( EnvLightData ) ) ) ;
217
+ s_DirectionalLightDatas = new ComputeBuffer ( k_MaxDirectionalLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( DirectionalLightData ) ) ) ;
218
+ s_LightDatas = new ComputeBuffer ( k_MaxPunctualLightsOnScreen + k_MaxAreaLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightData ) ) ) ;
219
+ s_EnvLightDatas = new ComputeBuffer ( k_MaxEnvLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( EnvLightData ) ) ) ;
220
220
s_shadowDatas = new ComputeBuffer ( k_MaxCascadeCount + k_MaxShadowOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( ShadowData ) ) ) ;
221
221
222
222
m_CookieTexArray = new TextureCache2D ( ) ;
@@ -233,9 +233,9 @@ public override void Build(TextureSettings textureSettings)
233
233
234
234
s_GenAABBKernel = buildScreenAABBShader . FindKernel ( "ScreenBoundsAABB" ) ;
235
235
s_GenListPerTileKernel = buildPerTileLightListShader . FindKernel ( enableBigTilePrepass ? "TileLightListGen_SrcBigTile" : "TileLightListGen" ) ;
236
- s_AABBBoundsBuffer = new ComputeBuffer ( 2 * k_MaxLightsOnSCreen , 3 * sizeof ( float ) ) ;
237
- s_ConvexBoundsBuffer = new ComputeBuffer ( k_MaxLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( SFiniteLightBound ) ) ) ;
238
- s_LightVolumeDataBuffer = new ComputeBuffer ( k_MaxLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightVolumeData ) ) ) ;
236
+ s_AABBBoundsBuffer = new ComputeBuffer ( 2 * k_MaxLightsOnScreen , 3 * sizeof ( float ) ) ;
237
+ s_ConvexBoundsBuffer = new ComputeBuffer ( k_MaxLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( SFiniteLightBound ) ) ) ;
238
+ s_LightVolumeDataBuffer = new ComputeBuffer ( k_MaxLightsOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( LightVolumeData ) ) ) ;
239
239
240
240
buildScreenAABBShader . SetBuffer ( s_GenAABBKernel , "g_data" , s_ConvexBoundsBuffer ) ;
241
241
buildPerTileLightListShader . SetBuffer ( s_GenListPerTileKernel , "g_vBoundsBuffer" , s_AABBBoundsBuffer ) ;
@@ -285,11 +285,20 @@ public override void Build(TextureSettings textureSettings)
285
285
m_DebugViewTilesMaterial = Utilities . CreateEngineMaterial ( "Hidden/HDRenderLoop/DebugViewTiles" ) ;
286
286
287
287
m_SingleDeferredMaterial = Utilities . CreateEngineMaterial ( "Hidden/HDRenderLoop/Deferred" ) ;
288
- m_SingleDeferredMaterial . EnableKeyword ( "LIGHTLOOP_SINGLE_PASS" ) ;
288
+ m_SingleDeferredMaterial . EnableKeyword ( "LIGHTLOOP_SINGLE_PASS" ) ;
289
+
290
+ #if UNITY_EDITOR
291
+ UnityEditor . SceneView . onSceneGUIDelegate -= OnSceneGUI ;
292
+ UnityEditor . SceneView . onSceneGUIDelegate += OnSceneGUI ;
293
+ #endif
289
294
}
290
295
291
296
public override void Cleanup ( )
292
- {
297
+ {
298
+ #if UNITY_EDITOR
299
+ UnityEditor . SceneView . onSceneGUIDelegate -= OnSceneGUI ;
300
+ #endif
301
+
293
302
Utilities . SafeRelease ( s_DirectionalLightDatas ) ;
294
303
Utilities . SafeRelease ( s_LightDatas ) ;
295
304
Utilities . SafeRelease ( s_EnvLightDatas ) ;
@@ -827,7 +836,7 @@ public override void PrepareLightsForGPU(CullResults cullResults, Camera camera,
827
836
int punctualLightcount = 0 ;
828
837
int areaLightCount = 0 ;
829
838
830
- var sortKeys = new uint [ Math . Min ( cullResults . visibleLights . Length , k_MaxLightsOnSCreen ) ] ;
839
+ var sortKeys = new uint [ Math . Min ( cullResults . visibleLights . Length , k_MaxLightsOnScreen ) ] ;
831
840
int sortCount = 0 ;
832
841
833
842
for ( int lightIndex = 0 , numLights = cullResults . visibleLights . Length ; lightIndex < numLights ; ++ lightIndex )
@@ -853,7 +862,7 @@ public override void PrepareLightsForGPU(CullResults cullResults, Camera camera,
853
862
switch ( light . lightType )
854
863
{
855
864
case LightType . Point :
856
- if ( punctualLightcount >= k_MaxPunctualLightsOnSCreen )
865
+ if ( punctualLightcount >= k_MaxPunctualLightsOnScreen )
857
866
continue ;
858
867
lightCategory = LightCategory . Punctual ;
859
868
gpuLightType = GPULightType . Point ;
@@ -862,7 +871,7 @@ public override void PrepareLightsForGPU(CullResults cullResults, Camera camera,
862
871
break ;
863
872
864
873
case LightType . Spot :
865
- if ( punctualLightcount >= k_MaxPunctualLightsOnSCreen )
874
+ if ( punctualLightcount >= k_MaxPunctualLightsOnScreen )
866
875
continue ;
867
876
lightCategory = LightCategory . Punctual ;
868
877
gpuLightType = GPULightType . Spot ;
@@ -871,7 +880,7 @@ public override void PrepareLightsForGPU(CullResults cullResults, Camera camera,
871
880
break ;
872
881
873
882
case LightType . Directional :
874
- if ( directionalLightcount >= k_MaxDirectionalLightsOnSCreen )
883
+ if ( directionalLightcount >= k_MaxDirectionalLightsOnScreen )
875
884
continue ;
876
885
lightCategory = LightCategory . Punctual ;
877
886
gpuLightType = GPULightType . Directional ;
@@ -967,14 +976,14 @@ public override void PrepareLightsForGPU(CullResults cullResults, Camera camera,
967
976
// Redo everything but this time with envLights
968
977
int envLightCount = 0 ;
969
978
970
- sortKeys = new uint [ Math . Min ( cullResults . visibleReflectionProbes . Length , k_MaxEnvLightsOnSCreen ) ] ;
979
+ sortKeys = new uint [ Math . Min ( cullResults . visibleReflectionProbes . Length , k_MaxEnvLightsOnScreen ) ] ;
971
980
sortCount = 0 ;
972
981
973
982
for ( int probeIndex = 0 , numProbes = cullResults . visibleReflectionProbes . Length ; probeIndex < numProbes ; probeIndex ++ )
974
983
{
975
984
var probe = cullResults . visibleReflectionProbes [ probeIndex ] ;
976
985
977
- if ( envLightCount >= k_MaxEnvLightsOnSCreen )
986
+ if ( envLightCount >= k_MaxEnvLightsOnScreen )
978
987
continue ;
979
988
980
989
// TODO: Support LightVolumeType.Sphere, currently in UI there is no way to specify a sphere influence volume
@@ -1182,15 +1191,32 @@ public override void PushGlobalParams(Camera camera, RenderLoop loop)
1182
1191
1183
1192
loop . ExecuteCommandBuffer ( cmd ) ;
1184
1193
cmd . Dispose ( ) ;
1185
- }
1186
-
1194
+ }
1195
+
1196
+ #if UNITY_EDITOR
1197
+ private Vector2 m_mousePosition = Vector2 . zero ;
1198
+ private void OnSceneGUI ( UnityEditor . SceneView sceneview )
1199
+ {
1200
+ m_mousePosition = Event . current . mousePosition ;
1201
+ }
1202
+ #endif
1203
+
1187
1204
public override void RenderDeferredLighting ( Camera camera , RenderLoop renderLoop , RenderTargetIdentifier cameraColorBufferRT )
1188
1205
{
1189
1206
var bUseClusteredForDeferred = ! usingFptl ;
1190
1207
1191
1208
var invViewProj = Utilities . GetViewProjectionMatrix ( camera ) . inverse ;
1192
- var screenSize = Utilities . ComputeScreenSize ( camera ) ;
1193
-
1209
+ var screenSize = Utilities . ComputeScreenSize ( camera ) ;
1210
+
1211
+ Vector2 mousePixelCoord = Input . mousePosition ;
1212
+ #if UNITY_EDITOR
1213
+ if ( ! UnityEditor . EditorApplication . isPlayingOrWillChangePlaymode )
1214
+ {
1215
+ mousePixelCoord = m_mousePosition ;
1216
+ mousePixelCoord . y = ( screenSize . y - 1.0f ) - mousePixelCoord . y ;
1217
+ }
1218
+ #endif
1219
+
1194
1220
m_DeferredDirectMaterial . SetMatrix ( "_InvViewProjMatrix" , invViewProj ) ;
1195
1221
m_DeferredDirectMaterial . SetVector ( "_ScreenSize" , screenSize ) ;
1196
1222
m_DeferredDirectMaterial . SetInt ( "_SrcBlend" , ( int ) UnityEngine . Rendering . BlendMode . One ) ;
@@ -1215,6 +1241,7 @@ public override void RenderDeferredLighting(Camera camera, RenderLoop renderLoop
1215
1241
m_DebugViewTilesMaterial . SetMatrix ( "_InvViewProjMatrix" , invViewProj ) ;
1216
1242
m_DebugViewTilesMaterial . SetVector ( "_ScreenSize" , screenSize ) ;
1217
1243
m_DebugViewTilesMaterial . SetInt ( "_ViewTilesFlags" , debugViewTilesFlags ) ;
1244
+ m_DebugViewTilesMaterial . SetVector ( "_MousePixelCoord" , mousePixelCoord ) ;
1218
1245
m_DebugViewTilesMaterial . EnableKeyword ( bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST" ) ;
1219
1246
m_DebugViewTilesMaterial . DisableKeyword ( ! bUseClusteredForDeferred ? "USE_CLUSTERED_LIGHTLIST" : "USE_FPTL_LIGHTLIST" ) ;
1220
1247
0 commit comments