-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(extensions): TerrainExtension GlobeView support #10251
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0a45963
feat(extensions): TerrainExtension GlobeView support
charlieforward9 59cd841
fix(extensions): lint — template literals + remove unnecessary assertion
charlieforward9 34d4813
fix(extensions): prettier formatting
charlieforward9 b3d4ecf
fix(extensions): address terrain globe review
charlieforward9 92f63bb
Tidy terrain_globe_to_mercator
felixpalmer 444afe7
Reduce comments
felixpalmer 5a6627e
Keep same behavior for non-globe case
felixpalmer 20765c0
Tidy
felixpalmer 408bc0a
Add back casts
felixpalmer abeed1a
chore(examples): move terrain view toggle to controls
charlieforward9 7dd49ce
Merge branch 'master' into cr/feat/terrain-extension-globe
charlieforward9 95b48f3
Merge branch 'master' into cr/feat/terrain-extension-globe
felixpalmer 9352f89
Merge branch 'master' into cr/feat/terrain-extension-globe
charlieforward9 6f4e2b2
Merge remote-tracking branch 'upstream/master' into cr/feat/terrain-e…
charlieforward9 0d3cbe2
Merge branch 'master' into cr/feat/terrain-extension-globe
charlieforward9 5aafcb7
Merge branch 'master' into cr/feat/terrain-extension-globe
charlieforward9 c2a667e
Merge branch 'master' into cr/feat/terrain-extension-globe
charlieforward9 b4f4a44
fix(terrain): address globe review feedback
charlieforward9 03d9af3
chore(example): remove unnecessary icon terrain offset
charlieforward9 7e0522b
chore(example): remove terrain view toggle
charlieforward9 aca1243
chore(example): show terrain in default globe view
charlieforward9 600cb82
fix(terrain): correct height map unit conversion for globe offset mode
chrisgervang c520bde
Merge branch 'master' into cr/feat/terrain-extension-globe
chrisgervang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,10 +67,20 @@ uniform sampler2D terrain_map; | |
| export const terrainModule = { | ||
| name: 'terrain', | ||
| dependencies: [project], | ||
| // eslint-disable-next-line prefer-template | ||
| vs: uniformBlock + /* glsl */ 'out vec3 commonPos;', | ||
| // eslint-disable-next-line prefer-template | ||
| fs: uniformBlock + /* glsl */ 'in vec3 commonPos;', | ||
| vs: `${uniformBlock} | ||
| out vec3 commonPos; | ||
| // In globe mode, absolute Mercator position for terrain FBO UV lookups | ||
| out vec2 terrainMercPos; | ||
|
|
||
| vec2 terrain_globe_to_mercator(vec3 globePosition) { | ||
| float D = length(globePosition); | ||
| float sinLat = clamp(globePosition.z / D, -0.999998, 0.999998); | ||
| float x = atan(globePosition.x, -globePosition.y); | ||
| float y = atanh(sinLat); | ||
| return (vec2(x, y) + PI) * WORLD_SCALE; | ||
| } | ||
| `, | ||
| fs: `${uniformBlock}in vec3 commonPos;\nin vec2 terrainMercPos;`, | ||
| inject: { | ||
| 'vs:#main-start': /* glsl */ ` | ||
| if (terrain.mode == TERRAIN_MODE_SKIP) { | ||
|
|
@@ -80,8 +90,13 @@ if (terrain.mode == TERRAIN_MODE_SKIP) { | |
| `, | ||
| 'vs:DECKGL_FILTER_GL_POSITION': /* glsl */ ` | ||
| commonPos = geometry.position.xyz; | ||
| if (project.projectionMode == PROJECTION_MODE_GLOBE) { | ||
| terrainMercPos = terrain_globe_to_mercator(commonPos); | ||
| } else { | ||
| terrainMercPos = commonPos.xy; | ||
| } | ||
| if (terrain.mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) { | ||
| vec2 texCoords = (commonPos.xy - terrain.bounds.xy) / terrain.bounds.zw; | ||
| vec2 texCoords = (terrainMercPos - terrain.bounds.xy) / terrain.bounds.zw; | ||
| position = vec4(texCoords * 2.0 - 1.0, 0.0, 1.0); | ||
| commonPos.z += project.commonOrigin.z; | ||
| } | ||
|
|
@@ -105,7 +120,7 @@ if (terrain.mode == TERRAIN_MODE_WRITE_HEIGHT_MAP) { | |
| `, | ||
| 'fs:DECKGL_FILTER_COLOR': /* glsl */ ` | ||
| if ((terrain.mode == TERRAIN_MODE_USE_COVER) || (terrain.mode == TERRAIN_MODE_USE_COVER_ONLY)) { | ||
| vec2 texCoords = (commonPos.xy - terrain.bounds.xy) / terrain.bounds.zw; | ||
| vec2 texCoords = (terrainMercPos - terrain.bounds.xy) / terrain.bounds.zw; | ||
| vec4 pixel = texture(terrain_map, texCoords); | ||
| if (terrain.mode == TERRAIN_MODE_USE_COVER_ONLY) { | ||
| color = pixel; | ||
|
|
@@ -169,7 +184,7 @@ if ((terrain.mode == TERRAIN_MODE_USE_COVER) || (terrain.mode == TERRAIN_MODE_US | |
| return { | ||
| mode, | ||
| terrain_map: sampler, | ||
| // Convert bounds to the common space, as [minX, minY, width, height] | ||
| // Convert bounds to common space, as [minX, minY, width, height] | ||
| bounds: bounds | ||
| ? [ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I worry this will introduce precision issues |
||
| bounds[0] - commonOrigin[0], | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.