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

Model lighting options #7025

Merged
merged 12 commits into from
Oct 19, 2018
Merged

Model lighting options #7025

merged 12 commits into from
Oct 19, 2018

Conversation

bagnell
Copy link
Contributor

@bagnell bagnell commented Sep 10, 2018

  • Adds Model.iblFactor which scales the IBLColor computed in the fragment shader.
  • Adds Model.lightColor which changes the sunlight color and intensity. For example, settingiblFactor = 0.0 makes the model much darker so the light intensity could be increased.
  • Adds the same properties to Cesium3DTileset

@cesium-concierge
Copy link

Thanks for the pull request @bagnell!

  • ✔️ Signed CLA found.
  • CHANGES.md was not updated.
    • If this change updates the public API in any way, please add a bullet point to CHANGES.md.
  • ❔ Changes to third party files were made.
    • Looks like 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.

Reviewers, don't forget to make sure that:

  • Cesium Viewer works.
  • Works in 2D/CV.
  • Works (or fails gracefully) in IE11.

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

🌍 🌎 🌏

@bagnell
Copy link
Contributor Author

bagnell commented Sep 10, 2018

Master:
image
This branch:
image

@@ -384,7 +384,9 @@ define([
uniformMapLoaded : batchTable.getUniformMapCallback(),
pickIdLoaded : getPickIdCallback(content),
addBatchIdToGeneratedShaders : (batchLength > 0), // If the batch table has values in it, generated shaders will need a batchId attribute
pickObject : pickObject
pickObject : pickObject,
iblFactor : tileset.iblFactor,
Copy link
Contributor

Choose a reason for hiding this comment

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

is ibla common enough abbreviation for our users, or should this be imageBasedLightingFactor?

@mramato
Copy link
Contributor

mramato commented Sep 12, 2018

That looks like a pretty awesome improvement.

@emackey
Copy link
Contributor

emackey commented Sep 13, 2018

Have you tried this with PBR models? The second image here shows an intense amount of contrast for what is a pretty plain white material, which makes me wonder how full PBR materials might perform. Haven't had time to try this branch myself yet.

Ideally, I would much rather see cities like this use AO instead of crazy amounts of diffuse contrast to visually separate the buildings.

@pjcozzi
Copy link
Contributor

pjcozzi commented Sep 15, 2018

As discussed offline, could we please include the killer gray building visual quality example perhaps akin to what @emackey suggests?

@bagnell @lilleyse

@pjcozzi
Copy link
Contributor

pjcozzi commented Sep 15, 2018

What prompted this PR? Are iblFactor and lightColor common practice in PBR/IBL? Can you point me to other engines / surveys?

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 6, 2018

Is this stalled on IBL?

@bagnell
Copy link
Contributor Author

bagnell commented Oct 8, 2018

What prompted this PR? Are iblFactor and lightColor common practice in PBR/IBL? Can you point me to other engines / surveys?

I was going to add an option to enable/disable IBL, but I added a scale when I saw it in the glTF reference implementation:
https://github.com/KhronosGroup/glTF-WebGL-PBR/blob/master/shaders/pbr-frag.glsl#L164

@bagnell
Copy link
Contributor Author

bagnell commented Oct 9, 2018

This is ready for another look.

Here is the PBR model with the diffuse factor set to 0.0:
image
For reference, here is what's in master:
image
Is this the difference users have mentioned on the forum?

EDIT: The difference in specular lighting is because I didn't set the clock to the same time.

@pjcozzi
Copy link
Contributor

pjcozzi commented Oct 10, 2018

@lilleyse can you please review to take this over the finish line?

@@ -282,6 +286,8 @@ define([
* @param {Number} [options.silhouetteSize=0.0] The size of the silhouette in pixels.
* @param {ClippingPlaneCollection} [options.clippingPlanes] The {@link ClippingPlaneCollection} used to selectively disable rendering the model.
* @param {Boolean} [options.dequantizeInShader=true] Determines if a {@link https://github.com/google/draco|Draco} encoded model is dequantized on the GPU. This decreases total memory usage for encoded models.
* @param {Number} [options.imageBasedLightingFactor=1.0] Scales the IBL lighting from the earth, sky, atmosphere and star skybox.
Copy link
Contributor

Choose a reason for hiding this comment

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

The doc should be Cartesian2 instead of Number.

/**
* The color and intensity of the sunlight used to shade the model.
* <p>
* For example, disabling additional light sources by setting <code>model.imageBasedLightingFactor = 0.0</code> will make the
Copy link
Contributor

Choose a reason for hiding this comment

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

Same note here.

if (value === lightColor || Color.equals(value, lightColor)) {
return;
}
this._regenerateShaders = this._regenerateShaders || (defined(lightColor) && !defined(value)) || (defined(value) && !defined(lightColor));
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it also regenerate the shader if the previous color was not (0,0,0) but the new color is (0,0,0) (and the reverse)?

Some of the other documentation makes it seem as if setting lightColor to undefined would result in using the default sun color. Should that be the behavior here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Meant to delete this comment. See #7025 (comment) instead.

fragmentShader += ' vec3 lightColor = vec3(1.5, 1.4, 1.2);\n';
fragmentShader += '#else \n';
Copy link
Contributor

@lilleyse lilleyse Oct 10, 2018

Choose a reason for hiding this comment

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

The default light color could also share the gltf_lightColor uniform.

Then USE_CUSTOM_LIGHT_COLOR might be just USE_LIGHT_COLOR, and switched off if the user sets the color to (0,0,0).

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at https://github.com/AnalyticalGraphicsInc/cesium/pull/7017/files#r216167338 and the Color doc, is this because colors are not allowed to have components greater than 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure about that comment. Can you explain @ggetz? Colors aren't supposed to have values >1 but you can as long as you aren't converting the components to bytes. Perhaps this should be a Cartesian3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd also like to keep the uniform the way it is since the compiler could optimize out the uniform when not set.

Copy link
Contributor

Choose a reason for hiding this comment

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

It was because I was using a Color with components greater than 1. Cartesian3 would work. 👍

@@ -1,5 +1,6 @@
defineSuite([
Copy link
Contributor

Choose a reason for hiding this comment

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

There should also be tests for Cesium3DTileset (b3dm and i3dm) and Model. It should be enough to check that the pixel color changed after setting the lighting values.

@lilleyse lilleyse mentioned this pull request Oct 12, 2018
4 tasks
@bagnell
Copy link
Contributor Author

bagnell commented Oct 16, 2018

@lilleyse Updated. This is ready for another look.

@lilleyse
Copy link
Contributor

Thanks @bagnell.

@lilleyse lilleyse merged commit 6795351 into master Oct 19, 2018
@lilleyse lilleyse deleted the model-lighting-options branch October 19, 2018 17:50
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.

7 participants