/// <summary> /// Draw components for shadow mapping /// </summary> /// <param name="context">Context</param> /// <param name="index">Culling index</param> /// <param name="components">Components to draw</param> protected void DrawShadowComponents(DrawContextShadows context, int index, IEnumerable <SceneObject> components) { var graphics = this.Game.Graphics; var objects = components.Where(c => IsVisible(c, index)).ToList(); if (objects.Any()) { objects.Sort((c1, c2) => Sort(c1, c2, index)); objects.ForEach((c) => DrawShadows(graphics, context, c)); } }
/// <summary> /// Draws the specified object shadows /// </summary> /// <param name="graphics">Graphics</param> /// <param name="context">Context</param> /// <param name="c">Scene object</param> private void DrawShadows(Graphics graphics, DrawContextShadows context, SceneObject c) { graphics.SetRasterizerShadowMapping(); graphics.SetDepthStencilShadowMapping(); if (c.AlphaEnabled) { graphics.SetBlendTransparent(); } else { graphics.SetBlendDefault(); } c.Get <IDrawable>().DrawShadows(context); }
/// <summary> /// Constructor /// </summary> /// <param name="game">Game</param> protected BaseSceneRenderer(Game game) { this.Game = game; // Directional shadow mapper this.ShadowMapperDirectional = new ShadowMapCascade(game, DirectionalShadowMapSize, MaxDirectionalCascadeShadowMaps, MaxDirectionalShadowMaps, CascadeShadowMapsDistances) { HighResolutionMap = true }; // Point shadow mapper this.ShadowMapperPoint = new ShadowMapPoint(game, CubicShadowMapSize, CubicShadowMapSize, MaxCubicShadows) { HighResolutionMap = true }; // Spot shadow mapper this.ShadowMapperSpot = new ShadowMapSpot(game, SpotShadowMapSize, SpotShadowMapSize, MaxSpotShadows) { HighResolutionMap = true }; this.cullManager = new SceneCullManager(); this.UpdateContext = new UpdateContext() { Name = "Primary", }; this.DrawContext = new DrawContext() { Name = "Primary", DrawerMode = DrawerModes.Forward, }; this.DrawShadowsContext = new DrawContextShadows() { Name = "Shadow mapping", }; }