feat: support getParameter from MaterialInstance
It has been a common user request to add the ability to read values from a MaterialInstance:
- https://github.com/google/filament/discussions/4504#discussioncomment-1208080
- https://github.com/google/filament/issues/1865
- https://github.com/google/filament/issues/7683#issuecomment-2009215476
- https://github.com/google/filament/issues/5736
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
@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!
@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.
@hannojg would you be able to rebase/update this branch? thanks!
Sorry for letting this go stale! Updated it + added the documentation comments.