filament icon indicating copy to clipboard operation
filament copied to clipboard

feat: support getParameter from MaterialInstance

Open hannojg opened this issue 1 year ago • 2 comments

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

hannojg avatar Mar 20 '24 15:03 hannojg

@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!

hannojg avatar Apr 05 '24 12:04 hannojg

@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 avatar Apr 19 '24 18:04 pixelflinger

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

pixelflinger avatar May 29 '24 19:05 pixelflinger

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

hannojg avatar Jun 07 '24 11:06 hannojg