-
Notifications
You must be signed in to change notification settings - Fork 3.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
Add support for KHR_materials_unlit #6977
Add support for KHR_materials_unlit #6977
Conversation
Thanks for the pull request @OmarShehata!
Reviewers, don't forget to make sure that:
I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome. 🌍 🌎 🌏 |
@OmarShehata Unlit materials should not apply emissive. KhronosGroup/glTF#1391 |
Also |
Thanks for the link @emackey ! I changed it to ignore emissive and occlusion as suggested there. The new shader looks like:
It should already be in there ! |
@OmarShehata There's no explcit tests for the |
@OmarShehata This looks good to me. One last thing to be aware of, currently Cesium is known to not be following the glTF spec which calls for calculating missing normals (issue #6506). If/when that bug gets fixed, we should make sure that normals are not calculated for unlit materials. |
@@ -660,6 +670,8 @@ define([ | |||
} | |||
fragmentShader += '}\n'; | |||
|
|||
console.log(fragmentShader); |
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.
Accidental debug code?
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.
Yes, sorry. Thanks for catching that!
} | ||
else if (defined(generatedMaterialValues.u_emissiveFactor)) { | ||
fragmentShader += ' color += u_emissiveFactor;\n'; | ||
} |
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.
Please run the auto-formatter on your blocks of changed code so that the source file stays consistently formatted.
} | ||
else if (defined(generatedMaterialValues.u_emissiveFactor)) { |
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.
else
and else if
blocks go on the same line as the previous brace } else if
Refer to the https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/CodingGuide
Thanks for the review Matt! @ggetz I added a test there to verify that it correctly renders the base color when using the unlit extension. I added a new glTF to test on. Since it was just a modified |
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.
Thanks @OmarShehata, just those comments.
Specs/Scene/ModelSpec.js
Outdated
@@ -2692,6 +2693,21 @@ defineSuite([ | |||
}); | |||
}); | |||
|
|||
fit('renders with the unlit extension', function() { |
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.
Remove the fit
Specs/Scene/ModelSpec.js
Outdated
@@ -120,6 +120,7 @@ defineSuite([ | |||
|
|||
var boomBoxUrl = './Data/Models/PBR/BoomBox/BoomBox.gltf'; | |||
var boxPbrUrl = './Data/Models/PBR/Box/Box.gltf'; | |||
var boxPbrUnlitUrl = './Data/Models/PBR/Box/Box-Unlit.gltf'; | |||
var boxAnimatedPbrUrl = './Data/Models/PBR/BoxAnimated/BoxAnimated.gltf'; |
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.
Put the model in it's own folder like we do here. Also use camel case like we do for the other models. The path should be ./Data/Models/PBR/BoxUnlit/BoxUnlit.gltf
. Just for consistency's sake.
I also tested this with a base texture instead of a base color and it seems to correctly render the unlit texture. Here's the produced shader in that case.
|
Base texture shader logic looks good, thanks. |
@ggetz I've just verified that the CI errors in this branch are also erroring in the base branch. It's also peculiar because the test I added passes when ran individually but fails when ran together with the other tests in Do you know why/is this expected? |
@OmarShehata the model tests can be a little weird at times and you may have missed resetting a model's show or something like that. Look at what other tests do to reset the state after they are finished. |
@OmarShehata There's an error in a previous test for |
CHANGES.md
Outdated
@@ -10,6 +10,7 @@ Change Log | |||
* Improved support for polygon entities using `perPositionHeight`, including supporting vertical polygons. This also improves KML compatibility. [#6791](https://github.com/AnalyticalGraphicsInc/cesium/pull/6791) | |||
* Added `Cartesian3.midpoint` to compute the midpoint between two `Cartesian3` positions [#6836](https://github.com/AnalyticalGraphicsInc/cesium/pull/6836) | |||
* Added `equalsEpsilon` methods to `OrthographicFrustum`, `PerspectiveFrustum`, `OrthographicOffCenterFrustum` and `PerspectiveOffCenterFrustum`. | |||
* Added support for glTF extension [KHR_materials_unlit](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit) [#6977](https://github.com/AnalyticalGraphicsInc/cesium/pull/6977). |
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.
Looks like this isn't targeting master, as the changelog is 2 versions out of date as of today's release.
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.
Yeah I'm merging into #6805 since that PR moves gltfPipeline
from ThirdParty
into Cesium core.
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.
@OmarShehata Create a section for October's release and move your changes there. Thanks!
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.
Oh, I see the problem now. I moved it into a new section for October. Thanks for pointing this out!
Took a quick look as well, looks good! |
Resolves #6507.
As described in the spec, any glTF that has this extension defined as shown below will be rendered just using its base color.
I implemented this by simply setting
hasNormals
andhasTangents
, which generates a simple shader with no lighting.Here is Suzanne with PBR.
And with the unlit extension.
Unlit materials are affected by shadows. This is
viewer.shadows = true
.@lilleyse any feedback is welcome! This is the current shader that gets generated:
processPbrMetallicRoughness
in this branch.