Added multisampling example to readme

This commit is contained in:
saschawillems 2016-03-29 22:16:32 +02:00
parent 1e3dcb98b6
commit 79df037c92
4 changed files with 18 additions and 14 deletions

View file

@ -99,10 +99,10 @@ Uses [assimp](https://github.com/assimp/assimp) to load and a mesh from a common
Shows the use of instancing for rendering the same mesh with differing uniforms with one single draw command. This saves performance if the same mesh has to be rendered multiple times. Shows the use of instancing for rendering the same mesh with differing uniforms with one single draw command. This saves performance if the same mesh has to be rendered multiple times.
<br><br> <br><br>
## [Skeletal animation](skeletalanimation/) ## [Multi sampling](multisampling/)
<img src="./screenshots/mesh_skeletalanimation.png" height="96px" align="right"> <img src="./screenshots/multisampling.png" height="96px" align="right">
Based on the mesh loading example, this example loads and displays a rigged COLLADA model including animations. Bone weights are extracted for each vertex and are passed to the vertex shader together with the final bone transformation matrices for vertex position calculations. Demonstrates the use of resolve attachments for doing multisampling. Instead of doing an explicit resolve from a multisampled image this example creates multisampled attachments for the color and depth buffer and sets up the render pass to use these as resolve attachments that will get resolved to the visible frame buffer at the end of this render pass. To highlight MSAA the example renders a mesh with fine details against a bright background. Here is a [screenshot without MSAA](./screenshots/multisampling_nomsaa.png) to compare.
<br><br> <br><br>
## [Particle system](particlefire/) ## [Particle system](particlefire/)
@ -110,8 +110,6 @@ Based on the mesh loading example, this example loads and displays a rigged COLL
Point sprite based particle system simulating a fire. Particles and their attributes are stored in a host visible vertex buffer that's updated on the CPU on each frame. Also makes use of pre-multiplied alpha for rendering particles with different blending modes (smoke and fire) in one single pass. Point sprite based particle system simulating a fire. Particles and their attributes are stored in a host visible vertex buffer that's updated on the CPU on each frame. Also makes use of pre-multiplied alpha for rendering particles with different blending modes (smoke and fire) in one single pass.
## [Push constants](pushconstants/) ## [Push constants](pushconstants/)
<img src="./screenshots/push_constants.png" height="96px" align="right"> <img src="./screenshots/push_constants.png" height="96px" align="right">
@ -178,6 +176,12 @@ Uses a (spherical) material capture texture containing environment lighting and
Like normal mapping, parallax mapping simulates geometry on a flat surface. In addition to normal mapping a heightmap is used to offset texture coordinates depending on the viewing angle giving the illusion of added depth. Like normal mapping, parallax mapping simulates geometry on a flat surface. In addition to normal mapping a heightmap is used to offset texture coordinates depending on the viewing angle giving the illusion of added depth.
<br><br> <br><br>
## [Skeletal animation](skeletalanimation/)
<img src="./screenshots/mesh_skeletalanimation.png" height="96px" align="right">
Based on the mesh loading example, this example loads and displays a rigged COLLADA model including animations. Bone weights are extracted for each vertex and are passed to the vertex shader together with the final bone transformation matrices for vertex position calculations.
<br><br>
## [(Tessellation shader) PN-Triangles](tessellation/) ## [(Tessellation shader) PN-Triangles](tessellation/)
<img src="./screenshots/tess_pntriangles.jpg" height="96px" align="right"> <img src="./screenshots/tess_pntriangles.jpg" height="96px" align="right">

View file

@ -1,8 +1,6 @@
/* /*
* Vulkan Example - Multisampling using resolve attachments * Vulkan Example - Multisampling using resolve attachments
* *
* todo : add second renderpass without msaa and allow toggle
*
* Copyright (C) 2016 by Sascha Willems - www.saschawillems.de * Copyright (C) 2016 by Sascha Willems - www.saschawillems.de
* *
* This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
@ -238,8 +236,7 @@ public:
attachments[1].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachments[1].initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
attachments[1].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; attachments[1].finalLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
// Depth attachment // Multisampled depth attachment we render to
// This needs to use the same number of samples as the msaa attachment
attachments[2].format = depthFormat; attachments[2].format = depthFormat;
attachments[2].samples = SAMPLE_COUNT; attachments[2].samples = SAMPLE_COUNT;
attachments[2].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR; attachments[2].loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
@ -249,7 +246,7 @@ public:
attachments[2].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; attachments[2].initialLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
attachments[2].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; attachments[2].finalLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
// Depth resolve // Depth resolve attachment
attachments[3].format = depthFormat; attachments[3].format = depthFormat;
attachments[3].samples = VK_SAMPLE_COUNT_1_BIT; attachments[3].samples = VK_SAMPLE_COUNT_1_BIT;
attachments[3].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE; attachments[3].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
@ -263,20 +260,22 @@ public:
colorReference.attachment = 0; colorReference.attachment = 0;
colorReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; colorReference.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
VkAttachmentReference depthReference = {};
depthReference.attachment = 2;
depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
// Two resolve attachment references for color and depth
std::array<VkAttachmentReference,2> resolveReferences = {}; std::array<VkAttachmentReference,2> resolveReferences = {};
resolveReferences[0].attachment = 1; resolveReferences[0].attachment = 1;
resolveReferences[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL; resolveReferences[0].layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
resolveReferences[1].attachment = 3; resolveReferences[1].attachment = 3;
resolveReferences[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL; resolveReferences[1].layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkAttachmentReference depthReference = {};
depthReference.attachment = 2;
depthReference.layout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL;
VkSubpassDescription subpass = {}; VkSubpassDescription subpass = {};
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS; subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
subpass.colorAttachmentCount = 1; subpass.colorAttachmentCount = 1;
subpass.pColorAttachments = &colorReference; subpass.pColorAttachments = &colorReference;
// Pass our resolve attachments to the sub pass
subpass.pResolveAttachments = resolveReferences.data(); subpass.pResolveAttachments = resolveReferences.data();
subpass.pDepthStencilAttachment = &depthReference; subpass.pDepthStencilAttachment = &depthReference;
@ -353,6 +352,7 @@ public:
VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo(); VkCommandBufferBeginInfo cmdBufInfo = vkTools::initializers::commandBufferBeginInfo();
VkClearValue clearValues[3]; VkClearValue clearValues[3];
// Clear to a white background for higher contrast
clearValues[0].color = { { 1.0f, 1.0f, 1.0f, 1.0f } }; clearValues[0].color = { { 1.0f, 1.0f, 1.0f, 1.0f } };
clearValues[1].color = { { 1.0f, 1.0f, 1.0f, 1.0f } }; clearValues[1].color = { { 1.0f, 1.0f, 1.0f, 1.0f } };
clearValues[2].depthStencil = { 1.0f, 0 }; clearValues[2].depthStencil = { 1.0f, 0 };

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB