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

Add custom color mix functions for volume mapper fragment shader #3029

Merged
merged 14 commits into from
Mar 14, 2024

Conversation

bruyeret
Copy link
Contributor

@bruyeret bruyeret commented Mar 6, 2024

The custom shader code is used to merge blend components
Presets can be used, I added an ADDITING preset that is useful when using medical images with labels
Also added a test with 2 baselines

When using independent components, and the first component was proportional, tColor.a was
multiplied by pwfValue because of the line `tColor *= pwfValue;`.
To avoid this kind of errors and make the code clearer, use a separte `vec3 tColor` and a
`float alpha`.
Only one minor change to the logic:
Enable complex lighting of dependent component rendering even when there is more than 1 component
To disable it, set vtlLightComplexity to 0
The mixing of independent components is now done in function
This function is very likely inlined by the compiler, it should not hurt performance
Create the UseIndependentComponents preprocessor macro
Move custom code computation to the volume property
@bruyeret bruyeret requested a review from finetjul March 6, 2024 13:22
@finetjul finetjul requested a review from sankhesh March 6, 2024 14:24
@bruyeret bruyeret marked this pull request as draft March 6, 2024 14:37
@bruyeret
Copy link
Contributor Author

bruyeret commented Mar 6, 2024

Just need to add a preset for COLORIZING to be ready

Sources/Rendering/OpenGL/glsl/vtkVolumeFS.glsl Outdated Show resolved Hide resolved
Sources/Rendering/Core/VolumeProperty/index.js Outdated Show resolved Hide resolved
Sources/Rendering/Core/VolumeProperty/Constants.d.ts Outdated Show resolved Hide resolved
applyLighting(tColor0, normal0);
applyLighting(tColor1, normal1);
#endif
vec3 mixedColor = mix(tColor0, tColor1, opacity1 / opacitySum);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm not understanding the big picture here.

How is this different from the current code where independent components are alpha-blended?
Secondly, this is not doing an additive blend, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have alphas a0 and a1, and colors c0 and c1, then:
With alpha blending:

color = (c0 * a0 + (1 - a0) * c1 * a1 ) / alpha
alpha = a0 + (1 - a0) * a1

With additive mode:

color = (c0 * a0 + c1 * a1) / alpha
alpha = a0 + a1

Also how to create alpha blending with independent components in the current shader?

Do you suggest a different name instead or additive mode ?

This makes using user defined shader replacements possible
The renderPass shader replacements are not implemented
Move the api specific code completely out of the VolumeProperty class
Add some documentation in the typescript header
Make the GLSL code clearer
@bruyeret bruyeret marked this pull request as ready for review March 13, 2024 18:09
@bruyeret bruyeret marked this pull request as draft March 13, 2024 18:20
Makes the code a lot clearer and more flexible to be able to use it in colorMixPresets
@bruyeret bruyeret marked this pull request as ready for review March 14, 2024 17:54
Copy link
Member

@finetjul finetjul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@finetjul finetjul added this pull request to the merge queue Mar 14, 2024
@finetjul
Copy link
Member

@sankhesh I had to merge it, but feel free to add comments if needed. @bruyeret can fix them in a following PR.

Merged via the queue into Kitware:master with commit 5359685 Mar 14, 2024
3 checks passed
@bruyeret bruyeret deleted the mask-volume branch March 15, 2024 09:23
Copy link

🎉 This PR is included in version 29.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Automated label label Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released Automated label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants