vulkan animation

This commit is contained in:
Jorijn van der Graaf 2026-01-30 00:09:37 +01:00
commit db1616ff0e
4 changed files with 30 additions and 6 deletions

View file

@ -88,9 +88,22 @@ int main() {
*/
window.FinishInit();
EventListener<VkCommandBuffer> updateListener(&window.onRender, [&](VkCommandBuffer cmd){
std::cout << window.currentBuffer << std::endl;
RenderingElement3DVulkan::BuildTLAS(cmd, window.currentBuffer);
Animation<std::tuple<float>> anim({
{std::chrono::seconds(3), -600, 600},
});
anim.Start(std::chrono::high_resolution_clock::now());
EventListener<void> updateListener(&window.onRender, [&](){
float value = std::get<0>(anim.Play(window.currentFrameTime.now));
if(anim.currentFrame == anim.keyframes.size()) {
anim.Start(window.currentFrameTime.now);
}
MatrixRowMajor<float, 4, 3, 1> transform = MatrixRowMajor<float, 4, 3, 1>::Translation(value, 0, 0);
std::memcpy(el.instance.transform.matrix, transform.m, sizeof(transform.m));
RenderingElement3DVulkan::BuildTLAS(window.drawCmdBuffers[window.currentBuffer], window.currentBuffer);
VkDescriptorImageInfo imageInfo = {
.imageView = window.imageViews[window.currentBuffer],
.imageLayout = VK_IMAGE_LAYOUT_GENERAL
@ -123,7 +136,6 @@ int main() {
}
};
vkUpdateDescriptorSets(VulkanDevice::device, 2, write, 0, nullptr);
window.descriptorsRt[0] = pool.sets[window.currentBuffer];
});

View file

@ -116,4 +116,14 @@ void RenderingElement3DVulkan::BuildTLAS(VkCommandBuffer cmd, std::uint32_t inde
VkAccelerationStructureBuildRangeInfoKHR* tlasRangeInfoPP = &tlasRangeInfo;
VulkanDevice::vkCmdBuildAccelerationStructuresKHR(cmd, 1, &tlasBuildGeometryInfo, &tlasRangeInfoPP);
vkCmdPipelineBarrier(
cmd,
VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR,
VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR,
0,
0, nullptr,
0, nullptr,
0, nullptr
);
}

View file

@ -368,7 +368,7 @@ void WindowVulkan::Render() {
range
);
onRender.Invoke(drawCmdBuffers[currentBuffer]);
onRender.Invoke();
vkCmdBindPipeline(drawCmdBuffers[currentBuffer], VK_PIPELINE_BIND_POINT_RAY_TRACING_KHR, rtPipeline);
VkBindDescriptorSetsInfo bindDescriptorSetsInfo{
@ -474,6 +474,7 @@ void WindowVulkan::wl_surface_frame_done(void* data, struct wl_callback *cb, uin
if(window->updating) {
cb = wl_surface_frame(window->surface);
wl_callback_add_listener(cb, &WindowVulkan::wl_callback_listener, window);
window->currentFrameTime = {start, start-window->lastFrameBegin};
window->onUpdate.Invoke({start, start-window->lastFrameBegin});
#ifdef CRAFTER_TIMING
window->totalUpdate = std::chrono::nanoseconds(0);

View file

@ -76,6 +76,7 @@ export namespace Crafter {
class MouseElement;
class Window {
public:
FrameTime currentFrameTime;
std::int32_t width;
std::int32_t height;
std::chrono::time_point<std::chrono::high_resolution_clock> lastFrameBegin;
@ -300,7 +301,7 @@ export namespace Crafter {
xkb_keymap* xkb_keymap;
xkb_context* xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
xkb_state* xkb_state;
Event<VkCommandBuffer> onRender;
Event<void> onRender;
std::vector<VkDescriptorSet> descriptorsRt;
void Render();
void QueueRender();