Skip to content

Commit

Permalink
perf: Apply flag "ZIncreasingDownwards" in vertex shaders MapLayer. (#…
Browse files Browse the repository at this point in the history
…1741)

- This is related to earlier commit. MapLayer was missing
- Earlier commit: performance:  Apply flag "ZIncreasingDownwards" in vertex shaders for relevant layers. #1724 (#1737)
  • Loading branch information
nilscb authored Oct 27, 2023
1 parent 270d5d4 commit ed85f7f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export type Params = {
frame: Frame;
smoothShading: boolean;
gridLines: boolean;
ZIncreasingDownwards: boolean;
};

/**
Expand Down Expand Up @@ -337,7 +336,6 @@ export default class MapLayer extends CompositeLayer<MapLayerProps> {
frame: this.props.frame,
smoothShading: this.props.smoothShading,
gridLines: this.props.gridLines,
ZIncreasingDownwards: this.props.ZIncreasingDownwards,
};

const [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default class privateMapLayer extends Layer<privateMapLayerProps> {
isColorMapClampColorTransparent,
isClampColor,
smoothShading,
ZIncreasingDownwards: this.props.ZIncreasingDownwards,
})
.draw();
gl.disable(GL.POLYGON_OFFSET_FILL);
Expand All @@ -236,7 +237,12 @@ export default class privateMapLayer extends Layer<privateMapLayerProps> {
}

if (this.props.gridLines) {
mesh_lines_model.draw();
mesh_lines_model
.setUniforms({
...uniforms,
ZIncreasingDownwards: this.props.ZIncreasingDownwards,
})
.draw();
}

if (!this.state["isLoaded"]) {
Expand Down
28 changes: 12 additions & 16 deletions typescript/packages/subsurface-viewer/src/layers/map/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ function calcNormal(
ox: number,
oy: number,
dx: number,
dy: number,
multZ: number
dy: number
) {
if (!smoothShading) {
return [1, 1, 1];
Expand Down Expand Up @@ -73,11 +72,11 @@ function calcNormal(
}

const hh = ny - 1 - h; // Note use hh for h for getting y values.
const p0 = [ox + w * dx, oy + hh * dy, i0_act ? -meshData[i0] * multZ : 0]; // eslint-disable-line
const p1 = [ ox + (w - 1) * dx, oy + hh * dy, i1_act ? -meshData[i1] * multZ : 0]; // eslint-disable-line
const p2 = [ ox + w * dx, oy + (hh + 1) * dy, i2_act ? -meshData[i2] * multZ : 0]; // eslint-disable-line
const p3 = [ ox + (w + 1) * dx, oy + hh * dy, i3_act ? -meshData[i3] * multZ : 0]; // eslint-disable-line
const p4 = [ ox + w * dx, oy + (hh - 1) * dy, i4_act ? -meshData[i4] * multZ : 0]; // eslint-disable-line
const p0 = [ox + w * dx, oy + hh * dy, i0_act ? meshData[i0] : 0]; // eslint-disable-line
const p1 = [ ox + (w - 1) * dx, oy + hh * dy, i1_act ? meshData[i1] : 0]; // eslint-disable-line
const p2 = [ ox + w * dx, oy + (hh + 1) * dy, i2_act ? meshData[i2] : 0]; // eslint-disable-line
const p3 = [ ox + (w + 1) * dx, oy + hh * dy, i3_act ? meshData[i3] : 0]; // eslint-disable-line
const p4 = [ ox + w * dx, oy + (hh - 1) * dy, i4_act ? meshData[i4] : 0]; // eslint-disable-line

const v1 = [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]] as Vec;
const v2 = [p2[0] - p0[0], p2[1] - p0[1], p2[2] - p0[2]] as Vec;
Expand Down Expand Up @@ -143,9 +142,6 @@ export function makeFullMesh(params: Params) {
const frame = params.frame;
const smoothShading = params.smoothShading;
const gridLines = params.gridLines;
const ZIncreasingDownwards = params.ZIncreasingDownwards;

const multZ = ZIncreasingDownwards ? 1 : -1;

const meshZValueRange = getFloat32ArrayMinMax(meshData);
const propertyValueRange = getFloat32ArrayMinMax(propertiesData);
Expand Down Expand Up @@ -206,7 +202,7 @@ export function makeFullMesh(params: Params) {

const x0 = ox + w * dx;
const y0 = oy + (ny - 1 - h) * dy; // See note above.
const z = isMesh ? -meshData[i0] * multZ : 0;
const z = isMesh ? meshData[i0] : 0;

const propertyValue = propertiesData[i0];

Expand All @@ -215,7 +211,7 @@ export function makeFullMesh(params: Params) {
positions[3 * i + 2] = z;

if (smoothShading) {
const normal = calcNormal(w, h, nx, ny, isMesh, smoothShading, meshData, ox, oy, dx, dy, multZ); // eslint-disable-line
const normal = calcNormal(w, h, nx, ny, isMesh, smoothShading, meshData, ox, oy, dx, dy); // eslint-disable-line
normals[3 * i + 0] = normal[0] * 127; // Normalize to signed 8 bit.
normals[3 * i + 1] = normal[1] * 127;
normals[3 * i + 2] = normal[2] * 127;
Expand Down Expand Up @@ -334,19 +330,19 @@ export function makeFullMesh(params: Params) {

const x0 = ox + w * dx;
const y0 = oy + hh * dy;
const z0 = isMesh ? -meshData[i0] * multZ : 0;
const z0 = isMesh ? meshData[i0] : 0;

const x1 = ox + (w + 1) * dx;
const y1 = oy + hh * dy;
const z1 = isMesh ? -meshData[i1] * multZ : 0;
const z1 = isMesh ? meshData[i1] : 0;

const x2 = ox + (w + 1) * dx;
const y2 = oy + (hh - 1) * dy; // Note hh - 1 here.
const z2 = isMesh ? -meshData[i2] * multZ : 0;
const z2 = isMesh ? meshData[i2] : 0;

const x3 = ox + w * dx;
const y3 = oy + (hh - 1) * dy; // Note hh - 1 here.
const z3 = isMesh ? -meshData[i3] * multZ : 0;
const z3 = isMesh ? meshData[i3] : 0;

const propertyIndex = h * (nx - 1) + w; // (nx - 1) -> the width of the property 2D array is one less than for the nodes in this case.
const propertyValue = propertiesData[propertyIndex];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,26 @@ out vec3 worldPos;
out float property;
flat out int vertexIndex;
uniform bool ZIncreasingDownwards;
void main(void) {
geometry.pickingColor = vec3(1.0, 1.0, 0.0);
vertexIndex = gl_VertexID;
vec3 position = positions;
position[2] *= ZIncreasingDownwards ? -1.0 : 1.0;
cameraPosition = project_uCameraPosition;
worldPos = positions;
worldPos = position;
normals_commonspace = normals;
vColor = vec4(colors.rgb, 1.0);
property = properties;
position_commonspace = vec4(project_position(positions), 0.0);
position_commonspace = vec4(project_position(position), 0.0);
gl_Position = project_common_position_to_clipspace(position_commonspace);
DECKGL_FILTER_GL_POSITION(gl_Position, geometry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ in vec3 positions;
out vec4 position_commonspace;
uniform bool ZIncreasingDownwards;
void main(void) {
vec3 position_commonspace = project_position(positions);
vec3 position = positions;
position[2] *= ZIncreasingDownwards ? -1.0 : 1.0;
vec3 position_commonspace = project_position(position);
gl_Position = project_common_position_to_clipspace(vec4(position_commonspace, 0.0));
}
`;

0 comments on commit ed85f7f

Please sign in to comment.