예제 #1
0
        /// <summary>
        /// Generate shadow
        /// </summary>
        internal void GenerateShadows(BaseGame.RenderDelegate renderObjects)
        {
            // Can't generate shadow if loading failed!
            if (xnaEffect == null)
                return;

            // This method sets all required shader variables.
            this.SetParameters();
            Matrix remViewMatrix = BaseGame.ViewMatrix;
            Matrix remProjMatrix = BaseGame.ProjectionMatrix;
            CalcSimpleDirectionalShadowMappingMatrix();

            DepthStencilBuffer remBackBufferSurface = null;
            // Time to generate the shadow texture
            try
            {
                // Start rendering onto the shadow map
                shadowMapTexture.SetRenderTarget();
                if (shadowMapTexture.ZBufferSurface != null)
                {
                    remBackBufferSurface = BaseGame.Device.DepthStencilBuffer;
                    BaseGame.Device.DepthStencilBuffer =
                        shadowMapTexture.ZBufferSurface;
                } // if (shadowMapTexture.ZBufferSurface)

                // Make sure depth buffer is on
                BaseGame.Device.RenderState.DepthBufferEnable = true;
                // Disable alpha
                BaseGame.Device.RenderState.AlphaBlendEnable = false;

                // Clear render target
                shadowMapTexture.Clear(Color.White);

                //tst:
                //ShaderEffect.normalMapping.RenderSinglePassShader(renderObjects);

                if (BaseGame.CanUsePS20)
                    xnaEffect.CurrentTechnique = xnaEffect.Techniques["GenerateShadowMap20"];
                else
                    xnaEffect.CurrentTechnique = xnaEffect.Techniques["GenerateShadowMap"];

                // Render shadows with help of the GenerateShadowMap shader
                RenderSinglePassShader(renderObjects);

                /*
                xnaEffect.Begin(SaveStateMode.None);
                foreach (EffectPass pass in xnaEffect.CurrentTechnique.Passes)
                {
                    pass.Begin();
                    renderObjects();
                    pass.End();
                } // foreach (pass)
                 */
            } // try
            finally
            {
                //xnaEffect.End();

                // Resolve the render target to get the texture (required for Xbox)
                shadowMapTexture.Resolve(false);

                // Set render target back to default
                //BaseGame.ResetRenderTarget(false);

                if (shadowMapTexture.ZBufferSurface != null)
                    BaseGame.Device.DepthStencilBuffer = remBackBufferSurface;

                /*
            #if DEBUG
                //tst: show light shadow view pos
                if (Input.Keyboard.IsKeyDown(Keys.Tab) == false)
            #endif
                {
                 */
                    BaseGame.ProjectionMatrix = remProjMatrix;
                    BaseGame.ViewMatrix = remViewMatrix;
                //} // if
            } // finally
        }
예제 #2
0
 public SimpleCamera(BaseGame game)
     : base(game)
 {
 }
예제 #3
0
        /// <summary>
        /// Calc shadows with help of generated light depth map,
        /// all objects have to be rendered again for comparing.
        /// We could save a pass when directly rendering here, but this
        /// has 2 disadvantages: 1. we can't post screen blur the shadow
        /// and 2. we can't use any other shader, especially bump and specular
        /// mapping shaders don't have any instructions left with ps_1_1.
        /// This way everything is kept simple, we can do as complex shaders
        /// as we want, the shadow shaders work seperately.
        /// </summary>
        /// <param name="renderObjects">Render objects</param>
        public void RenderShadows(BaseGame.RenderDelegate renderObjects)
        {
            // Can't calc shadows if loading failed!
            if (xnaEffect == null)
                return;

            // Make sure z buffer and writing z buffer is on
            BaseGame.Device.RenderState.DepthBufferEnable = true;
            BaseGame.Device.RenderState.DepthBufferWriteEnable = true;

            // Render shadows into our shadowMapBlur render target
            shadowMapBlur.RenderShadows(
                delegate
                {
                    if (BaseGame.CanUsePS20)
                        xnaEffect.CurrentTechnique = xnaEffect.Techniques["UseShadowMap20"];
                    else
                        xnaEffect.CurrentTechnique = xnaEffect.Techniques["UseShadowMap"];

                    // This method sets all required shader variables.
                    this.SetParameters();

                    // Use the shadow map texture here which was generated in
                    // GenerateShadows().
                    shadowMap.SetValue(shadowMapTexture.XnaTexture);

                    //ShaderEffect.normalMapping.RenderSinglePassShader(renderObjects);

                    // Render shadows with help of the UseShadowMap shader
                    RenderSinglePassShader(renderObjects);

                    /*not required
                    // Make sure warping is on, stupid xna bug again
                    BaseGame.Device.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
                    BaseGame.Device.SamplerStates[0].AddressV = TextureAddressMode.Wrap;
                    BaseGame.Device.SamplerStates[1].AddressU = TextureAddressMode.Wrap;
                    BaseGame.Device.SamplerStates[1].AddressV = TextureAddressMode.Wrap;
                     */

                    /*
                    // Render everything into the current render target (set before
                    // or just use the screen).
                    try
                    {
                        xnaEffect.Begin(SaveStateMode.None);
                        foreach (EffectPass pass in xnaEffect.CurrentTechnique.Passes)
                        {
                            pass.Begin();
                            renderObjects();
                            pass.End();
                        } // foreach (pass)
                    } // try
                    finally
                    {
                        xnaEffect.End();
                    } // finally
                     */
                });

            // Start rendering the shadow map blur (pass 1, which messes up our
            // background), pass 2 can be done below without any render targets.
            shadowMapBlur.ShowShadowsPart1();

            // Kill background z buffer
            XnaShooterGame.Device.Clear(ClearOptions.DepthBuffer, Color.Black, 1, 0);
        }
예제 #4
0
        /// <summary>
        /// Render single pass shader, little faster and simpler than
        /// Render and it just uses the current technique and renderes only
        /// the first pass (most shaders have only 1 pass anyway).
        /// Used for MeshRenderManager!
        /// </summary>
        /// <param name="renderDelegate">Render delegate</param>
        public void RenderSinglePassShader(
			BaseGame.RenderDelegate renderDelegate)
        {
            // Start effect (current technique should be set)
            xnaEffect.Begin(SaveStateMode.None);
            // Start first pass
            xnaEffect.CurrentTechnique.Passes[0].Begin();

            // Render
            renderDelegate();

            // End pass and shader
            xnaEffect.CurrentTechnique.Passes[0].End();
            xnaEffect.End();
        }
예제 #5
0
		} // Fps
		#endregion
		
		#region Constructor
		public FpsCounter(BaseGame game)
			: base(game)
		{
		} // FpsCounter(game)
예제 #6
0
        /// <summary>
        /// Render
        /// </summary>
        /// <param name="techniqueName">Technique name</param>
        /// <param name="renderDelegate">Render delegate</param>
        public void Render(string techniqueName,
			BaseGame.RenderDelegate renderDelegate)
        {
            Render(null, techniqueName, renderDelegate);
        }
예제 #7
0
        /// <summary>
        /// Render
        /// </summary>
        /// <param name="setMat">Set matrix</param>
        /// <param name="techniqueName">Technique name</param>
        /// <param name="renderDelegate">Render delegate</param>
        public void Render(Material setMat,
			string techniqueName,
			BaseGame.RenderDelegate renderDelegate)
        {
            SetParameters(setMat);

            /*will become important later in the book.
            // Can we do the requested technique?
            // For graphic cards not supporting ps2.0, fall back to ps1.1
            if (BaseGame.CanUsePS20 == false &&
                techniqueName.EndsWith("20"))
                // Use same technique without the 20 ending!
                techniqueName = techniqueName.Substring(0, techniqueName.Length - 2);
             */

            // Start shader
            xnaEffect.CurrentTechnique = xnaEffect.Techniques[techniqueName];
            xnaEffect.Begin(SaveStateMode.None);

            // Render all passes (usually just one)
            //foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            for (int num = 0; num < xnaEffect.CurrentTechnique.Passes.Count; num++)
            {
                EffectPass pass = xnaEffect.CurrentTechnique.Passes[num];

                pass.Begin();
                renderDelegate();
                pass.End();
            } // foreach (pass)

            // End shader
            xnaEffect.End();
        }
예제 #8
0
 public RotationCamera(BaseGame game)
     : base(game)
 {
 }
예제 #9
0
        /// <summary>
        /// Render shadows
        /// </summary>
        /// <param name="renderCode">Render code</param>
        public void RenderShadows(BaseGame.RenderDelegate renderCode)
        {
            // Render into our scene map texture
            sceneMapTexture.SetRenderTarget();
            //*TODO
            DepthStencilBuffer remBackBufferSurface = null;
            if (sceneMapTexture.ZBufferSurface != null)
            {
                remBackBufferSurface = BaseGame.Device.DepthStencilBuffer;
                BaseGame.Device.DepthStencilBuffer =
                    sceneMapTexture.ZBufferSurface;
            } // if (sceneMapTexture.ZBufferSurface)
            //*/

            // Clear render target
            sceneMapTexture.Clear(Color.White);

            // Render everything
            renderCode();

            // Resolve render target
            sceneMapTexture.Resolve(false);

            // Restore back buffer as render target
            //obs: BaseGame.ResetRenderTarget(false);
            //*TODO
            if (sceneMapTexture.ZBufferSurface != null)
                BaseGame.Device.DepthStencilBuffer = remBackBufferSurface;
            //*/
        }
예제 #10
0
 /// <summary>
 /// Create screenshot capturer
 /// </summary>
 /// <param name="setGame">Set game</param>
 public ScreenshotCapturer(BaseGame setGame)
     : base(setGame)
 {
     game = setGame;
     screenshotNum = GetCurrentScreenshotNum();
 }