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

KHR_materials_Specular #7564

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

KHR_materials_Specular #7564

wants to merge 10 commits into from

Conversation

PsycoTodd
Copy link

This branch contains the change for KHR_materials_specular support. Tested on test model and some edtited models.

For android, due to level support, we force material changes as below:

  1. KHR_materials_unlit and KHR_materials_specular, the ulit is dropped.
  2. KHR_materials_specular but we also have clearcoat normal texture or clear coat roghness texture, in this case we drop the latter two.
  3. KHR_materials_sheen and we have specular color texture, in this case we drop specular color texture.
  4. KHR_materials_volume and has specular color texture, in this case we drop specular color texture.
Screenshot 2024-01-09 at 4 59 05 PM

Copy link

google-cla bot commented Feb 8, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@PsycoTodd
Copy link
Author

I have pushed change in google/draco so not sure if I still need to sign the form again?

Copy link
Collaborator

@romainguy romainguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great contribution! I left a bunch of comments, mostly naming/formatting nitpicks, but a couple of actual issues with IOR/reflectance.

@@ -47,6 +47,8 @@ std::unordered_map<std::string, Property> Enums::mStringToProperty = {
{ "ior", Property::IOR },
{ "microThickness", Property::MICRO_THICKNESS },
{ "bentNormal", Property::BENT_NORMAL },
{"specularFactor", Property::SPECULAR_FACTOR },
{"specularColorFactor", Property::SPECULAR_COLOR_FACTOR }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call it specularColor, we don't use glTF naming conventions in our core material models.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cannot. The reason call this is because SpecularColor is already used above by the specularRoughness extension.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The properties defined in Filament are not glTF specific. The glTF material can combine the properties into one or use one over the other.

libs/filamat/src/Enums.cpp Outdated Show resolved Hide resolved
libs/filamat/src/shaders/CodeGenerator.cpp Outdated Show resolved Hide resolved
libs/gltfio/CMakeLists.txt Outdated Show resolved Hide resolved
libs/gltfio/include/gltfio/MaterialProvider.h Outdated Show resolved Hide resolved
shaders/src/common_lighting.fs Outdated Show resolved Hide resolved
shaders/src/light_indirect.fs Show resolved Hide resolved
@@ -88,6 +88,15 @@ struct MaterialInputs {
#endif
#endif
#endif

#if defined(MATERIAL_HAS_SPECULAR_FACTOR)
float specularFactor;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments above about naming for those two inputs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will work on next.

vec3 dielectricSpecularF0 = vec3(0.0);
float dielectricSpecularF90 = 0.0;
#if defined(MATERIAL_HAS_SPECULAR_COLOR_FACTOR)
dielectricSpecularF0 = min(0.04 * material.specularColorFactor, vec3(1.0));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the extension KHR_materials_ior is used, 0.04 must be replaced with the value computed from the IOR. See https://github.com/KhronosGroup/glTF/blob/main/extensions/2.0/Khronos/KHR_materials_specular/README.md#interaction-with-other-extensions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.04 also needs to be changed when reflectance is set

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like reflectance is a good replace of 0.04 since it is default to 0.04 and calculated correctly in IOR case.

shaders/src/shading_lit.fs Outdated Show resolved Hide resolved
@pixelflinger pixelflinger self-requested a review February 9, 2024 00:04
@pixelflinger pixelflinger added the internal Issue/PR does not affect clients label Feb 9, 2024
Fix some left issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Issue/PR does not affect clients
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants