Skip to content
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

Use UBOs in project module #8782

Merged
merged 44 commits into from May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
167d6c3
WIP
felixpalmer Apr 10, 2024
3b337da
Hook up getUniforms
felixpalmer Apr 11, 2024
18e2603
Tidy
felixpalmer Apr 11, 2024
ca48f7f
uCoordinateSystem
felixpalmer Apr 11, 2024
44f55be
projectionMode
felixpalmer Apr 11, 2024
19d53b2
project_uScale
felixpalmer Apr 11, 2024
af45e52
commonUnitsperWorldUnit
felixpalmer Apr 11, 2024
dfcabe8
project.center
felixpalmer Apr 11, 2024
7b3b511
modelMatrix
felixpalmer Apr 11, 2024
2d426cb
viewProjectionMatrix
felixpalmer Apr 11, 2024
837fa16
viewportSize
felixpalmer Apr 11, 2024
ab8bdf7
devicePixelRatio
felixpalmer Apr 11, 2024
3ab15bc
focalDistance
felixpalmer Apr 11, 2024
607718a
coordinateOrigin
felixpalmer Apr 11, 2024
1194ed1
commonOrigin
felixpalmer Apr 11, 2024
3046ac5
Update layer shaders
felixpalmer Apr 11, 2024
a01ad11
Update layers
felixpalmer Apr 11, 2024
5f0cb39
Migrate shader modules
felixpalmer Apr 11, 2024
ca64fcc
Shadow spec
felixpalmer Apr 11, 2024
4557364
Lint
felixpalmer Apr 11, 2024
dd57f79
Fix ScreenGridLayer binding
felixpalmer Apr 11, 2024
650b238
Merge branch 'master' into felix/project-ubo
felixpalmer Apr 11, 2024
f3565d3
Remove project32 hacks
felixpalmer Apr 16, 2024
fecbe18
Use varying to pass cameraPosition column fragment
felixpalmer Apr 19, 2024
6706560
Fix project tests
felixpalmer Apr 19, 2024
233e1cf
Fix transitions
felixpalmer Apr 19, 2024
c0387cd
Fix project-functions.spec
felixpalmer Apr 19, 2024
6822522
UBO for project64
felixpalmer Apr 19, 2024
a9a64ae
Rename
felixpalmer Apr 19, 2024
0d90fc3
Fix test
felixpalmer Apr 19, 2024
ddb80ad
Reinstate scale64
felixpalmer Apr 19, 2024
361bfed
Better imports
felixpalmer Apr 19, 2024
7f738a8
Merge branch 'master' into felix/project-ubo
felixpalmer Apr 19, 2024
7380682
autoWrap rename
felixpalmer Apr 19, 2024
44e7464
Bump to luma 9.0.12
felixpalmer Apr 30, 2024
cc4b460
Merge branch 'master' into felix/project-ubo
felixpalmer Apr 30, 2024
f1b53e2
Hack in project64 matrix to test
felixpalmer Apr 30, 2024
28addcf
Tidy
felixpalmer Apr 30, 2024
a4b45c1
Match order
felixpalmer Apr 30, 2024
af04130
Add geometry as default module
felixpalmer Apr 30, 2024
ae4edea
Pass modelMatrix to project
felixpalmer Apr 30, 2024
1d870cd
Merge branch 'master' into felix/project-ubo
felixpalmer May 7, 2024
f3f62b9
Set shader module props for fp64 in extension
felixpalmer May 7, 2024
dac757d
Remove project module hacks in transitions
felixpalmer May 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api-reference/core/project.md
Expand Up @@ -151,6 +151,6 @@ Returns a matrix that rotates any vector defined in the default common space to

## Remarks

* For consistent results, the screen space pixels are logical pixels, not device pixels, i.e. functions in the project module multiply `pixels` with `project_uDevicePixelRatio`.
* For consistent results, the screen space pixels are logical pixels, not device pixels, i.e. functions in the project module multiply `pixels` with `project.devicePixelRatio`.
* The pixels offsets will be divided by the `w` coordinate of `gl_Position`. This is simply the GPUs standard treatment of any coordinate. This means that there will be more pixels closer to the camera and less pixels further away from the camer. Setting the `focalDistance` uniform controls this.
* To avoid pixel sizes scaling with distance from camera, simply set `focalDistance` to 1 and multiply clipspace offset with `gl_Position.w`
2 changes: 1 addition & 1 deletion docs/api-reference/core/project64.md
Expand Up @@ -5,7 +5,7 @@ The `project64` shader module is an extension of the [project](./project.md) sha

## getUniforms

The uniforms needed by `project64` are extracted from the `project` module uniforms `project_uViewProjectionMatrix` and `project_uScale`.
The uniforms needed by `project64` are extracted from the `project` module uniforms `project.viewProjectionMatrix` and `project.scale`.


## GLSL Uniforms
Expand Down
2 changes: 1 addition & 1 deletion docs/developer-guide/custom-layers/subclassed-layers.md
Expand Up @@ -225,7 +225,7 @@ void main(void) {
/* replaced uniform 'radiusPixels' with 'instanceRadiusPixels' */
gl_Position.xy += project_pixel_size_to_clipspace(positions.xy * instanceRadiusPixels);

vec3 lightColor = lighting_getLightColor(instanceColors.rgb, project_uCameraPosition, position_commonspace.xyz, project_normal(instanceNormals));
vec3 lightColor = lighting_getLightColor(instanceColors.rgb, project.cameraPosition, position_commonspace.xyz, project_normal(instanceNormals));

vColor = vec4(lightColor, instanceColors.a * opacity) / 255.0;

Expand Down
Expand Up @@ -39,7 +39,7 @@ out vec4 vColor;
// offset_direction is -1 (left) or 1 (right)
vec2 getExtrusionOffset(vec2 line_clipspace, float offset_direction) {
// normalized direction of the line
vec2 dir_screenspace = normalize(line_clipspace * project_uViewportSize);
vec2 dir_screenspace = normalize(line_clipspace * project.viewportSize);
// rotate by 90 degrees
dir_screenspace = vec2(-dir_screenspace.y, dir_screenspace.x);

Expand Down
2 changes: 1 addition & 1 deletion examples/website/plot/plot-layer/grid-vertex.glsl.ts
Expand Up @@ -38,7 +38,7 @@ out float shouldDiscard;

// determines if the grid line is behind or in front of the center
float frontFacing(vec3 v) {
vec4 v_clipspace = project_uViewProjectionMatrix * project_uModelMatrix * vec4(v, 0.0);
vec4 v_clipspace = project.viewProjectionMatrix * project.modelMatrix * vec4(v, 0.0);
return step(v_clipspace.z, 0.0);
}

Expand Down
2 changes: 1 addition & 1 deletion examples/website/plot/plot-layer/label-vertex.glsl.ts
Expand Up @@ -50,7 +50,7 @@ float sum3(vec3 v) {

// determines if the grid line is behind or in front of the center
float frontFacing(vec3 v) {
vec4 v_clipspace = project_uViewProjectionMatrix * project_uModelMatrix * vec4(v, 0.0);
vec4 v_clipspace = project.viewProjectionMatrix * project.modelMatrix * vec4(v, 0.0);
return step(v_clipspace.z, 0.0);
}

Expand Down
4 changes: 2 additions & 2 deletions modules/aggregation-layers/package.json
Expand Up @@ -38,8 +38,8 @@
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
},
"dependencies": {
"@luma.gl/constants": "^9.0.11",
"@luma.gl/shadertools": "^9.0.11",
"@luma.gl/constants": "^9.0.12",
"@luma.gl/shadertools": "^9.0.12",
"@math.gl/web-mercator": "^4.0.0",
"d3-hexbin": "^0.2.1"
},
Expand Down
Expand Up @@ -134,7 +134,7 @@ void main(void) {
vec3 normals_commonspace = project_normal(normals);

if (extruded) {
vec3 lightColor = lighting_getLightColor(color.rgb, project_uCameraPosition, geometry.position.xyz, normals_commonspace);
vec3 lightColor = lighting_getLightColor(color.rgb, project.cameraPosition, geometry.position.xyz, normals_commonspace);
vColor = vec4(lightColor, color.a * opacity) / 255.;
} else {
vColor = vec4(color.rgb, color.a * opacity) / 255.;
Expand Down
Expand Up @@ -20,7 +20,15 @@

import {Texture} from '@luma.gl/core';
import {Model, Geometry} from '@luma.gl/engine';
import {Layer, LayerProps, log, picking, UpdateParameters, DefaultProps} from '@deck.gl/core';
import {
Layer,
LayerProps,
log,
project32,
picking,
UpdateParameters,
DefaultProps
} from '@deck.gl/core';
import {defaultColorRange, colorRangeToFlatArray} from '../utils/color-utils';
import vs from './screen-grid-layer-vertex.glsl';
import fs from './screen-grid-layer-fragment.glsl';
Expand Down Expand Up @@ -59,7 +67,7 @@ export default class ScreenGridCellLayer<DataT = any, ExtraPropsT extends {} = {
};

getShaders(): {vs: string; fs: string; modules: ShaderModule[]} {
return {vs, fs, modules: [picking as ShaderModule]};
return {vs, fs, modules: [project32, picking]};
}

initializeState() {
Expand Down
2 changes: 1 addition & 1 deletion modules/arcgis/package.json
Expand Up @@ -36,7 +36,7 @@
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env=dev"
},
"dependencies": {
"@luma.gl/constants": "^9.0.11",
"@luma.gl/constants": "^9.0.12",
"esri-loader": "^3.7.0"
},
"peerDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions modules/carto/package.json
Expand Up @@ -47,9 +47,9 @@
"@loaders.gl/mvt": "^4.2.0",
"@loaders.gl/schema": "^4.2.0",
"@loaders.gl/tiles": "^4.2.0",
"@luma.gl/constants": "^9.0.11",
"@luma.gl/core": "^9.0.11",
"@luma.gl/shadertools": "^9.0.11",
"@luma.gl/constants": "^9.0.12",
"@luma.gl/core": "^9.0.12",
"@luma.gl/shadertools": "^9.0.12",
"@math.gl/web-mercator": "^4.0.0",
"@types/d3-array": "^3.0.2",
"@types/d3-color": "^1.4.2",
Expand Down
6 changes: 3 additions & 3 deletions modules/carto/src/layers/raster-layer-vertex.glsl.ts
Expand Up @@ -46,8 +46,8 @@ void main(void) {
// Important to set geometry.position before using project_ methods below
// as geometry.worldPosition is not set (we don't know our lat/long)
geometry.position = vec4(common_position, 0.0, 1.0);
if (project_uProjectionMode == PROJECTION_MODE_WEB_MERCATOR_AUTO_OFFSET) {
geometry.position.xyz -= project_uCommonOrigin;
if (project.projectionMode == PROJECTION_MODE_WEB_MERCATOR_AUTO_OFFSET) {
geometry.position.xyz -= project.commonOrigin;
}

// calculate elevation, if 3d not enabled set to 0
Expand Down Expand Up @@ -86,7 +86,7 @@ void main(void) {
position_commonspace = geometry.position;
vColor = vec4(color.rgb, color.a * opacity);
#else
vec3 lightColor = lighting_getLightColor(color.rgb, project_uCameraPosition, geometry.position.xyz, geometry.normal);
vec3 lightColor = lighting_getLightColor(color.rgb, project.cameraPosition, geometry.position.xyz, geometry.normal);
vColor = vec4(lightColor, color.a * opacity);
#endif
} else {
Expand Down
10 changes: 5 additions & 5 deletions modules/core/package.json
Expand Up @@ -42,11 +42,11 @@
"dependencies": {
"@loaders.gl/core": "^4.2.0",
"@loaders.gl/images": "^4.2.0",
"@luma.gl/constants": "^9.0.11",
"@luma.gl/core": "^9.0.11",
"@luma.gl/engine": "^9.0.11",
"@luma.gl/shadertools": "^9.0.11",
"@luma.gl/webgl": "^9.0.11",
"@luma.gl/constants": "^9.0.12",
"@luma.gl/core": "^9.0.12",
"@luma.gl/engine": "^9.0.12",
"@luma.gl/shadertools": "^9.0.12",
"@luma.gl/webgl": "^9.0.12",
"@math.gl/core": "^4.0.0",
"@math.gl/sun": "^4.0.0",
"@math.gl/web-mercator": "^4.0.0",
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/effects/lighting/camera-light.ts
Expand Up @@ -8,15 +8,15 @@ export default class CameraLight extends PointLight {
const {projectedLight} = this;
const viewport = layer.context.viewport;
const {coordinateSystem, coordinateOrigin, modelMatrix} = layer.props;
const {project_uCameraPosition} = getUniformsFromViewport({
const {cameraPosition} = getUniformsFromViewport({
viewport,
modelMatrix,
coordinateSystem,
coordinateOrigin
});
projectedLight.color = this.color;
projectedLight.intensity = this.intensity;
projectedLight.position = project_uCameraPosition;
projectedLight.position = cameraPosition;
felixpalmer marked this conversation as resolved.
Show resolved Hide resolved
return projectedLight;
}
}
8 changes: 7 additions & 1 deletion modules/core/src/lib/layer.ts
Expand Up @@ -1065,8 +1065,14 @@ export default abstract class Layer<PropsT extends {} = {}> extends Component<
// TODO/ib - hack move to luma Model.draw
if (moduleParameters) {
const {isActive, isAttribute} = moduleParameters.picking;
const {viewport, devicePixelRatio, coordinateSystem, coordinateOrigin} = moduleParameters;
const {modelMatrix} = this.props;
this.setModuleParameters(moduleParameters);
this.setShaderModuleProps({picking: {isActive, isAttribute}});
this.setShaderModuleProps({
picking: {isActive, isAttribute},
project: {viewport, devicePixelRatio, modelMatrix, coordinateSystem, coordinateOrigin},
project64: {viewport}
});
}

// Apply polygon offset to avoid z-fighting
Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/shaderlib/index.ts
Expand Up @@ -21,12 +21,13 @@
import {ShaderAssembler} from '@luma.gl/shadertools';

import {gouraudLighting, phongLighting} from '@luma.gl/shadertools';
import geometry from './misc/geometry';
import project from './project/project';
import project32 from './project32/project32';
import shadow from './shadow/shadow';
import picking from './picking/picking';

const DEFAULT_MODULES = [project];
const DEFAULT_MODULES = [geometry];

const SHADER_HOOKS = [
'vs:DECKGL_FILTER_SIZE(inout vec3 size, VertexGeometry geometry)',
Expand Down