Example #1
0
        public void ShotToFile(int width, int height, string outputFile)
        {
            _width  = width;
            _height = height;

            DxResize();
            DrawFrame();

            var tmpTexture = new Texture2D(CurrentDevice, new Texture2DDescription {
                Width             = _width,
                Height            = _height,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.R8G8B8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None
            });

            var tmpRenderTarget = new RenderTargetView(CurrentDevice, tmpTexture);

            DrawPreviousFrameTo(tmpRenderTarget);

            Resource.SaveTextureToFile(_context, tmpTexture, outputFile.EndsWith(".jpg") ? ImageFileFormat.Jpg :
                                       outputFile.EndsWith(".bmp") ? ImageFileFormat.Bmp : ImageFileFormat.Png, outputFile);
            tmpRenderTarget.Dispose();
            tmpTexture.Dispose();
        }
        public void ShotBodyShadow(string outputFile)
        {
            _width  = 512;
            _height = 512;

            foreach (var obj in _objs.Where(obj => obj.Blen != null))
            {
                obj.Blen.Dispose();
                obj.Blen = null;
            }

            ShotBodyShadow_SetCamera();

            DxResize();
            DrawFrame();

            var doubleSided = RasterizerState.FromDescription(CurrentDevice, new RasterizerStateDescription {
                FillMode = FillMode.Solid,
                CullMode = CullMode.None,
                IsFrontCounterclockwise = true,
                IsDepthClipEnabled      = false
            });

            var tmpTexture = new Texture2D(CurrentDevice, new Texture2DDescription {
                Width             = _width,
                Height            = _height,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.R8G8B8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None
            });

            _effectShotBodyShadow = new EffectShotBodyShadow(CurrentDevice);

            var tmpRenderTarget = new RenderTargetView(CurrentDevice, tmpTexture);

            DrawPreviousBodyDepthTo(tmpRenderTarget, doubleSided);
            BlurBodyShadow(tmpTexture, 1);
            BlurSomething(tmpTexture, 5, 2f / AmbientBodyShadowSize.X, 2f / AmbientBodyShadowSize.Z);

            Resource.SaveTextureToFile(_context, tmpTexture, ImageFileFormat.Png, outputFile);

            _effectShotBodyShadow.Dispose();
            tmpRenderTarget.Dispose();
            tmpTexture.Dispose();
            doubleSided.Dispose();
        }
Example #3
0
        public void ShotTrackMap(string outputFile, Regex surfaceFilter, out TrackMapInformation information)
        {
            information = new TrackMapInformation {
                Margin = DefaultMargin
            };

            var bb = new BoundingBox(new Vector3(float.MaxValue), new Vector3(float.MinValue));

            var oldObjs = _objs;

            _objs = _objs.Where(x => surfaceFilter.IsMatch(x.Name)).ToList();

            try {
                foreach (var obj in _objs)
                {
                    if (obj.Blen != null)
                    {
                        obj.Blen.Dispose();
                        obj.Blen = null;
                    }

                    obj.Mat.MinAlpha = 1.0f;
                    obj.Mat.Diffuse  = obj.Mat.Ambient = new Color4(1.0f, 0.0f, 0.0f, 0.0f);

                    var meshObj = obj as MeshObjectKn5;
                    if (meshObj == null)
                    {
                        continue;
                    }

                    bb = bb.Expand(meshObj.MeshBox);
                }

                if (bb.Minimum.X > bb.Maximum.X)
                {
                    throw new ShotException("Surface not found");
                }

                Console.WriteLine(@"BB: {0} / {1}", bb.Minimum, bb.Maximum);

                _width  = (int)(bb.GetSizeX() + DefaultMargin * 2);
                _height = (int)(bb.GetSizeZ() + DefaultMargin * 2);

                information.Width   = bb.GetSizeX() + DefaultMargin * 2;
                information.Height  = bb.GetSizeZ() + DefaultMargin * 2;
                information.XOffset = bb.Maximum.X + DefaultMargin;
                information.ZOffset = -bb.Minimum.Z - DefaultMargin;

                ShotTrackMap_SetCamera(bb);

                DxResize();
                DrawFrame();

                var tmpTexture = new Texture2D(CurrentDevice, new Texture2DDescription {
                    Width             = _width,
                    Height            = _height,
                    MipLevels         = 1,
                    ArraySize         = 1,
                    Format            = Format.R8G8B8A8_UNorm,
                    SampleDescription = new SampleDescription(1, 0),
                    Usage             = ResourceUsage.Default,
                    BindFlags         = BindFlags.ShaderResource | BindFlags.RenderTarget,
                    CpuAccessFlags    = CpuAccessFlags.None,
                    OptionFlags       = ResourceOptionFlags.None
                });

                var tmpRenderTarget = new RenderTargetView(CurrentDevice, tmpTexture);
                DrawPreviousFrameTo(tmpRenderTarget);
                BlurSomething(tmpTexture, 1, 1.0f);
                ShotTrackMap_Process(tmpTexture);

                Resource.SaveTextureToFile(_context, tmpTexture, ImageFileFormat.Png, outputFile);
                tmpRenderTarget.Dispose();
                tmpTexture.Dispose();
            } finally {
                _objs = oldObjs;
            }
        }
        public void ShotWheelsShadow(params string[] outputFiles)
        {
            Debug.Assert(outputFiles.Length == 4);

            _width  = 64;
            _height = 64;

            foreach (var obj in _objs.Where(obj => obj.Blen != null))
            {
                obj.Blen.Dispose();
                obj.Blen = null;
            }

            var doubleSided = RasterizerState.FromDescription(CurrentDevice, new RasterizerStateDescription {
                FillMode = FillMode.Solid,
                CullMode = CullMode.None,
                IsFrontCounterclockwise = true,
                IsDepthClipEnabled      = false
            });

            var tmpTexture = new Texture2D(CurrentDevice, new Texture2DDescription {
                Width             = _width,
                Height            = _height,
                MipLevels         = 1,
                ArraySize         = 1,
                Format            = Format.R8G8B8A8_UNorm,
                SampleDescription = new SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
                BindFlags         = BindFlags.ShaderResource | BindFlags.RenderTarget,
                CpuAccessFlags    = CpuAccessFlags.None,
                OptionFlags       = ResourceOptionFlags.None
            });

            _effectShotWheelShadow = new EffectShotWheelShadow(CurrentDevice);
            var tmpRenderTarget = new RenderTargetView(CurrentDevice, tmpTexture);

            {
                Action <Kn5Node> temp = null;

                temp = x => {
                    if (x.Name.StartsWith("WHEEL_"))
                    {
                        return;
                    }
                    if (x.NodeClass == Kn5NodeClass.Base)
                    {
                        foreach (var child in x.Children)
                        {
                            temp(child);
                        }
                    }
                    else
                    {
                        foreach (var obj in _objs.OfType <MeshObjectKn5>().Where(obj => obj.OriginalNode == x))
                        {
                            obj.Visible = false;
                        }
                    }
                };

                temp(_kn5.RootNode);
            }

            var wheels = new[] { _wheelLfPos, _wheelRfPos, _wheelLrPos, _wheelRrPos };

            for (var i = 0; i < wheels.Length; i++)
            {
                ShotWheelShadow_SetCamera(wheels[i]);

                DxResize();
                DrawFrame();

                DrawPreviousWheelDepthTo(tmpRenderTarget, doubleSided);
                BlurWheelShadow(tmpTexture, 1);
                BlurSomething(tmpTexture, 3, 0.4f);

                Resource.SaveTextureToFile(_context, tmpTexture, ImageFileFormat.Png, outputFiles[i]);
            }

            _effectShotWheelShadow.Dispose();
            tmpRenderTarget.Dispose();
            tmpTexture.Dispose();
            doubleSided.Dispose();
        }
            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");
                }
            }