Use rotation for background gradient; fix timing

Update fragment shader to use ubo.rotation instead of ubo.time and sync
the SPIR-V. Add periodic debug output in VulkanRenderer. Track total
paused time in VulkanWidget (m_totalPausedTime) and subtract it from
elapsed time so animations remain in sync after lock/unlock.
This commit is contained in:
hoenking 2025-11-14 19:21:21 +08:00
parent 7fb1a8a538
commit 95a04efb91
6 changed files with 23 additions and 8 deletions

View File

@ -28,8 +28,8 @@ void main() {
// Normalize position to 0-1 range
vec2 uv = (fragPosition + 1.0) * 0.5;
// Create dynamic gradient based on time
float t = ubo.time / 360.0;
// Create dynamic gradient based on rotation angle (matching Qt CustomWidget)
float t = ubo.rotation / 360.0;
// Calculate color components matching Qt CustomWidget
float r = 0.392 + 0.196 * sin(t * 6.28318);

View File

@ -36,7 +36,7 @@
0x3f800000u, 0x0007002cu, 0x00000014u, 0x00000019u, 0x00000017u, 0x00000017u, 0x00000017u, 0x00000018u,
0x00040017u, 0x0000001bu, 0x00000006u, 0x00000002u, 0x00040020u, 0x0000001cu, 0x00000007u, 0x0000001bu,
0x00040020u, 0x0000001eu, 0x00000001u, 0x0000001bu, 0x0004003bu, 0x0000001eu, 0x0000001fu, 0x00000001u,
0x00040020u, 0x00000024u, 0x00000007u, 0x00000006u, 0x0004002bu, 0x0000000au, 0x00000026u, 0x00000000u,
0x00040020u, 0x00000024u, 0x00000007u, 0x00000006u, 0x0004002bu, 0x0000000au, 0x00000026u, 0x00000003u,
0x0004002bu, 0x00000006u, 0x00000029u, 0x43b40000u, 0x0004002bu, 0x00000006u, 0x0000002cu, 0x3ec8b439u,
0x0004002bu, 0x00000006u, 0x0000002du, 0x3e48b439u, 0x0004002bu, 0x00000006u, 0x0000002fu, 0x40c90fd0u,
0x0004002bu, 0x00000006u, 0x00000035u, 0x3f16872bu, 0x0004002bu, 0x00000006u, 0x00000038u, 0x3f860419u,

View File

@ -562,6 +562,15 @@ void VulkanRenderer::recordCommandBuffer(VkCommandBuffer commandBuffer,
m_ubo.wavePhase = static_cast<float>(wavePhase);
m_ubo.paintingEnabled = paintingEnabled ? 1.0f : 0.0f;
// Debug output every 60 frames
static int debugCounter = 0;
if (++debugCounter % 60 == 0) {
std::cout << "Background animation - time: " << m_ubo.time
<< ", rotation: " << m_ubo.rotation
<< ", wavePhase: " << m_ubo.wavePhase
<< ", paintingEnabled: " << m_ubo.paintingEnabled << std::endl;
}
// CRITICAL FIX: Update ALL uniform buffers every frame!

View File

@ -60,6 +60,7 @@ VulkanWidget::VulkanWidget(QWidget *parent)
, m_wavePhase(0.0)
, m_startTime(QDateTime::currentDateTime())
, m_lastLockDuration(0)
, m_totalPausedTime(0)
, m_lastLockFrameCount(0)
, m_lockPaintFrameCount(0)
, m_lockCount(0)
@ -134,17 +135,20 @@ void VulkanWidget::setRenderingEnabled(bool enabled)
qDebug() << "Render timer restarted";
}
// Unlocked: calculate lock duration
// Unlocked: calculate lock duration and accumulate paused time
if (m_lastLockTime.isValid()) {
QDateTime unlockTime = QDateTime::currentDateTime();
m_lastLockDuration = m_lastLockTime.secsTo(unlockTime);
m_lockPaintFrameCount = m_frameCount - m_lastLockFrameCount;
// 累积锁屏期间的暂停时间
m_totalPausedTime += m_lastLockDuration;
qDebug() << "Screen was locked for" << m_lastLockDuration << "seconds";
qDebug() << "Total paused time:" << m_totalPausedTime << "seconds";
qDebug() << "Frames at lock:" << m_lastLockFrameCount
<< "- Frames painted during lock:" << m_lockPaintFrameCount;
}
m_startTime = QDateTime::currentDateTime();
} else {
qDebug() << "Vulkan rendering DISABLED - Showing locked state";
// 关键修复:渲染一帧锁屏界面后停止定时器
@ -980,9 +984,10 @@ void VulkanWidget::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t i
.arg(m_lockCount);
}
// Calculate elapsed time in seconds
// Calculate elapsed time in seconds (total runtime minus paused time)
QDateTime now = QDateTime::currentDateTime();
qint64 elapsedTime = m_startTime.secsTo(now);
qint64 totalRuntime = m_startTime.secsTo(now);
qint64 elapsedTime = totalRuntime - m_totalPausedTime;
m_renderer->recordCommandBuffer(commandBuffer, imageIndex, imageView,
m_frameCount, static_cast<double>(elapsedTime),

View File

@ -254,6 +254,7 @@ private:
QDateTime m_pauseTime;
QDateTime m_lastLockTime;
qint64 m_lastLockDuration;
qint64 m_totalPausedTime; // 累积的暂停时间(秒)
int m_lastLockFrameCount;
int m_lockPaintFrameCount;
int m_lockCount;