修改为单纹理,在android上编译通过,apk修改为日期名字
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
layout (binding = 2) uniform sampler2D samplerColor_ex;
|
||||
|
||||
layout (location = 0) in vec2 inUV;
|
||||
layout (location = 1) in vec3 inNormal;
|
||||
@@ -12,45 +11,7 @@ layout (location = 0) out vec4 outFragColor;
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(samplerColor, inUV);
|
||||
vec4 color_ex = texture(samplerColor_ex, inUV);
|
||||
|
||||
vec3 N = normalize(inNormal);
|
||||
outFragColor = color;
|
||||
|
||||
// 计算与 (0,0,1) 的点乘
|
||||
float ndot = dot(N, vec3(0.0, 0.0, -1.0));
|
||||
|
||||
// 保证结果 >= 0
|
||||
ndot = max(ndot, 0.0);
|
||||
|
||||
// 重新映射ndot值,让中间2/3部分进行融合
|
||||
// 当ndot在[0.166, 0.833]范围内时进行混合,两端保持不变
|
||||
float blendFactor;
|
||||
if (ndot < 0.0) {
|
||||
blendFactor = 0.0; // 完全使用color_ex
|
||||
} else if (ndot > 0.1) {
|
||||
blendFactor = 1.0; // 完全使用color
|
||||
} else {
|
||||
// 在中间2/3部分进行平滑过渡
|
||||
blendFactor = (ndot - 0.0) / (1 - 0);
|
||||
}
|
||||
|
||||
// 使用smoothstep创建中间2/3的融合区域
|
||||
// 参数说明:smoothstep(edge0, edge1, x)
|
||||
// 当x < edge0时返回0,当x > edge1时返回1,在中间时平滑过渡
|
||||
//float blendFactor = smoothstep(0.166, 0.833, ndot);
|
||||
|
||||
|
||||
// vec4 blendedColor = mix(color_ex, color, ndot);
|
||||
|
||||
// outFragColor = blendedColor;
|
||||
|
||||
if (ndot < 0.3){
|
||||
outFragColor = color_ex;
|
||||
}
|
||||
else
|
||||
{
|
||||
outFragColor = color;
|
||||
}
|
||||
|
||||
// outFragColor = vec4(1, 0, 0, 1);
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,56 @@
|
||||
#version 450
|
||||
|
||||
layout (binding = 1) uniform sampler2D samplerColor;
|
||||
layout (binding = 2) uniform sampler2D samplerColor_ex;
|
||||
|
||||
layout (location = 0) in vec2 inUV;
|
||||
layout (location = 1) in vec3 inNormal;
|
||||
|
||||
|
||||
layout (location = 0) out vec4 outFragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 color = texture(samplerColor, inUV);
|
||||
vec4 color_ex = texture(samplerColor_ex, inUV);
|
||||
|
||||
vec3 N = normalize(inNormal);
|
||||
|
||||
// 计算与 (0,0,1) 的点乘
|
||||
float ndot = dot(N, vec3(0.0, 0.0, -1.0));
|
||||
|
||||
// 保证结果 >= 0
|
||||
ndot = max(ndot, 0.0);
|
||||
|
||||
// 重新映射ndot值,让中间2/3部分进行融合
|
||||
// 当ndot在[0.166, 0.833]范围内时进行混合,两端保持不变
|
||||
float blendFactor;
|
||||
if (ndot < 0.0) {
|
||||
blendFactor = 0.0; // 完全使用color_ex
|
||||
} else if (ndot > 0.1) {
|
||||
blendFactor = 1.0; // 完全使用color
|
||||
} else {
|
||||
// 在中间2/3部分进行平滑过渡
|
||||
blendFactor = (ndot - 0.0) / (1 - 0);
|
||||
}
|
||||
|
||||
// 使用smoothstep创建中间2/3的融合区域
|
||||
// 参数说明:smoothstep(edge0, edge1, x)
|
||||
// 当x < edge0时返回0,当x > edge1时返回1,在中间时平滑过渡
|
||||
//float blendFactor = smoothstep(0.166, 0.833, ndot);
|
||||
|
||||
|
||||
// vec4 blendedColor = mix(color_ex, color, ndot);
|
||||
|
||||
// outFragColor = blendedColor;
|
||||
|
||||
if (ndot < 0.3){
|
||||
outFragColor = color_ex;
|
||||
}
|
||||
else
|
||||
{
|
||||
outFragColor = color;
|
||||
}
|
||||
|
||||
// outFragColor = vec4(1, 0, 0, 1);
|
||||
}
|
||||
Binary file not shown.
@@ -4,5 +4,8 @@ glslangValidator -V app/src/main/assets/shaders/bg.vert -o app/src/main/assets/s
|
||||
glslangValidator -V app/src/main/assets/shaders/texture.frag -o app/src/main/assets/shaders/texture.frag.spv
|
||||
glslangValidator -V app/src/main/assets/shaders/texture.vert -o app/src/main/assets/shaders/texture.vert.spv
|
||||
|
||||
glslangValidator -V app/src/main/assets/shaders/texture_thick.frag -o app/src/main/assets/shaders/texture_thick.frag.spv
|
||||
glslangValidator -V app/src/main/assets/shaders/texture_thick.vert -o app/src/main/assets/shaders/texture_thick.vert.spv
|
||||
|
||||
glslangValidator -V app/src/main/assets/shaders/simple_shader.frag -o app/src/main/assets/shaders/simple_shader.frag.spv
|
||||
glslangValidator -V app/src/main/assets/shaders/simple_shader.vert -o app/src/main/assets/shaders/simple_shader.vert.spv
|
||||
@@ -7,7 +7,7 @@ android {
|
||||
compileSdk 36
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.hmwl.example"
|
||||
applicationId "com.hmwl.f20251028"
|
||||
minSdk 30
|
||||
targetSdk 36
|
||||
versionCode 1
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
@@ -7,7 +7,7 @@ public class MainActivity extends FaceActivity{
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
SetInitArg("{\"action_fps\":3,\"motion\":{\"png_name\":\"demo\",\"png_num\":1,\"show_type\":\"direction\",\"step\":\"press2\",\"technique\":\"base_makeup\",\"type\":\"bottom_makeup\"},\"zoom\":1.5}");
|
||||
SetInitArg("{\"action_fps\":3,\"motion\":{\"png_name\":\"test\",\"png_num\":1,\"show_type\":\"direction\",\"step\":\"press2\",\"technique\":\"base_makeup\",\"type\":\"bottom_makeup\"},\"zoom\":1.5}");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//这个是设置接口的参数,采用json传递,可以保证接口灵活性
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">example</string>
|
||||
<string name="app_name">f20251028</string>
|
||||
</resources>
|
||||
+93
-38
@@ -360,9 +360,20 @@ void FaceApp::create_face_pipelines()
|
||||
viewportState.scissorCount = 1;
|
||||
viewportState.pScissors = &scissor;
|
||||
|
||||
std::vector<char> vertShaderCode;
|
||||
std::vector<char> fragShaderCode;
|
||||
if (kThick)
|
||||
{
|
||||
vertShaderCode = readFile("shaders/texture_thick.vert.spv");
|
||||
fragShaderCode = readFile("shaders/texture_thick.frag.spv");
|
||||
}
|
||||
else
|
||||
{
|
||||
vertShaderCode = readFile("shaders/texture.vert.spv");
|
||||
fragShaderCode = readFile("shaders/texture.frag.spv");
|
||||
}
|
||||
|
||||
auto vertShaderCode = readFile("shaders/texture.vert.spv");
|
||||
auto fragShaderCode = readFile("shaders/texture.frag.spv");
|
||||
|
||||
|
||||
VkShaderModule vertShaderModule = createShaderModule(this->device, vertShaderCode);
|
||||
VkShaderModule fragShaderModule = createShaderModule(this->device, fragShaderCode);
|
||||
@@ -492,22 +503,38 @@ void FaceApp::setup_descriptor_set_layout()
|
||||
set_layout_binding_fragment.binding = 1;
|
||||
set_layout_binding_fragment.descriptorCount = 1;
|
||||
|
||||
// 添加第二个纹理绑定点
|
||||
VkDescriptorSetLayoutBinding set_layout_binding_fragment1{};
|
||||
set_layout_binding_fragment1.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
set_layout_binding_fragment1.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
set_layout_binding_fragment1.binding = 2;
|
||||
set_layout_binding_fragment1.descriptorCount = 1;
|
||||
if (kThick)
|
||||
{
|
||||
// 添加第二个纹理绑定点
|
||||
VkDescriptorSetLayoutBinding set_layout_binding_fragment1{};
|
||||
set_layout_binding_fragment1.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
set_layout_binding_fragment1.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
set_layout_binding_fragment1.binding = 2;
|
||||
set_layout_binding_fragment1.descriptorCount = 1;
|
||||
|
||||
std::vector<VkDescriptorSetLayoutBinding> set_layout_bindings{ set_layout_binding_vertex , set_layout_binding_fragment, set_layout_binding_fragment1 };
|
||||
std::vector<VkDescriptorSetLayoutBinding> set_layout_bindings{ set_layout_binding_vertex , set_layout_binding_fragment, set_layout_binding_fragment1 };
|
||||
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo descriptor_layout{};
|
||||
descriptor_layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
descriptor_layout.pBindings = set_layout_bindings.data();
|
||||
descriptor_layout.bindingCount = static_cast<uint32_t>(set_layout_bindings.size());
|
||||
VkDescriptorSetLayoutCreateInfo descriptor_layout{};
|
||||
descriptor_layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
descriptor_layout.pBindings = set_layout_bindings.data();
|
||||
descriptor_layout.bindingCount = static_cast<uint32_t>(set_layout_bindings.size());
|
||||
|
||||
VK_CHECK(vkCreateDescriptorSetLayout(device, &descriptor_layout, nullptr, &m_descriptorSetLayout));
|
||||
VK_CHECK(vkCreateDescriptorSetLayout(device, &descriptor_layout, nullptr, &m_descriptorSetLayout));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
std::vector<VkDescriptorSetLayoutBinding> set_layout_bindings{ set_layout_binding_vertex , set_layout_binding_fragment };
|
||||
|
||||
|
||||
VkDescriptorSetLayoutCreateInfo descriptor_layout{};
|
||||
descriptor_layout.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
|
||||
descriptor_layout.pBindings = set_layout_bindings.data();
|
||||
descriptor_layout.bindingCount = static_cast<uint32_t>(set_layout_bindings.size());
|
||||
|
||||
VK_CHECK(vkCreateDescriptorSetLayout(device, &descriptor_layout, nullptr, &m_descriptorSetLayout));
|
||||
}
|
||||
|
||||
|
||||
VkPipelineLayoutCreateInfo pipeline_layout_create_info{};
|
||||
@@ -550,12 +577,6 @@ void FaceApp::setup_descriptor_set()
|
||||
image_descriptor.sampler = m_texs[i].sampler;
|
||||
image_descriptor.imageLayout = m_texs[i].image_layout;
|
||||
|
||||
// 第二个纹理描述符 - 假设你的第二个纹理变量名为 tex_demo1
|
||||
VkDescriptorImageInfo image_descriptor1;
|
||||
image_descriptor1.imageView = m_texs_ex[i].view;
|
||||
image_descriptor1.sampler = m_texs_ex[i].sampler;
|
||||
image_descriptor1.imageLayout = m_texs_ex[i].image_layout;
|
||||
|
||||
VkWriteDescriptorSet write_descriptor_set_uniform{};
|
||||
write_descriptor_set_uniform.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
write_descriptor_set_uniform.dstSet = m_descriptor_sets[i];
|
||||
@@ -573,23 +594,51 @@ void FaceApp::setup_descriptor_set()
|
||||
write_descriptor_set_image.pImageInfo = &image_descriptor;
|
||||
write_descriptor_set_image.descriptorCount = 1;
|
||||
|
||||
// 添加第二个纹理的写入描述符
|
||||
VkWriteDescriptorSet write_descriptor_set_image1{};
|
||||
write_descriptor_set_image1.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
write_descriptor_set_image1.dstSet = m_descriptor_sets[i];
|
||||
write_descriptor_set_image1.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
write_descriptor_set_image1.dstBinding = 2; // 绑定到位置2
|
||||
write_descriptor_set_image1.pImageInfo = &image_descriptor1;
|
||||
write_descriptor_set_image1.descriptorCount = 1;
|
||||
|
||||
std::vector<VkWriteDescriptorSet> write_descriptor_sets =
|
||||
if (kThick)
|
||||
{
|
||||
write_descriptor_set_uniform,
|
||||
write_descriptor_set_image,
|
||||
write_descriptor_set_image1, // 添加第二个纹理
|
||||
};
|
||||
// 第二个纹理描述符 - 假设你的第二个纹理变量名为 tex_demo1
|
||||
VkDescriptorImageInfo image_descriptor1;
|
||||
image_descriptor1.imageView = m_texs_ex[i].view;
|
||||
image_descriptor1.sampler = m_texs_ex[i].sampler;
|
||||
image_descriptor1.imageLayout = m_texs_ex[i].image_layout;
|
||||
|
||||
vkUpdateDescriptorSets(device, static_cast<uint32_t>(write_descriptor_sets.size()), write_descriptor_sets.data(), 0, NULL);
|
||||
// 添加第二个纹理的写入描述符
|
||||
VkWriteDescriptorSet write_descriptor_set_image1{};
|
||||
write_descriptor_set_image1.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
write_descriptor_set_image1.dstSet = m_descriptor_sets[i];
|
||||
write_descriptor_set_image1.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
|
||||
write_descriptor_set_image1.dstBinding = 2; // 绑定到位置2
|
||||
write_descriptor_set_image1.pImageInfo = &image_descriptor1;
|
||||
write_descriptor_set_image1.descriptorCount = 1;
|
||||
|
||||
std::vector<VkWriteDescriptorSet> write_descriptor_sets =
|
||||
{
|
||||
write_descriptor_set_uniform,
|
||||
write_descriptor_set_image,
|
||||
write_descriptor_set_image1, // 添加第二个纹理
|
||||
};
|
||||
|
||||
vkUpdateDescriptorSets(device, static_cast<uint32_t>(write_descriptor_sets.size()), write_descriptor_sets.data(), 0, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<VkWriteDescriptorSet> write_descriptor_sets =
|
||||
{
|
||||
write_descriptor_set_uniform,
|
||||
write_descriptor_set_image,
|
||||
};
|
||||
|
||||
vkUpdateDescriptorSets(device, static_cast<uint32_t>(write_descriptor_sets.size()), write_descriptor_sets.data(), 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1099,13 +1148,19 @@ void FaceApp::changeMotion(Motion& motion)
|
||||
{
|
||||
string path = _curMotion.type + "/" + _curMotion.technique + "/" + _curMotion.step + "/" + _curMotion.show_type;
|
||||
string path_name = path + "/" + _curMotion.png_name + std::to_string(i) + ".png";
|
||||
string path_name_ex = path + "/" + _curMotion.png_name + std::to_string(i) + "_thick.png";
|
||||
#ifdef _WIN32
|
||||
loadTextureExample(path_name, m_texs[i], true);
|
||||
loadTextureExample(path_name_ex, m_texs_ex[i], true);
|
||||
if (kThick)
|
||||
{
|
||||
string path_name_ex = path + "/" + _curMotion.png_name + std::to_string(i) + "_thick.png";
|
||||
loadTextureExample(path_name_ex, m_texs_ex[i], true);
|
||||
}
|
||||
#else
|
||||
loadTexture(path_name, m_texs[i], true);
|
||||
loadTexture(path_name, m_texs_ex[i], true);
|
||||
if (kThick)
|
||||
{
|
||||
loadTexture(path_name, m_texs_ex[i], true);
|
||||
}
|
||||
#endif // _WIN32
|
||||
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ private:
|
||||
void setup_descriptor_pool();
|
||||
void setup_descriptor_set_layout();
|
||||
void setup_descriptor_set();
|
||||
const bool kThick = false;
|
||||
|
||||
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size);
|
||||
VkCommandBuffer beginSingleTimeCommands();
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ int main() {
|
||||
motion.technique = "base_makeup";
|
||||
motion.step = "press2";
|
||||
motion.show_type = "direction";
|
||||
motion.png_name = "demo";
|
||||
motion.png_name = "test";
|
||||
motion.png_num = 1;
|
||||
#
|
||||
|
||||
|
||||
Reference in New Issue
Block a user