/// <summary>
        /// Creates the directional shadows managers
        /// </summary>
        private void CreateDirectionalShadowsCollectors()
        {
            if (_directionalLightsShadowMapsCollector == null)
            {
                _directionalLightsShadowMapsCollector = new ShadowmapsCollector(DirectionalLightsManager.ShadowMapSize.x, DirectionalLightsManager.ShadowMapSize.y);
            }

            if (_directionalLightsShadowDataCollector == null)
            {
                _directionalLightsShadowDataCollector = new DirectionalShadowDataCollector();
            }
        }
Пример #2
0
        /// <summary>
        /// Releases the directional shadows managers
        /// </summary>
        private void ReleaseDirectionalShadowsCollectors()
        {
            if (_directionalLightsShadowMapsCollector != null)
            {
                _directionalLightsShadowMapsCollector = null;
            }

            if (_directionalLightsShadowDataCollector != null)
            {
                _directionalLightsShadowDataCollector = null;
            }
        }
        /// <summary>
        /// Releases the directional lights render textures collectors
        /// </summary>
        private void ReleaseDirectionalRenderTexturesCollectors()
        {
            if (_directionalLightsShadowMapsCollector != null)
            {
                _directionalLightsShadowMapsCollector.Release();
                _directionalLightsShadowMapsCollector = null;
            }

            if (_directionalLightsShadowDataCollector != null)
            {
                _directionalLightsShadowDataCollector.Release();
                _directionalLightsShadowDataCollector = null;
            }

            if (_directionalLightsCookieMapsCollector != null)
            {
                _directionalLightsCookieMapsCollector.Release();
                _directionalLightsCookieMapsCollector = null;
            }
        }
        /// <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;
        }