Пример #1
0
 public SimpleCamera(BaseGame game)
     : base(game)
 {
 }
        /// <summary>
        /// Render
        /// </summary>
        /// <param name="setMat">Set matrix</param>
        /// <param name="techniqueName">Technique name</param>
        /// <param name="renderDelegate">Render delegate</param>
        public void RenderCave(Material setMat,
			//auto: List<Vector3> setLightPositions,
			BaseGame.RenderDelegate renderDelegate)
        {
            // And set all the other parameters
            detailGroundDiffuseTexture.SetValue(groundDiffuseTexture.XnaTexture);
            detailGroundNormalTexture.SetValue(groundNormalTexture.XnaTexture);
            detailGroundHeightTexture.SetValue(groundHeightTexture.XnaTexture);
            detailWallDiffuseTexture.SetValue(wallDiffuseTexture.XnaTexture);
            detailWallNormalTexture.SetValue(wallNormalTexture.XnaTexture);
            detailWallHeightTexture.SetValue(wallHeightTexture.XnaTexture);

            // Set all the basic parameters.
            SetParameters(setMat);

            // Set all light positions that are close to us.
            if (LightManager.closestLightsForRendering.Count != 6)
                throw new InvalidOperationException(
                    "You must always set exactly " + LightManager.NumberOfLights +
                    " lights for the shader!");
            lightPositions.SetValue(LightManager.closestLightsForRendering.ToArray());

            // 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();
        }
Пример #3
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
            currentPass = 0;
            xnaEffect.CurrentTechnique.Passes[currentPass].Begin();

            // Render.
            // NOTE: This delegate might change the pass, e.g. used
            // when rendering complex shadow mapping shaders!
            renderDelegate();

            // End pass and shader
            xnaEffect.CurrentTechnique.Passes[currentPass].End();
            xnaEffect.End();
        }
Пример #4
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();

            // Restore back buffer as render target
            BaseGame.ResetRenderTarget(false);
            //*TODO
            if (sceneMapTexture.ZBufferSurface != null)
                BaseGame.Device.DepthStencilBuffer = remBackBufferSurface;
            //*/
        }
Пример #5
0
        /// <summary>
        /// Render
        /// </summary>
        /// <param name="techniqueName">Technique name</param>
        /// <param name="renderDelegate">Render delegate</param>
        public void RenderNoLight(string techniqueName,
			BaseGame.RenderDelegate renderDelegate)
        {
            RenderNoLight(null, techniqueName,
                renderDelegate);
        }
Пример #6
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(
			Material setMat,
			//always use the LightManager! List<Vector3> setLightPositions,
			BaseGame.RenderDelegate renderDelegate)
        {
            SetParameters(setMat);

            // Set all light positions that are close to us.
            //NOTE: We are only using 6 lights for the cave itself, all the
            // static and animated models are just using 3 lights (faster).
            if (LightManager.closestLightsForRendering.Count < 3)
                throw new InvalidOperationException(
                    "You must always have at least 3 lights for the shader!");
            if (lightPositions != null)
                lightPositions.SetValue(
                    LightManager.closestLightsForRendering.GetRange(0, 3).ToArray());

            // 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();
        }
Пример #7
0
 public RotationCamera(BaseGame game)
     : base(game)
 {
 }
Пример #8
0
        /// <summary>
        /// Render
        /// </summary>
        /// <param name="setMat">Set matrix</param>
        /// <param name="techniqueName">Technique name</param>
        /// <param name="renderDelegate">Render delegate</param>
        public void RenderNoLight(Material setMat,
			string techniqueName,
			BaseGame.RenderDelegate renderDelegate)
        {
            SetParameters(setMat);

            /*will become important later in the book.
            // Can we do the requested technique?0
            // 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();
        }
Пример #9
0
 public ScreenshotCapturer(BaseGame setGame)
     : base(setGame)
 {
     game = setGame;
     screenshotNum = GetCurrentScreenshotNum();
 }
Пример #10
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"];
                //not supported for skinning: 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();

                // 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
        }
Пример #11
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"];
                    //unsupported for skinning: 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
            DungeonQuestGame.Device.Clear(
                ClearOptions.DepthBuffer,
                //also kill color!
                //doesn't help: ClearOptions.DepthBuffer | ClearOptions.Target,
                BaseGame.BackgroundColor, 1, 0);
        }
Пример #12
0
 public ThirdPersonCamera(BaseGame game)
     : base(game)
 {
     // Assign keys. Warning: This is VERY slow, never use it
     // inside any render loop (getting Settings, etc.)!
     //Note: Not true anymore for the new GameSettings class, it is faster!
     moveLeftKey = GameSettings.Default.MoveLeftKey;
     moveRightKey = GameSettings.Default.MoveRightKey;
     moveUpKey = GameSettings.Default.MoveForwardKey;
     moveDownKey = GameSettings.Default.MoveBackwardKey;
 }
Пример #13
0
 /// <summary>
 /// Create base camera
 /// </summary>
 /// <param name="game">Game</param>
 public BaseCamera(BaseGame game)
     : base(game)
 {
 }