Transparency not working...

Hello.

I tried creating 2 rendered Meshes today. Everything works fine.
But there is a problem with the transparency of the objects.

I’m using for both Meshes the same VkPipeline.
In my opinion there shouldn’t be any difference at all between the two rendered meshes,
but there is. One is working totally perfect. You can look trough it and you can see the
other mesh. But the other one isn’t transparent. But they are using both the same VkPipeline.
How is that possible?

That is how my blending look like:

VkPipelineColorBlendAttachmentState blendAttachmentState[1] = {};
blendAttachmentState[0].colorWriteMask = 0x00000001 | 0x00000002 | 0x00000004;
blendAttachmentState[0].blendEnable = VK_TRUE;
blendAttachmentState[0].colorBlendOp = VK_BLEND_OP_ADD;
blendAttachmentState[0].alphaBlendOp = VK_BLEND_OP_SUBTRACT;
blendAttachmentState[0].srcColorBlendFactor = VK_BLEND_FACTOR_ONE;
blendAttachmentState[0].dstColorBlendFactor = VK_BLEND_FACTOR_ONE;
blendAttachmentState[0].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
blendAttachmentState[0].dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
VkPipelineColorBlendStateCreateInfo colorBlendState = {};
colorBlendState.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
colorBlendState.attachmentCount = 1;
colorBlendState.pAttachments = blendAttachmentState;

I hope you can help me with that. Thank you!

A bit hard to judge by the rough description, but this is possibly an ordering problem if you can see one mesh through the other but not vice-versa. So if you don’t already do that render your meshes back-to-front depending on your current view or use some of the known techniques for order-independent transparency.

If that doesn’t apply, please add some details or post a bit more source somewhere. Ideal would be an source that compiles out of the box.

Thank you for that good advice. I will definitely have a look about that.
Another short question came into my mind.
If I disable colorBlending by setting blendEnable = VK_FALSE; is it then impossible to create any transperancy?
I noticed, that changing the alpha parameter in my fragment-shader doesn’t effect anything.
Is that normal?

Yes, at least for traditional transparency. If blendEnable is set to false for a color attachment, the fragment’s color just get’s passed through.

Depends on your blending setup. If your blending setup uses factors that aren’t influenced by alpha then changing the alpha value won’t have any effect. See chapter 26.1.1 for a detailed rundown of the blending factors.

If you refer to the blending setup you posted above then it’s obvious since all your blend factors are FACTOR_ONE which doesn’t take alpha into account (FACTOR_ONE -> a = 1, see table from 26.1.1). If you want alpha to influence blending, use different factors (e.g. VK_BLEND_FACTOR_SRC_ALPHA or VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA).

Okay.
If I change the order of rendering the other Object is transparent…
That means. Everything works now like it should. Now is the time to take care of the cameras position.
Thank you for solving my problem!