Skip to content

Commit dbaf9aa

Browse files
ibgreenfelixpalmer
authored andcommitted
feat: line layer and project module port to WGSL, test app for WebGPU line (#9509)
1 parent 481dc61 commit dbaf9aa

25 files changed

+1054
-46
lines changed

examples/vite.config.local.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default defineConfig(async () => {
3030
port: 8080
3131
},
3232
optimizeDeps: {
33-
esbuildOptions: {target: 'es2020'}
33+
esbuildOptions: {target: 'es2022'}
3434
}
3535
};
3636
});

modules/core/src/shaderlib/misc/geometry.ts

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,41 @@
44

55
import type {ShaderModule} from '@luma.gl/shadertools';
66

7+
const source = /* wgsl */ `\
8+
const SMOOTH_EDGE_RADIUS: f32 = 0.5;
9+
10+
struct VertexGeometry {
11+
position: vec4<f32>,
12+
worldPosition: vec3<f32>,
13+
worldPositionAlt: vec3<f32>,
14+
normal: vec3<f32>,
15+
uv: vec2<f32>,
16+
pickingColor: vec3<f32>,
17+
};
18+
19+
var<private> geometry_: VertexGeometry = VertexGeometry(
20+
vec4<f32>(0.0, 0.0, 1.0, 0.0),
21+
vec3<f32>(0.0, 0.0, 0.0),
22+
vec3<f32>(0.0, 0.0, 0.0),
23+
vec3<f32>(0.0, 0.0, 0.0),
24+
vec2<f32>(0.0, 0.0),
25+
vec3<f32>(0.0, 0.0, 0.0)
26+
);
27+
28+
struct FragmentGeometry {
29+
uv: vec2<f32>,
30+
};
31+
32+
var<private> fragmentGeometry: FragmentGeometry;
33+
34+
fn smoothedge(edge: f32, x: f32) -> f32 {
35+
return smoothstep(edge - SMOOTH_EDGE_RADIUS, edge + SMOOTH_EDGE_RADIUS, x);
36+
}
37+
`;
38+
739
const defines = '#define SMOOTH_EDGE_RADIUS 0.5';
8-
const vs = `
40+
41+
const vs = /* glsl */ `\
942
${defines}
1043
1144
struct VertexGeometry {
@@ -25,7 +58,7 @@ struct VertexGeometry {
2558
);
2659
`;
2760

28-
const fs = `
61+
const fs = /* glsl */ `\
2962
${defines}
3063
3164
struct FragmentGeometry {
@@ -37,4 +70,9 @@ float smoothedge(float edge, float x) {
3770
}
3871
`;
3972

40-
export default {name: 'geometry', vs, fs} as const satisfies ShaderModule;
73+
export default {
74+
name: 'geometry',
75+
source,
76+
vs,
77+
fs
78+
} as const satisfies ShaderModule;

modules/core/src/shaderlib/project/project.glsl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const UNIT_GLSL_CONSTANTS = Object.keys(UNIT)
1515
.map(key => `const int UNIT_${key.toUpperCase()} = ${UNIT[key]};`)
1616
.join('');
1717

18-
export default /* glsl */ `\
18+
export const projectGLSL = /* glsl */ `\
1919
${COORDINATE_SYSTEM_GLSL_CONSTANTS}
2020
${PROJECTION_MODE_GLSL_CONSTANTS}
2121
${UNIT_GLSL_CONSTANTS}

modules/core/src/shaderlib/project/project.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import {fp32, ShaderModule} from '@luma.gl/shadertools';
66
import geometry from '../misc/geometry';
77
import {getUniformsFromViewport} from './viewport-uniforms';
8-
import projectShaderGLSL from './project.glsl';
8+
import {projectWGSL} from './project.wgsl';
9+
import {projectGLSL} from './project.glsl';
910

1011
import type {ProjectProps, ProjectUniforms} from './viewport-uniforms';
1112

@@ -21,7 +22,8 @@ function getUniforms(opts: ProjectProps | {} = INITIAL_MODULE_OPTIONS) {
2122
export default {
2223
name: 'project',
2324
dependencies: [fp32, geometry],
24-
vs: projectShaderGLSL,
25+
source: projectWGSL,
26+
vs: projectGLSL,
2527
getUniforms,
2628
uniformTypes: {
2729
wrapLongitude: 'f32',

0 commit comments

Comments
 (0)