Added starfield backdrop to instancing example

This commit is contained in:
saschawillems 2017-01-08 12:27:03 +01:00
parent d335e7be29
commit bb9310b94a
10 changed files with 70 additions and 2 deletions

View file

@ -81,6 +81,7 @@ public:
struct {
VkPipeline instancedRocks;
VkPipeline planet;
VkPipeline starfield;
} pipelines;
VkDescriptorSetLayout descriptorSetLayout;
@ -89,7 +90,6 @@ public:
VkDescriptorSet planet;
} descriptorSets;
VulkanExample() : VulkanExampleBase(ENABLE_VALIDATION)
{
title = "Vulkan Example - Instanced mesh rendering";
@ -105,6 +105,7 @@ public:
{
vkDestroyPipeline(device, pipelines.instancedRocks, nullptr);
vkDestroyPipeline(device, pipelines.planet, nullptr);
vkDestroyPipeline(device, pipelines.starfield, nullptr);
vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
vkDestroyBuffer(device, instanceBuffer.buffer, nullptr);
@ -148,6 +149,11 @@ public:
VkDeviceSize offsets[1] = { 0 };
// Star field
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.planet, 0, NULL);
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.starfield);
vkCmdDraw(drawCmdBuffers[i], 4, 1, 0, 0);
// Planet
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, &descriptorSets.planet, 0, NULL);
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.planet);
@ -378,6 +384,16 @@ public:
inputState.vertexBindingDescriptionCount = 1;
inputState.vertexAttributeDescriptionCount = 4;
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.planet));
// Star field pipeline
rasterizationState.cullMode = VK_CULL_MODE_NONE;
depthStencilState.depthWriteEnable = VK_FALSE;
shaderStages[0] = loadShader(getAssetPath() + "shaders/instancing/starfield.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
shaderStages[1] = loadShader(getAssetPath() + "shaders/instancing/starfield.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
// Vertices are generated in the vertex shader
inputState.vertexBindingDescriptionCount = 0;
inputState.vertexAttributeDescriptionCount = 0;
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.starfield));
}
float rnd(float range)