-
Notifications
You must be signed in to change notification settings - Fork 324
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 #1646
KHR materials #1646
Conversation
|
Principled Specular=0 doesn't roundtrip correctly. |
Cleanup for emissive_strength import (not tested) Patchdiff --git a/addons/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py b/addons/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
index 0bcecdff..1ad6df22 100644
--- a/addons/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
+++ b/addons/io_scene_gltf2/blender/imp/gltf2_blender_KHR_materials_pbrSpecularGlossiness.py
@@ -43,11 +43,13 @@ def pbr_specular_glossiness(mh):
make_volume_socket=None # No possible to have KHR_materials_volume with specular/glossiness
)
- emission(
- mh,
- location=(-200, 860),
- color_socket=emission_socket,
- )
+ if emission_socket:
+ emission(
+ mh,
+ location=(-200, 860),
+ color_socket=emission_socket,
+ strength_socket=emission_socket.node.inputs['Strength'],
+ )
base_color(
mh,
diff --git a/addons/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py b/addons/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
index a96b4e66..f6b9a61a 100644
--- a/addons/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
+++ b/addons/io_scene_gltf2/blender/imp/gltf2_blender_pbrMetallicRoughness.py
@@ -68,7 +68,7 @@ def pbr_metallic_roughness(mh: MaterialHelper):
mh.settings_node = make_settings_node(mh)
mh.settings_node.location = additional_location
mh.settings_node.width = 180
- additional_location = additional_location[0], additional_location[1] - 150
+ additional_location = additional_location[0], additional_location[1] - 150
_, _, volume_socket = make_output_nodes(
mh,
@@ -157,7 +157,7 @@ def pbr_metallic_roughness(mh: MaterialHelper):
)
specular(
- mh,
+ mh,
location_specular=locs['specularTexture'],
location_specular_tint=locs['specularColorTexture'],
specular_socket=pbr_node.inputs['Specular'],
@@ -252,31 +252,28 @@ def calc_locations(mh):
# [Texture] => [Emissive Factor] =>
-def emission(mh: MaterialHelper, location, color_socket, strength_socket=None):
+def emission(mh: MaterialHelper, location, color_socket, strength_socket):
x, y = location
emissive_factor = mh.pymat.emissive_factor or [0, 0, 0]
+ strength = 1
+ try:
+ strength = mh.pymat.extensions['KHR_materials_emissive_strength']['emissiveStrength']
+ except Exception:
+ pass
+
if color_socket is None:
return
if mh.pymat.emissive_texture is None:
color_socket.default_value = emissive_factor + [1]
-
- # KHR_materials_emissive_strength if needed
- if mh.pymat.extensions and mh.pymat.extensions.get('KHR_materials_emissive_strength'):
- emission_strength = mh.pymat.extensions['KHR_materials_emissive_strength']['emissiveStrength']
- strength_socket.default_value = emission_strength
+ strength_socket.default_value = strength
return
# Put grayscale emissive factors into the Emission Strength
e0, e1, e2 = emissive_factor
- if strength_socket and e0 == e1 == e2:
- # Set emission strength if extension KHR_materials_emissive_strength
- if mh.pymat.extensions and mh.pymat.extensions['KHR_materials_emissive_strength']:
- emission_strength = mh.pymat.extensions['KHR_materials_emissive_strength']['emissiveStrength']
- strength_socket.default_value = e0 * emission_strength
- else:
- strength_socket.default_value = e0
+ if e0 == e1 == e2:
+ strength_socket.default_value = e0 * strength
# Otherwise, use a multiply node for it
else:
@@ -294,10 +291,7 @@ def emission(mh: MaterialHelper, location, color_socket, strength_socket=None):
x -= 200
- # Set emission strength if extension KHR_materials_emissive_strength
- if strength_socket and mh.pymat.extensions and mh.pymat.extensions['KHR_materials_emissive_strength']:
- emission_strength = mh.pymat.extensions['KHR_materials_emissive_strength']['emissiveStrength']
- strength_socket.default_value = emission_strength
+ strength_socket.default_value = strength
texture(
mh, |
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'm a bit worried that KHR_materials_variants
is different enough from the rest of these extensions (and more complex...) that it might be best in a separate PR, would that be a lot of trouble?
Very excited to see these extensions added!
/cc #1344 (comment) Slightly off topic but I wonder if it's worth raising this with the Principled BSDF developers? If they intend for the Principled BSDF sheen to be energy-conserving in time, we could consider going ahead and supporting that even if it hasn't been implemented that way yet. |
If I'm remembering correctly, I believe it was @PascalSchoen's suggestion to use the Velvet node, and he and others had some comments on the call about Blender's own sheen as well. The bottom line is that the Principled BSDF node's current sheen is sufficiently different from glTF's sheen as to require a completely different shading model, not just because of energy conservation, but parameterization and overall appearance as well. [Very off-topic] Lately I've been wondering if Blender should be given a full "glTF Material" node with a proper mapping to the glTF PBR model in its modern state. The idea seems strangely similar to what UX3D had originally developed for the previous exporter so many years ago, but of course the new one would take modern PBR parameters and practices into account. Both MaterialX and Autodesk's 3DS Max have first-class "glTF Material" nodes now, perhaps it's time for Blender to acquire such a node once again. I'm sure it doesn't fit in the near-term 3.3 timeframe, but perhaps something we could think about down the road? |
Seems this PR is now feature complete. Note: There are still some unit tests and documentation to be updated |
I'm attempting to use the variant extension support added here. I see that the Material Properties tab has an entry called 'glTF Material Variants' which I assume lets you assign materials of a mesh to actual variants. I'm trying to figure out how to find where you define variants in the first place. I read in the addon code there is support to be a section for it but I can't seem to locate it. |
@Waterpicker
Then you can create your materials, and then Assign to Variants. More details documentation will come in next days/weeks |
Hi, nice work. That's great that the add-on supports glTF materials extensions. I have a question. When we discussed the materials variants extension support last time in #231, we thought that Blender doesn't really have a matching concept of material variants and the materials variants add-on needs an additional UI but we were not sure if additional glTF extension specific data So, question. Does the glTF blender add-on allow such additional UI now (does it have UI extensibility system)? Or does Blender have material variants concept in the core now? |
Hello, About glTF importer/exporter: About "User extension addons" : Because users decided to install a new Blender addon (that is a glTF User extension addon), these user extensions are free to add UI in Blender, using directly Blender API. |
For information : We have a chance to discuss with Blender devs to have better compatibility |
Thanks for the details so far, @julienduroure. Where will more documentation be available? Here, in this PR? Or is there another location where I might look to learn how to assign materials to variants and see them working? |
Documentation is here: |
Hi, Is there a thread somewhere in which we are investigating the lossless conversion at import of the KHR_materials_specular of gltf to Blender's shaders? I see that currently it is only imported as extra data and is not being used in the shaders. Thanks ! |
Hello, Importer already convert specular data and plug it into Principled Shader (with losses) (and also plug it into glTF Material node to be able to re-export without losses). You can see it, for example, importing this file https://github.com/KhronosGroup/glTF-Sample-Models/blob/master/2.0/SpecularTest/glTF-Binary/SpecularTest.glb For more technical background, see the following discussions: |
Some longer-term context on Principled BSDF v2 + Specular here: |
Thanks both of you, I will investigate these links. As for the SpecularTest.gdb yes I tested it and saw the loss of the specular color in the render. This is the missing property my company needs to be rendered. I will keep you in the loop regarding my development ! |
This PR will implement some official extensions about materials:
See following comments for status update