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

Support for emissive-only materials #6501

Merged
merged 7 commits into from Apr 27, 2018
Merged

Support for emissive-only materials #6501

merged 7 commits into from Apr 27, 2018

Conversation

lilleyse
Copy link
Contributor

@lilleyse lilleyse commented Apr 26, 2018

This PR fixes two related problems:

  • Fix model shader generation when normals are missing #5838 - When a glTF 2.0 model does not have normals the color is black.
  • Emissive only materials would generate plain-gray shaders because processPbrMetallicRoughness only runs if material.pbrMetallicRoughness is defined. Effectively the emissive texture gets ignored.

The code follows @emackey's suggestion in #5838 (comment):

Lately I've been pondering whether Cesium could just show "unlit" materials (baseColor * occlusion + emissive) in the absence of normals. It's technically not what the spec advises, but it's quick to implement and would get us visibility of models that are currently pitch black.

TODO :

  • More testing
  • Update CHANGES.md
  • Open a PR into gltf-pipeline

@cesium-concierge
Copy link

Signed CLA is on file.

@lilleyse, thanks for the pull request! Maintainers, we have a signed CLA from @lilleyse, so you can review this at any time.

⚠️ I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.

⚠️ I noticed that a file in one of our ThirdParty folders (ThirdParty/, Source/ThirdParty/) has been added or modified. Please verify that it has a section in LICENSE.md and that its license information is up to date with this new version. Once you do, please confirm by commenting on this pull request.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

@shehzan10
Copy link
Member

I can confirm that this fixes it using the AGI HQ with an emissive-only texture.

@lilleyse
Copy link
Contributor Author

lilleyse commented Apr 26, 2018

Updated. Confirmed that the models linked in #5838 are now rendering correctly using an unlit shader.

@emackey
Copy link
Contributor

emackey commented Apr 26, 2018

@lilleyse Just FYI, my suggestion was poorly received by the rest of the glTF WG. They would strongly prefer that engines do calculate the normal vectors, which shouldn't look bad once the rest of the 2.0 lighting issues are fixed.

That said though, certainly the glTF spec does not call for "pitch black", so, unlit isn't any more out of compliance than we are currently. I think unlit would be a good stepping stone to have in place so long as normals are still on the roadmap somewhere.

It looks like glTF pipeline 1.0 does have automatic calculation of normals in a helper class, and that class was never upgraded to 2.0.

@lilleyse
Copy link
Contributor Author

Yeah I guess generating normals is the right thing to do. It would make sense then to implement KHR_materials_unlit as soon as possible to support photogrammetry.

But I agree, that doesn't necessarily need to hold up this PR. We could keep #5838 open after this is merged.

@lilleyse
Copy link
Contributor Author

defined(material.occlusionTexture) ||
defined(material.emissiveTexture) ||
defined(material.emissiveFactor) ||
defined(material.alphaMpde) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo

@lilleyse
Copy link
Contributor Author

Updated.

@@ -493,6 +513,9 @@ define([
} else {
if (defined(parameterValues.baseColorFactor)) {
fragmentShader += ' vec4 baseColorWithAlpha = u_baseColorFactor;\n';
} else if (!hasNormals && (defined(parameterValues.emissiveFactor) || defined(parameterValues.emissiveTexture))) {
// Don't use the default base color of (1,1,1) if the material is emissive only. This handling will be better once we support KHR_materials_unlit.
fragmentShader += ' vec4 baseColorWithAlpha = vec4(vec3(0.0), 1.0);\n';
Copy link
Contributor

Choose a reason for hiding this comment

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

This breaks glTF spec, and I don't think we have any need to do it in code here. The models can and should simply specify baseColorFactor: [0, 0, 0, 1] so that all engines know to turn this off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that is the better thing to do. Fixed.

],
"materials": [
{
"emissiveTexture": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise here, we should add baseColorFactor: [0, 0, 0, 1].

CHANGES.md Outdated
@@ -41,6 +41,8 @@ Change Log
* Fixed crash bug in PolylineCollection when a polyline was updated and removed at the same time. [#6455](https://github.com/AnalyticalGraphicsInc/cesium/pull/6455)
* Fixed Imagery Layers Texture Filters Sandcastle example. [#6472](https://github.com/AnalyticalGraphicsInc/cesium/pull/6472).
* Fixed a bug causing Cesium 3D Tilesets to not clip properly when tiles were unloaded and reloaded. [#6484](https://github.com/AnalyticalGraphicsInc/cesium/issues/6484)
* Fixed rendering of glTF models that don't contain normals. [#6501](https://github.com/AnalyticalGraphicsInc/cesium/pull/6501)
Copy link
Contributor

Choose a reason for hiding this comment

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

"Fixed" isn't what happened here, we are just applying a temporary workaround for these models.

@emackey
Copy link
Contributor

emackey commented Apr 27, 2018

Travis apparently failed here. Doesn't look like the fault of this branch, but it's hard for me to tell.

@mramato
Copy link
Member

mramato commented Apr 27, 2018

The PR-side passed, so it was definitely just a travis/build hiccup.

Copy link
Contributor

@emackey emackey left a comment

Choose a reason for hiding this comment

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

Other than the Travis fail, I think this is good to go. Make sure the gltf-pipeline one is updated too.

@emackey
Copy link
Contributor

emackey commented Apr 27, 2018

OK, thanks @mramato. Merging.

@emackey emackey merged commit 5f56208 into master Apr 27, 2018
@emackey emackey deleted the emissive-fix branch April 27, 2018 19:01
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

5 participants