google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.44k stars 1.84k forks source link

feat: support getParameter from MaterialInstance #7686

Closed hannojg closed 1 month ago

hannojg commented 4 months ago

It has been a common user request to add the ability to read values from a MaterialInstance:

This PR is an attempt to add support for this. It works for my use case, where I want to change the alpha of a material (to control an entities opacity), e.g.:

math::float4 rgba = materialInstance->getParameter<math::float4>("baseColorFactor");
float newAlpha = 0.5;
materialInstance->setParameter("baseColorFactor", math::float4({rgba.r, rgba.g, rgba.b, newAlpha}));

Changed

I basically added a getParameter function that you can pass a type to.

-> Note: I am probably missing use cases. Please let me know where I am missing something or need to watch out for. Also happy to add tests if necessary šŸ˜Š !

Fixes: https://github.com/google/filament/issues/7683

hannojg commented 3 months ago

@poweifeng you're right they are currently not supported yet. I will look into either adding support for those, or clearly documentation what's supported and what's not. Either on the weekend or early next week!

pixelflinger commented 3 months ago

@poweifeng you're right they are currently not supported yet. I will look into either adding support for those, or clearly documentation what's supported and what's not. Either on the weekend or early next week!

I think it's fine to document it only works for non-texture parameters for now. We can always have another PR later that adds support for that.

pixelflinger commented 2 months ago

@hannojg would you be able to rebase/update this branch? thanks!

hannojg commented 1 month ago

Sorry for letting this go stale! Updated it + added the documentation comments.