コード例 #1
0
ファイル: WorldPass.cs プロジェクト: john-h-k/Voltium
        public override unsafe void Record(GraphicsContext context, ref Resolver resolver)
        {
            var resources  = resolver.GetComponent <RenderResources>();
            var sceneColor = resolver.ResolveResource(resources.SceneColor);
            var sceneDepth = resolver.ResolveResource(resources.SceneDepth);

            var frame = _frameConstants.As <FrameConstants>();

            frame->View       = _camera.View;
            frame->Projection = _camera.Projection;

            _device.CreateRenderTargetView(sceneColor, _rtvs[0]);
            _device.CreateDepthStencilView(sceneDepth, _dsvs[0]);

            var progressBuffer = _device.Allocator.AllocateBuffer(1024, MemoryAccess.GpuOnly);

            context.SetAndClearRenderTarget(_rtvs[0], DefaultSkyColor, _dsvs[0]);
            context.SetRootDescriptorTable(RootSignatureConstants.TextureIndex, _texViews[0]);
            context.SetConstantBuffer <FrameConstants>(RootSignatureConstants.FrameConstantsIndex, _frameConstants);
            context.SetTopology(Topology.TriangleList);
            context.SetViewportAndScissor(sceneColor.Resolution);

            for (var i = 0u; i < Chunks.Length; i++)
            {
                ref var chunk = ref Chunks[i];

                if (chunk.Chunk.NeedsRebuild)
                {
                    BuildMesh(ref chunk);
                }

                context.SetConstantBuffer <ChunkConstants>(RootSignatureConstants.ObjectConstantsIndex, chunk.Mesh.Constants);
                context.SetShaderResourceBuffer <uint>(RootSignatureConstants.ObjectTexIndicesIndex, chunk.Mesh.TexIndices);

                context.SetVertexBuffers <BlockVertex>(chunk.Mesh.Vertices, (uint)chunk.Mesh.VertexCount, 0);
                context.SetIndexBuffer <uint>(chunk.Mesh.Indices, (uint)chunk.Mesh.IndexCount);

                context.WriteBufferImmediate(progressBuffer.GpuAddress + (sizeof(int) * i), GetDrawIndex(i), WriteBufferImmediateMode.In);
                context.DrawIndexed(chunk.Mesh.IndexCount);
コード例 #2
0
ファイル: WorldPass.cs プロジェクト: john-h-k/Voltium
        private unsafe void SetConstants()
        {
            _frameConstants          = _device.Allocator.AllocateUploadBuffer <FrameConstants>();
            Chunks[0].Mesh.Constants = _device.Allocator.AllocateUploadBuffer <ChunkConstants>();

            FrameConstants *constants = _frameConstants.As <FrameConstants>();

            constants->View = Matrix4x4.CreateLookAt(
                new Vector3(0.0f, 0.7f, 1.5f),
                new Vector3(0.0f, -0.1f, 0.0f),
                new Vector3(0.0f, 1.0f, 0.0f)
                );

            const float defaultFov = 70.0f * (float)Math.PI / 180.0f;

            constants->Projection = Matrix4x4.CreatePerspectiveFieldOfView(defaultFov, 1, 0.01f, 100f);

            ChunkConstants *chunkConstants = Chunks[0].Mesh.Constants.As <ChunkConstants>();

            chunkConstants->TexTransform = Matrix4x4.Identity;
            chunkConstants->World        = Matrix4x4.CreateTranslation(0, 0, -5);
        }