SSAO sample: Render Sponza with textures
This commit is contained in:
parent
73e538c1b8
commit
70ec72e790
5 changed files with 29 additions and 15 deletions
|
|
@ -9,7 +9,7 @@ layout (location = 0) out vec4 outPosition;
|
||||||
layout (location = 1) out vec4 outNormal;
|
layout (location = 1) out vec4 outNormal;
|
||||||
layout (location = 2) out vec4 outAlbedo;
|
layout (location = 2) out vec4 outAlbedo;
|
||||||
|
|
||||||
layout (binding = 0) uniform UBO
|
layout (set = 0, binding = 0) uniform UBO
|
||||||
{
|
{
|
||||||
mat4 projection;
|
mat4 projection;
|
||||||
mat4 model;
|
mat4 model;
|
||||||
|
|
@ -18,6 +18,8 @@ layout (binding = 0) uniform UBO
|
||||||
float farPlane;
|
float farPlane;
|
||||||
} ubo;
|
} ubo;
|
||||||
|
|
||||||
|
layout (set = 1, binding = 0) uniform sampler2D samplerColormap;
|
||||||
|
|
||||||
float linearDepth(float depth)
|
float linearDepth(float depth)
|
||||||
{
|
{
|
||||||
float z = depth * 2.0f - 1.0f;
|
float z = depth * 2.0f - 1.0f;
|
||||||
|
|
@ -28,5 +30,5 @@ void main()
|
||||||
{
|
{
|
||||||
outPosition = vec4(inPos, linearDepth(gl_FragCoord.z));
|
outPosition = vec4(inPos, linearDepth(gl_FragCoord.z));
|
||||||
outNormal = vec4(normalize(inNormal) * 0.5 + 0.5, 1.0);
|
outNormal = vec4(normalize(inNormal) * 0.5 + 0.5, 1.0);
|
||||||
outAlbedo = vec4(inColor * 2.0, 1.0);
|
outAlbedo = texture(samplerColormap * inColor, inUV);
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -20,6 +20,9 @@ struct UBO
|
||||||
|
|
||||||
cbuffer ubo : register(b0) { UBO ubo; }
|
cbuffer ubo : register(b0) { UBO ubo; }
|
||||||
|
|
||||||
|
Texture2D textureColorMap : register(t0, space1);
|
||||||
|
SamplerState samplerColorMap : register(s0, space1);
|
||||||
|
|
||||||
struct FSOutput
|
struct FSOutput
|
||||||
{
|
{
|
||||||
float4 Position : SV_TARGET0;
|
float4 Position : SV_TARGET0;
|
||||||
|
|
@ -38,6 +41,6 @@ FSOutput main(VSOutput input)
|
||||||
FSOutput output = (FSOutput)0;
|
FSOutput output = (FSOutput)0;
|
||||||
output.Position = float4(input.WorldPos, linearDepth(input.Pos.z));
|
output.Position = float4(input.WorldPos, linearDepth(input.Pos.z));
|
||||||
output.Normal = float4(normalize(input.Normal) * 0.5 + 0.5, 1.0);
|
output.Normal = float4(normalize(input.Normal) * 0.5 + 0.5, 1.0);
|
||||||
output.Albedo = float4(input.Color * 2.0, 1.0);
|
output.Albedo = textureColorMap.Sample(samplerColorMap, input.UV) * float4(input.Color, 1.0);
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
|
@ -129,8 +129,8 @@ public:
|
||||||
#ifndef __ANDROID__
|
#ifndef __ANDROID__
|
||||||
camera.rotationSpeed = 0.25f;
|
camera.rotationSpeed = 0.25f;
|
||||||
#endif
|
#endif
|
||||||
camera.position = { 5.0f, 1.0f, 0.0f };
|
camera.position = { 1.0f, 0.75f, 0.0f };
|
||||||
camera.setRotation(glm::vec3(5.0f, 90.0f, 0.0f));
|
camera.setRotation(glm::vec3(0.0f, 90.0f, 0.0f));
|
||||||
camera.setPerspective(60.0f, (float)width / (float)height, uboSceneParams.nearPlane, uboSceneParams.farPlane);
|
camera.setPerspective(60.0f, (float)width / (float)height, uboSceneParams.nearPlane, uboSceneParams.farPlane);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -174,6 +174,11 @@ public:
|
||||||
textures.ssaoNoise.destroy();
|
textures.ssaoNoise.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getEnabledFeatures()
|
||||||
|
{
|
||||||
|
enabledFeatures.samplerAnisotropy = deviceFeatures.samplerAnisotropy;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a frame buffer attachment
|
// Create a frame buffer attachment
|
||||||
void createAttachment(
|
void createAttachment(
|
||||||
VkFormat format,
|
VkFormat format,
|
||||||
|
|
@ -482,7 +487,8 @@ public:
|
||||||
|
|
||||||
void loadAssets()
|
void loadAssets()
|
||||||
{
|
{
|
||||||
const uint32_t gltfLoadingFlags = vkglTF::FileLoadingFlags::FlipY | vkglTF::FileLoadingFlags::PreTransformVertices | vkglTF::FileLoadingFlags::DontLoadImages;
|
vkglTF::descriptorBindingFlags = vkglTF::DescriptorBindingFlags::ImageBaseColor;
|
||||||
|
const uint32_t gltfLoadingFlags = vkglTF::FileLoadingFlags::FlipY | vkglTF::FileLoadingFlags::PreTransformVertices;
|
||||||
scene.loadFromFile(getAssetPath() + "models/sponza/sponza.gltf", vulkanDevice, queue, gltfLoadingFlags);
|
scene.loadFromFile(getAssetPath() + "models/sponza/sponza.gltf", vulkanDevice, queue, gltfLoadingFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -530,7 +536,7 @@ public:
|
||||||
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.offscreen);
|
vkCmdBindPipeline(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelines.offscreen);
|
||||||
|
|
||||||
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.gBuffer, 0, 1, &descriptorSets.floor, 0, NULL);
|
vkCmdBindDescriptorSets(drawCmdBuffers[i], VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayouts.gBuffer, 0, 1, &descriptorSets.floor, 0, NULL);
|
||||||
scene.draw(drawCmdBuffers[i]);
|
scene.draw(drawCmdBuffers[i], vkglTF::RenderFlags::BindImages, pipelineLayouts.gBuffer);
|
||||||
|
|
||||||
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
vkCmdEndRenderPass(drawCmdBuffers[i]);
|
||||||
|
|
||||||
|
|
@ -653,7 +659,10 @@ public:
|
||||||
};
|
};
|
||||||
setLayoutCreateInfo = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
|
setLayoutCreateInfo = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast<uint32_t>(setLayoutBindings.size()));
|
||||||
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &setLayoutCreateInfo, nullptr, &descriptorSetLayouts.gBuffer));
|
VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &setLayoutCreateInfo, nullptr, &descriptorSetLayouts.gBuffer));
|
||||||
pipelineLayoutCreateInfo.pSetLayouts = &descriptorSetLayouts.gBuffer;
|
|
||||||
|
const std::vector<VkDescriptorSetLayout> setLayouts = { descriptorSetLayouts.gBuffer, vkglTF::descriptorSetLayoutImage };
|
||||||
|
pipelineLayoutCreateInfo.pSetLayouts = setLayouts.data();
|
||||||
|
pipelineLayoutCreateInfo.setLayoutCount = 2;
|
||||||
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayouts.gBuffer));
|
VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayouts.gBuffer));
|
||||||
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.gBuffer;
|
descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.gBuffer;
|
||||||
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.floor));
|
VK_CHECK_RESULT(vkAllocateDescriptorSets(device, &descriptorAllocInfo, &descriptorSets.floor));
|
||||||
|
|
@ -661,6 +670,7 @@ public:
|
||||||
vks::initializers::writeDescriptorSet(descriptorSets.floor, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.sceneParams.descriptor),
|
vks::initializers::writeDescriptorSet(descriptorSets.floor, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 0, &uniformBuffers.sceneParams.descriptor),
|
||||||
};
|
};
|
||||||
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
vkUpdateDescriptorSets(device, static_cast<uint32_t>(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL);
|
||||||
|
pipelineLayoutCreateInfo.setLayoutCount = 1;
|
||||||
|
|
||||||
// SSAO Generation
|
// SSAO Generation
|
||||||
setLayoutBindings = {
|
setLayoutBindings = {
|
||||||
|
|
@ -928,16 +938,15 @@ public:
|
||||||
|
|
||||||
virtual void render()
|
virtual void render()
|
||||||
{
|
{
|
||||||
if (!prepared)
|
if (!prepared) {
|
||||||
return;
|
return;
|
||||||
draw();
|
|
||||||
}
|
}
|
||||||
|
draw();
|
||||||
virtual void viewChanged()
|
if (camera.updated) {
|
||||||
{
|
|
||||||
updateUniformBufferMatrices();
|
updateUniformBufferMatrices();
|
||||||
updateUniformBufferSSAOParams();
|
updateUniformBufferSSAOParams();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue