Exemplo n.º 1
0
        private EffectParameter windowSize, sceneMap; //,

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Create shadow map screen blur shader.
        /// obs, using full size again: But only use 1/4 of the screen!
        /// </summary>
        public ShadowMapBlur()
            : base(Filename)
        {
            // Scene map texture
            sceneMapTexture = new RenderToTexture(
                //RenderToTexture.SizeType.FullScreen);
                //RenderToTexture.SizeType.FullScreenWithZBuffer);
                //improve performance:
                //RenderToTexture.SizeType.HalfScreen);
            //TODO if problems:
                RenderToTexture.SizeType.HalfScreenWithZBuffer);
            /*obs
            blurMapTexture = new RenderToTexture(
                RenderToTexture.SizeType.FullScreen);
                //RenderToTexture.SizeType.FullScreenWithZBuffer);
                //improve performance:
                //RenderToTexture.SizeType.HalfScreen);
             */
        }
Exemplo n.º 2
0
        //*/

        /// <summary>
        /// Test create render to texture
        /// </summary>
        public static void TestCreateRenderToTexture()
        {
            ColladaModel testModel = null;
            RenderToTexture renderToTexture = null;

            TestGame.Start(
                "TestCreateRenderToTexture",
                delegate
                {
                    testModel = new ColladaModel("Sword");
                    renderToTexture = new RenderToTexture(
                        //SizeType.QuarterScreen);
                        SizeType.HalfScreen);
                        //SizeType.FullScreen);
                        //SizeType.ShadowMap);
                },
                delegate
                {
                    bool renderToTextureWay =
                        Input.Keyboard.IsKeyUp(Keys.Space) &&
                        Input.GamePadAPressed == false;
                    BaseGame.Device.RenderState.DepthBufferEnable = true;

                    if (renderToTextureWay)
                    {
                        // Set render target to our texture
                        renderToTexture.SetRenderTarget();

                        // Clear background
                        renderToTexture.Clear(Color.Blue);

                        /*obs
                        // Draw background lines
                        BaseGame.DrawLine(new Point(0, 200), new Point(200, 0), Color.Blue);
                        BaseGame.DrawLine(new Point(0, 0), new Point(400, 400), Color.Red);
                        BaseGame.FlushLineManager2D();
                         */

                        // And draw object
                        testModel.Render(Matrix.CreateScale(1.5f));
                        //obs: BaseGame.MeshRenderManager.Render();

                        // Do we need to resolve?
                        renderToTexture.Resolve();
                        //BaseGame.Device.ResolveRenderTarget(0);

                        // Reset background buffer
                        BaseGame.ResetRenderTarget(true);
                    } // if (renderToTextureWay)
                    else
                    {
                        // Copy backbuffer way, render stuff normally first
                        // Clear background
                        BaseGame.Device.Clear(Color.Blue);

                        /*obs
                        // Draw background lines
                        BaseGame.DrawLine(new Point(0, 200), new Point(200, 0), Color.Blue);
                        BaseGame.DrawLine(new Point(0, 0), new Point(400, 400), Color.Red);
                        BaseGame.FlushLineManager2D();
                         */

                        // And draw object
                        testModel.Render(Matrix.CreateScale(1.5f));
                        //obs: BaseGame.MeshRenderManager.Render();
                    } // else

                    // Show render target in a rectangle on our screen
                    renderToTexture.RenderOnScreen(
                        //tst:
                        new Rectangle(100, 100, 256, 256));
                        //BaseGame.ResolutionRect);
                    //no need: BaseGame.UI.FlushUI();

                    TextureFont.WriteText(2, 0,
                        "               Press Space to toogle full screen rendering");
                    TextureFont.WriteText(2, 30,
                        "renderToTexture.Width=" + renderToTexture.Width);
                    TextureFont.WriteText(2, 60,
                        "renderToTexture.Height=" + renderToTexture.Height);
                    TextureFont.WriteText(2, 90,
                        "renderToTexture.Valid=" + renderToTexture.Valid);
                    TextureFont.WriteText(2, 120,
                        "renderToTexture.XnaTexture=" + renderToTexture.XnaTexture);
                    TextureFont.WriteText(2, 150,
                        "renderToTexture.ZBufferSurface=" + renderToTexture.ZBufferSurface);
                    TextureFont.WriteText(2, 180,
                        "renderToTexture.Filename=" + renderToTexture.Filename);
                });
        }
Exemplo n.º 3
0
        /// <summary>
        /// Shadow map shader
        /// </summary>
        public ShadowMapShader()
            : base(ShaderFilename)
        {
            if (BaseGame.CanUsePS20)
                // We use R32F, etc. and have a lot of precision
                compareDepthBias = 0.0002f;// 0.0001f;
            else
                // A8R8G8B8 isn't very precise, increase comparing depth bias
                compareDepthBias = 0.0075f;// 0.025f;

            // Ok, time to create the shadow map render target
            shadowMapTexture = new RenderToTexture(
                RenderToTexture.SizeType.ShadowMap);

            CalcShadowMapBiasMatrix();

            shadowMapBlur = new ShadowMapBlur();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create post screen menu. Also used for the constructor of
        /// PostScreenGlow (same RenderToTextures used there).
        /// </summary>
        protected PostScreenMenu(string shaderFilename)
            : base(shaderFilename)
        {
            // Scene map texture
            if (sceneMapTexture == null)
                sceneMapTexture = new RenderToTexture(
                    RenderToTexture.SizeType.FullScreen);
            // Downsample map texture (to 1/4 of the screen)
            if (downsampleMapTexture == null)
                downsampleMapTexture = new RenderToTexture(
                    RenderToTexture.SizeType.QuarterScreen);

            // Blur map texture
            if (blurMap1Texture == null)
                blurMap1Texture = new RenderToTexture(
                    RenderToTexture.SizeType.QuarterScreen);
            // Blur map texture
            if (blurMap2Texture == null)
                blurMap2Texture = new RenderToTexture(
                    RenderToTexture.SizeType.QuarterScreen);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create post screen glow
        /// </summary>
        public PostScreenGlow()
            : base(Filename)
        {
            // Scene map texture
            if (sceneMapTexture == null)
                sceneMapTexture = new RenderToTexture(
                    RenderToTexture.SizeType.FullScreenWithZBuffer);//.FullScreen);
            // Downsample map texture (to 1/4 of the screen)
            if (downsampleMapTexture == null)
                downsampleMapTexture = new RenderToTexture(
                    RenderToTexture.SizeType.QuarterScreen);

            // Blur map texture
            if (blurMap1Texture == null)
                blurMap1Texture = new RenderToTexture(
                    RenderToTexture.SizeType.QuarterScreen);
            // Blur map texture
            if (blurMap2Texture == null)
                blurMap2Texture = new RenderToTexture(
                    RenderToTexture.SizeType.QuarterScreen);

            // Final map for glow, used to perform radial blur next step
            radialSceneMapTexture = new RenderToTexture(
                RenderToTexture.SizeType.FullScreen);
        }