Esempio n. 1
0
        /// <summary>
        /// Test NormalMapping shader
        /// </summary>
        public static void TestNormalMappingShader()
        {
            PlaneRenderer testPlane = null;

            TestGame.Start("TestNormalMappingShader",
                delegate
                {
                    testPlane = new PlaneRenderer(
                        Vector3.Zero, new Plane(new Vector3(0, 0, 1), 0),
                        new Material("CaveDetailGround", "CaveDetailGroundNormal"), 25.0f);
                },
                delegate
                {
                    testPlane.Render(ShaderEffect.normalMapping);//, "DiffuseSpecular20");
                });
        }
Esempio n. 2
0
        //*/

        //*TODO
        /// <summary>
        /// Test shadow mapping
        /// </summary>
        public static void TestShadowMapping()
        {
            PlaneRenderer plane = null;
            //ColladaModel testModel = null;
            // We need a dummy animated model to set the right bones once.
            AnimatedColladaModel dummyAniModel = null;

            TestGame.Start("TestShadowMapping",
                delegate
                {
                    plane = new PlaneRenderer(
                        Vector3.Zero, new Plane(new Vector3(0, 0, 1), 0),
                        new Material(
                        Color.White, Color.White, Color.Black,
                        "CaveDetailGround", "CaveDetailGroundNormal", "", ""),
                        10.0f);
                    //testModel = new ColladaModel(
                        //"Door");
                        //"Hero");
                        //"Sword");
                    dummyAniModel = new AnimatedColladaModel("Hero");
                    //dummy:
                    dummyAniModel.Render(Matrix.Identity);

                    ShaderEffect.shadowMapping.SetVirtualLightPos(
                        new Vector3(0, 0, 2));
                },
                delegate
                {
                    // Start glow shader
                    BaseGame.GlowShader.Start();

                    // Clear background with white color, looks much cooler for the
                    // post screen glow effect.
                    BaseGame.Device.Clear(Color.Black);

                    if (Input.Keyboard.IsKeyDown(Keys.Tab))
                        BaseGame.ViewMatrix = Matrix.CreateLookAt(
                            //Mission.LookAtPosition +
                            BaseGame.LightDirection * ThirdPersonCamera.CameraDistance,
                            Vector3.Zero,//Mission.LookAtPosition,
                            new Vector3(0, 1, 0));

                    Matrix renderMatrix = Matrix.Identity;
                    Matrix groundMatrix = Matrix.Identity;

                    if (Input.Keyboard.IsKeyUp(Keys.LeftAlt) &&
                        Input.GamePadXPressed == false)
                    {
                        // Generate shadows
                        ShaderEffect.shadowMapping.GenerateShadows(
                            delegate
                            {
                                //testModel.GenerateShadow(renderMatrix);
                                dummyAniModel.GenerateShadow(renderMatrix);
                                //dummyAniModel.Render(renderMatrix);
                            });

                        // Render shadows
                        ShaderEffect.shadowMapping.RenderShadows(
                            delegate
                            {
                                //testModel.UseShadow(renderMatrix);
                                dummyAniModel.UseShadow(renderMatrix);
                                plane.UseShadow();
                            });
                    } // if

                    // Restore z buffer state
                    BaseGame.Device.RenderState.DepthBufferEnable = true;
                    BaseGame.Device.RenderState.DepthBufferWriteEnable = true;

                    // Update game time
                    Player.SetGameTimeMs(BaseGame.TotalTimeMs);

                    plane.Render();
                    //testModel.Render(renderMatrix);
                    dummyAniModel.Render(renderMatrix);
                    //unused: BaseGame.MeshRenderManager.Render();

                    Matrix weaponMatrix = dummyAniModel.HandlePlayerFlareAndWeapon();
                    ShaderEffect.shadowMapping.SetVirtualLightPos(
                        AnimatedColladaModel.finalPlayerFlarePos);

                    EffectManager.AddEffect(
                        AnimatedColladaModel.finalPlayerFlarePos,
                        EffectManager.EffectType.Flare, 0.3f, 0);
                    EffectManager.AddEffect(
                        AnimatedColladaModel.finalPlayerFlarePos,
                        EffectManager.EffectType.LightInstant, 0.3f * 2.5f, 0);

                    BaseGame.effectManager.HandleAllEffects();

                    if (Input.Keyboard.IsKeyUp(Keys.LeftAlt) &&
                        Input.GamePadXPressed == false)
                    {
                        ShaderEffect.shadowMapping.ShowShadows();
                    } // if

                    if (Input.Keyboard.IsKeyDown(Keys.LeftShift) ||
                        Input.GamePadAPressed)
                    {
                        //if (Input.KeyboardRightPressed)// == false)
                        ShaderEffect.shadowMapping.shadowMapTexture.RenderOnScreen(
                            new Rectangle(10, 10, 256, 256));
                        //if (Input.KeyboardLeftPressed)// == false)
                        ShaderEffect.shadowMapping.shadowMapBlur.SceneMapTexture.
                            RenderOnScreen(
                            new Rectangle(10 + 256 + 10, 10, 256, 256));
                        // Unused on xbox360
            //#if !XBOX360
                        //ShaderEffect.shadowMapping.shadowMapBlur.BlurMapTexture.
                        //	RenderOnScreen(
                        //	new Rectangle(10 + 256 + 10+256+10, 10, 256, 256));
            //#endif
                    } // if (Input.Keyboard.IsKeyDown)

                    DungeonQuestGame.GlowShader.Show();

                    TextureFont.WriteText(2, 510,
                        "Press left Shift or A to show all shadow pass textures.");
                    TextureFont.WriteText(2, 540,
                        "Press Alt or X to skip shadow map rendering.");
                    TextureFont.WriteText(2, 570,
                        "Camera pos="+BaseGame.CameraPos);//+
                        //", "+ShaderEffect.shadowMapping.shadowMapTexture.ZBufferSurface);
                });
        }