Skip to content

Removal of the layer count restriction#2612

Draft
gchoqueux wants to merge 7 commits into
iTowns:masterfrom
gchoqueux:refacto/oneMap
Draft

Removal of the layer count restriction#2612
gchoqueux wants to merge 7 commits into
iTowns:masterfrom
gchoqueux:refacto/oneMap

Conversation

@gchoqueux

@gchoqueux gchoqueux commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

WARNING : There’s still unresolved bugs:

  • tiles disappear because of an improperly initialized bbox.
  • Opacity, vibility and effects haven’t been reconnected yet.

Description

Replace all textures array by just 2 textures, map and displacement map. All array textures are flatten in these maps.

Motivation and Context

  • removal of the layer count restriction
  • code simplification
  • first step :
    • to replace LayeredMaterial with any Three.js materials
    • to support any raster re-projection

@Desplandis

Desplandis commented Oct 10, 2025

Copy link
Copy Markdown
Contributor

Could you open a proposal for this PR? Describing what problem you want to resolve and explain your solution. =)


rtCache.set(textureSetId, renderTarget);
} else {
drawMap(renderTarget, tiles, renderer, extent);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If we're caching the render targets, what is the use of redrawing their textures every time we access them? Am I missing something?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's temporary. I'll add a mechanism to update the texture and parent texture when the opacity changes.


drawMap(renderTarget, tiles, renderer, extent);

rtCache.set(textureSetId, renderTarget);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was caching array render targets instead of array textures because it was impossible to extract the textures from the RTs and manage their memory separately, but maybe now that you're using simple render targets, this becomes possible and we can just maintain a cache of textures directly, and only use one RT for everything?

@gchoqueux gchoqueux Oct 22, 2025

Copy link
Copy Markdown
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, There might be a problem with the framebuffer linked to the render target
To try

renderer.setRenderTarget(previousRenderTarget);
renderer.setClearAlpha(a);

return renderTarget;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The returned value is not used anymore and the documented type is now incorrect

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it's draft PR, it's still evolving, no need for an in-depth review right now

* @param tiles - An array of RasterTile objects, each containing textures.
* @param max - The maximum number of layers for the DataArrayTexture.
* @param type - Layer set identifier: 'c' for color, 'e' for elevation.
* @param renderer - The renderer used to render textures.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

To be updated

uniform vec4 offsetScale;
uniform float opacity;

const float CTOYL = 20037508.34 / 3.141592653589793 * 0.69314718;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you comment what these numbers represent?

@gchoqueux gchoqueux Oct 22, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i'll add some comment

  • 20037508.34 : max projection in speudo mercator
  • 0,69... : Ln(2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What do you mean by "max projection"?

uniforms: {
// This uniform will be updated with each source 2D texture
map: { value: null },
texture_footprint: { value: new THREE.Vector2() },

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you comment what these properties represent?

@gchoqueux gchoqueux Oct 22, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Footprint means the area/extent covered by something on the ground.

  • map: map to project on the ground
  • texture_footprint : texture coverage on ground
  • camera_footprint : camera coverage visible on ground
  • offsetScale: the map portion to be projected

@Desplandis

Copy link
Copy Markdown
Contributor

@Neptilo @HoloTheDrunk Could you take a look to this PR this week?

tile.material.setUniform('geoidHeight', geoidHeight);

const parent_uniforms = parent.material.uniforms;
const child_uniforms = tile.material.uniforms;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use camel-case to keep coding style consistent.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would you add camel-case in eslint rules ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think it would be good to do it eventually, but for now there would be too many variables to rename (111). In a separate PR, why not.

const parent_uniforms = parent.material.uniforms;
const child_uniforms = tile.material.uniforms;

if (parent.material.uniforms.map.value) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can use the previously defined parent_uniforms here.

Comment thread packages/Main/src/Converter/convertToTile.ts Outdated
tile.setBBoxZ({ min: rasterElevationNode.min, max: rasterElevationNode.max, scale: rasterElevationNode.layer.scale, geoidHeight });
} else {
tile.setBBoxZ({ min: parent.obb.z.min, max: parent.obb.z.max, geoidHeight });
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An explanatory comment for all this added code would be nice.

Comment thread packages/Main/src/Renderer/Shader/TileFS.glsl

float toY(float lat) {
float s = sin(lat);
return 0.5 * log2((1.0 + s) / (1.0 - s)) * CTOYL;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where does this formula come from?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could use this opportunity to already write this new file in TypeScript.


const quad = new THREE.Mesh(geometry, materialUnit);

export function drawMap(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you document the function?

depthBuffer: false, // No depth buffer needed for simple 2D texture copy
});
const arrayTexture = renderTarget.texture;
const forwarding = (from, to) => ((from == to) ? 'transformUnit' : `${from} => ${to}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you document what materials contains and give forwarding a more explicit name? For example, "makeProjectionId" if you think that makes sense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you document what the purpose of these materials is? As I understand it: running projection computations on the GPU?

@gchoqueux gchoqueux mentioned this pull request Apr 30, 2026
@gchoqueux gchoqueux force-pushed the refacto/oneMap branch 5 times, most recently from dfe65fd to 837c806 Compare May 4, 2026 15:39
@gchoqueux gchoqueux force-pushed the refacto/oneMap branch 10 times, most recently from ea09d17 to 1033823 Compare May 13, 2026 14:44
@gchoqueux gchoqueux force-pushed the refacto/oneMap branch 4 times, most recently from d552ff1 to 3f4a194 Compare May 20, 2026 09:08
@gchoqueux gchoqueux force-pushed the refacto/oneMap branch 3 times, most recently from 2279834 to 0a88be2 Compare June 3, 2026 15:34
@gchoqueux gchoqueux force-pushed the refacto/oneMap branch 2 times, most recently from a306bb9 to 6170906 Compare June 15, 2026 09:22
@gchoqueux gchoqueux force-pushed the refacto/oneMap branch 2 times, most recently from 2fec763 to dd87cfe Compare June 16, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants