/// <summary> /// Function called when the light is being disabled /// </summary> private void AuraLight_OnUninitialize(AuraLight auraLight, LightType typeBeforeUninitialize) { switch (typeBeforeUninitialize) { case LightType.Directional: { if (RegisteredDirectionalLightsList.Contains(auraLight)) { if (_directionalLightsShadowMapsCollector != null && _directionalLightsShadowMapsCollector.RemoveTexture(auraLight.shadowMapRenderTexture)) { _directionalLightsShadowDataCollector.RemoveTexture(auraLight.shadowDataRenderTexture); SetDirectionalShadowMapsId(); } if (_directionalLightsCookieMapsCollector != null && _directionalLightsCookieMapsCollector.RemoveTexture(auraLight.cookieMapRenderTexture)) { SetDirectionalCookieMapsId(); } RegisteredDirectionalLightsList.Remove(auraLight); } } break; case LightType.Spot: { if (RegisteredSpotLightsList.Contains(auraLight)) { if (_spotLightsShadowMapsCollector != null && _spotLightsShadowMapsCollector.RemoveTexture(auraLight.shadowMapRenderTexture)) { SetSpotShadowMapsId(); } if (_spotLightsCookieMapsCollector != null && _spotLightsCookieMapsCollector.RemoveTexture(auraLight.cookieMapRenderTexture)) { SetSpotCookieMapsId(); } RegisteredSpotLightsList.Remove(auraLight); if (OnUnregisterSpotLight != null) { OnUnregisterSpotLight(auraLight); } } } break; case LightType.Point: { if (RegisteredPointLightsList.Contains(auraLight)) { if (_pointLightsShadowMapsCollector != null && _pointLightsShadowMapsCollector.RemoveTexture(auraLight.shadowMapRenderTexture)) { SetPointShadowMapsId(); } if (_pointLightsCookieMapsCollector != null && _pointLightsCookieMapsCollector.RemoveTexture(auraLight.cookieMapRenderTexture)) { SetPointCookieMapsId(); } RegisteredPointLightsList.Remove(auraLight); if (OnUnregisterPointLight != null) { OnUnregisterPointLight(auraLight); } } } break; } auraLight.OnUninitialize -= AuraLight_OnUninitialize; }
/// <summary> /// Registers the Aura light to the global manager /// </summary> /// <param name="auraLight">The Aura Light to register</param> public void RegisterLight(AuraLight auraLight) { switch (auraLight.Type) { case LightType.Directional: { if (!RegisteredDirectionalLightsList.Contains(auraLight)) { RegisteredDirectionalLightsList.Add(auraLight); if (auraLight.CastsShadows) { if (_directionalLightsShadowMapsCollector == null) { _directionalLightsShadowMapsCollector = new ShadowmapsCollector(DirectionalLightsManager.ShadowMapSize.x, DirectionalLightsManager.ShadowMapSize.y); } _directionalLightsShadowMapsCollector.AddTexture(auraLight.shadowMapRenderTexture); SetDirectionalShadowMapsId(); if (_directionalLightsShadowDataCollector == null) { _directionalLightsShadowDataCollector = new DirectionalShadowDataCollector(); } _directionalLightsShadowDataCollector.AddTexture(auraLight.shadowDataRenderTexture); } if (auraLight.CastsCookie) { if (_directionalLightsCookieMapsCollector == null) { _directionalLightsCookieMapsCollector = new Texture2DArrayComposer(DirectionalLightsManager.cookieMapSize.x, DirectionalLightsManager.cookieMapSize.y, TextureFormat.R8, true); } _directionalLightsCookieMapsCollector.AddTexture(auraLight.cookieMapRenderTexture); SetDirectionalCookieMapsId(); } } } break; case LightType.Spot: { if (!RegisteredSpotLightsList.Contains(auraLight)) { RegisteredSpotLightsList.Add(auraLight); if (auraLight.CastsShadows) { if (_spotLightsShadowMapsCollector == null) { _spotLightsShadowMapsCollector = new ShadowmapsCollector(SpotLightsManager.shadowMapSize.x, SpotLightsManager.shadowMapSize.y); } _spotLightsShadowMapsCollector.AddTexture(auraLight.shadowMapRenderTexture); SetSpotShadowMapsId(); } if (auraLight.CastsCookie) { if (_spotLightsCookieMapsCollector == null) { _spotLightsCookieMapsCollector = new Texture2DArrayComposer(SpotLightsManager.cookieMapSize.x, SpotLightsManager.cookieMapSize.y, TextureFormat.R8, true); } _spotLightsCookieMapsCollector.AddTexture(auraLight.cookieMapRenderTexture); SetSpotCookieMapsId(); } if (OnRegisterSpotLight != null) { OnRegisterSpotLight(auraLight); } } } break; case LightType.Point: { if (!RegisteredPointLightsList.Contains(auraLight)) { RegisteredPointLightsList.Add(auraLight); if (auraLight.CastsShadows) { if (_pointLightsShadowMapsCollector == null) { _pointLightsShadowMapsCollector = new ShadowmapsCollector(PointLightsManager.shadowMapSize.x, PointLightsManager.shadowMapSize.y); } _pointLightsShadowMapsCollector.AddTexture(auraLight.shadowMapRenderTexture); SetPointShadowMapsId(); } if (auraLight.CastsCookie) { if (_pointLightsCookieMapsCollector == null) { _pointLightsCookieMapsCollector = new Texture2DArrayComposer(PointLightsManager.cookieMapSize.x, PointLightsManager.cookieMapSize.y, TextureFormat.R8, true); _pointLightsCookieMapsCollector.alwaysGenerateOnUpdate = true; } _pointLightsCookieMapsCollector.AddTexture(auraLight.cookieMapRenderTexture); SetPointCookieMapsId(); } if (OnRegisterPointLight != null) { OnRegisterPointLight(auraLight); } } } break; } auraLight.OnUninitialize += AuraLight_OnUninitialize; }