-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
GLTFLoader KHR_materials_unlit extension support. #13136
GLTFLoader KHR_materials_unlit extension support. #13136
Conversation
Thanks! The code looks good to me. Here's a demo of my viewer running this version of GLTFLoader: https://khr-materials-unlit-ooddguuati.now.sh/ ^ /cc @AurL would you want to try any of your examples to see if this looks reasonable? Here's one, edited by hand: |
Are you adding two versions ( |
The |
As far as I understand |
Yeah if keeping the repo size down is a concern, fine to remove glTF/bin version. Probably have more glTF examples than we need already. (cute robot though! 😊) |
@donmccurdy Do you have a live example showing |
Yes please, lets remove the standard metal/rough version from the PR. |
I must be missing something... Don't you want to approximate a PBR material with an unlit one? If that is the case, I think you should be using |
@WestLangley that might be the goal for this particular robot model, I'm not sure... But broadly the KHR_materials_unlit extension is only to specify "the model should be unlit", and the rest is up to the user. So this could also apply to 3D scans or anime/drawing styles where we do not want to approximate PBR at all. See KhronosGroup/glTF#1215. |
Off topic, I often think when the best timing of supporting new glTF spec/extension for
|
Yes, I would say As far as when to merge, I don't have a strong preference. I think I was too early with |
I see the status, thanks. How about merging for r91? (If I guess right) seems like r90 will be released soon, and there seems be a discussion left a bit for Update: oops I've just realized that this PR has been already added to the r91 milestone |
Sure, r91 seems fine to me. |
I believe if
which suggests the emissive terms should be explicitly ignored in the presence of this extension. Thoughts? |
As the extension is written, agreed that emissive should be stripped. Would also be open to removing that stipulation in the spec, since emissive isn't necessarily incompatible with an unlit material. |
I've come across the conflict only once, and it was clearly a mistake -- someone had left Are there good reasons to actually include emissive elements in the fallback material? I know I should ask this in the extension PR, but I'm terrified of disrupting the fragile tranquility that we've achieved there. :-) |
I can't think of a reason that emissive would be used in the fallback material, since it would necessarily be added to baseColor anyway... The use case I envisioned was that someone might want an emissive map on their (supported) unlit material, e.g. an unlit VR mobile scene with glowy lights. But choosing unlit for performance and then also wanting post processing might be an unlikely combination, I'm not sure... |
examples/js/loaders/GLTFLoader.js
Outdated
materialParams.color = new THREE.Color( 1.0, 1.0, 1.0 ); | ||
materialParams.opacity = 1.0; | ||
|
||
if ( Array.isArray( metallicRoughness.baseColorFactor ) ) { |
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.
At this point, we don't actually know that metallicRoughness is defined, do we? The material.pbrMetallicRoughness !== undefined
test in the calling function happens after the call to this extension. I think this would NPE in a (weird but valid) material lacking that particular subobject.=
About emissive, a bit of old code left over from glTF 1.0: if ( materialDef.emissiveFactor !== undefined ) {
if ( materialType === THREE.MeshBasicMaterial ) {
materialParams.color = new THREE.Color().fromArray( materialDef.emissiveFactor );
} else {
materialParams.emissive = new THREE.Color().fromArray( materialDef.emissiveFactor );
}
} overwriting if ( materialDef.emissiveFactor !== undefined ) {
materialParams.emissive = new THREE.Color().fromArray( materialDef.emissiveFactor );
} Whether emissive should be stripped or allowed I will ask on the extension PR. EDIT: oh, MeshBasicMaterial does not support emissive at all... |
We could discuss adding it, but first see if you can reasonably avoid needing this feature. |
We can avoid needing the feature. In that case I propose changing the above code to: if ( materialDef.emissiveFactor !== undefined && materialType !== THREE.MeshBasicMaterial ) {
materialParams.emissive = new THREE.Color().fromArray( materialDef.emissiveFactor );
} |
@donmccurdy I made the changes you recommended and also removed setting occlusion and normal maps on the MeshBasicMaterial. I also removed the |
Thanks!
Yeah, really the demo should default to the first available extension but that's a bug in our demo setup, and we can fix it later. |
Updated demo: https://khr-materials-unlit-ooddguuati.now.sh/ Vertex colors and (lack of) emissive in Quill example look good now: |
One tiny nit: if you are leaving |
Will remove it shortly: #13169 |
I think the KHR_materials_unlit extension is stable enough to support in three.js now. Here is a change set on the Blender exporter for testing: KhronosGroup/glTF-Blender-Exporter#160 @robertlong could you rebase this PR? |
6679cba
to
1a08472
Compare
I rebased the PR and made the glTF extensions example default to the model of the first available extension. I think this should be good to go now. |
Oops, I think the rebase merging has brought back the (deleted) GLTFMaterialsCommonExtension. |
Oops, yeah I didn't see that the GLTFMaterialsCommonExtension made it's way back in. I've removed it. Thanks! |
objectRotation: new THREE.Euler(0, 0, 0), | ||
addLights:true, | ||
extensions: ['glTF-MaterialsUnlit'], | ||
addEnvMap: true |
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: No need for addEnvMap: true
or addLights: true
on this one.
Thanks! Looks good to me. 🚀 |
Thanks! |
Adds support for the pending KHR_materials_unlit glTF extension.
When this extension exists on a material the THREE.MeshBasicMaterial is used. The
.map
and.color
properties are set appropriately.I've also added an example model from mozilla/mr-social-client that shows off the extension. When selecting
glTF-MaterialsUnlit
in the dropdown a model with the extension is loaded and THREE.MeshBasicMaterial is used. When you selectglTF
a model without the extension is loaded and THREE.StandardMaterial is used with the correct fallback properties.I could use some feedback on how to handle occlusion, emmisive, and normal maps. Exporters are expected to exclude these maps. I can ensure that these maps are removed from the material or I can leave it how it is and expect the exporters to remove them.
I also have a PR (facebookincubator/FBX2glTF#61) to export FBX models as unlit glTF models if you wish to test the loader with your own models.