Use toon shading, cleanup resources for debug marker example

This commit is contained in:
saschawillems 2016-05-26 20:13:28 +02:00
parent ea61df3b55
commit 8ee6a9f149
8 changed files with 45 additions and 3407 deletions

File diff suppressed because one or more lines are too long

View file

@ -1,5 +1,5 @@
glslangvalidator -V phongpass.vert -o phongpass.vert.spv glslangvalidator -V toon.vert -o toon.vert.spv
glslangvalidator -V phongpass.frag -o phongpass.frag.spv glslangvalidator -V toon.frag -o toon.frag.spv
glslangvalidator -V colorpass.vert -o colorpass.vert.spv glslangvalidator -V colorpass.vert -o colorpass.vert.spv
glslangvalidator -V colorpass.frag -o colorpass.frag.spv glslangvalidator -V colorpass.frag -o colorpass.frag.spv
glslangvalidator -V postprocess.vert -o postprocess.vert.spv glslangvalidator -V postprocess.vert -o postprocess.vert.spv

View file

@ -27,4 +27,13 @@ void main()
vec3 diffuse = max(dot(N, L), 0.0) * color; vec3 diffuse = max(dot(N, L), 0.0) * color;
vec3 specular = pow(max(dot(R, V), 0.0), 16.0) * vec3(0.75); vec3 specular = pow(max(dot(R, V), 0.0), 16.0) * vec3(0.75);
outFragColor = vec4(ambient + diffuse * 1.75 + specular, 1.0); outFragColor = vec4(ambient + diffuse * 1.75 + specular, 1.0);
float intensity = dot(N,L);
float shade = 1.0;
shade = intensity < 0.5 ? 0.75 : shade;
shade = intensity < 0.35 ? 0.6 : shade;
shade = intensity < 0.25 ? 0.5 : shade;
shade = intensity < 0.1 ? 0.25 : shade;
outFragColor.rgb = inColor * 3.0 * shade;
} }

Binary file not shown.

View file

@ -157,7 +157,7 @@ struct Scene {
class VulkanExample : public VulkanExampleBase class VulkanExample : public VulkanExampleBase
{ {
public: public:
bool wireframe = false; bool wireframe = true;
bool glow = true; bool glow = true;
struct { struct {
@ -179,7 +179,7 @@ public:
} uboVS; } uboVS;
struct { struct {
VkPipeline phong; VkPipeline toonshading;
VkPipeline color; VkPipeline color;
VkPipeline wireframe; VkPipeline wireframe;
VkPipeline postprocess; VkPipeline postprocess;
@ -223,9 +223,10 @@ public:
{ {
// Clean up used Vulkan resources // Clean up used Vulkan resources
// Note : Inherited destructor cleans up resources stored in base class // Note : Inherited destructor cleans up resources stored in base class
vkDestroyPipeline(device, pipelines.phong, nullptr); vkDestroyPipeline(device, pipelines.toonshading, nullptr);
vkDestroyPipeline(device, pipelines.color, nullptr); vkDestroyPipeline(device, pipelines.color, nullptr);
vkDestroyPipeline(device, pipelines.wireframe, nullptr); vkDestroyPipeline(device, pipelines.wireframe, nullptr);
vkDestroyPipeline(device, pipelines.postprocess, nullptr);
vkDestroyPipelineLayout(device, pipelineLayout, nullptr); vkDestroyPipelineLayout(device, pipelineLayout, nullptr);
vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr); vkDestroyDescriptorSetLayout(device, descriptorSetLayout, nullptr);
@ -235,8 +236,26 @@ public:
vkFreeMemory(device, scene.vertices.mem, nullptr); vkFreeMemory(device, scene.vertices.mem, nullptr);
vkDestroyBuffer(device, scene.indices.buf, nullptr); vkDestroyBuffer(device, scene.indices.buf, nullptr);
vkFreeMemory(device, scene.indices.mem, nullptr); vkFreeMemory(device, scene.indices.mem, nullptr);
vkDestroyBuffer(device, sceneGlow.vertices.buf, nullptr);
vkFreeMemory(device, sceneGlow.vertices.mem, nullptr);
vkDestroyBuffer(device, sceneGlow.indices.buf, nullptr);
vkFreeMemory(device, sceneGlow.indices.mem, nullptr);
vkTools::destroyUniformData(device, &uniformData.vsScene); vkTools::destroyUniformData(device, &uniformData.vsScene);
// Offscreen
// Texture target
textureLoader->destroyTexture(offScreenFrameBuf.textureTarget);
// Frame buffer
// Color attachment
vkDestroyImageView(device, offScreenFrameBuf.color.view, nullptr);
vkDestroyImage(device, offScreenFrameBuf.color.image, nullptr);
vkFreeMemory(device, offScreenFrameBuf.color.mem, nullptr);
// Depth attachment
vkDestroyImageView(device, offScreenFrameBuf.depth.view, nullptr);
vkDestroyImage(device, offScreenFrameBuf.depth.image, nullptr);
vkFreeMemory(device, offScreenFrameBuf.depth.mem, nullptr);
vkDestroyFramebuffer(device, offScreenFrameBuf.frameBuffer, nullptr);
} }
// Prepare a texture target and framebuffer for offscreen rendering // Prepare a texture target and framebuffer for offscreen rendering
@ -675,7 +694,7 @@ public:
void loadScene() void loadScene()
{ {
loadModel(getAssetPath() + "models/treasure.dae", &scene); loadModel(getAssetPath() + "models/treasure_smooth.dae", &scene);
loadModel(getAssetPath() + "models/treasure_glow.dae", &sceneGlow); loadModel(getAssetPath() + "models/treasure_glow.dae", &sceneGlow);
// Name the meshes // Name the meshes
@ -749,9 +768,9 @@ public:
// Solid rendering // Solid rendering
// Start a new debug marker region // Start a new debug marker region
DebugReportExt::beginDebugMarkerRegion(drawCmdBuffers[i], "Solid draw", glm::vec4(1.0f, 0.0f, 0.0f, 0.0f)); DebugReportExt::beginDebugMarkerRegion(drawCmdBuffers[i], "Toon shading draw", glm::vec4(1.0f, 0.0f, 0.0f, 0.0f));
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.phong); vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.toonshading);
scene.draw(drawCmdBuffers[i]); scene.draw(drawCmdBuffers[i]);
DebugReportExt::endDebugMarkerRegion(drawCmdBuffers[i]); DebugReportExt::endDebugMarkerRegion(drawCmdBuffers[i]);
@ -769,6 +788,10 @@ public:
scene.draw(drawCmdBuffers[i]); scene.draw(drawCmdBuffers[i]);
DebugReportExt::endDebugMarkerRegion(drawCmdBuffers[i]); DebugReportExt::endDebugMarkerRegion(drawCmdBuffers[i]);
scissor.offset.x = 0;
scissor.extent.width = width;
vkCmdSetScissor(drawCmdBuffers[i], 0, 1, &scissor);
} }
// Post processing // Post processing
@ -979,8 +1002,8 @@ public:
// Load shaders // Load shaders
std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages; std::array<VkPipelineShaderStageCreateInfo, 2> shaderStages;
shaderStages[0] = loadShader(getAssetPath() + "shaders/debugmarker/phongpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); shaderStages[0] = loadShader(getAssetPath() + "shaders/debugmarker/toon.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
shaderStages[1] = loadShader(getAssetPath() + "shaders/debugmarker/phongpass.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT); shaderStages[1] = loadShader(getAssetPath() + "shaders/debugmarker/toon.frag.spv", VK_SHADER_STAGE_FRAGMENT_BIT);
// Name shader moduels for debugging // Name shader moduels for debugging
DebugReportExt::setObjectName(device, (uint64_t)shaderModules[0], VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, "Mesh rendering vertex shader"); DebugReportExt::setObjectName(device, (uint64_t)shaderModules[0], VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, "Mesh rendering vertex shader");
@ -1003,7 +1026,7 @@ public:
pipelineCreateInfo.stageCount = shaderStages.size(); pipelineCreateInfo.stageCount = shaderStages.size();
pipelineCreateInfo.pStages = shaderStages.data(); pipelineCreateInfo.pStages = shaderStages.data();
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.phong)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.toonshading));
// Color only pipeline // Color only pipeline
shaderStages[0] = loadShader(getAssetPath() + "shaders/debugmarker/colorpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT); shaderStages[0] = loadShader(getAssetPath() + "shaders/debugmarker/colorpass.vert.spv", VK_SHADER_STAGE_VERTEX_BIT);
@ -1039,7 +1062,7 @@ public:
VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.postprocess)); VK_CHECK_RESULT(vkCreateGraphicsPipelines(device, pipelineCache, 1, &pipelineCreateInfo, nullptr, &pipelines.postprocess));
// Name pipelines for debugging // Name pipelines for debugging
DebugReportExt::setObjectName(device, (uint64_t)pipelines.phong, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, "Phong lighting pipeline"); DebugReportExt::setObjectName(device, (uint64_t)pipelines.toonshading, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, "Toon shading pipeline");
DebugReportExt::setObjectName(device, (uint64_t)pipelines.color, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, "Color only pipeline"); DebugReportExt::setObjectName(device, (uint64_t)pipelines.color, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, "Color only pipeline");
DebugReportExt::setObjectName(device, (uint64_t)pipelines.wireframe, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, "Wireframe rendering pipeline"); DebugReportExt::setObjectName(device, (uint64_t)pipelines.wireframe, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, "Wireframe rendering pipeline");
DebugReportExt::setObjectName(device, (uint64_t)pipelines.postprocess, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, "Post processing pipeline"); DebugReportExt::setObjectName(device, (uint64_t)pipelines.postprocess, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, "Post processing pipeline");