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

Get parameter value of material from gltfio #7683

Open
hannojg opened this issue Mar 19, 2024 · 5 comments · May be fixed by #7686
Open

Get parameter value of material from gltfio #7683

hannojg opened this issue Mar 19, 2024 · 5 comments · May be fixed by #7686
Assignees

Comments

@hannojg
Copy link
Contributor

hannojg commented Mar 19, 2024

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.

@hannojg
Copy link
Contributor Author

hannojg commented Mar 20, 2024

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.

@hannojg hannojg changed the title Support for copying / editing materials to add new properties (e.g. to add transparency support to an opaque material) Get parameter value of material from gltfio Mar 20, 2024
@romainguy
Copy link
Collaborator

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

@hannojg
Copy link
Contributor Author

hannojg commented Mar 20, 2024

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)

@hannojg hannojg linked a pull request Mar 20, 2024 that will close this issue
@hannojg
Copy link
Contributor Author

hannojg commented Mar 20, 2024

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

Let me know what you think!

@pixelflinger pixelflinger self-assigned this Mar 26, 2024
@pixelflinger
Copy link
Collaborator

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

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