public void Render(DeviceContext context, Camera camera, Int2 screenResolution, Span <TInstance> instances, int start, int count)
        {
            var vertexConstantsData = new RasterizedVertexConstants
            {
                Projection     = Matrix.Transpose(camera.Projection), //compensate for the shader packing.
                CameraPosition = camera.Position,
                CameraRight    = camera.Right,
                CameraUp       = camera.Up,
                CameraBackward = camera.Backward,
            };

            vertexConstants.Update(context, ref vertexConstantsData);

            //This assumes that render states have been set appropriately for opaque rendering.
            context.InputAssembler.InputLayout       = null;
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            OnDrawSetup(context);
            context.VertexShader.Set(vertexShader);
            context.VertexShader.SetConstantBuffer(0, vertexConstants.Buffer);
            context.VertexShader.SetShaderResource(0, this.instances.SRV);
            context.PixelShader.Set(pixelShader);

            while (count > 0)
            {
                var batchCount = Math.Min(this.instances.Capacity, count);
                this.instances.Update(context, instances, batchCount, start);
                OnBatchDraw(context, batchCount);
                count -= batchCount;
                start += batchCount;
            }
        }
Пример #2
0
        public void Render(DeviceContext context, Int2 screenResolution, UILineInstance[] lines, int start, int count)
        {
            //This assumes that rasterizer, blend, and depth states have been set appropriately for screenspace transparent rendering.
            context.InputAssembler.InputLayout = null;
            context.InputAssembler.SetIndexBuffer(indices);
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.VertexShader.Set(vertexShader);
            context.VertexShader.SetConstantBuffer(0, vertexConstants.Buffer);
            context.VertexShader.SetShaderResource(0, instances.SRV);
            var vertexConstantsData = new VertexConstants
            {
                //The packed minimum must permit subpixel locations. So, distribute the range 0 to 65535 over the pixel range 0 to resolution.
                PackedToScreenScale = new Vector2(screenResolution.X / 65535f, screenResolution.Y / 65535f),
                ScreenToNDCScale    = new Vector2(2f / screenResolution.X, -2f / screenResolution.Y),
            };

            vertexConstants.Update(context, ref vertexConstantsData);
            context.PixelShader.Set(pixelShader);

            while (count > 0)
            {
                var batchCount = Math.Min(instances.Capacity, count);
                instances.Update(context, lines, batchCount, start);
                context.DrawIndexed(batchCount * 6, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Пример #3
0
        public void Render(Camera camera, Int2 screenResolution, Span <TInstance> instances, int start, int count)
        {
            Use();
            vertexConstants.Bind(0);
            this.instances.Bind(0);
            OnDrawSetup();

            var vertexConstantsData = new RasterizedVertexConstants
            {
                Projection     = camera.Projection,
                CameraPosition = camera.Position,
                CameraRight    = camera.Right,
                CameraUp       = camera.Up,
                CameraBackward = camera.Backward,
            };

            vertexConstants.Update(ref vertexConstantsData);

            while (count > 0)
            {
                var batchCount = Math.Min(this.instances.Capacity, count);
                this.instances.Update(instances, batchCount, start);
                OnBatchDraw(batchCount);
                count -= batchCount;
                start += batchCount;
            }
        }
Пример #4
0
        public void Render(DeviceContext context, Camera camera, Int2 resolution, LineInstance[] instances, int start, int count)
        {
            var vertexConstantsData = new VertexConstants
            {
                ViewProjection   = Matrix.Transpose(camera.ViewProjection), //compensate for the shader packing.
                NDCToScreenScale = new Vector2(resolution.X / 2f, resolution.Y / 2f),
                CameraForward    = camera.Forward,
                TanAnglePerPixel = (float)Math.Tan(camera.FieldOfView / resolution.Y),
                CameraRight      = camera.Right,
                CameraPosition   = camera.Position,
            };

            vertexConstants.Update(context, ref vertexConstantsData);

            //This assumes that render states have been set appropriately for opaque rendering.
            context.InputAssembler.InputLayout = null;
            context.InputAssembler.SetIndexBuffer(indices);
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.VertexShader.Set(vertexShader);
            context.VertexShader.SetConstantBuffer(0, vertexConstants.Buffer);
            context.VertexShader.SetShaderResource(0, this.instances.SRV);
            context.PixelShader.Set(pixelShader);

            while (count > 0)
            {
                var batchCount = Math.Min(this.instances.Capacity, count);
                this.instances.Update(context, instances, batchCount, start);
                context.DrawIndexed(batchCount * 36, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Пример #5
0
        public void Render(Font font, Int2 screenResolution, Span <GlyphInstance> glyphs)
        {
            font.Sources.Bind(1);
            GL.BindTexture(TextureTarget.Texture2D, font.Atlas);
            var vertexConstantsData = new VertexConstants {
                //These first two scales could be uploaded once, but it would require another buffer. Not important enough.
                //The packed minimum must permit subpixel locations. So, distribute the range 0 to 65535 over the pixel range 0 to resolution.
                PackedToScreenScale    = new Vector2(screenResolution.X / 65535f, screenResolution.Y / 65535f),
                ScreenToNDCScale       = new Vector2(2f / screenResolution.X, -2f / screenResolution.Y),
                InverseAtlasResolution = new Vector2(1f / font.Content.Atlas.Width, 1f / font.Content.Atlas.Height)
            };

            vertexConstants.Update(ref vertexConstantsData);
            var count = glyphs.Length;
            var start = 0;

            while (count > 0)
            {
                var batchCount = Math.Min(instances.Capacity, count);
                instances.Update(glyphs.Slice(start, batchCount));
                GL.DrawElements(PrimitiveType.Triangles, batchCount * 6, indices.Type, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Пример #6
0
        public void Render(DeviceContext context, Font font, Int2 screenResolution, Span <GlyphInstance> glyphs)
        {
            var vertexConstantsData = new VertexConstants
            {
                //These first two scales could be uploaded once, but it would require another buffer. Not important enough.
                //The packed minimum must permit subpixel locations. So, distribute the range 0 to 65535 over the pixel range 0 to resolution.
                PackedToScreenScale    = new Vector2(screenResolution.X / 65535f, screenResolution.Y / 65535f),
                ScreenToNDCScale       = new Vector2(2f / screenResolution.X, -2f / screenResolution.Y),
                InverseAtlasResolution = new Vector2(1f / font.Content.Atlas.Width, 1f / font.Content.Atlas.Height)
            };

            vertexConstants.Update(context, ref vertexConstantsData);
            context.VertexShader.SetShaderResource(1, font.Sources.SRV);
            context.PixelShader.SetShaderResource(0, font.AtlasSRV);

            var count = glyphs.Length;
            var start = 0;

            while (count > 0)
            {
                var batchCount = Math.Min(instances.Capacity, count);
                instances.Update(context, glyphs.Slice(start, batchCount));
                context.DrawIndexed(batchCount * 6, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Пример #7
0
        public void Render(int source)
        {
            Use();
            constants.Bind(0);
            GL.BindTexture(TextureTarget.Texture2D, source);
            float inverseGamma = 1f / Gamma;

            constants.Update(ref inverseGamma);
            GL.DrawArrays(PrimitiveType.Triangles, 0, 3);
        }
Пример #8
0
        public void Render(DeviceContext context, Camera camera)
        {
            var constantsData = Matrix.Transpose(Matrix.Invert(camera.ViewProjection)); //Compensate for the shader packing we use.

            constants.Update(context, ref constantsData);

            context.InputAssembler.InputLayout       = null;
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.VertexShader.Set(vertexShader);
            context.VertexShader.SetConstantBuffer(0, constants.Buffer);
            context.PixelShader.Set(pixelShader);
            context.Draw(3, 0);
        }
Пример #9
0
        public void Render(DeviceContext context, ShaderResourceView source, RenderTargetView target)
        {
            float inverseGamma = 1f / Gamma;

            constants.Update(context, ref inverseGamma);

            context.OutputMerger.SetRenderTargets(null, target);
            context.OutputMerger.SetDepthStencilState(depthState);
            context.VertexShader.Set(vertexShader);
            context.PixelShader.Set(pixelShader);
            context.PixelShader.SetConstantBuffer(0, constants.Buffer);
            context.PixelShader.SetShaderResource(0, source);
            context.Draw(3, 0);
            context.PixelShader.SetShaderResource(0, null); //Unhook the SRV to allow the underlying resource to be used as an RTV next time around.
        }
Пример #10
0
        public void Render(DeviceContext context, Camera camera, Int2 screenResolution, Span <TInstance> instances, int start, int count)
        {
            var vertexConstantsData = new RayTracedVertexConstants
            {
                Projection     = Matrix.Transpose(camera.Projection), //compensate for the shader packing.
                CameraPosition = camera.Position,
                CameraRight    = camera.Right,
                NearClip       = camera.NearClip,
                CameraUp       = camera.Up,
                CameraBackward = camera.Backward,
            };

            vertexConstants.Update(context, ref vertexConstantsData);
            var viewportHeight     = 2 * (float)Math.Tan(camera.FieldOfView / 2);
            var viewportWidth      = viewportHeight * camera.AspectRatio;
            var pixelConstantsData = new RayTracedPixelConstants
            {
                CameraRight          = camera.Right,
                NearClip             = camera.NearClip,
                CameraUp             = camera.Up,
                FarClip              = camera.FarClip,
                CameraBackward       = camera.Backward,
                PixelSizeAtUnitPlane = new Vector2(viewportWidth / screenResolution.X, viewportHeight / screenResolution.Y)
            };

            pixelConstants.Update(context, ref pixelConstantsData);

            //This assumes that render states have been set appropriately for opaque rendering.
            context.InputAssembler.InputLayout = null;
            context.InputAssembler.SetIndexBuffer(indices);
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.VertexShader.Set(vertexShader);
            context.VertexShader.SetConstantBuffer(0, vertexConstants.Buffer);
            context.VertexShader.SetShaderResource(0, this.instances.SRV);
            context.PixelShader.Set(pixelShader);
            context.PixelShader.SetConstantBuffer(1, pixelConstants.Buffer);

            while (count > 0)
            {
                var batchCount = Math.Min(this.instances.Capacity, count);
                this.instances.Update(context, instances, batchCount, start);
                context.DrawIndexed(batchCount * 36, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Пример #11
0
        public void Render(DeviceContext context, Camera camera, SphereInstance[] instances, int start, int count)
        {
            var vertexConstantsData = new VertexConstants
            {
                Projection     = Matrix.Transpose(camera.Projection), //compensate for the shader packing.
                CameraPosition = camera.Position,
                CameraRight    = camera.Right,
                NearClip       = camera.NearClip,
                CameraUp       = camera.Up,
                CameraBackward = camera.Backward,
            };

            vertexConstants.Update(context, ref vertexConstantsData);
            var pixelConstantsData = new PixelConstants
            {
                CameraForward = camera.Forward,
                NearClip      = camera.NearClip,
                FarClip       = camera.FarClip
            };

            pixelConstants.Update(context, ref pixelConstantsData);

            //This assumes that render states have been set appropriately for opaque rendering.
            context.InputAssembler.InputLayout = null;
            context.InputAssembler.SetIndexBuffer(indices);
            context.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            context.VertexShader.Set(vertexShader);
            context.VertexShader.SetConstantBuffer(0, vertexConstants.Buffer);
            context.VertexShader.SetShaderResource(0, this.instances.SRV);
            context.PixelShader.Set(pixelShader);
            context.PixelShader.SetConstantBuffer(0, pixelConstants.Buffer);

            while (count > 0)
            {
                var batchCount = Math.Min(this.instances.Capacity, count);
                this.instances.Update(context, instances, batchCount, start);
                context.DrawIndexed(batchCount * 36, 0, 0);
                count -= batchCount;
                start += batchCount;
            }
        }
Пример #12
0
        public void Render(Camera camera, Int2 screenResolution, Span <TInstance> instances, int start, int count)
        {
            Use();
            indices.Bind();
            vertexConstants.Bind(0);
            this.instances.Bind(0);
            pixelConstants.Bind(1);

            var vertexConstantsData = new RayTracedVertexConstants {
                Projection     = camera.Projection,
                CameraPosition = camera.Position,
                CameraRight    = camera.Right,
                NearClip       = camera.NearClip,
                CameraUp       = camera.Up,
                CameraBackward = camera.Backward,
            };

            vertexConstants.Update(ref vertexConstantsData);
            var viewportHeight     = 2 * (float)Math.Tan(camera.FieldOfView / 2);
            var viewportWidth      = viewportHeight * camera.AspectRatio;
            var pixelConstantsData = new RayTracedPixelConstants {
                CameraRight          = camera.Right,
                NearClip             = camera.NearClip,
                CameraUp             = camera.Up,
                FarClip              = camera.FarClip,
                CameraBackward       = camera.Backward,
                PixelSizeAtUnitPlane = new Vector2(viewportWidth / screenResolution.X, viewportHeight / screenResolution.Y)
            };

            pixelConstants.Update(ref pixelConstantsData);

            while (count > 0)
            {
                var batchCount = Math.Min(this.instances.Capacity, count);
                this.instances.Update(instances, batchCount, start);
                GL.DrawElements(PrimitiveType.Triangles, 36 * batchCount, indices.Type, 0);
                count -= batchCount;
                start += batchCount;
            }
        }