Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OIT Sample blending is off #1066

Closed
pascal-weber-git opened this issue Jun 11, 2024 · 3 comments · Fixed by #1186
Closed

OIT Sample blending is off #1066

pascal-weber-git opened this issue Jun 11, 2024 · 3 comments · Fixed by #1186
Assignees

Comments

@pascal-weber-git
Copy link

pascal-weber-git commented Jun 11, 2024

I implemented "order independent linked list transparency" with the guidance of the Vulkan sample. In our engine, we have different transparency modes, linked list transparency was supposed to be our newest one. Since we have a lot of integration tests, I noticed that with the linked list transparency, the blended colors are completely different, almost inverted. The blending function provided in oit_linked_lists/combine.frag seemed strange to me, especially that there is a need to invert the resulting accumulated alpha in line 141. The blending operations for our Combine pass are the following (which seem to me like they basic premultiplied alpha blending):

  • blend op: Add
  • Color blend factors (eSrcAlpha, eOneMinusSrcAlpha)
  • Alpha blend factors (eOne, eOneMinusSrcAlpha)

To fix the compositing, I had to switch up the blending function in combine.frag to this:

vec4 blendColors(vec4 srcColor, vec4 dstColor)
{
	float alphaResult = srcColor.a + dstColor.a * (1.0f - srcColor.a);
	vec3 rgbResult = (srcColor.rgb * srcColor.a + dstColor.rgb * dstColor.a * (1.0f - srcColor.a)) / alphaResult;

	return vec4(rgbResult, alphaResult);
}

color needs to be initialized like this: vec4 color = vec4(0.0f, 0.0f, 0.0f, 0.0f);

and the alpha inversion in line 141 can be removed. With these changes, the resulting colors are the same as with basic transparency rendering.

I guess for the sample, it's not a problem if the blending is off, but for anyone using your sample as reference, it could lead to unnecessary problem solving. Just a suggestion :)

@asuessenbach
Copy link
Contributor

Could you please provide some images without and with your proposed changes?

@pascal-weber-git
Copy link
Author

Of course, see here:

In the spheres example, most of the spheres are a lot less visible in general, and especially in the overlap areas, the results look strange.

"Fixed" Blending:
BlendingFixed_Spheres

Original Blending:
OriginalSampleBlending_Spheres

With the transparent textures the blending problem becomes more apparent, as darker and brighter areas are almost inverted in both cases.

"Fixed" Blending:
BlendingFixed_Textures

Original Blending:
OriginalSampleBlending_Textures

jeroenbakker-atmind added a commit to jeroenbakker-atmind/Vulkan-Samples that referenced this issue Oct 9, 2024
Issue already reported what to fix in order to get the blending correct.
@jeroenbakker-atmind
Copy link
Collaborator

I applied your comments to the sample in the PR above #1186
Thanks for the clear instructions :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants