diff --git a/projects/indirect_dispatch/resources/shaders/mesh.frag b/projects/indirect_dispatch/resources/shaders/mesh.frag index 7da116a50b330b531de7e1f0a80a58fd8a0277d8..7e57746eb8621dff65ce5896ec81d3b7d26d0533 100644 --- a/projects/indirect_dispatch/resources/shaders/mesh.frag +++ b/projects/indirect_dispatch/resources/shaders/mesh.frag @@ -2,13 +2,13 @@ #extension GL_ARB_separate_shader_objects : enable layout(location = 0) in vec3 passNormal; -layout(location = 1) in vec3 passPos; +layout(location = 1) in vec3 passPosObject; layout(location = 0) out vec3 outColor; void main() { - vec3 albedo = vec3(sin(passPos.y * 100) * 0.5 + 0.5); + vec3 albedo = vec3(sin(passPosObject.y * 100) * 0.5 + 0.5); vec3 N = normalize(passNormal); float light = max(N.y * 0.5 + 0.5, 0); - outColor = light * albedo; + outColor = light * albedo; } \ No newline at end of file diff --git a/projects/indirect_dispatch/resources/shaders/mesh.vert b/projects/indirect_dispatch/resources/shaders/mesh.vert index 769867e3a0ebc0ce55bbf73b62d2b8a299b80b91..175d88c859bc9c7aab32a78023c7bab42c1e8e8b 100644 --- a/projects/indirect_dispatch/resources/shaders/mesh.vert +++ b/projects/indirect_dispatch/resources/shaders/mesh.vert @@ -5,14 +5,15 @@ layout(location = 0) in vec3 inPosition; layout(location = 1) in vec3 inNormal; layout(location = 0) out vec3 passNormal; -layout(location = 1) out vec3 passPos; +layout(location = 1) out vec3 passPosObject; layout( push_constant ) uniform constants{ mat4 mvp; + mat4 model; }; void main() { - gl_Position = mvp * vec4(inPosition, 1.0); - passNormal = inNormal; - passPos = inPosition; + gl_Position = mvp * vec4(inPosition, 1.0); + passNormal = (model * vec4(inNormal, 0)).xyz; + passPosObject = inPosition; } \ No newline at end of file diff --git a/projects/indirect_dispatch/src/App.cpp b/projects/indirect_dispatch/src/App.cpp index b27798b6573b24ecfdfc9b1087e070f5dd92d67c..8fb9031ba76cfa14f27ecaa56d3e7e89ea84f4b6 100644 --- a/projects/indirect_dispatch/src/App.cpp +++ b/projects/indirect_dispatch/src/App.cpp @@ -92,8 +92,10 @@ void App::run() { eMotionVectorMode motionBlurMotionMode = eMotionVectorMode::MaxTileNeighbourhood; float objectVerticalSpeed = 5; - float objectAmplitude = 1; + float objectAmplitude = 0; float objectMeanHeight = 1; + float objectRotationSpeedX = 5; + float objectRotationSpeedY = 5; int cameraShutterSpeedInverse = 24; float motionVectorVisualisationRange = 0.008; @@ -116,7 +118,10 @@ void App::run() { sphere.meshResources = m_cubeMesh; sphere.modelMatrixUpdate = [&](float time, Object& obj) { const float currentHeight = objectMeanHeight + objectAmplitude * glm::sin(time * objectVerticalSpeed); - obj.modelMatrix = glm::translate(glm::mat4(1), glm::vec3(0, currentHeight, 0)); + const glm::mat4 translation = glm::translate(glm::mat4(1), glm::vec3(0, currentHeight, 0)); + const glm::mat4 rotationX = glm::rotate(glm::mat4(1), objectRotationSpeedX * time, glm::vec3(1, 0, 0)); + const glm::mat4 rotationY = glm::rotate(glm::mat4(1), objectRotationSpeedY * time, glm::vec3(0, 1, 0)); + obj.modelMatrix = translation * rotationX * rotationY; }; sceneObjects.push_back(sphere); @@ -203,9 +208,10 @@ void App::run() { m_renderTargets.colorBuffer, m_renderTargets.depthBuffer }; - vkcv::PushConstants meshPushConstants(sizeof(glm::mat4)); + vkcv::PushConstants meshPushConstants(2 * sizeof(glm::mat4)); for (const Object& obj : sceneObjects) { - meshPushConstants.appendDrawcall(obj.mvp); + glm::mat4 matrices[2] = { obj.mvp, obj.modelMatrix }; + meshPushConstants.appendDrawcall(matrices); } m_core.recordDrawcallsToCmdStream( @@ -322,6 +328,8 @@ void App::run() { ImGui::InputFloat("Object movement speed", &objectVerticalSpeed); ImGui::InputFloat("Object movement amplitude", &objectAmplitude); ImGui::InputFloat("Object mean height", &objectMeanHeight); + ImGui::InputFloat("Object rotation speed X", &objectRotationSpeedX); + ImGui::InputFloat("Object rotation speed Y", &objectRotationSpeedY); ImGui::End(); gui.endGUI();