Exemple #1
0
        unsafe public override void Render(Renderer.IndirectDrawEncoder encoder, SceneRenderPipeline sp)
        {
            if (!IsVisible)
            {
                return;
            }

            if (NvmResource == null || !NvmResource.IsLoaded || NvmResource.Get() == null)
            {
                return;
            }

            if (NvmResource.TryLock())
            {
                var resource   = NvmResource.Get();
                var geombuffer = resource.GeomBuffer;

                if (geombuffer.AllocStatus != VertexIndexBufferAllocator.VertexIndexBufferHandle.Status.Resident)
                {
                    NvmResource.Unlock();
                    return;
                }

                uint indexStart = geombuffer.IAllocationStart / 4u;
                var  args       = new Renderer.IndirectDrawIndexedArgumentsPacked();
                args.FirstInstance = WorldBuffer.AllocationStart / (uint)sizeof(InstanceData);
                args.VertexOffset  = (int)(geombuffer.VAllocationStart / Resource.CollisionLayout.SizeInBytes);
                args.InstanceCount = 1;
                args.FirstIndex    = indexStart;
                args.IndexCount    = geombuffer.IAllocationSize / 4u;
                encoder.AddDraw(ref args, geombuffer.BufferIndex, RenderPipeline, PerObjRS, IndexFormat.UInt32);
                NvmResource.Unlock();
            }
        }
Exemple #2
0
        public override void CreateDeviceObjects(GraphicsDevice gd, CommandList cl, SceneRenderPipeline sp)
        {
            var factory = gd.ResourceFactory;

            WorldBuffer = Renderer.UniformBufferAllocator.Allocate(128, 128);
            WorldBuffer.FillBuffer(cl, ref _World);

            VertexLayoutDescription[] mainVertexLayouts = new VertexLayoutDescription[]
            {
                new VertexLayoutDescription(
                    new VertexElementDescription("position", VertexElementSemantic.TextureCoordinate, Veldrid.VertexElementFormat.Float3),
                    new VertexElementDescription("normal", VertexElementSemantic.TextureCoordinate, Veldrid.VertexElementFormat.SByte4),
                    new VertexElementDescription("color", VertexElementSemantic.TextureCoordinate, Veldrid.VertexElementFormat.Byte4))
            };

            var res = StaticResourceCache.GetShaders(gd, gd.ResourceFactory, "Collision").ToTuple();

            Shaders = new Shader[] { res.Item1, res.Item2 };

            ResourceLayout projViewLayout = StaticResourceCache.GetResourceLayout(
                gd.ResourceFactory,
                StaticResourceCache.SceneParamLayoutDescription);

            ResourceLayout mainPerObjectLayout = StaticResourceCache.GetResourceLayout(gd.ResourceFactory, new ResourceLayoutDescription(
                                                                                           new ResourceLayoutElementDescription("WorldBuffer", ResourceKind.StructuredBufferReadWrite, ShaderStages.Vertex | ShaderStages.Fragment, ResourceLayoutElementOptions.None)));

            PerObjRS = StaticResourceCache.GetResourceSet(factory, new ResourceSetDescription(mainPerObjectLayout,
                                                                                              Renderer.UniformBufferAllocator._backingBuffer));

            bool isTriStrip = false;
            var  fres       = ColResource.Get();

            if (fres != null)
            {
                var mesh = fres.GPUMeshes[ColMeshIndex];
            }

            GraphicsPipelineDescription pipelineDescription = new GraphicsPipelineDescription();

            pipelineDescription.BlendState        = BlendStateDescription.SingleOverrideBlend;
            pipelineDescription.DepthStencilState = DepthStencilStateDescription.DepthOnlyGreaterEqual;
            pipelineDescription.RasterizerState   = new RasterizerStateDescription(
                cullMode: FaceCullMode.Back,
                fillMode: PolygonFillMode.Solid,
                frontFace: WindClockwise ? FrontFace.Clockwise : FrontFace.CounterClockwise,
                depthClipEnabled: true,
                scissorTestEnabled: false);
            pipelineDescription.PrimitiveTopology = isTriStrip ? PrimitiveTopology.TriangleStrip : PrimitiveTopology.TriangleList;
            pipelineDescription.ShaderSet         = new ShaderSetDescription(
                vertexLayouts: mainVertexLayouts,
                shaders: Shaders);
            pipelineDescription.ResourceLayouts = new ResourceLayout[] { projViewLayout, mainPerObjectLayout, Renderer.GlobalTexturePool.GetLayout(), Renderer.GlobalCubeTexturePool.GetLayout(), Renderer.MaterialBufferAllocator.GetLayout(), SamplerSet.SamplersLayout };
            pipelineDescription.Outputs         = gd.SwapchainFramebuffer.OutputDescription;
            RenderPipeline = StaticResourceCache.GetPipeline(factory, ref pipelineDescription);
        }
Exemple #3
0
        private void OnWorldMatrixChanged()
        {
            var res = Resource.Get();

            if (res != null)
            {
                RenderMesh.WorldTransform = _WorldMatrix;
            }
            if (DebugBoundingBox != null)
            {
                //DebugBoundingBox.Transform = new Transform(_WorldMatrix);
            }
        }
Exemple #4
0
        private void OnWorldMatrixChanged()
        {
            var res = Resource.Get();

            if (res != null)
            {
                foreach (var sm in Submeshes)
                {
                    sm.WorldTransform = _WorldMatrix;
                }
            }
            if (DebugBoundingBox != null)
            {
                //DebugBoundingBox.Transform = new Transform(_WorldMatrix);
            }
        }
 public override bool HasMeshData()
 {
     if (_resource.IsLoaded && _resource.Get().VertexCount > 0)
     {
         return(true);
     }
     return(false);
 }
 public override bool HasMeshData()
 {
     if (_resource.Get().GPUMeshes[_meshIndex].VertexCount == 0)
     {
         return(false);
     }
     return(true);
 }
        private void CreateSubmeshes()
        {
            _submeshes = new List <CollisionSubmeshProvider>();
            var res = _resource.Get();

            _bounds = res.Bounds;
            if (res.GPUMeshes != null)
            {
                for (int i = 0; i < res.GPUMeshes.Length; i++)
                {
                    var sm = new CollisionSubmeshProvider(_resource, i);
                    _submeshes.Add(sm);
                }
            }
        }