private void updateDirectionalShadows(DirectionalLightRenderer r, FrustumCullerView[] views)
        {
            var mainCamera = game.Camera;

            if (DEBUG_SeperateCullCamera != null)
            {
                mainCamera = DEBUG_SeperateCullCamera;
            }
            int num = 0;

            r.UpdateShadowmap(delegate(OrthographicCamera lightCamera)
            {
                var view = views[0];
                num++;
                var oldCam  = game.Camera;
                game.Camera = lightCamera;
                //TODO: fix culling+removing of elements
                //view.UpdateVisibility(lightCamera.ViewProjection);
                //setMeshRendererVisibles(view);
                meshesRenderer.DrawShadowCastersDepth();
                game.Camera = oldCam;
            }, mainCamera);
        }
예제 #2
0
        public void TestDirectionalLightShadowing()
        {
            var game = new DX11Game();

            game.InitDirectX();
            var device  = game.Device;
            var context = device.ImmediateContext;

            var filledGBuffer = new TestFilledGBuffer(game, 800, 600);

            var light = new DirectionalLightRenderer(game, filledGBuffer.GBuffer);

            light.ShadowsEnabled = true;

            var toggle = false;


            game.GameLoopEvent += delegate
            {
                filledGBuffer.DrawUpdatedGBuffer();


                light.UpdateShadowmap(delegate(OrthographicCamera lightCamera)
                {
                    game.Camera = lightCamera;

                    filledGBuffer.Draw();

                    game.Camera = game.SpectaterCamera;
                }, game.SpectaterCamera);


                game.SetBackbuffer();

                if (game.Keyboard.IsKeyPressed(Key.C))
                {
                    toggle = !toggle;
                }

                if (toggle)
                {
                    light.LightDirection = game.SpectaterCamera.CameraDirection;
                }


                if (game.Keyboard.IsKeyDown(Key.I))
                {
                    GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer);
                }
                else
                {
                    light.Draw();
                    game.TextureRenderer.Draw(light.CSMRenderer.ShadowMapRV, new Vector2(10, 10), new Vector2(590, 200));
                    for (int i = 0; i < 6; i++)
                    {
                        //game.LineManager3D.AddViewFrustum(light.LightCameras[i].ViewProjection,
                        //new Color4(0, 1, 0));
                    }
                }
            };

            game.Run();
        }