Beispiel #1
0
        public void Render(List <ViewEntity> entities, float time, ITransformation camera)
        {
            UpdateInstancing(entities);

            var arrTrans = new Dictionary <Enums.EntityType, Matrix4x4[]>();

            foreach (var transform in _transforms)
            {
                arrTrans.Add(transform.Key, transform.Value.ToArray());
            }

            _renderInstanceGroup.UpdateGeometry(arrTrans);

            _deferred.Draw(_renderState, camera, _instanceCounts, _textures, _normalMaps, _heightMaps, _intensities, _disableBackFaceCulling, time);

            _directShadowMap.Draw(_renderState, camera, _instanceCounts, _deferred.Depth, _lights[0].Direction, _disableBackFaceCulling, _deferred.Position, _deferred.Normal);
            _blurredShadowMap.Draw(_directShadowMap.Output);

            _environmentMap.CreateMap(entities[2], _renderState, 0, arrTrans, _instanceCounts, _textures, _normalMaps, _heightMaps, _intensities, _disableBackFaceCulling, _lights, camera, time);
            _environmentMap.Draw(_renderState, _deferred.Depth);
            _addEnvMap.Draw(_deferred.Color, _environmentMap.Output, 0.5f);

            _lighting.Draw(camera, _addEnvMap.Output, _deferred.Normal, _deferred.Position, _blurredShadowMap.Output, _deferred.IntensityMap, _lights);

            //_addProjectileColor.Draw(_deferred.ProjectileDepth, _deferred.Depth, _deferred.ProjectileColor, _lighting.Output, _deferred.ProjectileColor, _lighting.Output, _deferred.ProjectileColor, _lighting.Output, _deferred.ProjectileColor, _lighting.Output);

            _sphereCut.Draw(camera, _lighting.Output, _deferred.Depth);

            _skybox.Draw(camera);
            _addSkybox.Draw(_skybox.Output, _sphereCut.Output);

            if (Bloom)
            {
                _bloom.Draw(_addSkybox.Output);
                _ssaoWithBlur.Draw(_deferred.Depth, _bloom.Output);
            }
            else
            {
                _ssaoWithBlur.Draw(_deferred.Depth, _addSkybox.Output);
            }


            TextureDrawer.Draw(_ssaoWithBlur.Output);
        }
Beispiel #2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.SetRenderTarget(_renderTarget1);
            GraphicsDevice.Clear(Color.Transparent);
            //Draw all game object to render target here
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive);
            WarpingGrid.Draw(spriteBatch);
            ParticleManager.Draw(spriteBatch);
            EntityManager.Draw(spriteBatch);
            spriteBatch.End();
            bloom.Draw(_renderTarget1, _renderTarget2);
            GraphicsDevice.SetRenderTarget(null);
            //Draw post bloom here
            spriteBatch.Begin(0, BlendState.AlphaBlend);
            spriteBatch.Draw(_renderTarget2, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White); // draw all glowing components
            spriteBatch.End();
            //Draw all UI Component here
            spriteBatch.Begin();
            spriteBatch.DrawString(Art.Font, "Lives: " + PlayerStatus.Lives, new Vector2(5), Color.White);
            DrawRightAlignedString("Score: " + PlayerStatus.Score, 5);
            DrawRightAlignedString("Multiplier: " + PlayerStatus.Multiplier, 35);
            spriteBatch.Draw(Art.Pointer, Input.MousePosition, Color.White);
            if (GameManager.IsPausedWhenGameOver)
            {
                var text = "Game Over\n" +
                           "Your Score: " + PlayerStatus.Score + "\n" +
                           "High Score: " + PlayerStatus.HighScore + "\n" +
                           $"Restart in {GameManager.PauseFrame / 60 + 1:D1}";

                var textSize = Art.Font.MeasureString(text);
                spriteBatch.DrawString(Art.Font, text, ScreenSize / 2 - textSize / 2, Color.White);
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }
Beispiel #3
0
        private void Draw(GraphicsDevice graphics, DwarfTime time)
        {
            if (DwarfGame.SpriteBatch.IsDisposed)
            {
                return;
            }

            if (Tiles.IsDisposed)
            {
                CreateAssets();
            }

            Bloom.BeginDraw();
            try
            {
                graphics.Clear(Color.SkyBlue);
                DwarfGame.SafeSpriteBatchBegin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, Drawer2D.PointMagLinearMin,
                                               DepthStencilState.Default, RasterizerState.CullNone, null, Matrix.Identity);


                Rectangle screenRect = graphics.Viewport.Bounds;

                int maxX = screenRect.Width / TileSize + 2;
                int maxY = screenRect.Width / TileSize;


                float t = (float)time.TotalRealTime.TotalSeconds;

                float offsetX = t * 2.0f;
                float offsetY = 0.0f;

                float st = (float)Math.Abs(Math.Sin(t));

                float lava     = LavaHeight;
                int   backSize = 2;

                for (int ix = 0; ix < maxX * backSize; ix++)
                {
                    float x = ix + (int)(offsetX * 0.6f);

                    float height = Noise.Noise(x * HeightScale * 3, 0, 100) * 0.5f + 0.6f;
                    for (int iy = 0; iy < maxY * backSize; iy++)
                    {
                        float y           = iy + (int)offsetY;
                        float normalizedY = (1.0f) - (float)y / (float)(maxY * backSize);

                        if (normalizedY < height)
                        {
                            float tileX = ix * (TileSize / backSize) - ((offsetX * 0.6f) * (TileSize / backSize)) % (TileSize / backSize);
                            float tileY = iy * (TileSize / backSize);

                            Drawer2D.FillRect(DwarfGame.SpriteBatch, new Rectangle((int)tileX, (int)tileY, TileSize / backSize, TileSize / backSize),
                                              new Color((int)(Color.SkyBlue.R * normalizedY * 0.8f), (int)(Color.SkyBlue.G * normalizedY * 0.8f),
                                                        (int)(Color.SkyBlue.B * normalizedY)));
                        }
                    }
                }


                for (int ix = 0; ix < maxX; ix++)
                {
                    float x      = ix + (int)offsetX;
                    float height = Noise.Noise(x * HeightScale, 0, 0) * 0.8f + MinHeight;
                    for (int iy = 0; iy < maxY; iy++)
                    {
                        float y           = iy + (int)offsetY;
                        float normalizedY = (1.0f) - (float)y / (float)maxY;

                        if (Math.Abs(normalizedY - height) < 0.01f)
                        {
                            Color tint = new Color(normalizedY, normalizedY, normalizedY);

                            RenderTile(Grass, DwarfGame.SpriteBatch, ix, iy, offsetX, t, tint);
                        }
                        else if (normalizedY > height - 0.1f && normalizedY < height)
                        {
                            Color tint = new Color((float)Math.Pow(normalizedY, 1.5f), (float)Math.Pow(normalizedY, 1.6f),
                                                   normalizedY);

                            RenderTile(Soil, DwarfGame.SpriteBatch, ix, iy, offsetX, t, tint);
                        }
                        else if (normalizedY < height)
                        {
                            float caviness = Noise.Noise(x * CaveScale, y * CaveScale, 0);

                            if (caviness < CaveThreshold)
                            {
                                TerrainElement?oreFound = null;

                                int i = 0;
                                foreach (TerrainElement ore in Ores)
                                {
                                    i++;
                                    float oreNess = Noise.Noise(x * ore.SpawnScale, y * ore.SpawnScale, i);

                                    if (oreNess > ore.SpawnThreshold)
                                    {
                                        oreFound = ore;
                                    }
                                }

                                Color tint = new Color((float)Math.Pow(normalizedY, 1.5f) * 0.5f,
                                                       (float)Math.Pow(normalizedY, 1.6f) * 0.5f, normalizedY * 0.5f);

                                if (oreFound == null)
                                {
                                    RenderTile(Substrate, DwarfGame.SpriteBatch, ix, iy, offsetX, t, tint);
                                }
                                else
                                {
                                    RenderTile(oreFound.Value, DwarfGame.SpriteBatch, ix, iy, offsetX, t, tint);
                                }
                            }
                            else
                            {
                                if (normalizedY < lava)
                                {
                                    float glowiness = Noise.Noise(x * CaveScale * 2, y * CaveScale * 2, t);
                                    RenderTile(Lava, DwarfGame.SpriteBatch, ix, iy, offsetX, t,
                                               new Color(0.5f * glowiness + 0.5f, 0.7f * glowiness + 0.3f * st, glowiness));
                                }
                                else
                                {
                                    RenderTile(Cave, DwarfGame.SpriteBatch, ix, iy, offsetX, t,
                                               new Color((float)Math.Pow(normalizedY, 1.5f) * (1.0f - caviness) * 0.8f,
                                                         (float)Math.Pow(normalizedY, 1.6f) * (1.0f - caviness) * 0.8f,
                                                         normalizedY * (1.0f - caviness)));
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                DwarfGame.SpriteBatch.End();
            }

            Bloom.Draw(time.ToRealTime());
        }
Beispiel #4
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.SetRenderTarget(renderTarget1); // bloom shader
            GraphicsDevice.Clear(Color.TransparentBlack);
            // particle effects
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, camera.transform);

            Systems.ParticleSystem.Draw(spriteBatch);
            spriteBatch.End();
            bloom.Draw(renderTarget1, renderTarget2);

            GraphicsDevice.SetRenderTarget(null);



            // Background
            GraphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin();
            world.DrawBackground(spriteBatch);
            spriteBatch.End();

            // player space
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, camera.transform);
            GUI.GUI.Draw(spriteBatch);
            world.Draw(spriteBatch);
            player.Draw(spriteBatch);

            Systems.ProjectileManager.Draw(spriteBatch);
            spriteBatch.End();


            // Draw bloomed layer over top:
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            spriteBatch.Draw(renderTarget2, new Rectangle(0, 0, width, height), Color.White);
            spriteBatch.End();

            // Dev stuff
            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
            GUI.GUI.Draw(spriteBatch);
            GUI.GUI.DrawString("DEVELOPMENT BUILD", new Vector2(GUI.GUI.screenBounds.X + 20, GUI.GUI.screenBounds.Height - 20), 1, 1, Color.Gray);
            if (Utilities.Debug.showTextualDebug)
            {
                GUI.GUI.DrawString("Mouse Position: " + worldPosition.ToString(), new Vector2(10, 10), 1, 1, Color.White);
                GUI.GUI.DrawString("Cell Mouse Position: " + (worldPosition / 128).ToPoint(), new Vector2(10, 30), 1, 1, Color.White);
                GUI.GUI.DrawString("Cell Position: " +
                                   world.spaceStation.CellSpacePartition.PositionToCell(player.GetEntityPosition()) +
                                   " - " + player.GetCenterPartition().ToString(),
                                   new Vector2(10, 50), 1, 1, Color.White);
                try
                {
                    GUI.GUI.DrawString("Tile Position: " + world.spaceStation.CellSpacePartition.staticCells[world.spaceStation.CellSpacePartition.PositionToIndex(worldPosition)].
                                       GetEntityIndex(new Point((int)worldPosition.X, (int)worldPosition.Y)).ToString(), new Vector2(10, 70), 1, 1, Color.White);
                }
                catch (Exception ex)
                {
                }
                GUI.GUI.DrawString("Active Particles: " + Systems.ParticleSystem.currentParticles, new Vector2(10, 90), 1, 1, Color.White);
                GUI.GUI.DrawString(
                    "World Cell Position: " + world.dynamicCellSpacePartition.PositionToCell(player.GetEntityPosition()),
                    new Vector2(10, 110), 1, 1, Color.White);
            }

            // draw inventory gui & regular gui
            player.DrawInventory();

            debug.Draw();

            spriteBatch.End();


            base.Draw(gameTime);
        }
Beispiel #5
0
        public void Draw(GameTime gameTime)
        {
            // Start by render the bloomed elements into a render target
            if (GameConfig.EnableBloom)
            {
                _game.PerformanceManager.StartStopwatch(PerformanceStopwatchType.BloomDraw);

                // The next draw calls will be rendered in the first render target
                _game.GraphicsDevice.SetRenderTarget(_renderTarget1);
                _game.GraphicsDevice.Clear(Color.Transparent);

                DrawBloomedElements(gameTime);

                // Apply bloom effect on the first render target and store the
                // result into the second render target
                Bloom.Draw(_renderTarget1, _renderTarget2);

                // We want to render into the back buffer from now on
                _game.GraphicsDevice.SetRenderTarget(null);

                // Reset the viewport
                _game.ViewportAdapter.Reset();

                _game.PerformanceManager.StopStopwatch(PerformanceStopwatchType.BloomDraw);
            }

            _game.PerformanceManager.StartStopwatch(PerformanceStopwatchType.BackgroundDraw);
            Background?.Draw();
            _game.PerformanceManager.StopStopwatch(PerformanceStopwatchType.BackgroundDraw);

            BeginDrawViewportSpace();

            // Draw background sprites
            foreach (var sprite in BackgroundSprites)
            {
                sprite.Draw(_game.SpriteBatch);
            }

            foreach (var animator in _backgroundSpriterAnimators)
            {
                animator.Draw(_game.SpriteBatch);
            }

            _game.PerformanceManager.StartStopwatch(PerformanceStopwatchType.BackgroundParticleDraw);

            foreach (var particle in BackgroundParticles)
            {
                _game.SpriteBatch.Draw(particle);
            }

            _game.PerformanceManager.StopStopwatch(PerformanceStopwatchType.BackgroundParticleDraw);

            _game.SpriteBatch.End();

            BeginDrawCameraSpace();

            // Draw player
            Player?.CurrentAnimator.Draw(_game.SpriteBatch);

            _game.SpriteBatch.End();

            // Draw boss
            DrawBoss();

            BeginDrawCameraSpace();

            // Draw game sprites
            foreach (var sprite in GameSprites)
            {
                sprite.Draw(_game.SpriteBatch);
            }

            _game.PerformanceManager.StartStopwatch(PerformanceStopwatchType.GameParticleDraw);

            foreach (var particle in GameParticles)
            {
                _game.SpriteBatch.Draw(particle);
            }

            _game.PerformanceManager.StopStopwatch(PerformanceStopwatchType.GameParticleDraw);

            _game.SpriteBatch.End();

            if (GameConfig.EnableBloom)
            {
                _game.PerformanceManager.StartStopwatch(PerformanceStopwatchType.BloomRenderTargetDraw);

                // Draw bloom render target
                // Draw the second render target on top of everything
                BeginDrawViewportSpace();

                _game.SpriteBatch.Draw(_renderTarget2, new Rectangle(
                                           0, 0,
                                           GameConfig.VirtualResolution.X,
                                           GameConfig.VirtualResolution.Y
                                           ), Color.White);

                _game.SpriteBatch.End();

                _game.PerformanceManager.StopStopwatch(PerformanceStopwatchType.BloomRenderTargetDraw);
            }
            else
            {
                DrawBloomedElements(gameTime);
            }

            _game.PerformanceManager.StartStopwatch(PerformanceStopwatchType.UIDraw);

            BeginDrawViewportSpace();

            // Draw UI elements
            foreach (var sprite in UISprites)
            {
                sprite.Draw(_game.SpriteBatch);
            }

            foreach (var animator in _uiSpriterAnimators)
            {
                animator.Draw(_game.SpriteBatch);
            }

            // Draw strings
            foreach (var label in UILabels)
            {
                label.Draw(_game.SpriteBatch);
            }

            _game.SpriteBatch.End();

            _game.PerformanceManager.StopStopwatch(PerformanceStopwatchType.UIDraw);
        }
Beispiel #6
0
        protected override void Draw(GameTime gameTime)
        {
            var deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            _frameCounter.Update(deltaTime);
            var fps = $"FPS: {_frameCounter.AverageFramesPerSecond}";

            GraphicsDevice.SetRenderTarget(renderTarget1); // bloom shader
            GraphicsDevice.Clear(Color.TransparentBlack);
            // particle effects
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, camera.transform);

            ParticleSystem.Draw(spriteBatch);
            spriteBatch.End();
            bloom.Draw(renderTarget1, renderTarget2);

            GraphicsDevice.SetRenderTarget(null);



            // Background
            GraphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin();
            // world.DrawBackground(spriteBatch);
            spriteBatch.End();

            // player space
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null, null, camera.transform);
            GUI.GUI.Draw(spriteBatch);
            //world.Draw(spriteBatch);

            ProjectileManager.Draw(spriteBatch);

            if (Debug.ShowTextualDebug)
            {
                PhysicsWorld.Instance.DrawDebug();
            }
            spriteBatch.End();


            // Draw bloomed layer over top:
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
            spriteBatch.Draw(renderTarget2, new Rectangle(0, 0, width, height), Color.White);
            spriteBatch.End();

            // Dev stuff
            spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
            GUI.GUI.Draw(spriteBatch);
            GUI.GUI.DrawString("DEVELOPMENT BUILD", new Vector2(GUI.GUI.ScreenBounds.X + 20, GUI.GUI.ScreenBounds.Height - 20), 1, 1, Color.Gray);
            if (Debug.ShowTextualDebug)
            {
                GUI.GUI.DrawString("Mouse Position: " + worldPosition.ToString(), new Vector2(10, 10), 1, 1, Color.White);
                GUI.GUI.DrawString("Cell Mouse Position: " + (worldPosition / 128).ToPoint(), new Vector2(10, 30), 1, 1, Color.White);

                GUI.GUI.DrawString("Active Particles: " + ParticleSystem.currentParticles, new Vector2(10, 90), 1, 1, Color.White);
                GUI.GUI.DrawString($"Physics Partition: {PhysicsWorld.Instance.ColliderPartition.PositionToIndex(camera.center)}", new Vector2(10, 130), 1, 1, Color.White);
                GUI.GUI.DrawString($"{PhysicsWorld.Instance.ToString()}", new Vector2(10, 150), 1, 1, Color.White);
                GUI.GUI.DrawString($"Colliders: {PhysicsWorld.Instance.GetNumberOfActiveColliders()}", new Vector2(10, 170), 1, 1, Color.White);

                GUI.GUI.DrawBox(GUI.GUI.ScreenBounds.Width - 82, GUI.GUI.ScreenBounds.Y, 100, 28, Color.Black * .7f);
                GUI.GUI.DrawString(fps,
                                   new Vector2(
                                       GUI.GUI.ScreenBounds.Width - 80,
                                       GUI.GUI.ScreenBounds.Y + 10), 1, 1, Color.LimeGreen);

                Debug.Draw(spriteBatch);
            }

            // draw inventory gui & regular gui

            spriteBatch.End();


            base.Draw(gameTime);
        }