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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support getParameter from MaterialInstance #7686
base: main
Are you sure you want to change the base?
Conversation
MaterialInstance
MaterialInstance
b16f9ef
to
c96e506
Compare
* @throws utils::PreConditionPanic if name doesn't exist or no-op if exceptions are disabled. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you could also add one can check the paramter exists with Material::hasParameter
and add a @see
tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Added the @see
tag , but what do you mean by "can check"?
getFieldInfo(name)
already has a ASSERT_PRECONDITION
that checks if the info with the given name was found, so I thought that'd be sufficient.
Where would you like me to add the hasParameter
check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just meant we can add in the documentation that it's possible to check the that parameter exists using hasParameter
. For some applications, it's not acceptable to fail, so they can check up-front.
fae1d08
to
cf856cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when you try to get a texture. Or when you try to get a color, it doesn't return whether it's Linear or sRGB? If those aren't supported, maybe we need to be explicit what is supported and what is not?
} | ||
|
||
// explicit template instantiation of our supported types | ||
template UTILS_PUBLIC float MaterialInstance::getParameter<float> (const char* name, size_t nameLength) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: why all the spaces here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, its the same here, and I thought thats how you'd prefer to have it:
filament/filament/src/MaterialInstance.cpp
Lines 109 to 111 in de3c4b6
// explicit template instantiation of our supported types | |
template UTILS_PUBLIC void MaterialInstance::setParameter<float> (const char* name, size_t nameLength, float const& v); | |
template UTILS_PUBLIC void MaterialInstance::setParameter<int32_t> (const char* name, size_t nameLength, int32_t const& v); |
@poweifeng you're right they are currently not supported yet. |
7f46cea
to
3a29ba4
Compare
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. |
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.:
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: #7683