长话短说,alpha 值的表现非常奇怪:合理地在 1.0 到 0.5 之间过渡,但从 0.5 到 0.0 从半不透明-{颜色}过渡到不透明-黑色。
^ 这是我的字体渲染器(从发送到 iphone 的任务中捕获)替换了着色器。它应该根据片段 x 坐标的 sin 显示淡入和淡出透明度的红色四边形,而不是显示字体。我不知道“黑色”是从哪里来的。这是着色器:
#version 450
#extension GL_KHR_vulkan_glsl : enable
#extension GL_ARB_separate_shader_objects : enable
#extension GL_EXT_multiview : enable
layout(set = 0, binding = 2) uniform sampler2D colorSampler;
layout(location = 0) in vec2 fragUV;
layout(location = 0) out vec4 outColor;
void main()
{
float x = (sin(gl_FragCoord.x/20.0)+1.0)/2.0;
outColor = vec4(1.0,0.0,0.0,x)
}
我的管道混合配置是:
VkPipelineColorBlendAttachmentState colorBlendAttachment = {};
//alpha blend
colorBlendAttachment.colorWriteMask =
VK_COLOR_COMPONENT_R_BIT |
VK_COLOR_COMPONENT_G_BIT |
VK_COLOR_COMPONENT_B_BIT |
VK_COLOR_COMPONENT_A_BIT |
0;
colorBlendAttachment.blendEnable = VK_TRUE;
colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD;
colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD;
VkPipelineColorBlendStateCreateInfo colorBlendInfo = {};
colorBlendInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
colorBlendInfo.logicOpEnable = VK_FALSE;
colorBlendInfo.logicOp = VK_LOGIC_OP_COPY;
colorBlendInfo.attachmentCount = 1;
colorBlendInfo.pAttachments = &colorBlendAttachment;
colorBlendInfo.blendConstants[0] = 0.0f;
colorBlendInfo.blendConstants[1] = 0.0f;
colorBlendInfo.blendConstants[2] = 0.0f;
colorBlendInfo.blendConstants[3] = 0.0f;
最古怪的是,当从 pcvr 运行时,它可以完美地工作(如预期的那样)(两者之间的代码路径没有重大差异:相同的 spirv、相同的管道生成等......)