Beispiel #1
0
 public static void vkCmdSetViewport(VkCommandBuffer commandBuffer, uint firstViewport, VkViewport viewport)
 {
     vkCmdSetViewport(commandBuffer, firstViewport, 1, &viewport);
 }
Beispiel #2
0
        public override void Draw(RenderContext rc, CommandBuffer cmd)
        {
            var view = View;

            if (view.Camera == null)
            {
                return;
            }

            UpdateCascades(view);
            UpdateUniformBuffers(view);

            casters[0].Clear();
            casters[1].Clear();
            casters[2].Clear();

            shadowCasterQuery.Init(view.Camera, Drawable.DRAWABLE_ANY, view.ViewMask);

            view.Scene.GetDrawables(shadowCasterQuery, (drawable) =>
            {
                if (drawable.CastShadows)
                {
                    foreach (SourceBatch batch in drawable.Batches)
                    {
                        casters[batch.material.blendType].Add(batch);

                        if (batch.frameNum != view.Frame.frameNumber)
                        {
                            batch.frameNum = view.Frame.frameNumber;
                            batch.offset   = FrameGraph.GetTransform(batch.worldTransform, (uint)batch.numWorldTransforms);
                        }
                    }
                }
            });

            VkClearValue[] clearDepth = { new VkClearDepthStencilValue(1.0f, 0) };

            if (RenderPass == null)
            {
                CreateRenderPass();
                CreateRenderTargets();
            }

            //todo:multi thread
            for (int i = 0; i < SHADOW_MAP_CASCADE_COUNT; i++)
            {
                VkViewport viewport   = new VkViewport(0, 0, SHADOWMAP_DIM, SHADOWMAP_DIM, 0.0f, 1.0f);
                VkRect2D   renderArea = new VkRect2D(0, 0, SHADOWMAP_DIM, SHADOWMAP_DIM);

                BeginRenderPass(cmd, cascades[i].frameBuffer, renderArea, clearDepth);

                cmd.SetViewport(viewport);
                cmd.SetScissor(renderArea);

                uint cascade = (uint)i;

                Span <ConstBlock> consts = stackalloc ConstBlock[]
                {
                    new ConstBlock(VkShaderStageFlags.Vertex, 0, 4, Utilities.AsPointer(ref cascade))
                };

                foreach (var batch in casters[0])
                {
                    DrawBatch(cmd, passID, batch, consts, vsSet);
                }

                EndRenderPass(cmd);
            }
        }

        void DrawBatch(CommandBuffer cb, ulong passID, SourceBatch batch, Span <ConstBlock> pushConsts,
                       DescriptorSet resourceSet)
        {
            var shader = batch.material.Shader;

            if ((passID & shader.passFlags) == 0)
            {
                return;
            }

            var pass = shader.GetPass(passID);
            var pipe = pass.GetGraphicsPipeline(RenderPass, 0, batch.geometry);

            cb.BindPipeline(VkPipelineBindPoint.Graphics, pipe);

            batch.Draw(cb, pushConsts, resourceSet, default, pass);