Пример #1
0
        /// <inheritdoc/>
        public override void Update(GameTime time)
        {
            base.Update(time);
            if (ManageShadows)
            {
                InternalActiveShadowMaps.Clear();
                InternalActiveShadowMapTextures.Clear();

                foreach (var light in Lights)
                {
                    // create new shadow maps
                    if (light.Value.Light.Shadow != null)
                    {
                        CreateShadowMap(light.Value);
                    }

                    // TODO: handle shadow maps that does no require to be updated like static shadow maps.
                    // update shadow maps info
                    if (light.Value.Light.Enabled && light.Value.Light.Shadow != null && light.Value.Light.Shadow.Enabled && light.Value.ShadowMap.Update)
                    {
                        UpdateEntityLightShadow(light.Value);
                        InternalActiveShadowMaps.Add(light.Value.ShadowMap);
                        InternalActiveShadowMapTextures.Add(light.Value.ShadowMap.Texture);
                    }
                }
            }
        }
        /// <inheritdoc/>
        public override void Update(GameTime time)
        {
            base.Update(time);
            if (ManageShadows)
            {
                // clear the virtual allocation
                foreach (var texture in shadowMapDefaultTextures)
                {
                    texture.GuillotinePacker.Clear(texture.ShadowMapDepthTexture.ViewWidth, texture.ShadowMapDepthTexture.ViewHeight);
                    texturesDefault[texture] = texture.ShadowMapDepthTexture.ViewWidth * texture.ShadowMapDepthTexture.ViewHeight;
                }
                foreach (var texture in shadowMapVsmTextures)
                {
                    texture.GuillotinePacker.Clear(texture.ShadowMapDepthTexture.ViewWidth, texture.ShadowMapDepthTexture.ViewHeight);
                    texturesVsm[texture] = texture.ShadowMapDepthTexture.ViewWidth * texture.ShadowMapDepthTexture.ViewHeight;
                }

                // sort the textures based on the available size.
                shadowMapDefaultTextures.Sort(ShadowMapTextureComparerDefault);
                shadowMapVsmTextures.Sort(ShadowMapTextureComparerVsm);

                // create shadow maps for new lights
                foreach (var light in Lights)
                {
                    // create new shadow maps
                    if (light.Value.Light.Shadow != null && light.Value.ShadowMap == null)
                    {
                        CreateShadowMap(light.Value);
                    }

                    // remove shadow maps
                    if ((light.Value.Light.Shadow == null || !light.Value.Light.Shadow.Enabled) && light.Value.ShadowMap != null)
                    {
                        RemoveShadowMap(light.Value);
                    }
                }

                FillActiveLightShadowMaps();

                InternalActiveShadowMaps.Clear();
                InternalActiveShadowMapTextures.Clear();

                foreach (var light in activeLightShadowMaps)
                {
                    var shadowMap = (LightShadowMap)light.Light.Shadow;

                    if (shadowMap.FilterType == LightShadowMapFilterType.Variance)
                    {
                        // if it was inserted, sort the shadow maps
                        if (ChooseShadowMapTexture(light, shadowMapVsmTextures, texturesVsm))
                        {
                            shadowMapVsmTextures.Sort(ShadowMapTextureComparerVsm);
                            InternalActiveShadowMaps.Add(light.ShadowMap);
                            InternalActiveShadowMapTextures.Add(light.ShadowMap.Texture);
                        }
                    }
                    else
                    {
                        // if it was inserted, sort the shadow maps
                        if (ChooseShadowMapTexture(light, shadowMapDefaultTextures, texturesDefault))
                        {
                            shadowMapDefaultTextures.Sort(ShadowMapTextureComparerDefault);
                            InternalActiveShadowMaps.Add(light.ShadowMap);
                            InternalActiveShadowMapTextures.Add(light.ShadowMap.Texture);
                        }
                    }
                }

                // update shadow map infos
                foreach (var light in activeLightShadowMaps)
                {
                    UpdateEntityLightShadow(light);
                }

                activeLightShadowMaps.Clear();

                // clear the virtual allocation again
                foreach (var texture in shadowMapDefaultTextures)
                {
                    texture.GuillotinePacker.Clear(texture.ShadowMapDepthTexture.ViewWidth, texture.ShadowMapDepthTexture.ViewHeight);
                }
                foreach (var texture in shadowMapVsmTextures)
                {
                    texture.GuillotinePacker.Clear(texture.ShadowMapDepthTexture.ViewWidth, texture.ShadowMapDepthTexture.ViewHeight);
                }
            }
        }