コード例 #1
0
        /// <inheritdoc/>
        protected override void OnEntityRemoved(Entity entity, EntityLightShadow data)
        {
            if (ManageShadows && data.ShadowMap != null)
            {
                InternalShadowMaps.Remove(data.ShadowMap);

                List <ShadowMap> shadowMaps = null;
                if (!texturesDefault.TryGetValue(data.ShadowMap.Texture, out shadowMaps))
                {
                    texturesVsm.TryGetValue(data.ShadowMap.Texture, out shadowMaps);
                }

                if (shadowMaps == null)
                {
                    throw new Exception("Untracked shadow map texture");
                }

                shadowMaps.Remove(data.ShadowMap);

                // if no more shadow maps on this texture, delete it.
                if (shadowMaps.Count == 0)
                {
                    InternalShadowMapTextures.Remove(data.ShadowMap.Texture);
                    Utilities.Dispose(ref data.ShadowMap.Texture.ShadowMapDepthTexture);
                    Utilities.Dispose(ref data.ShadowMap.Texture.ShadowMapTargetTexture);
                    Utilities.Dispose(ref data.ShadowMap.Texture.IntermediateBlurTexture);

                    if (!texturesDefault.Remove(data.ShadowMap.Texture))
                    {
                        texturesVsm.Remove(data.ShadowMap.Texture);
                    }
                }
            }
            base.OnEntityRemoved(entity, data);
        }
コード例 #2
0
        protected override void CreateShadowMap(EntityLightShadow light)
        {
            var shadowMapDesc = light.Light.Shadow as LightShadowMap;


            // create the shadow map
            var shadowMap = new ShadowMap
            {
                LightDirection     = light.Light.Direction,
                LightPosition      = light.Entity.Transformation.Translation,
                ShadowMapSize      = shadowMapDesc.MaxSize,
                ShadowNearDistance = shadowMapDesc.NearDistance,
                ShadowFarDistance  = shadowMapDesc.FarDistance,
                CascadeCount       = light.Light.Type is LightDirectional ? shadowMapDesc.CascadeCount : 1, // cascades are only supported for directional shadow maps
                //Fov = light.Light.SpotFieldAngle,
                Filter = shadowMapDesc.FilterType,
                Layers = light.Light.Layers
            };

            // find or create the shadow map texture
            ShadowMapTexture chosenTexture = null;

            chosenTexture = AllocateOrChooseTexture(shadowMap, shadowMapDesc.FilterType == LightShadowMapFilterType.Variance ? texturesVsm : texturesDefault);

            shadowMap.Texture = chosenTexture;
            InternalShadowMaps.Add(shadowMap);
            light.ShadowMap = shadowMap;
        }
コード例 #3
0
        protected override void CreateShadowMap(EntityLightShadow light)
        {
            // create the shadow map
            var shadowMap = new ShadowMap
            {
                LightDirection     = light.Light.LightDirection,
                ShadowMapSize      = light.Light.ShadowMapMinSize,
                ShadowNearDistance = light.Light.ShadowNearDistance,
                ShadowFarDistance  = light.Light.ShadowFarDistance,
                CascadeCount       = light.Light.ShadowMapCascadeCount,
                Filter             = light.Light.ShadowMapFilterType,
                Layers             = light.Light.Layers
            };

            InternalShadowMaps.Add(shadowMap);
            light.ShadowMap = shadowMap;
        }
コード例 #4
0
 private void RemoveShadowMap(EntityLightShadow data)
 {
     InternalShadowMaps.Remove(data.ShadowMap);
     InternalActiveShadowMaps.Remove(data.ShadowMap);
     data.ShadowMap = null;
 }