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

Custom light source #8493

Merged
merged 21 commits into from
Jan 8, 2020
Merged

Custom light source #8493

merged 21 commits into from
Jan 8, 2020

Conversation

lilleyse
Copy link
Contributor

@lilleyse lilleyse commented Dec 24, 2019

Fixes #6553

This PR adds more customizability to Cesium's lighting system. There is now a property scene.light that lets you swap the default sun light with a directional light of your choosing. For example:

viewer.scene.light = new Cesium.DirectionalLight({
    direction: new Cesium.Cartesian3(1, 0, 0),
    color: Cesium.Color.ORANGE,
    intensity: 0.5
});

What this PR doesn't add is multiple light sources. That will need to be a future PR.

Some more notes about this PR:

  • I decided to go with the color + intensity paradigm. light.color is a Color instance and light.intensity is a scalar multiplier which can greater than 1.0 to support HDR lighting. This seems to be similar to what ThreeJS, BabylonJS, and Blender do. Note that only glTF 2.0 PBR models actually use the HDR color, everything else uses an equivalent SDR color for their lighting calculations.
  • I removed moon specular lighting from phong.glsl and other areas. This concept doesn't fit in the new design. The default material shininess is pretty rough so the specular contribution was not that noticeable anyways. In the future this would be implemented with two light sources.
  • scene.sunColor is deprecated and will be removed in 1.69. The recommended approach now is to set scene.light.color. This property only affected glTF 2.0 PBR models whereas scene.light affects all systems.
  • Some glTF models won't look any different. These are glTF 1.0 or glTF 2.0 / KHR_techniques_webgl models. Since the shaders are hardcoded there's no good fix except to upgrade to glTF 2.0 (Upgrade all SampleData models to gltf 2.0 #7802). I upgraded the Cesium Balloon in this PR and @sanjeetsuhag will upgrade the rest as part of onramping. The Bentley BIM tileset uses custom shaders heavily and actually hardcodes czm_sunDirectionWC so we'd have to go through and change that to czm_lightDirectionWC.
  • Added globe.dynamicAtmosphereLighting and globe.dynamicAtmosphereLightingFromSun to add more atmosphere and fog customization. This made the flashlight and moonlight demos look a lot better.

Some screenshots from the Sandcastle example:

Fixed lighting
fixed-lighting
Flashlight
flashlight
Moonlight
moonlight
Sunlight
sunlight
Custom color
custom-color

To do:

  • Once merged, open issue to remove scene.sunColor in 1.69.

@cesium-concierge
Copy link

Thanks for the pull request @lilleyse!

  • ✔️ Signed CLA found.
  • ❔ Unit tests were not updated.
    • Make sure you've updated tests to reflect your changes, added tests for any new code, and ran the code coverage tool.

Reviewers, don't forget to make sure that:

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

@lilleyse lilleyse mentioned this pull request Dec 24, 2019
Copy link
Contributor

@IanLilleyT IanLilleyT left a comment

Choose a reason for hiding this comment

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

This looks pretty thorough. Not having sun be the only light source is good.

My main API confusion is Globe.dynamicAtmosphereLightingFromSun, since the light source is the sun in most cases anyway, and so users might think they must set this property too. I can't think of a better name though. This isn't a big deal as it might be solved in the future by giving the atmosphere system its own light source, and then we can remove this custom behavior for the sun.

Source/Scene/ModelInstanceCollection.js Outdated Show resolved Hide resolved
Source/Scene/Scene.js Outdated Show resolved Hide resolved
Specs/Scene/SceneSpec.js Outdated Show resolved Hide resolved
Specs/Renderer/AutomaticUniformSpec.js Outdated Show resolved Hide resolved
Apps/Sandcastle/gallery/Lighting.html Show resolved Hide resolved
@lilleyse
Copy link
Contributor Author

lilleyse commented Jan 7, 2020

Does anyone else want to review this before we merge? Mainly looking for feedback on the API. From CHANGES.md:

Deprecated ⏳
  • The property Scene.sunColor has been deprecated and will be removed in Cesium 1.69. Use scene.light.color and scene.light.intensity instead. #8493
Additions 🎉
  • Add more customization to Cesium's lighting system #8493
    • Added Light, DirectionalLight, and SunLight classes for creating custom light sources.
    • Added Scene.light for setting the scene's light source, which defaults to a SunLight.
    • Added Globe.dynamicAtmosphereLighting for enabling lighting effects on atmosphere and fog, such as day/night transitions. It is true by default but may be set to false if the atmosphere should stay unchanged regardless of the scene's light direction.
    • Added Globe.dynamicAtmosphereLightingFromSun for using the sun direction instead of the scene's light direction when Globe.dynamicAtmosphereLighting is enabled. See the moonlight example in the Lighting Sandcastle example.
    • Primitives and the globe are now shaded with the scene light's color.

@mramato
Copy link
Contributor

mramato commented Jan 8, 2020

@lilleyse latest version looks good to me. Can't wait to use this, the flashlight is something we've wanted in Cesium since before it was even called Cesium.

The sooner we can get this in the better since it should get as much testing as possible before the next release. I say we merge today and we can always tweak the API based on feedback before we release on Feb. @IanLilleyT any objections?

Is there an updated issue with ideas for expanding this into an array of lights (and I assume adding different types of lights as well)? It would be could to capture your thoughts while still fresh in your head.

Thanks again @lilleyse!

@IanLilleyT IanLilleyT merged commit 56373c4 into master Jan 8, 2020
@IanLilleyT
Copy link
Contributor

Everything looks good!

@IanLilleyT IanLilleyT deleted the light-direction branch January 8, 2020 14:11
@mramato
Copy link
Contributor

mramato commented Jan 8, 2020

🔥 🔥 🔥

@lilleyse
Copy link
Contributor Author

lilleyse commented Jan 8, 2020

Opened #8517 for removing scene.sunColor

Also opened #8518 for future lighting ideas.

@lilleyse lilleyse mentioned this pull request Aug 25, 2021
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.

Flashlight
4 participants