Пример #1
0
        public void TestToneMap()
        {
            var game = new DX11Game();

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


            var toneMap = new ToneMapRenderer(game);


            var hdrImage = Texture2D.FromFile(device, HdrImageDDS);

            var hdrImageRV = new ShaderResourceView(device, hdrImage);

            var avgLuminance = 1f;

            game.GameLoopEvent += delegate
            {
                if (game.Keyboard.IsKeyDown(Key.UpArrow))
                {
                    avgLuminance += game.Elapsed;
                }
                if (game.Keyboard.IsKeyDown(Key.DownArrow))
                {
                    avgLuminance -= game.Elapsed;
                }

                toneMap.DrawTonemapped(hdrImageRV, avgLuminance);
            };

            game.Run();
        }
        public void Draw()
        {
            resetDevice();

            drawGBuffer(GBuffer);
            drawLines(GBuffer);
            drawLights(combineFinalRenderer);
            updateSSAO();

            drawCombinedHdrImage(hdrImageRtv, GBuffer, combineFinalRenderer, skyColorRV, ssao.MSsaoBuffer.pSRV);
            updateTonemapLuminance(calculater);

            context.ClearState();
            game.SetBackbuffer();
            context.OutputMerger.SetTargets(postProcessRT1.RTV);

            toneMap.DrawTonemapped(hdrImageRV, calculater.CurrAverageLumRV);

            context.ClearState();
            game.SetBackbuffer();
            fogRenderer.PostProcessFog(postProcessRT1.RV, GBuffer, postProcessRT2.RTV);
            context.ClearState();
            game.SetBackbuffer();

            game.TextureRenderer.Draw(postProcessRT2.RV, new Vector2(0, 0), new Vector2(screenWidth, screenHeight));
            // TODO: currently cheat
            context.OutputMerger.SetTargets(GBuffer.DepthStencilView, game.BackBufferRTV);

            //game.TextureRenderer.Draw(hdrImageRV, new Vector2(10, 10), new Vector2(100, 100));
            //drawLines();
            //game.TextureRenderer.Draw(directionalLightRenderer.CSMRenderer.ShadowMapRV, new Vector2(10, 10), new Vector2(550, 200));


            //var currAv = readPixel<float>(calculater.CurrAverageLumRV.Resource);
            //var av = 1e-5 + (float)Math.Exp(readPixel<float>(calculater.AverageLuminanceRV.Resource));
            //var text = string.Format("Average: {0:00.000}  Curr: {1:00.000}", av, currAv);
            //game.AddToWindowTitle(" " + text);
            //Console.WriteLine(text);
        }
Пример #3
0
        public void TestFog()
        {
            var game = new DX11Game();

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



            var desc = new Texture2DDescription
            {
                BindFlags =
                    BindFlags.RenderTarget | BindFlags.ShaderResource,
                Format            = Format.R16G16B16A16_Float,
                Width             = 800,
                Height            = 600,
                ArraySize         = 1,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.GenerateMipMaps
            };
            var hdrImage = new Texture2D(device, desc);

            var hdrImageRTV = new RenderTargetView(device, hdrImage);
            var hdrImageRV  = new ShaderResourceView(device, hdrImage);


            var desc2 = new Texture2DDescription
            {
                BindFlags =
                    BindFlags.RenderTarget | BindFlags.ShaderResource,
                Format            = Format.R8G8B8A8_UNorm,
                Width             = 800,
                Height            = 600,
                ArraySize         = 1,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.GenerateMipMaps
            };

            var toneMappedImage = new Texture2D(device, desc2);

            var toneMappedImageRTV = new RenderTargetView(device, toneMappedImage);
            var toneMappedImageRV  = new ShaderResourceView(device, toneMappedImage);

            var foggedImage = new Texture2D(device, desc2);

            var foggedImageRTV = new RenderTargetView(device, foggedImage);
            var foggedImageRV  = new ShaderResourceView(device, foggedImage);


            var calculater = new AverageLuminanceCalculater(game, hdrImageRV);

            var toneMap = new ToneMapRenderer(game);

            var combineFinal = new TestCombineFinalClass(game);

            var fogRenderer = new FogEffect(game);

            game.GameLoopEvent += delegate
            {
                combineFinal.DrawUpdatedDeferredRendering();
                if (game.Keyboard.IsKeyDown(Key.I))
                {
                    return;
                }
                context.Rasterizer.SetViewports(new Viewport(0, 0, 800, 600));

                context.OutputMerger.SetTargets(hdrImageRTV);

                combineFinal.DrawCombined();



                calculater.DrawUpdatedLogLuminance();
                calculater.DrawUpdatedAdaptedLogLuminance();

                context.ClearState();
                game.SetBackbuffer();
                context.OutputMerger.SetTargets(toneMappedImageRTV);



                if (game.Keyboard.IsKeyDown(Key.K))
                {
                    game.TextureRenderer.Draw(calculater.AverageLuminanceRV, new Vector2(10, 10),
                                              new Vector2(300, 300));
                    game.TextureRenderer.Draw(hdrImageRV, new Vector2(320, 10),
                                              new Vector2(300, 300));
                    game.TextureRenderer.Draw(calculater.CurrAverageLumRV, new Vector2(10, 320),
                                              new Vector2(270, 270));
                }
                else
                {
                    toneMap.DrawTonemapped(hdrImageRV, calculater.CurrAverageLumRV);
                }


                context.ClearState();
                game.SetBackbuffer();
                fogRenderer.PostProcessFog(toneMappedImageRV, combineFinal.FilledGBuffer.GBuffer, foggedImageRTV);
                context.ClearState();
                game.SetBackbuffer();
                //context.ClearRenderTargetView(foggedImageRTV, new Color4(1, 1, 0));
                game.TextureRenderer.Draw(foggedImageRV, new Vector2(0, 0), new Vector2(800, 600));
            };

            game.Run();
        }
Пример #4
0
        public void TestAutoAdjustTonemap()
        {
            var game = new DX11Game();

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



            var hdrImage1 = Texture2D.FromFile(device, HdrImageDDS);

            var hdrImage1RV = new ShaderResourceView(device, hdrImage1);



            var desc = new Texture2DDescription
            {
                BindFlags =
                    BindFlags.RenderTarget | BindFlags.ShaderResource,
                Format            = Format.R16G16B16A16_Float,
                Width             = 300,
                Height            = 300,
                ArraySize         = 1,
                SampleDescription = new SampleDescription(1, 0),
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.GenerateMipMaps
            };
            var hdrImage = new Texture2D(device, desc);

            var hdrImageRTV = new RenderTargetView(device, hdrImage);
            var hdrImageRV  = new ShaderResourceView(device, hdrImage);

            var calculater = new AverageLuminanceCalculater(game, hdrImageRV);

            var toneMap = new ToneMapRenderer(game);

            game.GameLoopEvent += delegate
            {
                context.Rasterizer.SetViewports(new Viewport(0, 0, 300, 300));

                context.OutputMerger.SetTargets(hdrImageRTV);

                if (game.Keyboard.IsKeyPressed(Key.D1))
                {
                    game.TextureRenderer.Draw(hdrImage1RV, new Vector2(), new Vector2(300, 300));
                }
                if (game.Keyboard.IsKeyPressed(Key.D2))
                {
                    context.ClearRenderTargetView(hdrImageRTV, new Color4(1, 1, 1, 1));
                }


                calculater.DrawUpdatedLogLuminance();
                calculater.DrawUpdatedAdaptedLogLuminance();

                context.ClearState();
                game.SetBackbuffer();


                //game.TextureRenderer.Draw(calculater.AverageLuminanceRV, new Vector2(10, 10),
                //                          new Vector2(300, 300));
                game.TextureRenderer.Draw(hdrImageRV, new Vector2(320, 10),
                                          new Vector2(300, 300));
                game.TextureRenderer.Draw(calculater.CurrAverageLumRV, new Vector2(10, 320),
                                          new Vector2(270, 270));

                context.Rasterizer.SetViewports(new Viewport(10, 10, 300, 300));

                toneMap.DrawTonemapped(hdrImageRV, calculater.CurrAverageLumRV);
            };

            game.Run();
        }