google/filament

Get parameter value of material from gltfio

hannojg opened this issue · 5 comments

Is your feature request related to a problem? Please describe.

(I am kinda new to filament, so not sure if I am missing anything.)

Right now I am rendering from glb files using filament. That means I don't control the materials.
I now want to make changes to the materials. For example a material's blend mode might be "opaque" and it has no transparency, but I want to change it to something else (e.g. to support transparency).
However, I want to make that change "at runtime" when the material instance has already been created.
I feel like with the current API thats not possible? I can only change parameters of a material that are already part of the material.

Describe the solution you'd like

My use case really is to add "transparency support for entities". Meaning I want to control the alpha value of a whole entity (for which I need to control the transparency alpha on the materials if I understand correctly).

Describe alternatives you've considered

If you control the material creation it seems possible, but if you don't it looks like you don't really have any options?

Note: I feel like it has been indirectly mentioned before in this issue: #1865

OS and backend

Not OS or backend specific.

After looking into this more detailed, and for the specific use case of controlling the opacity I found this discussion:

It seems like we'd be able to control the opacity / alpha of an material by calling e.g.

materialInstance->setParameter("baseColorFactor", math::float4({1,1,1, 0.4}));

The only issue is that we would also override the rgb values.

So a solution would be to get the value of a parameter as well, which seems to be missing right now in gltfio.

Setting the base color is not enough, the material needs to be marked transparent (it changes the generated shader code).

When you say "material needs to be marked transparent", you mean that it needs to have a blend mode of transparent or fade, right?

It seems like the blending mode can't be changed at runtime, which is understandable. However it would be nice if we could set the blending mode during asset / material instantiation from the public API.
You wrote that it should be possible here:

But I haven't found a way to make that work (given that I only import a glb file and don't control the material itself)

I just opened a proposal draft PR for getting the parameters from a MaterialInstance:

Let me know what you think!

I've seen the PR we need more time to get to it. Please bare with us! thanks!