diff --git a/data/shaders/glsl/ssao/gbuffer.frag b/data/shaders/glsl/ssao/gbuffer.frag index bd281aad..e0c93478 100644 --- a/data/shaders/glsl/ssao/gbuffer.frag +++ b/data/shaders/glsl/ssao/gbuffer.frag @@ -9,7 +9,7 @@ layout (location = 0) out vec4 outPosition; layout (location = 1) out vec4 outNormal; layout (location = 2) out vec4 outAlbedo; -layout (binding = 0) uniform UBO +layout (set = 0, binding = 0) uniform UBO { mat4 projection; mat4 model; @@ -18,6 +18,8 @@ layout (binding = 0) uniform UBO float farPlane; } ubo; +layout (set = 1, binding = 0) uniform sampler2D samplerColormap; + float linearDepth(float depth) { float z = depth * 2.0f - 1.0f; @@ -28,5 +30,5 @@ void main() { outPosition = vec4(inPos, linearDepth(gl_FragCoord.z)); outNormal = vec4(normalize(inNormal) * 0.5 + 0.5, 1.0); - outAlbedo = vec4(inColor * 2.0, 1.0); + outAlbedo = texture(samplerColormap * inColor, inUV); } \ No newline at end of file diff --git a/data/shaders/glsl/ssao/gbuffer.frag.spv b/data/shaders/glsl/ssao/gbuffer.frag.spv index fdee49c2..40d1af46 100644 Binary files a/data/shaders/glsl/ssao/gbuffer.frag.spv and b/data/shaders/glsl/ssao/gbuffer.frag.spv differ diff --git a/data/shaders/hlsl/ssao/gbuffer.frag b/data/shaders/hlsl/ssao/gbuffer.frag index 8232da34..6b59dd50 100644 --- a/data/shaders/hlsl/ssao/gbuffer.frag +++ b/data/shaders/hlsl/ssao/gbuffer.frag @@ -20,6 +20,9 @@ struct UBO cbuffer ubo : register(b0) { UBO ubo; } +Texture2D textureColorMap : register(t0, space1); +SamplerState samplerColorMap : register(s0, space1); + struct FSOutput { float4 Position : SV_TARGET0; @@ -38,6 +41,6 @@ FSOutput main(VSOutput input) FSOutput output = (FSOutput)0; output.Position = float4(input.WorldPos, linearDepth(input.Pos.z)); 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; } \ No newline at end of file diff --git a/data/shaders/hlsl/ssao/gbuffer.frag.spv b/data/shaders/hlsl/ssao/gbuffer.frag.spv index 982d6fd5..8ab0e21d 100644 Binary files a/data/shaders/hlsl/ssao/gbuffer.frag.spv and b/data/shaders/hlsl/ssao/gbuffer.frag.spv differ diff --git a/examples/ssao/ssao.cpp b/examples/ssao/ssao.cpp index b5fbde4f..db7a4763 100644 --- a/examples/ssao/ssao.cpp +++ b/examples/ssao/ssao.cpp @@ -129,8 +129,8 @@ public: #ifndef __ANDROID__ camera.rotationSpeed = 0.25f; #endif - camera.position = { 5.0f, 1.0f, 0.0f }; - camera.setRotation(glm::vec3(5.0f, 90.0f, 0.0f)); + camera.position = { 1.0f, 0.75f, 0.0f }; + camera.setRotation(glm::vec3(0.0f, 90.0f, 0.0f)); camera.setPerspective(60.0f, (float)width / (float)height, uboSceneParams.nearPlane, uboSceneParams.farPlane); } @@ -174,6 +174,11 @@ public: textures.ssaoNoise.destroy(); } + void getEnabledFeatures() + { + enabledFeatures.samplerAnisotropy = deviceFeatures.samplerAnisotropy; + } + // Create a frame buffer attachment void createAttachment( VkFormat format, @@ -482,7 +487,8 @@ public: 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); } @@ -530,7 +536,7 @@ public: 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); - scene.draw(drawCmdBuffers[i]); + scene.draw(drawCmdBuffers[i], vkglTF::RenderFlags::BindImages, pipelineLayouts.gBuffer); vkCmdEndRenderPass(drawCmdBuffers[i]); @@ -653,7 +659,10 @@ public: }; setLayoutCreateInfo = vks::initializers::descriptorSetLayoutCreateInfo(setLayoutBindings.data(), static_cast(setLayoutBindings.size())); VK_CHECK_RESULT(vkCreateDescriptorSetLayout(device, &setLayoutCreateInfo, nullptr, &descriptorSetLayouts.gBuffer)); - pipelineLayoutCreateInfo.pSetLayouts = &descriptorSetLayouts.gBuffer; + + const std::vector setLayouts = { descriptorSetLayouts.gBuffer, vkglTF::descriptorSetLayoutImage }; + pipelineLayoutCreateInfo.pSetLayouts = setLayouts.data(); + pipelineLayoutCreateInfo.setLayoutCount = 2; VK_CHECK_RESULT(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, nullptr, &pipelineLayouts.gBuffer)); descriptorAllocInfo.pSetLayouts = &descriptorSetLayouts.gBuffer; 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), }; vkUpdateDescriptorSets(device, static_cast(writeDescriptorSets.size()), writeDescriptorSets.data(), 0, NULL); + pipelineLayoutCreateInfo.setLayoutCount = 1; // SSAO Generation setLayoutBindings = { @@ -928,15 +938,14 @@ public: virtual void render() { - if (!prepared) + if (!prepared) { return; + } draw(); - } - - virtual void viewChanged() - { - updateUniformBufferMatrices(); - updateUniformBufferSSAOParams(); + if (camera.updated) { + updateUniformBufferMatrices(); + updateUniformBufferSSAOParams(); + } } virtual void OnUpdateUIOverlay(vks::UIOverlay *overlay)