Control transparency when using metallic materials

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 !

Attachments: 
gkv311 n's picture

Lets simplify scenario, start with Phong shading and go step by step:

pload MODELING VISUALIZATION
box b 0 0 100 200 100 0 -preview
psphere s 50
vinit View1
vdisplay -dispMode 1 s b
vfit
vtexture b texure.png

vrenderparams -shadingModel PHONG
# opaque rendering - ignore both texture and material transparency
vaspects b -material SILVER -alphaMode opaque WHITE -transparency 0.0

# normal transparency - take alpha from texture
vaspects b -material SILVER -alphaMode blend -color WHITE -transparency 0.0

# modulate transparency from texture and material
vaspects b -material SILVER -alphaMode blend -color WHITE -transparency 0.5

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).

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:

vrenderparams -shadingModel PBR
# will not work - metal cannot be made transparent
vaspects b -material SILVER -alphaMode blend -color WHITE -transparency 0.0

# OK, transparency will be taken from texture
vaspects b -material GLASS -alphaMode blend -color WHITE -transparency 0.0

# OK, transparency will be modulated
vaspects b -material GLASS -alphaMode blend -color WHITE -transparency 0.5

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.

Guillaume CHAFFAROD's picture

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 ;)

Attachments: