示例#1
0
        /// <summary>
        /// Generate shadow
        /// </summary>
        internal void GenerateShadows(BaseGame.RenderHandler renderObjects)
        {
            // Can't generate shadow if loading failed!
            if (effect == null)
                return;

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

            // Time to generate the shadow texture
            DepthStencilBuffer remBackBufferSurface = null;
            // 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);

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

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

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

            // Set render target back to default
            //not required anymore: RenderToTexture.ResetRenderTarget(false);

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

            BaseGame.ViewMatrix = remViewMatrix;
            BaseGame.ProjectionMatrix = remProjMatrix;
        }
示例#2
0
        /// <summary>
        /// Render single pass shader
        /// </summary>
        /// <param name="renderDelegate">Render delegate</param>
        public void RenderSinglePassShader(
			BaseGame.RenderHandler renderCode)
        {
            if (renderCode == null)
                throw new ArgumentNullException("renderCode");

            // Start effect (current technique should be set)
            try
            {
                effect.Begin(SaveStateMode.None);
                // Start first pass
                effect.CurrentTechnique.Passes[0].Begin();

                // Render
                renderCode();

                // End pass and shader
                effect.CurrentTechnique.Passes[0].End();
            } // try
            finally
            {
                effect.End();
            } // finally
        }
示例#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.RenderHandler renderObjects)
        {
            // Can't calc shadows if loading failed!
            if (effect == 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)
                        effect.CurrentTechnique = effect.Techniques["UseShadowMap20"];
                    else
                        effect.CurrentTechnique = effect.Techniques["UseShadowMap"];

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

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

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

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

            // Kill background z buffer (else glass will not be rendered correctly)
            RacingGameManager.Device.Clear(
                ClearOptions.DepthBuffer, Color.Black, 1, 0);
        }
示例#4
0
        /// <summary>
        /// Render
        /// </summary>
        /// <param name="setMat">Set matrix</param>
        /// <param name="passName">Pass name</param>
        /// <param name="renderDelegate">Render delegate</param>
        public void Render(Material setMat,
			string techniqueName,
			BaseGame.RenderHandler renderCode)
        {
            if (techniqueName == null)
                throw new ArgumentNullException("techniqueName");
            if (renderCode == null)
                throw new ArgumentNullException("renderCode");

            SetParameters(setMat);

            // 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
            effect.CurrentTechnique = effect.Techniques[techniqueName];
            try
            {
                effect.Begin(SaveStateMode.None);

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

                    pass.Begin();
                    renderCode();
                    pass.End();
                } // foreach (pass)
            } // try
            finally
            {
                // End shader
                effect.End();
            } // finally
        }
示例#5
0
        /// <summary>
        /// Render
        /// </summary>
        /// <param name="techniqueName">Technique name</param>
        /// <param name="renderDelegate">Render delegate</param>
        public void Render(string techniqueName,
			BaseGame.RenderHandler renderDelegate)
        {
            Render(null, techniqueName, renderDelegate);
        }
 public ScreenshotCapturer(BaseGame setGame)
     : base(setGame)
 {
     game = setGame;
     screenshotNum = GetCurrentScreenshotNum();
 }
        /// <summary>
        /// Generate shadow
        /// </summary>
        internal void GenerateShadows(BaseGame.RenderHandler renderObjects)
        {
            // Can't generate shadow if loading failed!
            if (effect == null)
                return;

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

            // Time to generate the shadow texture
            // Start rendering onto the shadow map
            shadowMapTexture.SetRenderTarget();

            // Make sure depth buffer is on
            BaseGame.Device.DepthStencilState = DepthStencilState.Default;
            // Disable alpha
            BaseGame.Device.BlendState = BlendState.Opaque;

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

            effect.CurrentTechnique = effect.Techniques["GenerateShadowMap20"];

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

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

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

            BaseGame.ViewMatrix = remViewMatrix;
            BaseGame.ProjectionMatrix = remProjMatrix;
        }
示例#8
0
        /// <summary>
        /// Render shadows
        /// </summary>
        /// <param name="renderCode">Render code</param>
        public void RenderShadows(BaseGame.RenderHandler renderCode)
        {
            if (renderCode == null)
                throw new ArgumentNullException("renderCode");

            // Render into our scene map texture
            sceneMapTexture.SetRenderTarget();

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

            // Render everything
            renderCode();

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

            // Restore back buffer as render target
            //obs: RenderToTexture.ResetRenderTarget(false);
        }
        /// <summary>
        /// Render single pass shader
        /// </summary>
        /// <param name="renderDelegate">Render delegate</param>
        public void RenderSinglePassShader(
            BaseGame.RenderHandler renderCode)
        {
            if (renderCode == null)
                throw new ArgumentNullException("renderCode");

            // Start effect (current technique should be set)

                // Start first pass
                effect.CurrentTechnique.Passes[0].Apply();

                // Render
                renderCode();

        }
        /// <summary>
        /// Render
        /// </summary>
        /// <param name="setMat">Set matrix</param>
        /// <param name="passName">Pass name</param>
        /// <param name="renderDelegate">Render delegate</param>
        public void Render(Material setMat,
            string techniqueName,
            BaseGame.RenderHandler renderCode)
        {
            if (techniqueName == null)
                throw new ArgumentNullException("techniqueName");
            if (renderCode == null)
                throw new ArgumentNullException("renderCode");

            SetParameters(setMat);

            // Start shader
            effect.CurrentTechnique = effect.Techniques[techniqueName];


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

                    pass.Apply();
                    renderCode();
                }
        }