예제 #1
0
        public void TestDirectionalLightAccumulation()
        {
            //TODO: add a way to show the specular in the alpha channel

            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);

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

                game.SetBackbuffer();

                if (game.Keyboard.IsKeyDown(Key.C))
                {
                    game.SpectaterCamera.Enabled = false;

                    var mat = Matrix.RotationY(game.Mouse.RelativeX * game.Elapsed * 5) * Matrix.RotationX(game.Mouse.RelativeY * game.Elapsed * 5);

                    light.LightDirection = Vector3.TransformNormal(light.LightDirection, mat);
                }
                else
                {
                    game.SpectaterCamera.Enabled = true;
                }

                if (game.Keyboard.IsKeyDown(Key.I))
                {
                    GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer);
                }
                else
                {
                    light.Draw();
                }
            };

            game.Run();
        }
예제 #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();
        }
예제 #3
0
        public void TestMultipleLightAccumulation()
        {
            //TODO: add a way to show the specular in the alpha channel

            var game = new DX11Game();

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

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

            var spot        = new SpotLightRenderer(game, filledGBuffer.GBuffer);
            var point       = new PointLightRenderer(game, filledGBuffer.GBuffer);
            var directional = new DirectionalLightRenderer(game, filledGBuffer.GBuffer);

            var state = 0;

            var bsDesc = new BlendStateDescription();
            var b      = new RenderTargetBlendDescription();

            b.BlendEnable           = true;
            b.BlendOperation        = BlendOperation.Add;
            b.BlendOperationAlpha   = BlendOperation.Add;
            b.DestinationBlend      = BlendOption.One;
            b.DestinationBlendAlpha = BlendOption.One;
            b.SourceBlend           = BlendOption.One;
            b.SourceBlendAlpha      = BlendOption.One;
            b.RenderTargetWriteMask = ColorWriteMaskFlags.All;
            bsDesc.RenderTargets[0] = b;


            var blendState = BlendState.FromDescription(device, bsDesc);
            var depthState = DepthStencilState.FromDescription(device, new DepthStencilStateDescription
            {
                IsDepthEnabled   = false,
                IsStencilEnabled = false,
            });


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

                game.SetBackbuffer();

                if (game.Keyboard.IsKeyPressed(Key.D1))
                {
                    state = 0;
                }
                if (game.Keyboard.IsKeyPressed(Key.D2))
                {
                    state = 1;
                }
                if (game.Keyboard.IsKeyPressed(Key.D3))
                {
                    state = 2;
                }
                if (game.Keyboard.IsKeyPressed(Key.D4))
                {
                    state = 3;
                }

                switch (state)
                {
                case 0:
                    break;

                case 1:
                    directional.LightDirection = game.SpectaterCamera.CameraDirection;
                    break;

                case 2:
                    point.LightPosition = game.SpectaterCamera.CameraPosition;

                    break;

                case 3:
                    spot.LightPosition = game.SpectaterCamera.CameraPosition;
                    spot.SpotDirection = game.SpectaterCamera.CameraDirection;
                    break;
                }



                if (game.Keyboard.IsKeyDown(Key.I))
                {
                    GBufferTest.DrawGBuffer(game, filledGBuffer.GBuffer);
                }
                else
                {
                    context.OutputMerger.DepthStencilState = depthState;
                    directional.Draw();
                    context.OutputMerger.BlendState = blendState;
                    spot.Draw();
                    point.Draw();
                    context.OutputMerger.BlendState        = null;
                    context.OutputMerger.DepthStencilState = null;
                }
            };

            game.Run();
        }
예제 #4
0
            public void DrawUpdatedDeferredRendering()
            {
                FilledGBuffer.DrawUpdatedGBuffer();


                if (game.Keyboard.IsKeyPressed(Key.D1))
                {
                    state = 0;
                }
                if (game.Keyboard.IsKeyPressed(Key.D2))
                {
                    state = 1;
                }
                if (game.Keyboard.IsKeyPressed(Key.D3))
                {
                    state = 2;
                }
                if (game.Keyboard.IsKeyPressed(Key.D4))
                {
                    state = 3;
                }

                switch (state)
                {
                case 0:
                    break;

                case 1:
                    directional.LightDirection = game.SpectaterCamera.CameraDirection;
                    break;

                case 2:
                    point.LightPosition = game.SpectaterCamera.CameraPosition;

                    break;

                case 3:
                    spot.LightPosition = game.SpectaterCamera.CameraPosition;
                    spot.SpotDirection = game.SpectaterCamera.CameraDirection;
                    break;
                }



                if (game.Keyboard.IsKeyDown(Key.I))
                {
                    context.ClearState();
                    game.SetBackbuffer();
                    GBufferTest.DrawGBuffer(game, FilledGBuffer.GBuffer);
                }
                else
                {
                    combineFinal.ClearLightAccumulation();
                    combineFinal.SetLightAccumulationStates();
                    directional.Draw();
                    spot.Draw();
                    point.Draw();



                    context.ClearState();
                    game.SetBackbuffer(); // This is to set viewport, not sure this is correct

                    context.OutputMerger.SetTargets(hdrImageRTV);
                    DrawCombined();
                }



                if (game.Keyboard.IsKeyPressed(Key.O))
                {
                    Resource.SaveTextureToFile(game.Device.ImmediateContext, hdrImage, ImageFileFormat.Dds,
                                               TWDir.Test.CreateSubdirectory("Deferred") + "\\HdrImage.dds");
                }
            }