Пример #1
0
        internal static void CreateScreenResources()
        {
            var width   = m_resolution.X;
            var height  = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            if (MyGBuffer.Main == null)
            {
                MyGBuffer.Main = new MyGBuffer();
            }
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            m_resolvedLight = new MyRenderTarget(width, height, Format.R11G11B10_Float, 1, 0);
            m_reduce0       = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce0.SetDebugName("reduce0");
            m_reduce1 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce1.SetDebugName("reduce1");
            m_uav3 = new MyUnorderedAccessTexture(width, height, Format.R11G11B10_Float);

            m_localLum = new MyUnorderedAccessTexture(
                (width + MyLuminanceAverage.NumThreads - 1) / MyLuminanceAverage.NumThreads,
                (height + MyLuminanceAverage.NumThreads - 1) / MyLuminanceAverage.NumThreads,
                Format.R32_Float);

            m_div2   = new MyUnorderedAccessTexture(width / 2, height / 2, Format.R11G11B10_Float);
            m_div4   = new MyUnorderedAccessTexture(width / 4, height / 4, Format.R11G11B10_Float);
            m_div8   = new MyUnorderedAccessTexture(width / 8, height / 8, Format.R11G11B10_Float);
            m_div8_1 = new MyUnorderedAccessTexture(width / 8, height / 8, Format.R11G11B10_Float);

            m_rgba8_linear = new MyUnorderedAccessTexture(width, height, Format.R8G8B8A8_UNorm);

            m_rgba8_0 = new MyCustomTexture(width, height, BindFlags.RenderTarget | BindFlags.ShaderResource, Format.R8G8B8A8_Typeless);
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView
            });
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView
            });
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView
            });

            m_rgba8_1 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            m_rgba8_2 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            if (samples > 1)
            {
                m_rgba8_ms = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, samples, 0);
            }
            m_prevLum = new MyUnorderedAccessTexture(1, 1, Format.R32G32_Float);

            Debug.Assert(m_shadowsHelper == RwTexId.NULL);
            m_shadowsHelper  = MyRwTextures.CreateUav2D(width, height, Format.R8_UNorm, "cascade shadows gather");
            m_shadowsHelper1 = MyRwTextures.CreateUav2D(width, height, Format.R8_UNorm, "cascade shadows gather 2");

            m_gbuffer1Copy = MyRwTextures.CreateScratch2D(width, height, Format.R8G8B8A8_UNorm, samples, 0, "gbuffer 1 copy");
        }
Пример #2
0
        internal static void CreateScreenResources()
        {
            var width   = m_resolution.X;
            var height  = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            MyUtils.Init(ref MyGBuffer.Main);
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            m_reduce0 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce0.SetDebugName("reduce0");
            m_reduce1 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce1.SetDebugName("reduce1");
            m_uav3 = new MyUnorderedAccessTexture(width, height, MyGBuffer.LBufferFormat);

            m_transparencyAccum    = new MyUnorderedAccessTexture(width, height, Format.R16G16B16A16_Float);
            m_transparencyCoverage = new MyUnorderedAccessTexture(width, height, Format.R8_UNorm);

            HalfScreenUavHDR         = new MyUnorderedAccessTexture(width / 2, height / 2, MyGBuffer.LBufferFormat);
            QuarterScreenUavHDR      = new MyUnorderedAccessTexture(width / 4, height / 4, MyGBuffer.LBufferFormat);
            EighthScreenUavHDR       = new MyUnorderedAccessTexture(width / 8, height / 8, MyGBuffer.LBufferFormat);
            EighthScreenUavHDRHelper = new MyUnorderedAccessTexture(width / 8, height / 8, MyGBuffer.LBufferFormat);

            m_rgba8_linear = new MyUnorderedAccessTexture(width, height, Format.R8G8B8A8_UNorm);

            m_rgba8_0 = new MyCustomTexture(width, height, BindFlags.RenderTarget | BindFlags.ShaderResource, Format.R8G8B8A8_Typeless);
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView
            });
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView
            });
            m_rgba8_0.AddView(new MyViewKey {
                Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView
            });

            m_rgba8_1 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            m_rgba8_2 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            if (samples > 1)
            {
                m_rgba8_ms = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, samples, 0);
            }
            m_prevLum = new MyUnorderedAccessTexture(1, 1, Format.R32G32_Float);

            Debug.Assert(PostProcessedShadows == RwTexId.NULL);
            Debug.Assert(CascadesHelper == RwTexId.NULL);
            PostProcessedShadows = MyRwTextures.CreateUavRenderTarget(width, height, Format.R8_UNorm);
            CascadesHelper       = MyRwTextures.CreateRenderTarget(width, height, Format.R8_UNorm);

            m_gbuffer1Copy = MyRwTextures.CreateScratch2D(width, height, Format.R8G8B8A8_UNorm, samples, 0, "gbuffer 1 copy");
        }
Пример #3
0
        internal static void CreateScreenResources()
        {
            var width = m_resolution.X;
            var height = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            MyUtils.Init(ref MyGBuffer.Main);
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            m_reduce0 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce0.SetDebugName("reduce0");
            m_reduce1 = new MyUnorderedAccessTexture(width, height, Format.R32G32_Float);
            m_reduce1.SetDebugName("reduce1");
            m_uav3 = new MyUnorderedAccessTexture(width, height, MyGBuffer.LBufferFormat);

            HalfScreenUavHDR = new MyUnorderedAccessTexture(width / 2, height / 2, MyGBuffer.LBufferFormat);
            QuarterScreenUavHDR = new MyUnorderedAccessTexture(width / 4, height / 4, MyGBuffer.LBufferFormat);
            EighthScreenUavHDR = new MyUnorderedAccessTexture(width / 8, height / 8, MyGBuffer.LBufferFormat);
            EighthScreenUavHDRHelper = new MyUnorderedAccessTexture(width / 8, height / 8, MyGBuffer.LBufferFormat);

            m_rgba8_linear = new MyUnorderedAccessTexture(width, height, Format.R8G8B8A8_UNorm);

            m_rgba8_0 = new MyCustomTexture(width, height, BindFlags.RenderTarget | BindFlags.ShaderResource, Format.R8G8B8A8_Typeless);
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView });
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.RtvView });
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView });

            m_rgba8_1 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            m_rgba8_2 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            if (samples > 1)
            {
                m_rgba8_ms = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, samples, 0);
            }
            m_prevLum = new MyUnorderedAccessTexture(1, 1, Format.R32G32_Float);

            Debug.Assert(PostProcessedShadows == RwTexId.NULL);
            Debug.Assert(CascadesHelper == RwTexId.NULL);
            PostProcessedShadows = MyRwTextures.CreateUavRenderTarget(width, height, Format.R8_UNorm);
            CascadesHelper = MyRwTextures.CreateRenderTarget(width, height, Format.R8_UNorm);

            m_gbuffer1Copy = MyRwTextures.CreateScratch2D(width, height, Format.R8G8B8A8_UNorm, samples, 0, "gbuffer 1 copy");
        }
        internal static void CreateScreenResources()
        {
            var width = m_resolution.X;
            var height = m_resolution.Y;
            var samples = RenderSettings.AntialiasingMode.SamplesCount();

            if(MyGBuffer.Main == null)
            {
                MyGBuffer.Main = new MyGBuffer();
            }
            MyGBuffer.Main.Resize(width, height, samples, 0);

            MyScreenDependants.Resize(width, height, samples, 0);

            RemoveScreenResources();

            m_resolvedLight = new MyRenderTarget(width, height, Format.R11G11B10_Float, 1, 0);
            m_reduce0 = new MyUnorderedAccessTexture(width, height, Format.R32_Float);
            m_reduce0.SetDebugName("reduce0");
            m_reduce1 = new MyUnorderedAccessTexture(width, height, Format.R32_Float);
            m_reduce1.SetDebugName("reduce1");
            m_uav3 = new MyUnorderedAccessTexture(width, height, Format.R11G11B10_Float);

            m_localLum = new MyUnorderedAccessTexture(
                (width + MyLuminanceAverage.NumThreads - 1) / MyLuminanceAverage.NumThreads,
                (height + MyLuminanceAverage.NumThreads - 1) / MyLuminanceAverage.NumThreads,
                Format.R32_Float);

            m_div2 = new MyUnorderedAccessTexture(width / 2, height / 2, Format.R11G11B10_Float);
            m_div4 = new MyUnorderedAccessTexture(width / 4, height / 4, Format.R11G11B10_Float);
            m_div8 = new MyUnorderedAccessTexture(width / 8, height / 8, Format.R11G11B10_Float);
            m_div8_1 = new MyUnorderedAccessTexture(width / 8, height / 8, Format.R11G11B10_Float);

            m_rgba8_linear = new MyUnorderedAccessTexture(width, height, Format.R8G8B8A8_UNorm);

            m_rgba8_0 = new MyCustomTexture(width, height, BindFlags.RenderTarget | BindFlags.ShaderResource, Format.R8G8B8A8_Typeless);
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm, View = MyViewEnum.RtvView });
            m_rgba8_0.AddView(new MyViewKey { Fmt = Format.R8G8B8A8_UNorm_SRgb, View = MyViewEnum.SrvView });

            m_rgba8_1 = new MyRenderTarget(width, height, Format.R8G8B8A8_UNorm_SRgb, 1, 0);
            m_prevLum = new MyUnorderedAccessTexture(1, 1, Format.R32_Float);

            Debug.Assert(m_shadowsHelper == RwTexId.NULL);
            m_shadowsHelper = MyRwTextures.CreateUav2D(width, height, Format.R8_UNorm, "cascade shadows gather");
            m_shadowsHelper1 = MyRwTextures.CreateUav2D(width, height, Format.R8_UNorm, "cascade shadows gather 2");
        }
Пример #5
0
 public void Init(MyCustomTexture owner, Format format)
 {
     m_owner = owner;
     m_format = format;
 }
Пример #6
0
        private unsafe static byte[] GetScreenData(Vector2I resolution, byte[] screenData = null)
        {
            const uint headerPadding    = 256; // Need to allocate some space for the bitmap headers
            const uint bytesPerPixel    = 4;
            uint       imageSizeInBytes = (uint)(resolution.Size() * bytesPerPixel);
            uint       dataSizeInBytes  = imageSizeInBytes + headerPadding;

            byte[] returnData = null;
            if (screenData == null)
            {
                screenData = new byte[imageSizeInBytes];
            }
            else if (screenData.Length != imageSizeInBytes)
            {
                Debug.Fail("Preallocated buffer for GetScreenData incorrect size: " + imageSizeInBytes.ToString() + " expected, " + screenData.Length + " received");
                return(returnData);
            }

            MyBindableResource imageSource             = Backbuffer;
            MyBindableResource imageSourceResourceView = null;

            if (imageSource != null && (resolution.X != imageSource.GetSize().X || resolution.Y != imageSource.GetSize().Y))
            {
                MyViewKey viewKey = new MyViewKey {
                    View = MyViewEnum.SrvView, Fmt = MyRender11Constants.DX11_BACKBUFFER_FORMAT
                };
                if (m_backbufferCopyResource == null)
                {
                    m_backbufferCopyResource = new MyCustomTexture(m_resolution.X, m_resolution.Y, BindFlags.ShaderResource, MyRender11Constants.DX11_BACKBUFFER_FORMAT);
                    m_backbufferCopyResource.AddView(viewKey);
                }
                MyRenderContext.Immediate.DeviceContext.CopyResource(imageSource.m_resource, m_backbufferCopyResource.m_resource);
                imageSource             = m_backbufferCopyResource;
                imageSourceResourceView = m_backbufferCopyResource.GetView(viewKey);
            }

            if (imageSource == null)
            {
                return(returnData);
            }

            if (imageSizeInBytes > int.MaxValue)
            {
                Debug.Fail("Image size too large to read!");
                return(returnData);
            }

            MyBindableResource imageResource = imageSource;
            bool shouldResize = imageSourceResourceView != null;

            if (shouldResize)
            {
                imageResource = m_lastScreenDataResource;
                if (imageResource == null || (imageResource.GetSize().X != resolution.X || imageResource.GetSize().Y != resolution.Y))
                {
                    if (m_lastScreenDataResource != null && (m_lastScreenDataResource != m_backbufferCopyResource && m_lastScreenDataResource != Backbuffer))
                    {
                        m_lastScreenDataResource.Release();
                    }
                    m_lastScreenDataResource = null;

                    imageResource = new MyRenderTarget(resolution.X, resolution.Y, MyRender11Constants.DX11_BACKBUFFER_FORMAT, 1, 0);
                }
                var RC            = MyRenderContext.Immediate;
                var deviceContext = RC.DeviceContext;
                deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                deviceContext.Rasterizer.SetViewport(0, 0, resolution.X, resolution.Y);
                deviceContext.PixelShader.Set(MyDebugRenderer.BlitTextureShader);
                deviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

                RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, imageResource);
                RC.BindSRV(0, imageSourceResourceView);
                MyDebugRenderer.DrawQuad(0, 0, resolution.X, resolution.Y, MyScreenPass.QuadVS);
                //MyCopyToRT.Run(imageResource, imageSourceResourceView, new MyViewport(resolution));
            }

            m_lastScreenDataResource = imageResource;

            Stream dataStream = m_lastDataStream;

            if (m_lastDataStream == null || m_lastDataStream.Length != dataSizeInBytes)
            {
                if (m_lastDataStream != null)
                {
                    m_lastDataStream.Dispose();
                    m_lastDataStream = null;
                }
                dataStream = new DataStream((int)dataSizeInBytes, true, true);
                dataStream.Seek(0, SeekOrigin.Begin);
            }

            m_lastDataStream = dataStream;

            Resource.ToStream(MyRenderContext.Immediate.DeviceContext, imageResource.m_resource, ImageFileFormat.Bmp, dataStream);

            if (!(dataStream.CanRead && dataStream.CanSeek))
            {
                Debug.Fail("Screen data stream does not support the necessary operations to get the data");
                return(returnData);
            }

            fixed(byte *dataPointer = screenData)
            {
                GetBmpDataFromStream(dataStream, dataPointer, imageSizeInBytes);
            }

            returnData = screenData;

            if (m_lastDataStream != null)
            {
                m_lastDataStream.Seek(0, SeekOrigin.Begin);
            }

            return(returnData);
        }
Пример #7
0
        private unsafe static byte[] GetScreenData(Vector2I resolution, byte[] screenData = null)
        {
            const uint headerPadding = 256; // Need to allocate some space for the bitmap headers
            const uint bytesPerPixel = 4;
            uint imageSizeInBytes = (uint)(resolution.Size() * bytesPerPixel);
            uint dataSizeInBytes = imageSizeInBytes + headerPadding;

            byte[] returnData = null;
            if(screenData == null)
                screenData = new byte[imageSizeInBytes];
            else if(screenData.Length != imageSizeInBytes)
            {
                Debug.Fail("Preallocated buffer for GetScreenData incorrect size: " + imageSizeInBytes.ToString() + " expected, " + screenData.Length + " received");
                return returnData;
            }

            MyBindableResource imageSource = Backbuffer;
            MyBindableResource imageSourceResourceView = null;

            if (imageSource != null && (resolution.X != imageSource.GetSize().X || resolution.Y != imageSource.GetSize().Y))
            {
                MyViewKey viewKey = new MyViewKey { View = MyViewEnum.SrvView, Fmt = MyRender11Constants.DX11_BACKBUFFER_FORMAT };
                if(m_backbufferCopyResource == null)
                {
                    m_backbufferCopyResource = new MyCustomTexture(m_resolution.X, m_resolution.Y, BindFlags.ShaderResource, MyRender11Constants.DX11_BACKBUFFER_FORMAT);
                    m_backbufferCopyResource.AddView(viewKey);
                }
                MyRenderContext.Immediate.DeviceContext.CopyResource(imageSource.m_resource, m_backbufferCopyResource.m_resource);
                imageSource = m_backbufferCopyResource;
                imageSourceResourceView = m_backbufferCopyResource.GetView(viewKey);
            }

            if (imageSource == null)
                return returnData;

            if(imageSizeInBytes > int.MaxValue)
            {
                Debug.Fail("Image size too large to read!");
                return returnData;
            }

            MyBindableResource imageResource = imageSource;
            bool shouldResize = imageSourceResourceView != null;
            if (shouldResize)
            {
                imageResource = m_lastScreenDataResource;
                if (imageResource == null || (imageResource.GetSize().X != resolution.X || imageResource.GetSize().Y != resolution.Y))
                {
                    if (m_lastScreenDataResource != null && (m_lastScreenDataResource != m_backbufferCopyResource && m_lastScreenDataResource != Backbuffer))
                    {
                        m_lastScreenDataResource.Release();
                    }
                    m_lastScreenDataResource = null;

                    imageResource = new MyRenderTarget(resolution.X, resolution.Y, MyRender11Constants.DX11_BACKBUFFER_FORMAT, 1, 0);
                }
                var RC = MyRenderContext.Immediate;
                var deviceContext = RC.DeviceContext;
                deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                deviceContext.Rasterizer.SetViewport(0, 0, resolution.X, resolution.Y);
                deviceContext.PixelShader.Set(MyDebugRenderer.BlitTextureShader);
                deviceContext.PixelShader.SetConstantBuffer(MyCommon.FRAME_SLOT, MyCommon.FrameConstants);

                RC.BindDepthRT(null, DepthStencilAccess.ReadWrite, imageResource);
                RC.BindSRV(0, imageSourceResourceView);
                MyDebugRenderer.DrawQuad(0, 0, resolution.X, resolution.Y, MyScreenPass.QuadVS);
                //MyCopyToRT.Run(imageResource, imageSourceResourceView, new MyViewport(resolution));
            }

            m_lastScreenDataResource = imageResource;

            Stream dataStream = m_lastDataStream;
            if (m_lastDataStream == null || m_lastDataStream.Length != dataSizeInBytes)
            {
                if (m_lastDataStream != null)
                {
                    m_lastDataStream.Dispose();
                    m_lastDataStream = null;
                }
                dataStream = new DataStream((int)dataSizeInBytes, true, true);
                dataStream.Seek(0, SeekOrigin.Begin);
            }

            m_lastDataStream = dataStream;

            Resource.ToStream(MyRenderContext.Immediate.DeviceContext, imageResource.m_resource, ImageFileFormat.Bmp, dataStream);

            if (!(dataStream.CanRead && dataStream.CanSeek))
            {
                Debug.Fail("Screen data stream does not support the necessary operations to get the data");
                return returnData;
            }

            fixed (byte* dataPointer = screenData)
            {
                GetBmpDataFromStream(dataStream, dataPointer, imageSizeInBytes);
            }

            returnData = screenData;

            if (m_lastDataStream != null)
                m_lastDataStream.Seek(0, SeekOrigin.Begin);

            return returnData;
        }