-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(mesh-layers): port ScenegraphLayer to WebGPU #10477
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
Open
ibgreen-openai
wants to merge
1
commit into
codex/scenegraph-example-local-data
Choose a base branch
from
codex/webgpu-scenegraph-layer-port
base: codex/scenegraph-example-local-data
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
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
125 changes: 125 additions & 0 deletions
125
modules/mesh-layers/src/scenegraph-layer/scenegraph-layer.wgsl.ts
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 |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // deck.gl | ||
| // SPDX-License-Identifier: MIT | ||
| // Copyright (c) vis.gl contributors | ||
|
|
||
| export default /* wgsl */ `\ | ||
| struct VertexInputs { | ||
| @location(0) positions: vec3<f32>, | ||
| #ifdef HAS_NORMALS | ||
| @location(1) normals: vec3<f32>, | ||
| #endif | ||
| #ifdef HAS_UV | ||
| @location(3) texCoords: vec2<f32>, | ||
| #endif | ||
| @location(6) instancePositions: vec3<f32>, | ||
| @location(7) instancePositions64Low: vec3<f32>, | ||
| @location(8) instanceColors: vec4<f32>, | ||
| @location(10) instanceModelMatrixCol0: vec3<f32>, | ||
| @location(11) instanceModelMatrixCol1: vec3<f32>, | ||
| @location(12) instanceModelMatrixCol2: vec3<f32>, | ||
| @location(13) instanceTranslation: vec3<f32>, | ||
| }; | ||
|
|
||
| struct FragmentInputs { | ||
| @builtin(position) position: vec4<f32>, | ||
| @location(0) vColor: vec4<f32>, | ||
| @location(1) vTexCoord: vec2<f32>, | ||
| @location(2) pbrPosition: vec3<f32>, | ||
| @location(3) pbrUV: vec2<f32>, | ||
| @location(4) pbrNormal: vec3<f32>, | ||
| }; | ||
|
|
||
| @vertex | ||
| fn vertexMain( | ||
| inputs: VertexInputs, | ||
| @builtin(instance_index) instanceIndex: u32 | ||
| ) -> FragmentInputs { | ||
| var outputs: FragmentInputs; | ||
|
|
||
| geometry.worldPosition = inputs.instancePositions; | ||
| geometry.pickingColor = picking_getPickingColorFromIndex(instanceIndex); | ||
|
|
||
| var vertexPosition = inputs.positions; | ||
| var texCoord = vec2<f32>(0.0, 0.0); | ||
| var normal = vec3<f32>(0.0, 0.0, 1.0); | ||
|
|
||
| #ifdef HAS_UV | ||
| texCoord = inputs.texCoords; | ||
| #endif | ||
| #ifdef HAS_NORMALS | ||
| normal = inputs.normals; | ||
| #endif | ||
|
|
||
| geometry.uv = texCoord; | ||
|
|
||
| let instanceModelMatrix = mat3x3<f32>( | ||
| inputs.instanceModelMatrixCol0, | ||
| inputs.instanceModelMatrixCol1, | ||
| inputs.instanceModelMatrixCol2 | ||
| ); | ||
|
|
||
| let scenePosition = (scenegraph.sceneModelMatrix * vec4<f32>(vertexPosition, 1.0)).xyz; | ||
| let worldNormal = instanceModelMatrix * (scenegraph.sceneModelMatrix * vec4<f32>(normal, 0.0)).xyz; | ||
|
|
||
| let originalSize = project_meter_size_to_pixel(scenegraph.sizeScale); | ||
| let clampedSize = clamp(originalSize, scenegraph.sizeMinPixels, scenegraph.sizeMaxPixels); | ||
| let sizeRatio = select(0.0, clampedSize / originalSize, originalSize > 0.0); | ||
|
|
||
| let pos = | ||
| (instanceModelMatrix * scenePosition) * scenegraph.sizeScale * sizeRatio + | ||
| inputs.instanceTranslation; | ||
|
|
||
| if (scenegraph.composeModelMatrix > 0.5) { | ||
| geometry.normal = project_normal(worldNormal); | ||
| geometry.worldPosition = inputs.instancePositions + pos; | ||
| geometry.position = vec4<f32>( | ||
| project_position_vec3_f64(inputs.instancePositions + pos, inputs.instancePositions64Low), | ||
| 1.0 | ||
| ); | ||
| } else { | ||
| let sizeAdjustedPos = project_size_vec3(pos); | ||
| // Scenegraph offsets are east/north/up in globe mode. Use project32's helper so it can | ||
| // rotate the offset onto the local tangent plane before producing the common position. | ||
| let projectResult = project_position_to_clipspace_and_commonspace( | ||
| inputs.instancePositions, | ||
| inputs.instancePositions64Low, | ||
| sizeAdjustedPos | ||
| ); | ||
| geometry.position = projectResult.commonPosition; | ||
| geometry.normal = project_normal(worldNormal); | ||
| } | ||
|
|
||
| outputs.position = project_common_position_to_clipspace(geometry.position); | ||
| outputs.vColor = inputs.instanceColors; | ||
| outputs.vTexCoord = texCoord; | ||
| outputs.pbrPosition = geometry.position.xyz; | ||
| outputs.pbrUV = texCoord; | ||
| outputs.pbrNormal = geometry.normal; | ||
| return outputs; | ||
| } | ||
|
|
||
| @fragment | ||
| fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> { | ||
| fragmentGeometry.uv = inputs.vTexCoord; | ||
|
|
||
| var fragColor = inputs.vColor; | ||
|
|
||
| #ifdef LIGHTING_PBR | ||
| fragmentInputs.pbr_vPosition = inputs.pbrPosition; | ||
| // scenegraphPbrMaterial uses the indexed UV fields from the current PBR module. | ||
| fragmentInputs.pbr_vUV0 = inputs.pbrUV; | ||
| fragmentInputs.pbr_vUV1 = vec2<f32>(0.0); | ||
| fragmentInputs.pbr_vNormal = inputs.pbrNormal; | ||
| fragColor = fragColor * pbr_filterColor(vec4<f32>(0.0)); | ||
| #else | ||
| #ifdef HAS_BASECOLORMAP | ||
| fragColor = | ||
| fragColor * | ||
| textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, inputs.vTexCoord); | ||
| #endif | ||
| #endif | ||
|
|
||
| fragColor.a *= layer.opacity; | ||
| return deckgl_premultiplied_alpha(fragColor); | ||
| } | ||
| `; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a WebGPU picking pass sets
picking.isActive, this fragment still returns the shaded material color. Although the vertex shader calculatesgeometry.pickingColor, it is never carried throughFragmentInputsor selected infragmentMain, unlike the other WGSL layer shaders. Consequently,pickObjectAsync, hover tooltips, and auto-highlighting on a pickableScenegraphLayerdecode arbitrary material RGB values instead of the instance index; pass the picking color as a varying and emit it during picking.Useful? React with 👍 / 👎.