Пример #1
0
        void setupVertexDescriptions()
        {
            // Binding description
            vDescription.bindingDescriptions              = VkVertexInputBindingDescription.Alloc();
            vDescription.bindingDescriptions[0].binding   = VERTEX_BUFFER_BIND_ID;
            vDescription.bindingDescriptions[0].stride    = (uint)sizeof(Vertex);
            vDescription.bindingDescriptions[0].inputRate = VkVertexInputRate.Vertex;

            // Attribute descriptions
            // Describes memory layout and shader positions
            vDescription.attributeDescriptions = VkVertexInputAttributeDescription.Alloc(3);
            // Location 0 : Position
            vDescription.attributeDescriptions[0].binding  = VERTEX_BUFFER_BIND_ID;
            vDescription.attributeDescriptions[0].location = 0;
            vDescription.attributeDescriptions[0].format   = VkFormat.R32g32b32Sfloat;
            vDescription.attributeDescriptions[0].offset   = Vertex.PositionOffset;
            // Location 1 : Texture coordinates
            vDescription.attributeDescriptions[1].binding  = VERTEX_BUFFER_BIND_ID;
            vDescription.attributeDescriptions[1].location = 1;
            vDescription.attributeDescriptions[1].format   = VkFormat.R32g32Sfloat;
            vDescription.attributeDescriptions[1].offset   = Vertex.UvOffset;
            // Location 1 : Vertex normal
            vDescription.attributeDescriptions[2].binding  = VERTEX_BUFFER_BIND_ID;
            vDescription.attributeDescriptions[2].location = 2;
            vDescription.attributeDescriptions[2].format   = VkFormat.R32g32b32Sfloat;
            vDescription.attributeDescriptions[2].offset   = Vertex.NormalOffset;

            vDescription.inputState = VkPipelineVertexInputStateCreateInfo.Alloc();
            vDescription.inputState[0].vertexBindingDescriptions.count     = 1;
            vDescription.inputState[0].vertexBindingDescriptions.pointer   = vDescription.bindingDescriptions;
            vDescription.inputState[0].vertexAttributeDescriptions.count   = 3;
            vDescription.inputState[0].vertexAttributeDescriptions.pointer = vDescription.attributeDescriptions;
        }
        void setupVertexDescriptions()
        {
            // Binding description
            vbindingDescs = new VkVertexInputBindingDescription[]
            {
                new VkVertexInputBindingDescription(
                    binding: VERTEX_BUFFER_BIND_ID,
                    stride: (uint)sizeof(Vertex),
                    inputRate: VkVertexInputRate.Vertex)
            };

            // Attribute descriptions
            vAttrDescs = new VkVertexInputAttributeDescription[] {
                // layout (location = 0) in vec3 inPos;
                new VkVertexInputAttributeDescription(
                    location: 0,
                    binding: VERTEX_BUFFER_BIND_ID,
                    format: VkFormat.R32g32b32Sfloat,
                    offset: 0),
                // layout (location = 1) in vec3 inColor;
                new VkVertexInputAttributeDescription(
                    location: 1,
                    binding: VERTEX_BUFFER_BIND_ID,
                    format: VkFormat.R32g32b32Sfloat,
                    offset: (uint)sizeof(Vector3)),
            };

            vertices_inputState = VkPipelineVertexInputStateCreateInfo.Alloc();
            vertices_inputState->vertexBindingDescriptions   = vbindingDescs;
            vertices_inputState->vertexAttributeDescriptions = vAttrDescs;
        }
Пример #3
0
        void setupVertexDescriptions()
        {
            // Binding description
            vBindingDescriptions              = new VkVertexInputBindingDescription[1];
            vBindingDescriptions[0]           = new VkVertexInputBindingDescription();
            vBindingDescriptions[0].binding   = VERTEX_BUFFER_BIND_ID;
            vBindingDescriptions[0].stride    = (uint)sizeof(Vertex);
            vBindingDescriptions[0].inputRate = VkVertexInputRate.Vertex;

            // Attribute descriptions
            // Describes memory layout and shader positions
            vAttrDescriptions = new VkVertexInputAttributeDescription[4];
            // Location 0 : Position
            vAttrDescriptions[0]          = new VkVertexInputAttributeDescription();
            vAttrDescriptions[0].binding  = VERTEX_BUFFER_BIND_ID;
            vAttrDescriptions[0].location = 0;
            vAttrDescriptions[0].format   = VkFormat.R32g32b32Sfloat;
            vAttrDescriptions[0].offset   = Vertex.PositionOffset;
            // Location 1 : Normal
            vAttrDescriptions[1]          = new VkVertexInputAttributeDescription();
            vAttrDescriptions[1].binding  = VERTEX_BUFFER_BIND_ID;
            vAttrDescriptions[1].location = 1;
            vAttrDescriptions[1].format   = VkFormat.R32g32b32Sfloat;
            vAttrDescriptions[1].offset   = Vertex.NormalOffset;
            // Location 2 : Texture coordinates
            vAttrDescriptions[2]          = new VkVertexInputAttributeDescription();
            vAttrDescriptions[2].binding  = VERTEX_BUFFER_BIND_ID;
            vAttrDescriptions[2].location = 2;
            vAttrDescriptions[2].format   = VkFormat.R32g32Sfloat;
            vAttrDescriptions[2].offset   = Vertex.UvOffset;
            // Location 3 : Color
            vAttrDescriptions[3]          = new VkVertexInputAttributeDescription();
            vAttrDescriptions[3].binding  = VERTEX_BUFFER_BIND_ID;
            vAttrDescriptions[3].location = 3;
            vAttrDescriptions[3].format   = VkFormat.R32g32b32Sfloat;
            vAttrDescriptions[3].offset   = Vertex.ColorOffset;

            vInputStateInfo = VkPipelineVertexInputStateCreateInfo.Alloc();
            vInputStateInfo->vertexBindingDescriptions   = vBindingDescriptions;
            vInputStateInfo->vertexAttributeDescriptions = vAttrDescriptions;
        }
Пример #4
0
        void setupVertexDescriptions()
        {
            // Binding description
            bindingDescs              = new VkVertexInputBindingDescription[1];
            bindingDescs[0].binding   = VERTEX_BUFFER_BIND_ID;
            bindingDescs[0].stride    = vertexLayout.stride();
            bindingDescs[0].inputRate = VkVertexInputRate.Vertex;// VK_VERTEX_INPUT_RATE_VERTEX;

            // Attribute descriptions
            attributeDescs = VkVertexInputAttributeDescription.Alloc(4);
            // Location 0 : Position
            attributeDescs[0].binding  = VERTEX_BUFFER_BIND_ID;
            attributeDescs[0].location = 0;
            attributeDescs[0].format   = VkFormat.R32g32b32Sfloat;// VK_FORMAT_R32G32B32_SFLOAT,
            attributeDescs[0].offset   = 0;
            // Location 1 : Texture coordinates
            attributeDescs[1].binding  = VERTEX_BUFFER_BIND_ID;
            attributeDescs[1].location = 1;
            attributeDescs[1].format   = VkFormat.R32g32Sfloat;// VK_FORMAT_R32G32_SFLOAT,
            attributeDescs[1].offset   = sizeof(float) * 3;
            // Location 2 : Color
            attributeDescs[2].binding  = VERTEX_BUFFER_BIND_ID;
            attributeDescs[2].location = 2;
            attributeDescs[2].format   = VkFormat.R32g32b32Sfloat;// VK_FORMAT_R32G32B32_SFLOAT,
            attributeDescs[2].offset   = sizeof(float) * 5;
            // Location 3 : Normal
            attributeDescs[3].binding  = VERTEX_BUFFER_BIND_ID;
            attributeDescs[3].location = 3;
            attributeDescs[3].format   = VkFormat.R32g32b32Sfloat;// VK_FORMAT_R32G32B32_SFLOAT,
            attributeDescs[3].offset   = sizeof(float) * 8;

            inputInfo = VkPipelineVertexInputStateCreateInfo.Alloc();
            inputInfo[0].vertexBindingDescriptions           = bindingDescs;
            inputInfo[0].vertexAttributeDescriptions.count   = 4;
            inputInfo[0].vertexAttributeDescriptions.pointer = attributeDescs;
        }
Пример #5
0
        void preparePipelines()
        {
            var inputAssemblyState = VkPipelineInputAssemblyStateCreateInfo.Alloc();

            inputAssemblyState->topology = VkPrimitiveTopology.TriangleList;
            inputAssemblyState->primitiveRestartEnable = false;

            var rasterizationState = VkPipelineRasterizationStateCreateInfo.Alloc();

            rasterizationState->polygonMode = VkPolygonMode.Fill;
            rasterizationState->cullMode    = VkCullModeFlagBits.None;
            rasterizationState->frontFace   = VkFrontFace.CounterClockwise;
            rasterizationState->lineWidth   = 1.0f;

            var blendAttachmentState = VkPipelineColorBlendAttachmentState.Alloc();

            blendAttachmentState->colorWriteMask = (VkColorComponentFlagBits)0xf;
            blendAttachmentState->blendEnable    = false;

            var colorBlendState = VkPipelineColorBlendStateCreateInfo.Alloc();

            colorBlendState->attachments.count   = 1;
            colorBlendState->attachments.pointer = blendAttachmentState;

            var depthStencilState = VkPipelineDepthStencilStateCreateInfo.Alloc();

            depthStencilState->depthTestEnable  = true;
            depthStencilState->depthWriteEnable = true;
            depthStencilState->depthCompareOp   = VkCompareOp.LessOrEqual;
            depthStencilState->front            = depthStencilState->back;
            depthStencilState->back.compareOp   = VkCompareOp.Always;

            var viewportState = VkPipelineViewportStateCreateInfo.Alloc();

            viewportState[0].viewports.count = 1;
            viewportState[0].scissors.count  = 1;

            var multisampleState = VkPipelineMultisampleStateCreateInfo.Alloc();

            multisampleState->rasterizationSamples = VkSampleCountFlagBits._1;

            var dynamicStateEnables = new VkDynamicState[] { VkDynamicState.Viewport, VkDynamicState.Scissor };
            var dynamicState        = VkPipelineDynamicStateCreateInfo.Alloc();

            dynamicState[0].dynamicStates = dynamicStateEnables;

            var shaderStages = VkPipelineShaderStageCreateInfo.Alloc(2);

            var pipelineCreateInfo = VkGraphicsPipelineCreateInfo.Alloc();

            pipelineCreateInfo->layout              = pipelineLayoutRadialBlur;
            pipelineCreateInfo->renderPass          = renderPass;
            pipelineCreateInfo->basePipelineIndex   = -1;
            pipelineCreateInfo->pInputAssemblyState = inputAssemblyState;
            pipelineCreateInfo->pRasterizationState = rasterizationState;
            pipelineCreateInfo->pColorBlendState    = colorBlendState;
            pipelineCreateInfo->pMultisampleState   = multisampleState;
            pipelineCreateInfo->pViewportState      = viewportState;
            pipelineCreateInfo->pDepthStencilState  = depthStencilState;
            pipelineCreateInfo->pDynamicState       = dynamicState;
            pipelineCreateInfo->stages.count        = 2;
            pipelineCreateInfo->stages.pointer      = shaderStages;

            // Radial blur pipeline
            shaderStages[0] = loadShader(getAssetPath() + "shaders/radialblur/radialblur.vert.spv", VkShaderStageFlagBits.Vertex);
            shaderStages[1] = loadShader(getAssetPath() + "shaders/radialblur/radialblur.frag.spv", VkShaderStageFlagBits.Fragment);
            // Empty vertex input state
            var emptyInputState = VkPipelineVertexInputStateCreateInfo.Alloc();

            pipelineCreateInfo->pVertexInputState = emptyInputState;
            pipelineCreateInfo->layout            = pipelineLayoutRadialBlur;
            // Additive blending
            blendAttachmentState->colorWriteMask      = (VkColorComponentFlagBits)0xF;
            blendAttachmentState->blendEnable         = true;
            blendAttachmentState->colorBlendOp        = VkBlendOp.Add;
            blendAttachmentState->srcColorBlendFactor = VkBlendFactor.One;
            blendAttachmentState->dstColorBlendFactor = VkBlendFactor.One;
            blendAttachmentState->alphaBlendOp        = VkBlendOp.Add;
            blendAttachmentState->srcAlphaBlendFactor = VkBlendFactor.SrcAlpha;
            blendAttachmentState->dstAlphaBlendFactor = VkBlendFactor.DstAlpha;
            {
                VkPipeline pipeline;
                vkCreateGraphicsPipelines(device, pipelineCache, 1, pipelineCreateInfo, null, &pipeline);
                this.pipelineRadialBlur = pipeline;
            }

            // No blending (for debug display)
            blendAttachmentState->blendEnable = false;
            {
                VkPipeline pipeline;
                vkCreateGraphicsPipelines(device, pipelineCache, 1, pipelineCreateInfo, null, &pipeline);
                this.pipelineOffscreenDisplay = pipeline;
            }

            // Phong pass
            pipelineCreateInfo->layout            = pipelineLayoutScene;
            shaderStages[0]                       = loadShader(getAssetPath() + "shaders/radialblur/phongpass.vert.spv", VkShaderStageFlagBits.Vertex);
            shaderStages[1]                       = loadShader(getAssetPath() + "shaders/radialblur/phongpass.frag.spv", VkShaderStageFlagBits.Fragment);
            pipelineCreateInfo->pVertexInputState = inputInfo;
            blendAttachmentState->blendEnable     = false;
            depthStencilState->depthWriteEnable   = true;
            {
                VkPipeline pipeline;
                vkCreateGraphicsPipelines(device, pipelineCache, 1, pipelineCreateInfo, null, &pipeline);
                this.pipelinePhongPass = pipeline;
            }

            // Color only pass (offscreen blur base)
            shaderStages[0] = loadShader(getAssetPath() + "shaders/radialblur/colorpass.vert.spv", VkShaderStageFlagBits.Vertex);
            shaderStages[1] = loadShader(getAssetPath() + "shaders/radialblur/colorpass.frag.spv", VkShaderStageFlagBits.Fragment);
            pipelineCreateInfo->renderPass = offscreenPass.renderPass;
            {
                VkPipeline pipeline;
                vkCreateGraphicsPipelines(device, pipelineCache, 1, pipelineCreateInfo, null, &pipeline);
                this.pipelineColorPass = pipeline;
            }
        }