9
9
namespace Microsoft . MixedReality . Toolkit . Utilities
10
10
{
11
11
/// <summary>
12
- /// Utility component to animate and visualize a light that can be used with
12
+ /// Utility component to animate and visualize a light that can be used with
13
13
/// the "MixedRealityToolkit/Standard" shader "_ProximityLight" feature.
14
14
/// </summary>
15
15
[ ExecuteInEditMode ]
16
16
[ HelpURL ( "https://docs.microsoft.com/windows/mixed-reality/mrtk-unity/features/rendering/proximity-light" ) ]
17
17
[ AddComponentMenu ( "Scripts/MRTK/Core/ProximityLight" ) ]
18
18
public class ProximityLight : MonoBehaviour
19
19
{
20
- // Two proximity lights are supported at this time.
20
+ // Two proximity lights are supported at this time. Excess lights will
21
+ // be held in a queue and addded to the shader in a first-in, first-out
22
+ // manner.
21
23
private const int proximityLightCount = 2 ;
24
+ private const int proximityLightQueueSize = 6 ;
22
25
private const int proximityLightDataSize = 6 ;
23
- private static List < ProximityLight > activeProximityLights = new List < ProximityLight > ( proximityLightCount ) ;
26
+ private static List < ProximityLight > activeProximityLights = new List < ProximityLight > ( proximityLightQueueSize ) ;
24
27
private static Vector4 [ ] proximityLightData = new Vector4 [ proximityLightCount * proximityLightDataSize ] ;
25
28
private static int proximityLightDataID ;
26
29
private static int lastProximityLightUpdate = - 1 ;
@@ -213,11 +216,6 @@ private void OnDrawGizmosSelected()
213
216
214
217
private static void AddProximityLight ( ProximityLight light )
215
218
{
216
- if ( activeProximityLights . Count >= proximityLightCount )
217
- {
218
- Debug . LogWarningFormat ( "Max proximity light count ({0}) exceeded." , proximityLightCount ) ;
219
- }
220
-
221
219
activeProximityLights . Add ( light ) ;
222
220
}
223
221
@@ -243,13 +241,15 @@ private static void UpdateProximityLights(bool forceUpdate = false)
243
241
return ;
244
242
}
245
243
246
- for ( int i = 0 ; i < proximityLightCount ; ++ i )
244
+ int lightIndex , queueIndex ;
245
+ for ( lightIndex = queueIndex = 0 ; queueIndex < activeProximityLights . Count && lightIndex < proximityLightCount ; ++ queueIndex )
247
246
{
248
- ProximityLight light = ( i >= activeProximityLights . Count ) ? null : activeProximityLights [ i ] ;
249
- int dataIndex = i * proximityLightDataSize ;
247
+ ProximityLight light = activeProximityLights [ queueIndex ] ;
250
248
251
249
if ( light )
252
250
{
251
+ int dataIndex = lightIndex ++ * proximityLightDataSize ;
252
+
253
253
proximityLightData [ dataIndex ] = new Vector4 ( light . transform . position . x ,
254
254
light . transform . position . y ,
255
255
light . transform . position . z ,
@@ -267,10 +267,12 @@ private static void UpdateProximityLights(bool forceUpdate = false)
267
267
proximityLightData [ dataIndex + 4 ] = light . Settings . MiddleColor ;
268
268
proximityLightData [ dataIndex + 5 ] = light . Settings . OuterColor ;
269
269
}
270
- else
271
- {
272
- proximityLightData [ dataIndex ] = Vector4 . zero ;
273
- }
270
+ }
271
+
272
+ for ( ; lightIndex < proximityLightCount ; ++ lightIndex )
273
+ {
274
+ int dataIndex = lightIndex * proximityLightDataSize ;
275
+ proximityLightData [ dataIndex ] = Vector4 . zero ;
274
276
}
275
277
276
278
Shader . SetGlobalVectorArray ( proximityLightDataID , proximityLightData ) ;
0 commit comments