Skip to content

Shadows#2691

Open
Neptilo wants to merge 12 commits intoiTowns:masterfrom
Neptilo:shadows
Open

Shadows#2691
Neptilo wants to merge 12 commits intoiTowns:masterfrom
Neptilo:shadows

Conversation

@Neptilo
Copy link
Contributor

@Neptilo Neptilo commented Jan 30, 2026

Description

Integrate shadows separately from the "realistic lighting" mode. Add UI to control date/time in one example. The Sun position is defined from the date and shared between the shadow rendering and the "realistic lighting", if enabled.

Motivation and Context

Visualizing shadows can be useful to view illumination of buildings or simply to make the rendering more realistic.
Fixes #1825

Screenshots (if appropriate)

4096-pcf image

@Neptilo Neptilo requested a review from Desplandis January 30, 2026 14:47
private readonly scene: THREE.Scene;
private readonly composer: EffectComposer;
private readonly fog: THREE.Fog;
private readonly view: View;
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 like to add _ before all private members but it will mess up the diff, so maybe it's better to wait for a first review

@Desplandis Desplandis requested a review from gchoqueux January 30, 2026 15:31
Copy link
Contributor

@gchoqueux gchoqueux left a comment

Choose a reason for hiding this comment

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

Nice feature.
I mainly added architectural comments to simplify the code and increase its robustness.

There is also an integration of THREE.js passes; I think this logic should be integrated into the iTowns renderer, since others might want to use it as well, like @Desplandis for his EDL (points cloud rendering).

mesh.material.color = new THREE.Color(0xffffff);
}

mesh.castShadow = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

mesh.castShadow = true; is hard coded value
We prefer global property : TiledGeometryLayer.castShadow to handle castShadow tile meshes

Comment on lines 94 to 100
// disable fog only during render
// to let its parameters be modified elsewhere
if (this.enabled) { this.scene.fog = null; }
this.update(camera);
this.update();
};
scene.onAfterRender = () => {
if (this.enabled) { this.scene.fog = this.fog; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Practice using updates and rendering in iTowns to take advantage of other features (user events, visibility, frozen

  • extends SkyManager, from LayerGeometry to use LayerGeometry.updateinstead ofscene.onBeforeRender`,
  • use LayerGeometry.visible instead of enable/disable
  • use LayerGeometry.object3d.onAfterRender instead of scene.onAfterRender
  • add this.sky, this.sunLight, this.sunLight.target, this.skyLight in LayerGeometry.object3d and Layer.visible = false, this will avoid additions and deletions in scene.
  • As it is preferable to avoid this.composer.addPass and removePass and use pass.enabled.


update(camera: THREE.Camera) {
update() {
const camera = this.view.camera3D as THREE.PerspectiveCamera | THREE.OrthographicCamera;
Copy link
Contributor

Choose a reason for hiding this comment

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

if you use LayerGeometry.update(context, layer, node) the context have the view and the current camera.

Comment on lines 79 to 80
this.receiveShadow = true;

Copy link
Contributor

Choose a reason for hiding this comment

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

same comment, could use global property ?

Comment on lines 591 to 592
model.castShadow = true;
model.receiveShadow = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

could use global property, from 3d tile layer ?

@jailln
Copy link
Contributor

jailln commented Feb 4, 2026

Nice feature @Neptilo , great visual improvement 🤩
I made some tests and 3D tiles display seemed quite slower so I ran a quick performance test and found out that we spend a lot of time picking:

Screenshot from 2026-02-04 10-03-01

Do you think we could remove replace the picking by something less costly?

@Neptilo
Copy link
Contributor Author

Neptilo commented Feb 4, 2026

I made some tests and 3D tiles display seemed quite slower so I ran a quick performance test and found out that we spend a lot of time picking
Do you think we could remove replace the picking by something less costly?

My computer is too good to notice any performance issue! ^^" At least I can see it in the profiler.
I found a way to fix this.

@Neptilo
Copy link
Contributor Author

Neptilo commented Feb 4, 2026

@gchoqueux I suggest we discuss the architecture decisions of SkyManager separately since they are not directly related to shadow integration and deal with code that was there prior to this PR

@jailln
Copy link
Contributor

jailln commented Feb 5, 2026

I made some tests and 3D tiles display seemed quite slower so I ran a quick performance test and found out that we spend a lot of time picking
Do you think we could remove replace the picking by something less costly?

My computer is too good to notice any performance issue! ^^" At least I can see it in the profiler. I found a way to fix this.

Thanks, the perfs are way better !

@gchoqueux
Copy link
Contributor

@gchoqueux I suggest we discuss the architecture decisions of SkyManager separately since they are not directly related to shadow integration and deal with code that was there prior to this PR

There are issues in the SkyManager class, on the master branch, and I don’t think it’s a good idea to postpone fixing them, because:

  1. These existing issues are creating additional problems in this PR Shadows #2691, which means more work for both development and review.
  2. If the original issues are fixed later, it will require more work on SkyManager, shadows, and another review on these two areas.

Basically, the first step would be a waste of time, since we would end up reworking all the points mentioned in the second one anyway. It would be more logical and consistent to adapt the architecture right away.

@Neptilo Neptilo requested a review from gchoqueux February 18, 2026 14:29
@gchoqueux
Copy link
Contributor

The Shadows PR currently relies on the skyManager, which, in my opinion, shows some architectural and algorithmic weaknesses.

In addition, a performance issue has been reported in issue #2701. It's possible that this slowdown is related to an imperfect integration of the @takram packages, which would deserve clarification and stabilization before introducing an additional functional layer on top of it.

In this context, continuing to develop the Shadows feature without addressing these underlying points could make performance diagnostics more difficult and potentially lead us to rework this feature later.

I believe it would be preferable to first consolidate the foundation — particularly regarding the dependency integration and the performance issue — in order to ensure a more stable base moving forward.

@Desplandis
Copy link
Contributor

@gchoqueux Both of you asked for my input on this PR, so here it is.

We discussed the other day with @Neptilo and I think we've reached a compromise that could satisfy both of you (didn't have time to discuss it with you yet). In my opinion, this PR could be implemented independently from the previous one. This would introduce a clearer separation of concerns (instead of the initially proposed monolithic approach) and allow this PR to be reviewed on its own.

We should address the sky manager in a dedicated issue (which I haven't open yet, lack of time!). The "layerisation" part seems relatively straightforward. However, the implementation of the "local" (or not?) post-processing passes requires further discussions before implementing any changes. I would gladly have your input in this subject.

Given that this new code implements the shadows independently of sky manager (minus some caveats, see below), I think it can be reviewed separately of the previous one.

Some ideas that I suggested when we discussed:

  • The sun position (required by both sky manager and sun light) should be derived from the date and stored in GlobeView
  • Have a backed SunDirectionalLight added as the default light of the globe scene (which owns a reference to the sun position)
  • Keep sky manager as it (the only change being the reference ownership of the sun position)

P.S.: The performance issue is also upstream, so we should open an issue !
See https://takram-design-engineering.github.io/three-geospatial/?path=/story/atmosphere-3d-tiles-renderer-integration--manhattan

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.

How to cast shadows on tiles

4 participants