Ejemplo n.º 1
0
        /// <summary>
        /// Downscales the source to 1/16th size, using hardware filtering
        /// </summary>
        /// <param name="source">The source to be downscaled</param>
        /// <param name="result">The RT in which to store the result</param>
        protected void GenerateDownscaleTargetHW(RenderTarget2D source, RenderTarget2D result)
        {
            GraphicsDevice.SetRenderTarget(0, downscale1RT);
            GraphicsDevice.Clear(Color.Orange);
            finalCombineEffect.SetTechnique("ScaleHW");
            finalCombineEffect.SetParameter("linearTex0", source.GetTexture());
            finalCombineEffect.RenderMultipass(fullScreenQuad.Draw);

            GraphicsDevice.SetRenderTarget(0, downscale2RT);
            GraphicsDevice.Clear(Color.Orange);
            finalCombineEffect.SetParameter("linearTex0", downscale1RT.GetTexture());
            finalCombineEffect.RenderMultipass(fullScreenQuad.Draw);

            GraphicsDevice.SetRenderTarget(0, downscale3RT);
            GraphicsDevice.Clear(Color.Orange);
            finalCombineEffect.SetParameter("linearTex0", downscale2RT.GetTexture());
            finalCombineEffect.RenderMultipass(fullScreenQuad.Draw);

            GraphicsDevice.SetRenderTarget(0, result);
            GraphicsDevice.Clear(Color.Orange);
            finalCombineEffect.SetParameter("linearTex0", downscale3RT.GetTexture());
            finalCombineEffect.RenderMultipass(fullScreenQuad.Draw);

            GraphicsDevice.SetRenderTarget(0, null);

            if (OutputMode == DeferredOutputMode.Downsample)
            {
                ((XNAGame)game).SpriteBatch.Begin(SpriteBlendMode.None);
                ((XNAGame)game).SpriteBatch.Draw(downscale1RT.GetTexture(), new Vector2(0, 0), Color.White);
                ((XNAGame)game).SpriteBatch.Draw(downscale2RT.GetTexture(), new Vector2(downscale1RT.Width, 0), Color.White);
                ((XNAGame)game).SpriteBatch.Draw(downscale3RT.GetTexture(), new Vector2(0, downscale1RT.Height), Color.White);
                ((XNAGame)game).SpriteBatch.Draw(result.GetTexture(), new Vector2(downscale3RT.Width, downscale1RT.Height), Color.White);
                ((XNAGame)game).SpriteBatch.End();
            }
        }
Ejemplo n.º 2
0
        public void Process(GraphicsDevice g, RenderTarget2D sceneTarget)
        {
            // extract brightest parts of the scene
            g.SetRenderTarget(0, rTarget1);
            Texture2D sceneTexture = sceneTarget.GetTexture();

            ppManager.RenderScreenQuad(e, luminosityExtractTechnique, sceneTexture);

            // blur the luminosity extract horizontally
            g.SetRenderTarget(0, rTarget2);
            e.Parameters["fWeights"].SetValue(horizontalBlurParameters.Weights);
            e.Parameters["vOffsets"].SetValue(horizontalBlurParameters.Offsets);
            ppManager.RenderScreenQuad(e, gaussianBlurTechnique, rTarget1.GetTexture());

            // blur the luminosity extract vertically
            g.SetRenderTarget(0, rTarget1);
            e.Parameters["fWeights"].SetValue(verticalBlurParameters.Weights);
            e.Parameters["vOffsets"].SetValue(verticalBlurParameters.Offsets);
            ppManager.RenderScreenQuad(e, gaussianBlurTechnique, rTarget2.GetTexture());

            // combine blurred luminosity extract with scene
            g.SetRenderTarget(0, null);
            g.Textures[1] = sceneTexture;
            ppManager.RenderScreenQuad(e, compositeTechnique, rTarget1.GetTexture());
        }
Ejemplo n.º 3
0
        //Draws the bloom: Extracts the brightest parts of screen --> Horizontal gaussian blur --> Vertical gaussian blur --> combine this with original screen
        public override void Draw(GameTime gameTime)
        {
            if (!SurfaceTower.App.Instance.ApplicationActivated)
            {
                return;
            }

            //Create a texture from the screen
            device.ResolveBackBuffer(resolveTarget);

            // Pass 1: Extract only the brightest parts of resolveTarget onto rendertarget1
            extractEffect.Parameters["BloomThreshold"].SetValue(bloomThreshold);
            DrawToRenderTarget(resolveTarget, renderTarget1, extractEffect);

            // Pass 2: Draw from rendertarger1 to renderTarget2 applying a horizontal gaussian blur.
            SetupGaussBlur(1.0f / (float)renderTarget1.Width, 0);
            DrawToRenderTarget(renderTarget1.GetTexture(), renderTarget2, gaussBlurEffect);

            // Pass 3: Draw from renderTarget2 to rengerTarget1 applying a vertical gaussian blur.
            SetupGaussBlur(0, 1.0f / (float)renderTarget1.Height);
            DrawToRenderTarget(renderTarget2.GetTexture(), renderTarget1, gaussBlurEffect);

            // Pass 4: draw renderTarget1 contents and original scene combined as output, this gives the scene but bloomed
            device.SetRenderTarget(0, null);
            EffectParameterCollection parameters = combineEffect.Parameters;

            parameters["BloomIntensity"].SetValue(bloomIntensity);
            parameters["BaseIntensity"].SetValue(baseIntensity);
            parameters["BloomSaturation"].SetValue(bloomSaturation);
            parameters["BaseSaturation"].SetValue(baseSaturation);
            device.Textures[1] = resolveTarget;
            DrawToRenderTarget(renderTarget1.GetTexture(), null, combineEffect);
        }
Ejemplo n.º 4
0
        private void drawHDRDownsampled()
        {
            GraphicsDevice.SetRenderTarget(0, downsampleRT);

            GraphicsDevice.Clear(Color.TransparentBlack);

            downsampleShader.SetParameter("lightMap", lightRT.GetTexture());
            downsampleShader.SetParameter("diffuseMap", diffuseRT.GetTexture());
            downsampleShader.SetParameter("halfPixel", downsampleHalfPixel);
            downsampleShader.SetTechnique("Technique1");

            downsampleShader.RenderMultipass(fullScreenQuad.Draw);
            GraphicsDevice.SetRenderTarget(0, null);

            if (OutputMode == DeferredOutputMode.Downsample)
            {
                ((XNAGame)game).SpriteBatch.Begin(SpriteBlendMode.None);
                ((XNAGame)game).SpriteBatch.Draw(downsampleRT.GetTexture(), new Vector2(0, 0), Color.White);
                ((XNAGame)game).SpriteBatch.End();
                return;
            }

            GraphicsDevice.SetRenderTarget(0, downsampleBlurYRT);
            blurShader.SetParameter("blurMap", downsampleRT.GetTexture());
            blurShader.SetParameter("BlurOffset", new Vector2(downsampleHalfPixel.X, 0));
            blurShader.SetParameter("halfPixel", downsampleHalfPixel);
            blurShader.SetTechnique("GaussionBlur");

            blurShader.RenderMultipass(fullScreenQuad.Draw);

            GraphicsDevice.SetRenderTarget(0, null);

            if (OutputMode == DeferredOutputMode.DownsampleBlurX)
            {
                ((XNAGame)game).SpriteBatch.Begin(SpriteBlendMode.None);
                ((XNAGame)game).SpriteBatch.Draw(downsampleBlurYRT.GetTexture(), new Vector2(0, 0), Color.White);
                ((XNAGame)game).SpriteBatch.End();
                return;
            }

            GraphicsDevice.SetRenderTarget(0, downsampleRT);

            blurShader.SetParameter("blurMap", downsampleBlurYRT.GetTexture());
            blurShader.SetParameter("BlurOffset", new Vector2(0, downsampleHalfPixel.Y));
            blurShader.SetParameter("halfPixel", downsampleHalfPixel);
            blurShader.SetTechnique("GaussionBlur");

            blurShader.RenderMultipass(fullScreenQuad.Draw);

            GraphicsDevice.SetRenderTarget(0, null);

            if (OutputMode == DeferredOutputMode.DownsampleBlurY)
            {
                ((XNAGame)game).SpriteBatch.Begin(SpriteBlendMode.None);
                ((XNAGame)game).SpriteBatch.Draw(downsampleRT.GetTexture(), new Vector2(0, 0), Color.White);
                ((XNAGame)game).SpriteBatch.End();
                return;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// This is where it all happens. Grabs a scene that has already been rendered,
        /// and uses postprocess magic to add a glowing bloom effect over the top of it.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            DepthStencilBuffer oldBuffer = GraphicsDevice.DepthStencilBuffer;

            GraphicsDevice.DepthStencilBuffer = null;
            // Resolve the scene into a texture, so we can
            // use it as input data for the bloom processing.
            GraphicsDevice.ResolveBackBuffer(resolveTarget);

            // Pass 1: draw the scene into rendertarget 1, using a
            // shader that extracts only the brightest parts of the image.
            bloomExtractEffect.Parameters["BloomThreshold"].SetValue(
                Settings.BloomThreshold);

            DrawFullscreenQuad(resolveTarget, renderTarget1,
                               bloomExtractEffect,
                               IntermediateBuffer.PreBloom);

            // Pass 2: draw from rendertarget 1 into rendertarget 2,
            // using a shader to apply a horizontal gaussian blur filter.
            SetBlurEffectParameters(1.0f / (float)renderTarget1.Width, 0);

            DrawFullscreenQuad(renderTarget1.GetTexture(), renderTarget2,
                               gaussianBlurEffect,
                               IntermediateBuffer.BlurredHorizontally);

            // Pass 3: draw from rendertarget 2 back into rendertarget 1,
            // using a shader to apply a vertical gaussian blur filter.
            SetBlurEffectParameters(0, 1.0f / (float)renderTarget1.Height);

            DrawFullscreenQuad(renderTarget2.GetTexture(), renderTarget1,
                               gaussianBlurEffect,
                               IntermediateBuffer.BlurredBothWays);

            // Pass 4: draw both rendertarget 1 and the original scene
            // image back into the main backbuffer, using a shader that
            // combines them to produce the final bloomed result.
            GraphicsDevice.SetRenderTarget(0, null);

            EffectParameterCollection parameters = bloomCombineEffect.Parameters;

            parameters["BloomIntensity"].SetValue(Settings.BloomIntensity);
            parameters["BaseIntensity"].SetValue(Settings.BaseIntensity);
            parameters["BloomSaturation"].SetValue(Settings.BloomSaturation);
            parameters["BaseSaturation"].SetValue(Settings.BaseSaturation);

            GraphicsDevice.Textures[1] = resolveTarget;

            Viewport viewport = GraphicsDevice.Viewport;

            DrawFullscreenQuad(renderTarget1.GetTexture(),
                               viewport.Width, viewport.Height,
                               bloomCombineEffect,
                               IntermediateBuffer.FinalResult);

            GraphicsDevice.DepthStencilBuffer = oldBuffer;
        }
Ejemplo n.º 6
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)
        {
            graphics.GraphicsDevice.SetRenderTarget(0, buffer);
            GraphicsDevice.Clear(Color.Black);

            // render the levels, entity and any first-person player-related elements (ie. crosshair, weapon, etc.)
            if (level != null)
            {
                level.RenderLevel(player.position, player.view, player.projection, gameTime, graphics.GraphicsDevice);

                entitySystem.draw(player.view, player.projection);

                player.draw(spriteBatch);
            }

            // disable the render target for post processing
            graphics.GraphicsDevice.SetRenderTarget(0, null);

            // blur game screen if menu is open
            if (menu.active)
            {
                blur.Begin();
                spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState);
                foreach (EffectTechnique t in blur.Techniques)
                {
                    foreach (EffectPass p in t.Passes)
                    {
                        p.Begin();
                        spriteBatch.Draw(buffer.GetTexture(), Vector2.Zero, Color.White);
                        p.End();
                    }
                }
                spriteBatch.End();
                blur.End();
            }
            // otherwise apply other post-processing effects
            else
            {
                post.Begin();
                spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.SaveState);
                foreach (EffectTechnique t in post.Techniques)
                {
                    foreach (EffectPass p in t.Passes)
                    {
                        p.Begin();
                        spriteBatch.Draw(buffer.GetTexture(), Vector2.Zero, Color.White);
                        p.End();
                    }
                }
                spriteBatch.End();
                post.End();
            }

            screenManager.draw(spriteBatch, graphics.GraphicsDevice);

            base.Draw(gameTime);
        }
        private Texture2D GenerateShadingMap()
        {
            shadingMap = blackImage;

            for (int i = 0; i < NumberOfLights; i++)
            {
                RenderShadowMap(spotLights[i]);
                AddLight(spotLights[i]);
            }

            return(shadingTarget.GetTexture());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Uses the ParticlePhysics.fx shader to do physics calculations for velocity and position
        /// on the gpu.
        /// </summary>
        /// <param name="technique">the shader technique to apply</param>
        /// <param name="resultTarget">the rendertarget to copy the resulting data to</param>
        private void DoPhysicsPass(string technique, RenderTarget2D resultTarget)
        {
            //store old rendertarget
            RenderTarget2D     oldRT = graphics.GraphicsDevice.GetRenderTarget(0) as RenderTarget2D;
            DepthStencilBuffer oldDS = graphics.GraphicsDevice.DepthStencilBuffer;

            //set render targets, clear, and choose technique
            graphics.GraphicsDevice.SetRenderTarget(0, temporaryRT);
            graphics.GraphicsDevice.DepthStencilBuffer = simulationDepthBuffer;
            graphics.GraphicsDevice.Clear(Color.White);
            physicsEffect.CurrentTechnique = physicsEffect.Techniques[technique];

            if (isPhysicsReset) //set if not already set
            {
                physicsEffect.Parameters["positionMap"].SetValue(positionRT.GetTexture());
                physicsEffect.Parameters["velocityMap"].SetValue(velocityRT.GetTexture());
            }

            //first operation
            //perform the shader operations
            spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
            physicsEffect.Begin();

            physicsEffect.CurrentTechnique.Passes[0].Begin();
            spriteBatch.Draw(randomTexture, new Rectangle(0, 0, particleCount, particleCount), Color.White);     //must draw something to get shader to go
            spriteBatch.End();

            physicsEffect.CurrentTechnique.Passes[0].End();
            physicsEffect.End();

            //second operation to copy back to the final rendertarget,
            //because we cannot read from and write to the same render target in one pass.
            //set render target
            graphics.GraphicsDevice.SetRenderTarget(0, resultTarget);

            //set effect parameters
            physicsEffect.Parameters["temporaryMap"].SetValue(temporaryRT.GetTexture());
            physicsEffect.CurrentTechnique = physicsEffect.Techniques["CopyTexture"];

            //draw with effect onto rendertarget
            spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Immediate, SaveStateMode.None);
            physicsEffect.Begin();
            physicsEffect.CurrentTechnique.Passes[0].Begin();
            spriteBatch.Draw(temporaryRT.GetTexture(), new Rectangle(0, 0, particleCount, particleCount), Color.White);
            spriteBatch.End();
            physicsEffect.CurrentTechnique.Passes[0].End();
            physicsEffect.End();

            //set back old rendertargets
            graphics.GraphicsDevice.SetRenderTarget(0, oldRT);
            graphics.GraphicsDevice.DepthStencilBuffer = oldDS;
        }
Ejemplo n.º 9
0
        private void CreateMainMenu()
        {
            Recellection.graphics.GraphicsDevice.SetRenderTarget(0, textRenderTex);
            Recellection.graphics.GraphicsDevice.Clear(Color.White);

            textDrawer.Begin();
            //textDrawer.Draw(Recellection.textureMap.GetTexture(Globals.TextureTypes.MainMenu), Vector2.Zero, Color.White);
            float textScale = 2;

            //This is the offset from the buttonvector where the text will be drawn
            Vector2 offset = new Vector2(buttonDimension.X / 4, (buttonDimension.Y / 2) - ((fontSzInPx / 2) * textScale));

            icons = new List <GUIRegion>();

            //Init the regions!
            icons.Add(new GUIRegion(Recellection.windowHandle, new System.Windows.Rect(0, 0, buttonDimension.X, buttonDimension.Y)));
            textDrawer.DrawString(Recellection.screenFont, Language.Instance.GetString("MainMenu1"), offset, Color.Black, 0, Vector2.Zero, textScale, SpriteEffects.None, 0);

            icons.Add(new GUIRegion(Recellection.windowHandle, new System.Windows.Rect(buttonDimension.X, 0, buttonDimension.X, buttonDimension.Y)));
            textDrawer.DrawString(Recellection.screenFont, Language.Instance.GetString("MainMenu2"), new Vector2(buttonDimension.X, 0) + offset, Color.Black, 0, Vector2.Zero, textScale, SpriteEffects.None, 0);

            icons.Add(new GUIRegion(Recellection.windowHandle, new System.Windows.Rect(buttonDimension.X * 2, 0, buttonDimension.X, buttonDimension.Y)));
            textDrawer.DrawString(Recellection.screenFont, Language.Instance.GetString("MainMenu3"), new Vector2(buttonDimension.X * 2, 0) + offset, Color.Black, 0, Vector2.Zero, textScale, SpriteEffects.None, 0);

            /////////////

            icons.Add(new GUIRegion(Recellection.windowHandle, new System.Windows.Rect(0, buttonDimension.Y, buttonDimension.X, buttonDimension.Y)));
            textDrawer.DrawString(Recellection.screenFont, Language.Instance.GetString("MainMenu4"), new Vector2(0, buttonDimension.Y) + offset, Color.Black, 0, Vector2.Zero, textScale, SpriteEffects.None, 0);

            //The center region is not used
            icons.Add(new GUIRegion(Recellection.windowHandle, new System.Windows.Rect(buttonDimension.X * 2, buttonDimension.Y, buttonDimension.X, buttonDimension.Y)));
            textDrawer.DrawString(Recellection.screenFont, Language.Instance.GetString("MainMenu5"), new Vector2(buttonDimension.X * 2, buttonDimension.Y) + offset, Color.Black, 0, Vector2.Zero, textScale, SpriteEffects.None, 0);

            ////////////

            icons.Add(new GUIRegion(Recellection.windowHandle, new System.Windows.Rect(0, buttonDimension.Y * 2, buttonDimension.X, buttonDimension.Y)));
            textDrawer.DrawString(Recellection.screenFont, Language.Instance.GetString("MainMenu6"), new Vector2(0, buttonDimension.Y * 2) + offset, Color.Black, 0, Vector2.Zero, textScale, SpriteEffects.None, 0);

            icons.Add(new GUIRegion(Recellection.windowHandle, new System.Windows.Rect(buttonDimension.X, buttonDimension.Y * 2, buttonDimension.X, buttonDimension.Y)));
            textDrawer.DrawString(Recellection.screenFont, Language.Instance.GetString("MainMenu7"), new Vector2(buttonDimension.X, buttonDimension.Y * 2) + offset, Color.Black, 0, Vector2.Zero, textScale, SpriteEffects.None, 0);

            icons.Add(new GUIRegion(Recellection.windowHandle, new System.Windows.Rect(buttonDimension.X * 2, buttonDimension.Y * 2, buttonDimension.X, buttonDimension.Y)));
            textDrawer.DrawString(Recellection.screenFont, Language.Instance.GetString("MainMenu8"), new Vector2(buttonDimension.X * 2, buttonDimension.Y * 2) + offset, Color.Black, 0, Vector2.Zero, textScale, SpriteEffects.None, 0);

            textDrawer.End();

            Recellection.graphics.GraphicsDevice.SetRenderTarget(0, null);

            menuPic = textRenderTex.GetTexture();

            helpMenu = new Menu(Globals.MenuTypes.CommandMenu, true);
        }
Ejemplo n.º 10
0
        public static void RenderToTex(GraphicsDevice gd, Texture2D texture, RenderTarget2D renderTarget)
        {
            int         width  = renderTarget.GetTexture().Width;
            int         height = renderTarget.GetTexture().Height;
            SpriteBatch batch  = PrimalDevistation.Instance.Batch;

            gd.SetRenderTarget(0, renderTarget);
            //gd.Clear(ClearOptions.Target, new Color(100, 149, 237, 0), 0, 0);
            batch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.None);
            batch.Draw(texture, new Rectangle(0, 0, width, height), Color.White);
            batch.End();
            gd.SetRenderTarget(0, null);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Calculates the fog map for the player based on all of her
        /// units.
        /// </summary>
        public void CalculateFogMap()
        {
            if (HasFogMap && !IsOmniscient)
            {
                // Turn vision into fog

                for (int i = 0; i < FogMapPixels.Length; i++)
                {
                    if (FogMapPixels[i] != Color.Black)
                    {
                        FogMapPixels[i] = Color.Gray;
                    }
                }

                FogMap.GetTexture().SetData <Color>(FogMapPixels);
            }

            RenderTarget oldRT = GraphicsDevice.GetRenderTarget(0);

            GraphicsDevice.SetRenderTarget(0, FogMap);


            Batch.Begin(SpriteBlendMode.Additive, SpriteSortMode.Immediate, SaveStateMode.SaveState);

            lock (League.Engine.Units) {
                try {
                    foreach (Unit unit in League.Engine.Units)
                    {
                        if (unit.Owner == this)
                        {
                            // Draw the circle
                            Rectangle destRect = new Rectangle();
                            destRect.X      = (int)(unit.Position.X + (League.Engine.CurrentMap.Width / 2.0f) * (512f / League.Engine.CurrentMap.Width)) - (unit.Type.Sight / 2);
                            destRect.Y      = (int)(unit.Position.Y + (League.Engine.CurrentMap.Height / 2.0f) * (512f / League.Engine.CurrentMap.Height)) - (unit.Type.Sight / 2);
                            destRect.Width  = unit.Type.Sight;
                            destRect.Height = unit.Type.Sight;
                            Batch.Draw(SightCircle, destRect, Color.White);
                        }
                    }
                } catch { }
            }

            Batch.End();

            GraphicsDevice.SetRenderTarget(0, oldRT as RenderTarget2D);
            FogMap.GetTexture().GetData(FogMapPixels);

            HasFogMap = true;

            League.Engine.CurrentMap.DrawMinimap();
        }
Ejemplo n.º 12
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)
        {
            if (save)
            {
                GraphicsDevice.SetRenderTarget(0, renderTarget);
                GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, color, 1, 0);

                // Left
                DrawImage((int)Direction.Left);
                base.Draw(gameTime);

                GraphicsDevice.SetRenderTarget(0, null);
                Texture2D resolvedTexture1 = renderTarget.GetTexture();

                string suffix1 = String.Empty;
                if (ActionType.Idle != actionType)
                {
                    suffix1 = "_" + Direction.Left.ToString();
                }
                String fileName1 = String.Format("{0}/{1}{2}.png", entityType, actionType, suffix1);
                resolvedTexture1.Save(fileName1, ImageFileFormat.Png);

                // Right
                GraphicsDevice.SetRenderTarget(0, renderTarget);
                GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, color, 1, 0);

                DrawImage((int)Direction.Rght);
                base.Draw(gameTime);

                GraphicsDevice.SetRenderTarget(0, null);
                Texture2D resolvedTexture2 = renderTarget.GetTexture();

                string suffix2 = String.Empty;
                if (ActionType.Idle != actionType)
                {
                    suffix2 = "_" + Direction.Rght.ToString();
                }
                String fileName2 = String.Format("{0}/{1}{2}.png", entityType, actionType, suffix2);
                resolvedTexture2.Save(fileName2, ImageFileFormat.Png);

                Exit();
            }
            else
            {
                DrawImage(0);
                base.Draw(gameTime);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>a
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (save)
            {
                const int count = 10;
                for (int index = 0; index < count; index++)
                {
                    GraphicsDevice.SetRenderTarget(0, renderTarget);
                    GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, color, 1, 0);

                    //DrawPlayer(loops, index);
                    DrawImage(index);
                    base.Draw(gameTime);

                    GraphicsDevice.SetRenderTarget(0, null);
                    Texture2D resolvedTexture = renderTarget.GetTexture();

                    String fileName = String.Format("{0}_{1}.png", assetName, (index + 1).ToString().PadLeft(2, '0'));
                    resolvedTexture.Save(fileName, ImageFileFormat.Png);
                }

                Exit();
            }
            else
            {
                DrawImage(0);

                base.Draw(gameTime);
            }
        }
        private void RenderSceneTo3RenderTargets()
        {
            //bind render targets to outputs of pixel shaders
            device.SetRenderTarget(0, colorTarget);
            device.SetRenderTarget(1, normalTarget);
            device.SetRenderTarget(2, depthTarget);

            //clear all render targets
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1, 0);

            //render the scene using custom effect that writes to all render targets simultaneously
            effect1Scene.CurrentTechnique = effect1Scene.Techniques["MultipleTargets"];
            effect1Scene.Parameters["xView"].SetValue(fpsCam.ViewMatrix);
            effect1Scene.Parameters["xProjection"].SetValue(fpsCam.ProjectionMatrix);
            RenderScene(effect1Scene);

            //de-activate render targets to resolve them
            device.SetRenderTarget(0, null);
            device.SetRenderTarget(1, null);
            device.SetRenderTarget(2, null);

            //copy contents of render targets into texture
            colorMap  = colorTarget.GetTexture();
            normalMap = normalTarget.GetTexture();
            depthMap  = depthTarget.GetTexture();
        }
Ejemplo n.º 15
0
        private void BlurAmbientOcclusion()
        {
            if (OutputMode != DeferredOutputMode.BlurX)
            {
                GraphicsDevice.SetRenderTarget(0, blurRT);
            }
            blurShader.SetParameter("blurMap", ambientOcclusionRT.GetTexture());
            blurShader.SetParameter("BlurOffset", new Vector2(halfPixel.X, 0));
            blurShader.SetParameter("halfPixel", halfPixel);
            blurShader.SetTechnique("GaussionBlur");

            blurShader.RenderMultipass(fullScreenQuad.Draw);

            if (OutputMode == DeferredOutputMode.BlurX)
            {
                return;
            }
            GraphicsDevice.SetRenderTarget(0, null);

            blurShader.SetParameter("blurMap", blurRT.GetTexture());
            blurShader.SetParameter("BlurOffset", new Vector2(0, halfPixel.Y));
            blurShader.SetParameter("halfPixel", halfPixel);
            blurShader.SetTechnique("GaussionBlur");

            blurShader.RenderMultipass(fullScreenQuad.Draw);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// This is where it all happens. Grabs a scene that has already been rendered,
        /// and uses postprocess magic to add a glowing bloom effect over the top of it.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            game.Renderer.SetDefaultRenderStates();

            // Resolve the scene into a texture, so we can
            // use it as input data for the bloom processing.
            GraphicsDevice.ResolveBackBuffer(resolveTarget);

            radialBlurEffect.Parameters["InvScreenWidth"].SetValue(1.0f / resolveTarget.Width);

            DrawFullscreenQuad(resolveTarget, renderTarget1,
                               radialBlurEffect,
                               IntermediateBuffer.Blurred);

            // Pass 4: draw both rendertarget 1 and the original scene
            // image back into the main backbuffer, using a shader that
            // combines them to produce the final bloomed result.
            GraphicsDevice.SetRenderTarget(0, null);

            EffectParameterCollection parameters = blurCombineEffect.Parameters;

            GraphicsDevice.Textures[1] = resolveTarget;

            Viewport viewport = GraphicsDevice.Viewport;

            blurCombineEffect.Parameters["Power"].SetValue(game.World.Players[0].RelativeSpeed);

            DrawFullscreenQuad(renderTarget1.GetTexture(),
                               viewport.Width, viewport.Height,
                               blurCombineEffect,
                               IntermediateBuffer.FinalResult);
        }
Ejemplo n.º 17
0
        private void GeneratePerlinNoise(float time)
        {
            Device.RenderState.AlphaBlendEnable = false;
            Device.RenderState.AlphaTestEnable  = false;

            Device.SetRenderTarget(0, cloudsRenderTarget);
            effect.CurrentTechnique = effect.Techniques["PerlinNoise"];
            effect.Parameters["xTexture"].SetValue(cloudStaticMap);
            effect.Parameters["xOvercast"].SetValue(1.1f);
            effect.Parameters["xTime"].SetValue(time / 1000.0f);

            effect.Begin();
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();

                Device.VertexDeclaration = fullScreenVertexDeclaration;
                Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, fullScreenVertices, 0, 2);

                pass.End();
            }
            effect.End();

            Device.RenderState.AlphaTestEnable  = true;
            Device.RenderState.AlphaBlendEnable = true;
            Device.SetRenderTarget(0, null);
            cloudMap = cloudsRenderTarget.GetTexture();
        }
Ejemplo n.º 18
0
        public static Texture2D CalculateShadowMapForScene(GraphicsDevice graphicsDevice, RenderTarget2D renderTarget, DepthStencilBuffer depthBuffer, Vector3 lightDirection, BoundingSphere bounds, int SceneId)
        {
            DepthStencilBuffer old = SetupShadowMap(graphicsDevice, ref renderTarget, ref depthBuffer);

            ShaderManager.SetCurrentEffect(ShaderManager.EFFECT_ID.SHADOWMAP);
            ShaderManager.SetValue("LightProj", CalcLightProjection(bounds, lightDirection, graphicsDevice.Viewport));
            ShaderManager.SetValue("LightView", Matrix.CreateLookAt(lightDirection * bounds.Radius + bounds.Center, bounds.Center, Vector3.Up));

            foreach (DrawableSceneComponent
                     dsc in ObjectManager.drawableSceneComponents[SceneId])
            {
                if (!dsc.Visible)
                {
                    continue;
                }

                if (dsc is AnimatedModel)
                {
                    dsc.DrawWithEffect(ShaderManager.EFFECT_ID.SHADOWMAP, "ShadowMapRenderAnimation");
                }
                else
                {
                    dsc.DrawWithEffect(ShaderManager.EFFECT_ID.SHADOWMAP, "ShadowMapRenderStatic");
                }
            }
            ResetGraphicsDevice(graphicsDevice, old);

            return(renderTarget.GetTexture());
        }
Ejemplo n.º 19
0
        public static void RenderToTex(GraphicsDevice gd, Texture2D texture, RenderTarget2D renderTarget, Effect effect)
        {
            int         width  = renderTarget.GetTexture().Width;
            int         height = renderTarget.GetTexture().Height;
            SpriteBatch batch  = PrimalDevistation.Instance.Batch;

            gd.SetRenderTarget(0, renderTarget);
            batch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);
            effect.Begin();
            effect.CurrentTechnique.Passes[0].Begin();
            batch.Draw(texture, new Rectangle(0, 0, width, height), new Color(100, 100, 100));
            batch.End();
            effect.CurrentTechnique.Passes[0].End();
            effect.End();
            gd.SetRenderTarget(0, null);
        }
Ejemplo n.º 20
0
        public Texture2D DrawNormals(SpriteBatch s)
        {
            gRef.GraphicsDevice.SetRenderTarget(0, target);
            gRef.GraphicsDevice.Clear(normalClear);
            s.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Immediate, SaveStateMode.SaveState);

            int loopX = Game1.ScreenX / tileSize + 1;
            int loopY = Game1.ScreenY / tileSize + 1;

            for (int x = 0; x < loopX; x++)
            {
                for (int y = 0; y < loopY; y++)
                {
                    s.Draw(veinMap, new Vector2(x * tileSize, y * tileSize), pulseForce);
                }
            }

            //s.Draw(veinMap, new Rectangle(0,0, Game1.ScreenX, Game1.ScreenY), pulseForce);
            foreach (BlastWave w in waves)
            {
                w.Draw(s);
            }
            s.End();
            gRef.GraphicsDevice.SetRenderTarget(0, null);

            return(target.GetTexture());
        }
Ejemplo n.º 21
0
        public void SetText(string text)
        {
            this.text = text;
            width     = (int)ServiceManager.Game.Font.MeasureString(text).X * 2;
            height    = (int)ServiceManager.Game.Font.MeasureString(text).Y * 2;

            GraphicsDevice device = Renderer.GraphicOptions.graphics.GraphicsDevice;

            const int      numberOfLevels     = 1;
            const int      multisampleQuality = 0;
            RenderTarget2D renderTarget       = new RenderTarget2D(device, width,
                                                                   height, numberOfLevels, SurfaceFormat.Color,
                                                                   MultiSampleType.None, multisampleQuality, RenderTargetUsage.PreserveContents);

            device.SetRenderTarget(0, renderTarget);
            device.Clear(Color.TransparentWhite);
            ServiceManager.Game.Batch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Texture, SaveStateMode.SaveState);
            //ServiceManager.Game.Batch.Begin();
            ServiceManager.Game.Batch.DrawString(ServiceManager.Game.Font, text, Vector2.Zero, Color.Black, 0.0f, Vector2.Zero, 2.0f, SpriteEffects.None, 0f);
            ServiceManager.Game.Batch.End();

            device.SetRenderTarget(0, null);
            texture = renderTarget.GetTexture();

            //texture.Save("C:\\img.png", ImageFileFormat.Png);

            AdjustVertices();
            Ready();
        }
Ejemplo n.º 22
0
        // override EndDraw to handle unsetting the render target, resetting the Viewport,
        // and drawing the render target's contents to the screen
        protected override void EndDraw()
        {
            GraphicsDevice.SetRenderTarget(0, null);
            GraphicsDevice.Viewport = new Viewport
            {
                X        = 0,
                Y        = 0,
                Width    = 272,
                Height   = 480,
                MinDepth = GraphicsDevice.Viewport.MinDepth,
                MaxDepth = GraphicsDevice.Viewport.MaxDepth
            };

            GraphicsDevice.Clear(Color.Black);

            spriteBatch.Begin();
            spriteBatch.Draw(
                renderTarget.GetTexture(),
                new Vector2(136f, 240f),
                null,
                Color.White,
                Orientation == LandscapeOrientation.Right ? MathHelper.PiOver2 : -MathHelper.PiOver2,
                new Vector2(240f, 136f),
                1f,
                SpriteEffects.None,
                0);
            spriteBatch.End();

            base.EndDraw();
        }
Ejemplo n.º 23
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)
        {
            if (save)
            {
                for (int index = 0; index < 5; index++)
                {
                    GraphicsDevice.SetRenderTarget(0, renderTarget);
                    GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, color, 1, 0);

                    DrawPlayer(index);
                    base.Draw(gameTime);

                    GraphicsDevice.SetRenderTarget(0, null);
                    Texture2D resolvedTexture = renderTarget.GetTexture();

                    //String fileName = monstNames[index] + ".png";
                    String fileName = playerNames[index] + ".png";
                    resolvedTexture.Save(fileName, ImageFileFormat.Png);
                }
                Exit();
            }
            else
            {
                DrawMonst(0);
                base.Draw(gameTime);
            }
        }
Ejemplo n.º 24
0
        public static Texture2D Scale(GraphicsDevice gd, Texture2D texture, float scaleX, float scaleY)
        {
            var newWidth  = (int)(texture.Width * scaleX);
            var newHeight = (int)(texture.Height * scaleY);

            RenderTarget2D renderTarget = new RenderTarget2D(
                gd,
                newWidth, newHeight, 1,
                SurfaceFormat.Color);

            gd.SetRenderTarget(0, renderTarget);

            SpriteBatch batch = new SpriteBatch(gd);

            Rectangle destinationRectangle = new Rectangle(0, 0, newWidth, newHeight);

            batch.Begin();
            batch.Draw(texture, destinationRectangle, Color.White);
            batch.End();

            gd.SetRenderTarget(0, null);

            var newTexture = renderTarget.GetTexture();

            return(newTexture);
        }
Ejemplo n.º 25
0
 public void Draw(SpriteBatch s, GraphicsDevice gd, RenderTarget2D r)
 {
     if (this.start)
     {
         gd.SetRenderTarget(0, r);
         gd.Clear(Color.Black);
         foreach (BSprite bsprite in this.bsc)
         {
             if (!bsprite.Add)
             {
                 bsprite.Draw(s);
             }
         }
         s.End();
         s.Begin(SpriteBlendMode.Additive);
         foreach (BSprite bsprite in this.bsc)
         {
             if (bsprite.Add)
             {
                 bsprite.Draw(s);
             }
         }
         s.End();
         s.Begin();
         gd.SetRenderTarget(0, (RenderTarget2D)null);
         this.render = r.GetTexture();
     }
     else
     {
         this.render = (Texture2D)null;
     }
 }
Ejemplo n.º 26
0
        public void DrawRefractionMap(Camera camera, RenderRefractionHandler render)
        {
            Vector3 planeNormalDirection = new Vector3(0, -1, 0);

            planeNormalDirection.Normalize();
            Vector4 planeCoefficients = new Vector4(planeNormalDirection, waterHeight);

            Matrix camMatrix    = camera.View * camera.Projection;
            Matrix invCamMatrix = Matrix.Invert(camMatrix);

            invCamMatrix = Matrix.Transpose(invCamMatrix);

            planeCoefficients = Vector4.Transform(planeCoefficients, invCamMatrix);
            Plane refractionClipPlane = new Plane(planeCoefficients);


            //device.SetRenderTarget(0, refractionRT);
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);


            render.Invoke();


            refractionMap = refractionRT.GetTexture();
        }
Ejemplo n.º 27
0
        protected override void DrawProject()
        {
            if (ProjectDoc.Instance.SelectedSceneInfo == null)
            {
                return;
            }
            if (!IsFullScreen)
            {
                base.DrawProject();
            }
            else
            {
                GraphicsDevice.Viewport = ViewportMain;
                GraphicsDevice.SetRenderTarget(0, null);
                GraphicsDevice.Clear(Color.Black);
                ProjectDoc.Instance.SelectedSceneInfo.Draw(GraphicsDevice);
                GraphicsDevice.Present(null, null, (IntPtr)m_SrcGameForm.Handle);

                if (m_PlayControlForm.IsRecording)
                {
                    GraphicsDevice.SetRenderTarget(0, m_RenderTarget);
                    GraphicsDevice.Clear(Color.Black);
                    ProjectDoc.Instance.SelectedSceneInfo.Draw(GraphicsDevice);
                    GraphicsDevice.SetRenderTarget(0, null);

                    var txt = m_RenderTarget.GetTexture();
                    txt.GetData <uint>(m_VideoBuffer);
                    WriteFrame(m_VideoBuffer);
                }
            }
        }
Ejemplo n.º 28
0
        public void DrawReflectionMap(Camera camera, RenderReflectionHandler render)
        {
            reflectionViewMatrix = ((FreeCamera)camera).UpdateReflectiveMatrices();
            float   reflectionCamYCoord   = -camera.Position.Y + (waterHeight * 2);
            Vector3 reflectionCamPosition = new Vector3(camera.Position.X, reflectionCamYCoord, camera.Position.Z);

            Vector3 planeNormalDirection = new Vector3(0, 1, 0);

            planeNormalDirection.Normalize();
            Vector4 planeCoefficients = new Vector4(planeNormalDirection, -3f);

            Matrix camMatrix    = reflectionViewMatrix * camera.Projection;
            Matrix invCamMatrix = Matrix.Invert(camMatrix);

            invCamMatrix = Matrix.Transpose(invCamMatrix);

            planeCoefficients = Vector4.Transform(planeCoefficients, invCamMatrix);
            Plane refractionClipPlane = new Plane(planeCoefficients);

            //device.ClipPlanes[0].Plane = refractionClipPlane;
            //device.ClipPlanes[0].IsEnabled = true;
            //device.SetRenderTarget(0, reflectionRT);
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);


            render.Invoke(reflectionViewMatrix, reflectionCamPosition);

            device.SetRenderTarget(0, null);
            reflectionMap = reflectionRT.GetTexture();

            device.ClipPlanes[0].IsEnabled = false;
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Draws the gameplay scene.
        /// </summary>
        private void DrawGameplayScene()
        {
            // Render explosions to texture
            if (renderTarget != null && stampSpriteList.Count > 0)
            {
                device.SetRenderTarget(0, renderTarget);
                DepthStencilBuffer old = device.DepthStencilBuffer;
                device.DepthStencilBuffer = depthStencilBuffer;
                spriteBatch.Begin(SpriteBlendMode.None, SpriteSortMode.Deferred, SaveStateMode.None);
                DrawTerrain(Model.TerrainTexture);
                foreach (StampSprite e in stampSpriteList)
                {
                    spriteBatch.Draw(e.Texture, e.Position, Color.White);
                }
                stampSpriteList.Clear();
                spriteBatch.End();

                device.SetRenderTarget(0, null);
                device.DepthStencilBuffer = old;

                Model.TerrainTexture = renderTarget.GetTexture();
            }
            device.Clear(backgroundColor);

            /* Draw background image */
            Rectangle screenRect = new Rectangle(0, 0, device.PresentationParameters.BackBufferWidth,
                                                 device.PresentationParameters.BackBufferHeight);

            spriteBatch.Begin();
            spriteBatch.Draw(Model.BackGround, screenRect, Color.White);
            spriteBatch.End();

            /* Draw terrain, entities and lines */
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None, Camera.Transform);
            DrawTerrain(Model.TerrainTexture);
            DrawEntities(Model.EntityList);
            DrawPlayerInfo(Model.PlayerList);
            DrawLines();
            spriteBatch.End();

            spriteBatch.Begin(SpriteBlendMode.AlphaBlend, SpriteSortMode.Deferred, SaveStateMode.None);
            DrawScores(Model.PlayerList);

            if (Model.GameOver)
            {
                //Draw end game and win notice
                Color   color        = ColorFromPlayerIndex(Model.GetWinner());
                string  gameOver     = "Game Over! Player " + Model.GetWinner() + " wins!";
                string  quit         = "Press ESC to go back to the menu.";
                Vector2 gameOverSize = Sprites.MenuRegularFont.MeasureString(gameOver);
                Vector2 quitSize     = Sprites.MenuRegularFont.MeasureString(quit);
                spriteBatch.DrawString(Sprites.MenuRegularFont, gameOver, Camera.Position - new Vector2(gameOverSize.X / 2, gameOverSize.Y), color);
                spriteBatch.DrawString(Sprites.MenuRegularFont, quit, Camera.Position - new Vector2(quitSize.X / 2, 0), color);
            }

            spriteBatch.End();

            /* Update camera */
            UpdateCamera();
        }
Ejemplo n.º 30
0
        public override Texture2D Process(Texture2D baseTexture_, Texture2D inputTexture_, float tick)
        {
            effect.CurrentTechnique = effect.Techniques["VertBlur"];
            Draw_Base(effect, surface, inputTexture_, tick);

            return(surface.GetTexture());
        }