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

GLTFLoader KHR_materials_unlit extension support. #13136

Merged
merged 5 commits into from Feb 21, 2018

Conversation

robertlong
Copy link
Contributor

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 select glTF 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.

@mrdoob mrdoob added this to the r91 milestone Jan 19, 2018
@donmccurdy
Copy link
Collaborator

donmccurdy commented Jan 19, 2018

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:
screen shot 2018-01-19 at 2 09 21 pm

@mrdoob
Copy link
Owner

mrdoob commented Jan 20, 2018

Are you adding two versions (gltf/bin and glb) of the same model intentionally?

@donmccurdy
Copy link
Collaborator

The gltf/bin model does not use the unlit extension, it is standard metal/rough for comparison. No preference on whether it should be included though.

@mrdoob
Copy link
Owner

mrdoob commented Jan 20, 2018

As far as I understand glb also includes the textures, so we're adding the textures twice too...

@donmccurdy
Copy link
Collaborator

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! 😊)

@WestLangley
Copy link
Collaborator

@donmccurdy Do you have a live example showing MeshStandardMaterial and the unlit material side-by-side?

@donmccurdy
Copy link
Collaborator

donmccurdy commented Jan 20, 2018

@WestLangley sure —

Robot:

FTM (original)

Main expected use cases here are improved performance on mobile devices for VR, and photogrammetry.

EDIT: Oh, I don't have a demo showing side-by-side in the same scene though.

@mrdoob
Copy link
Owner

mrdoob commented Jan 20, 2018

Yes please, lets remove the standard metal/rough version from the PR.

@WestLangley
Copy link
Collaborator

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 MeshBasicMaterial with an enviornment map and dialing the reflectivity based on the metalness. You will have to select the best combine value, too.

@donmccurdy
Copy link
Collaborator

donmccurdy commented Jan 20, 2018

Don't you want to approximate a PBR material with an unlit one?

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

@takahirox
Copy link
Collaborator

takahirox commented Jan 20, 2018

Off topic, I often think when the best timing of supporting new glTF spec/extension for GLTFLoader is. (Maybe depending on the specific spec/extension tho).

  1. Made PR/issue in glTF GitHub and started discussion
  2. Likely almost fixed
  3. Fixed and published in https://github.com/KhronosGroup/glTF/tree/master/specification/2.0 or https://github.com/KhronosGroup/glTF/tree/master/extensions

KHR_materials_unlit is in the phase 2?

@donmccurdy
Copy link
Collaborator

donmccurdy commented Jan 21, 2018

Yes, I would say KHR_materials_unlit is in "likely almost fixed" phase. The list of extensions in glTF/extensions are not necessarily farther along though, e.g. KHR_technique_webgl is still a "draft" and further from finished than this one, even though this one is still a PR.

As far as when to merge, I don't have a strong preference. I think I was too early with KHR_lights in glTF 2.0 as that one is still changing, but fewer moving parts in an unlit extension. :)

@takahirox
Copy link
Collaborator

takahirox commented Jan 22, 2018

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 KHR_materials_unlit KhronosGroup/glTF#1163 (comment)

Update: oops I've just realized that this PR has been already added to the r91 milestone

@donmccurdy
Copy link
Collaborator

Sure, r91 seems fine to me.

@zellski
Copy link

zellski commented Jan 23, 2018

I believe if material.emissiveFactor or material.emissiveTexture are present in the glTF file, they will override materialParams.color and materialParams.map a little further down in the same function. The extension PR not explicit about what should happen if emissive properties are present (except to suggest they should not be), but it does request:

color = <baseColorTerm>

which suggests the emissive terms should be explicitly ignored in the presence of this extension. Thoughts?

@donmccurdy
Copy link
Collaborator

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.

@zellski
Copy link

zellski commented Jan 23, 2018

I've come across the conflict only once, and it was clearly a mistake -- someone had left emissiveFactor: [0, 0, 0] in place, and they couldn't work out why everything was pitch black even though KHR_materials_unlit was in place, and the baseColor* properties were correct. While it was a little perplexing that emissive was still relevant, this is clearly an edge case.

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. :-)

@donmccurdy
Copy link
Collaborator

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...

materialParams.color = new THREE.Color( 1.0, 1.0, 1.0 );
materialParams.opacity = 1.0;

if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
Copy link

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.=

@donmccurdy
Copy link
Collaborator

donmccurdy commented Jan 24, 2018

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 materialParams.color is not what we want, for now I think that should be:

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...

@WestLangley
Copy link
Collaborator

MeshBasicMaterial does not support emissive at all...

We could discuss adding it, but first see if you can reasonably avoid needing this feature.

@donmccurdy
Copy link
Collaborator

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 );

}

@robertlong
Copy link
Contributor Author

@donmccurdy I made the changes you recommended and also removed setting occlusion and normal maps on the MeshBasicMaterial.

I also removed the .glb model. Is the example correct now? It feels a bit odd that nothing displays until you select the unlit material extension from the dropdown.

@donmccurdy
Copy link
Collaborator

Thanks!

I also removed the .glb model. Is the example correct now? It feels a bit odd that nothing displays until you select the unlit material extension from the dropdown.

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.

@donmccurdy
Copy link
Collaborator

Updated demo: https://khr-materials-unlit-ooddguuati.now.sh/

Vertex colors and (lack of) emissive in Quill example look good now:

screen shot 2018-01-25 at 8 10 10 pm

@zellski
Copy link

zellski commented Jan 27, 2018

One tiny nit: if you are leaving KHR_materials_common support in for now, given that its days are probably numbered, does it make sense to check for KHR_materials_unlit first? It seems both the more specific request on behalf of the author, and also the more likely-to-survive-the-coming-culling way to go.

@donmccurdy
Copy link
Collaborator

Will remove it shortly: #13169

@donmccurdy
Copy link
Collaborator

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?

@robertlong robertlong force-pushed the feature/gltf-KHR_materials_unlit branch from 6679cba to 1a08472 Compare February 21, 2018 02:57
@robertlong
Copy link
Contributor Author

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.

@donmccurdy
Copy link
Collaborator

Oops, I think the rebase merging has brought back the (deleted) GLTFMaterialsCommonExtension.

@robertlong
Copy link
Contributor Author

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
Copy link
Collaborator

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.

@donmccurdy
Copy link
Collaborator

Thanks! Looks good to me. 🚀

@mrdoob mrdoob merged commit fc102a3 into mrdoob:dev Feb 21, 2018
@mrdoob
Copy link
Owner

mrdoob commented Feb 21, 2018

Thanks!

@takahirox
Copy link
Collaborator

IMO, the unlit example is a bit hard to see. Better to change background?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants