Tue, 06/11/2024 - 13:53
Hello here.
I have some problems using metallic materials in a PBR environment.
I have a VisualMaterial with a PBR material defined like this:
- use a texture file that contains transparent colors where alpha can be any value and opaque colors (see attached example, it has green fully opaque and red 50% transparent)
- is metallic (metallic factor = 1)
I would like the user to choose a flag indicating if alpha channel of the texture should be used or not (let's consider a boolean named "UseAlphaChannel"):
- if set to true, then transparency of the texture should be strictly considered.
- if set to false, then transparency should not be used (fully opaque).
Moreover, I may call the "SetTransparency" function of "TPrsStd_AISPresentation" for shapes where this material is applied.
In this case, I expect the transparency to be really applied everywhere:
- if "UseAlphaChannel" flag is set to false, the transparency on the complete object must be set using this value.
- if "UseAlphaChannel" flag is set to true, the alpha of texture pixels must be multiplied by this value (for example, if I use the value "0.5" with the attached texture, alpha of red squares should be interpreted as 0.25).
If this last point can't be achieved, I'd like at least to use the alpha sent in the "SetTransparency" method and do as if the "UseAlphaChannel" flag was set to false.
My view rendering params is defined with "Graphic3d_TypeOfShadingModel_Pbr" shading model.
I tried many options (especially AlphaMode of the visual material with different alpha cutoff values) but could never achieve this goal.
Can anyone help me to know how I can do please (if I can do...).
PS: I'd really like that I don't need to create a custom shader program.. :)
Thank you very much !
Tue, 06/11/2024 - 16:14
Lets simplify scenario, start with Phong shading and go step by step:
There is no flag in OCCT material that would enable or disable reading of texture transparency. If texture format is RGBA - it will consider alpha channel for transparency, if RGB - the alpha channel will be filled with 1. You may switch alpha mode to opaque, but this would disable transparency of both - taken from texture and from material. Otherwise, you will need to switch the texture (create two textures with and without transparency or re-upload the same texture on demand), or use custom GLSL program.
Now lets take a look at PBR:
The requirement to make metallic material transparent is not feasible in case of OCCT PBR shading model. If you think this limitation is a problem / inconsistent with other PBR engines - consider reporting a ticket / share references to other engines how they handle such metals / propose a patch.
Normally, when you apply the color texture in PBR you'll also apply metal-roughness texture as well. In this case, semitransparent pixels in baseColor texture will have metalness=0 in the other texture (metalness could be set to 1 in the material, as it will be multiplied with texture). However, when you want to modulate transparency for entire object, you'll have to reset metalness to 0 for entire material.
Tue, 06/11/2024 - 19:05
I was afraid of an answer like that :)
I managed to do what I need in Unity (see attached picture) but not in OCCT viewer.
I tried many things but it looks like I really can't achieve the same result or something near of it.
Will try to use OpenCascade support but I know it's not really easy to get support of the team in this moment.
Anyway, thank you for your help ;)