From b6ac86a134ed560f25c648dc6f39e8787a65bd50 Mon Sep 17 00:00:00 2001 From: Xiang Silian Date: Fri, 19 Dec 2025 18:55:44 +0800 Subject: [PATCH] save code --- app/src/main/assets/shaders/texture.frag | 5 ++ app/src/main/assets/shaders/texture.frag.spv | Bin 732 -> 904 bytes vulkan/FaceApp.cpp | 78 +++++++++---------- vulkan/FaceApp.h | 2 + 4 files changed, 45 insertions(+), 40 deletions(-) diff --git a/app/src/main/assets/shaders/texture.frag b/app/src/main/assets/shaders/texture.frag index 79cefca..b3e0d70 100644 --- a/app/src/main/assets/shaders/texture.frag +++ b/app/src/main/assets/shaders/texture.frag @@ -5,6 +5,11 @@ layout (binding = 1) uniform sampler2D samplerColor; layout (location = 0) in vec2 inUV; layout (location = 1) in vec3 inNormal; +layout(push_constant) uniform PushConstantsFS { + float ux; + float uy; +} pc_fs; + layout (location = 0) out vec4 outFragColor; diff --git a/app/src/main/assets/shaders/texture.frag.spv b/app/src/main/assets/shaders/texture.frag.spv index 023edc11ea515c1a8e3be93abd56ab8e1017dcfc..c54133dbbdb5c68bf377c5e2a80dea1edfcce56c 100644 GIT binary patch delta 199 zcmcb^+QH7t%%sfDz`)4B&A`DRJCXOkD=PyVgA@Y;LqKV9hI4*iaY@Jn?0)p*sUJSOXJK&;uw9G86=qArxE;WB^Ev nWwRxtFr%&<)E+jV5C|&(`O-j|6No`ZSVQ?ByErF%GED{mP#P6f delta 34 qcmeBRzr)JQ%%sfDz`)4B&A`DRHIeuJWD~}K%{v$c7$^T=ng9T9RtO3J diff --git a/vulkan/FaceApp.cpp b/vulkan/FaceApp.cpp index 576eda6..2871723 100644 --- a/vulkan/FaceApp.cpp +++ b/vulkan/FaceApp.cpp @@ -660,6 +660,21 @@ void FaceApp::render(VkCommandBuffer commandBuffer, long long frameTime) vkCmdPushConstants(commandBuffer, m_pipelineLayout_bg, VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(float), &myFloatValue); + + float fsValues[2] = { 0, 0 }; + if (_curMotionIndex < _curMotions.size()) + { + if (_curFrameIndex < _curMotions[_curMotionIndex].frames.size()) + { + float ux = _curMotions[_curMotionIndex].frames[_curFrameIndex].x; + float uy = _curMotions[_curMotionIndex].frames[_curFrameIndex].y; + fsValues[0] = ux; + fsValues[1] = uy; + } + } + + vkCmdPushConstants(commandBuffer, m_pipelineLayout_bg, VK_SHADER_STAGE_FRAGMENT_BIT, 4, sizeof(fsValues), fsValues); + vkCmdDraw(commandBuffer, 6, 1, 0, 0); @@ -1081,13 +1096,17 @@ void FaceApp::setup_descriptor_set_layout_bg() pipeline_layout_create_info.pSetLayouts = &m_descriptorSetLayout_bg; - VkPushConstantRange pushConstantRange{}; - pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT; // 只在片段着色器中使用 - pushConstantRange.offset = 0; - pushConstantRange.size = sizeof(float); // 或者 sizeof(PushConstants) + VkPushConstantRange pushConstantRanges[2]; + pushConstantRanges[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT; // 只在片段着色器中使用 + pushConstantRanges[0].offset = 0; + pushConstantRanges[0].size = sizeof(float); // 或者 sizeof(PushConstants) - pipeline_layout_create_info.pushConstantRangeCount = 1; - pipeline_layout_create_info.pPushConstantRanges = &pushConstantRange; + pushConstantRanges[1].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; // 只在片段着色器中使用 + pushConstantRanges[1].offset = sizeof(float); + pushConstantRanges[1].size = 2 * sizeof(float); // 或者 sizeof(PushConstants) + + pipeline_layout_create_info.pushConstantRangeCount = 2; + pipeline_layout_create_info.pPushConstantRanges = &pushConstantRanges[0]; VK_CHECK(vkCreatePipelineLayout(device, &pipeline_layout_create_info, nullptr, &m_pipelineLayout_bg)); } @@ -1410,13 +1429,8 @@ void FaceApp::loadMotionThread() _callback_loadfinish(); } -void FaceApp::changeMotionList(AnimationFinishedCallback callback, bool loop) +void FaceApp::doChangeMotion() { - if (_isLoadMotion) - { - return; - } - std::unique_lock lock_changeMotion(changeMotionMtx); @@ -1433,36 +1447,20 @@ void FaceApp::changeMotionList(AnimationFinishedCallback callback, bool loop) update_descriptor_set(m_texs); _curMotions = _preLoadMotions; - _animationFinishedCallback = callback; - _animationLoop = loop; + _curFrameIndex = 0; _curMotionIndex = 0; +} +void FaceApp::changeMotionList(AnimationFinishedCallback callback, bool loop) +{ + if (_isLoadMotion) + { + return; + } + _animationFinishedCallback = callback; + _animationLoop = loop; + _needChangeMotion = true; -// for (int i = 0; i < _curMotion.png_names.size(); ++i) -// { -// -//#ifdef _WIN32 -// //string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type; -// string path = "pic"; -// string path_name = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i];// +std::to_string(i) + ".png"; -// loadTextureExample(UTF8ToWideString(path_name), m_texs[i], true); -// if (kThick) -// { -// string path_name_ex = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i] + std::to_string(i) + "_thick.png"; -// loadTextureExample(UTF8ToWideString(path_name_ex), m_texs_ex[i], true); -// } -//#else -// //string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type; -// string path = "pic"; -// string path_name = path + "/" + _curMotion.type + "/" + _curMotion.png_names[i];// +std::to_string(i) + ".png"; -// loadTexture(path_name, m_texs[i], true); -// if (kThick) -// { -// loadTexture(path_name, m_texs_ex[i], true); -// } -//#endif // _WIN32 -// -// -// } + } \ No newline at end of file diff --git a/vulkan/FaceApp.h b/vulkan/FaceApp.h index e30b9e3..64ceda7 100644 --- a/vulkan/FaceApp.h +++ b/vulkan/FaceApp.h @@ -155,6 +155,8 @@ public: void loadMotionThread(); std::thread worker_; bool _isLoadMotion = false; + bool _needChangeMotion = false; + void doChangeMotion(); Callback _callback_loadfinish; AnimationFinishedCallback _animationFinishedCallback; bool _animationLoop = true;