Skip to content
Snippets Groups Projects
Commit 9d0c4b86 authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#106] Add grid texture to better judge motion blur

parent d0073d09
No related branches found
No related tags found
1 merge request!89Resolve "Indirect Dispatch"
Pipeline #26824 passed
Showing
with 83 additions and 32 deletions
No preview for this file type
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
File deleted
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
......@@ -2,12 +2,15 @@
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 passNormal;
layout(location = 1) in vec3 passPosObject;
layout(location = 1) in vec2 passUV;
layout(location = 0) out vec3 outColor;
layout(set=0, binding=0) uniform texture2D albedoTexture;
layout(set=0, binding=1) uniform sampler textureSampler;
void main() {
vec3 albedo = vec3(sin(passPosObject.y * 100) * 0.5 + 0.5);
vec3 albedo = texture(sampler2D(albedoTexture, textureSampler), passUV).rgb;
vec3 N = normalize(passNormal);
float light = max(N.y * 0.5 + 0.5, 0);
outColor = light * albedo;
......
......@@ -3,9 +3,10 @@
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inUV;
layout(location = 0) out vec3 passNormal;
layout(location = 1) out vec3 passPosObject;
layout(location = 1) out vec2 passUV;
layout( push_constant ) uniform constants{
mat4 mvp;
......@@ -13,7 +14,7 @@ layout( push_constant ) uniform constants{
};
void main() {
gl_Position = mvp * vec4(inPosition, 1.0);
passNormal = (model * vec4(inNormal, 0)).xyz;
passPosObject = inPosition;
gl_Position = mvp * vec4(inPosition, 1.0);
passNormal = (model * vec4(inNormal, 0)).xyz;
passUV = inUV;
}
\ No newline at end of file
......@@ -2,7 +2,6 @@
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 0) out vec4 passNDC;
layout(location = 1) out vec4 passNDCPrevious;
......
......@@ -39,15 +39,15 @@ bool App::initialize() {
if (!loadComputePass(m_core, "resources/shaders/gammaCorrection.comp", &m_gammaCorrectionPass))
return false;
if (!loadMesh(m_core, "resources/models/sphere.gltf", & m_sphereMesh))
return false;
if (!loadMesh(m_core, "resources/models/cube.gltf", &m_cubeMesh))
return false;
if (!loadMesh(m_core, "resources/models/ground.gltf", &m_groundMesh))
return false;
if(!loadImage(m_core, "resources/models/grid.png", &m_gridTexture))
return false;
if (!m_motionBlur.initialize(&m_core, m_windowWidth, m_windowHeight))
return false;
......@@ -63,6 +63,11 @@ bool App::initialize() {
m_cameraManager.getCamera(cameraIndex).setPosition(glm::vec3(0, 1, -3));
m_cameraManager.getCamera(cameraIndex).setNearFar(0.1f, 30.f);
vkcv::DescriptorWrites meshPassDescriptorWrites;
meshPassDescriptorWrites.sampledImageWrites = { vkcv::SampledImageDescriptorWrite(0, m_gridTexture) };
meshPassDescriptorWrites.samplerWrites = { vkcv::SamplerDescriptorWrite(1, m_linearSampler) };
m_core.writeDescriptorSet(m_meshPass.descriptorSet, meshPassDescriptorWrites);
return true;
}
......@@ -101,6 +106,8 @@ void App::run() {
glm::mat4 viewProjectionPrevious = m_cameraManager.getActiveCamera().getMVP();
struct Object {
MeshResources meshResources;
glm::mat4 modelMatrix = glm::mat4(1.f);
......@@ -175,9 +182,9 @@ void App::run() {
m_renderTargets.motionBuffer,
m_renderTargets.depthBuffer };
std::vector<vkcv::DrawcallInfo> sceneDrawcalls;
std::vector<vkcv::DrawcallInfo> prepassSceneDrawcalls;
for (const Object& obj : sceneObjects) {
sceneDrawcalls.push_back(vkcv::DrawcallInfo(obj.meshResources.mesh, {}));
prepassSceneDrawcalls.push_back(vkcv::DrawcallInfo(obj.meshResources.mesh, {}));
}
m_core.recordDrawcallsToCmdStream(
......@@ -185,7 +192,7 @@ void App::run() {
m_prePass.renderPass,
m_prePass.pipeline,
prepassPushConstants,
sceneDrawcalls,
prepassSceneDrawcalls,
prepassRenderTargets);
// sky prepass
......@@ -214,12 +221,19 @@ void App::run() {
meshPushConstants.appendDrawcall(matrices);
}
std::vector<vkcv::DrawcallInfo> forwardSceneDrawcalls;
for (const Object& obj : sceneObjects) {
forwardSceneDrawcalls.push_back(vkcv::DrawcallInfo(
obj.meshResources.mesh,
{ vkcv::DescriptorSetUsage(0, m_core.getDescriptorSet(m_meshPass.descriptorSet).vulkanHandle) }));
}
m_core.recordDrawcallsToCmdStream(
cmdStream,
m_meshPass.renderPass,
m_meshPass.pipeline,
meshPushConstants,
sceneDrawcalls,
forwardSceneDrawcalls,
renderTargets);
// sky
......
......@@ -21,7 +21,8 @@ private:
MotionBlur m_motionBlur;
MeshResources m_sphereMesh;
vkcv::ImageHandle m_gridTexture;
MeshResources m_cubeMesh;
MeshResources m_groundMesh;
......
......@@ -48,13 +48,40 @@ bool loadMesh(vkcv::Core& core, const std::filesystem::path& path, MeshResources
const std::vector<vkcv::VertexBufferBinding> vertexBufferBindings = {
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[0].offset), vertexBuffer.getVulkanHandle()),
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[1].offset), vertexBuffer.getVulkanHandle()) };
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[1].offset), vertexBuffer.getVulkanHandle()),
vkcv::VertexBufferBinding(static_cast<vk::DeviceSize>(attributes[2].offset), vertexBuffer.getVulkanHandle()) };
outMesh->mesh = vkcv::Mesh(vertexBufferBindings, indexBuffer.getVulkanHandle(), scene.vertexGroups[0].numIndices);
return true;
}
bool loadImage(vkcv::Core& core, const std::filesystem::path& path, vkcv::ImageHandle* outImage) {
assert(outImage);
const vkcv::asset::TextureData textureData = vkcv::asset::loadTexture(path);
if (textureData.componentCount != 4) {
vkcv_log(vkcv::LogLevel::ERROR, "Expecting image with four components");
return false;
}
vkcv::Image image = core.createImage(
vk::Format::eR8G8B8A8Srgb,
textureData.width,
textureData.height,
1,
true);
image.fill(textureData.data.data(), textureData.data.size());
image.generateMipChainImmediate();
image.switchLayout(vk::ImageLayout::eReadOnlyOptimalKHR);
*outImage = image.getHandle();
return true;
}
bool loadGraphicPass(
vkcv::Core& core,
const std::filesystem::path vertexPath,
......@@ -93,13 +120,22 @@ bool loadGraphicPass(
const vkcv::VertexLayout vertexLayout(bindings);
const auto descriptorBindings = shaderProgram.getReflectedDescriptors();
const bool hasDescriptor = descriptorBindings.size() > 0;
if (hasDescriptor)
outPassHandles->descriptorSet = core.createDescriptorSet(descriptorBindings[0]);
std::vector<vk::DescriptorSetLayout> descriptorLayouts;
if (hasDescriptor)
descriptorLayouts.push_back(core.getDescriptorSet(outPassHandles->descriptorSet).layout);
vkcv::PipelineConfig pipelineConfig{
shaderProgram,
UINT32_MAX,
UINT32_MAX,
outPassHandles->renderPass,
{ vertexLayout },
{},
descriptorLayouts,
true };
pipelineConfig.m_depthTest = depthTest;
outPassHandles->pipeline = core.createGraphicsPipeline(pipelineConfig);
......
......@@ -8,8 +8,9 @@ struct AppRenderTargets {
};
struct GraphicPassHandles {
vkcv::PipelineHandle pipeline;
vkcv::PassHandle renderPass;
vkcv::PipelineHandle pipeline;
vkcv::PassHandle renderPass;
vkcv::DescriptorSetHandle descriptorSet;
};
struct ComputePassHandles {
......@@ -23,9 +24,11 @@ struct MeshResources {
vkcv::BufferHandle indexBuffer;
};
// loads position and normal of the first mesh in a scene
// loads position, uv and normal of the first mesh in a scene
bool loadMesh(vkcv::Core& core, const std::filesystem::path& path, MeshResources* outMesh);
bool loadImage(vkcv::Core& core, const std::filesystem::path& path, vkcv::ImageHandle* outImage);
bool loadGraphicPass(
vkcv::Core& core,
const std::filesystem::path vertexPath,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment