diff --git a/.github/workflows/typescript.yml b/.github/workflows/typescript.yml index be4ecfa43..1c9659f3f 100644 --- a/.github/workflows/typescript.yml +++ b/.github/workflows/typescript.yml @@ -88,8 +88,8 @@ jobs: - name: 📚 Update Storybook if: github.event_name == 'push' && github.ref == 'refs/heads/master' run: | - rm -rf ../storybook-static - mv ./storybook-static .. + rm -rf ../../storybook-static + mv ./storybook-static ../.. git config --local user.email "webviz-github-action" git config --local user.name "webviz-github-action" @@ -98,7 +98,7 @@ jobs: git clean -f -f -d -x git rm -r --ignore-unmatch * - mv ../storybook-static . + mv ../../storybook-static . git add . diff --git a/typescript/packages/subsurface-viewer/CHANGELOG.md b/typescript/packages/subsurface-viewer/CHANGELOG.md index dfe50ea35..b4ea0ee0a 100644 --- a/typescript/packages/subsurface-viewer/CHANGELOG.md +++ b/typescript/packages/subsurface-viewer/CHANGELOG.md @@ -1,3 +1,17 @@ +## [0.5.4](https://github.com/equinor/webviz-subsurface-components/compare/subsurface-viewer@0.5.3...subsurface-viewer@0.5.4) (2023-10-27) + + +### Performance Improvements + +* Apply flag "ZIncreasingDownwards" in vertex shaders MapLayer. ([#1741](https://github.com/equinor/webviz-subsurface-components/issues/1741)) ([ed85f7f](https://github.com/equinor/webviz-subsurface-components/commit/ed85f7f6bd5e1841518e0c52448e90eba3c8b988)), closes [#1724](https://github.com/equinor/webviz-subsurface-components/issues/1724) [#1737](https://github.com/equinor/webviz-subsurface-components/issues/1737) + +## [0.5.3](https://github.com/equinor/webviz-subsurface-components/compare/subsurface-viewer@0.5.2...subsurface-viewer@0.5.3) (2023-10-27) + + +### Bug Fixes + +* force publishing a new package ([#1740](https://github.com/equinor/webviz-subsurface-components/issues/1740)) ([64938ee](https://github.com/equinor/webviz-subsurface-components/commit/64938ee977db4ec01c1ea09135827bc2af837018)) + ## [0.5.2](https://github.com/equinor/webviz-subsurface-components/compare/subsurface-viewer@0.5.1...subsurface-viewer@0.5.2) (2023-10-25) diff --git a/typescript/packages/subsurface-viewer/package.json b/typescript/packages/subsurface-viewer/package.json index ba8887dc7..f2da4847b 100644 --- a/typescript/packages/subsurface-viewer/package.json +++ b/typescript/packages/subsurface-viewer/package.json @@ -1,6 +1,6 @@ { "name": "@webviz/subsurface-viewer", - "version": "0.5.2", + "version": "0.5.4", "description": "", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/typescript/packages/subsurface-viewer/src/layers/grid3d/fragment.fs.glsl.ts b/typescript/packages/subsurface-viewer/src/layers/grid3d/fragment.fs.glsl.ts index 9482c1617..c85f81014 100644 --- a/typescript/packages/subsurface-viewer/src/layers/grid3d/fragment.fs.glsl.ts +++ b/typescript/packages/subsurface-viewer/src/layers/grid3d/fragment.fs.glsl.ts @@ -55,9 +55,9 @@ void main(void) { color = texture2D(colormap, vec2(x, 0.5)); } - // Use normal lighting. This has no effect if "material" property is not set. - vec3 lightColor = lighting_getLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal); - gl_FragColor = vec4(lightColor, 1.0); + // Use two sided phong lighting. This has no effect if "material" property is not set. + vec3 lightColor = getPhongLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal); + gl_FragColor = vec4(lightColor, 1.0); DECKGL_FILTER_COLOR(gl_FragColor, geometry); } `; diff --git a/typescript/packages/subsurface-viewer/src/layers/grid3d/grid3dLayer.ts b/typescript/packages/subsurface-viewer/src/layers/grid3d/grid3dLayer.ts index 831018bdb..a4775fe45 100644 --- a/typescript/packages/subsurface-viewer/src/layers/grid3d/grid3dLayer.ts +++ b/typescript/packages/subsurface-viewer/src/layers/grid3d/grid3dLayer.ts @@ -1,7 +1,7 @@ import type { Color } from "@deck.gl/core/typed"; import { CompositeLayer } from "@deck.gl/core/typed"; -import type { Material } from "./privateLayer"; -import privateLayer from "./privateLayer"; +import type { Material } from "./privateGrid3dLayer"; +import privateLayer from "./privateGrid3dLayer"; import type { ExtendedLayerProps, colorMapFunctionType, diff --git a/typescript/packages/subsurface-viewer/src/layers/grid3d/privateLayer.ts b/typescript/packages/subsurface-viewer/src/layers/grid3d/privateGrid3dLayer.ts similarity index 100% rename from typescript/packages/subsurface-viewer/src/layers/grid3d/privateLayer.ts rename to typescript/packages/subsurface-viewer/src/layers/grid3d/privateGrid3dLayer.ts diff --git a/typescript/packages/subsurface-viewer/src/layers/grid3d/webworker.ts b/typescript/packages/subsurface-viewer/src/layers/grid3d/webworker.ts index 7c2d87436..027b4c4e4 100644 --- a/typescript/packages/subsurface-viewer/src/layers/grid3d/webworker.ts +++ b/typescript/packages/subsurface-viewer/src/layers/grid3d/webworker.ts @@ -1,4 +1,4 @@ -import type { MeshType, MeshTypeLines } from "./privateLayer"; +import type { MeshType, MeshTypeLines } from "./privateGrid3dLayer"; import type { WebWorkerParams } from "./grid3dLayer"; export function makeFullMesh(e: { data: WebWorkerParams }): void { diff --git a/typescript/packages/subsurface-viewer/src/layers/map/fragment.fs.glsl.ts b/typescript/packages/subsurface-viewer/src/layers/map/fragment.fs.glsl.ts index ad9056be3..e7991498c 100644 --- a/typescript/packages/subsurface-viewer/src/layers/map/fragment.fs.glsl.ts +++ b/typescript/packages/subsurface-viewer/src/layers/map/fragment.fs.glsl.ts @@ -93,10 +93,9 @@ void main(void) { color = color * vec4(c, c, c, 1.0); } - // Use normal lighting. This has no effect if "material" property is not set. - vec3 lightColor = lighting_getLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal); + // Use two sided phong lighting. This has no effect if "material" property is not set. + vec3 lightColor = getPhongLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal); gl_FragColor = vec4(lightColor, 1.0); - DECKGL_FILTER_COLOR(gl_FragColor, geometry); } `; diff --git a/typescript/packages/subsurface-viewer/src/layers/map/mapLayer.ts b/typescript/packages/subsurface-viewer/src/layers/map/mapLayer.ts index 12e80d168..09b7d41c1 100644 --- a/typescript/packages/subsurface-viewer/src/layers/map/mapLayer.ts +++ b/typescript/packages/subsurface-viewer/src/layers/map/mapLayer.ts @@ -55,7 +55,6 @@ export type Params = { frame: Frame; smoothShading: boolean; gridLines: boolean; - ZIncreasingDownwards: boolean; }; /** @@ -337,7 +336,6 @@ export default class MapLayer extends CompositeLayer { frame: this.props.frame, smoothShading: this.props.smoothShading, gridLines: this.props.gridLines, - ZIncreasingDownwards: this.props.ZIncreasingDownwards, }; const [ diff --git a/typescript/packages/subsurface-viewer/src/layers/map/privateMapLayer.ts b/typescript/packages/subsurface-viewer/src/layers/map/privateMapLayer.ts index 4e967abd0..ed994b7fa 100644 --- a/typescript/packages/subsurface-viewer/src/layers/map/privateMapLayer.ts +++ b/typescript/packages/subsurface-viewer/src/layers/map/privateMapLayer.ts @@ -227,6 +227,7 @@ export default class privateMapLayer extends Layer { isColorMapClampColorTransparent, isClampColor, smoothShading, + ZIncreasingDownwards: this.props.ZIncreasingDownwards, }) .draw(); gl.disable(GL.POLYGON_OFFSET_FILL); @@ -236,7 +237,12 @@ export default class privateMapLayer extends Layer { } if (this.props.gridLines) { - mesh_lines_model.draw(); + mesh_lines_model + .setUniforms({ + ...uniforms, + ZIncreasingDownwards: this.props.ZIncreasingDownwards, + }) + .draw(); } if (!this.state["isLoaded"]) { diff --git a/typescript/packages/subsurface-viewer/src/layers/map/utils.ts b/typescript/packages/subsurface-viewer/src/layers/map/utils.ts index 3bdeae46a..b0f8a5422 100644 --- a/typescript/packages/subsurface-viewer/src/layers/map/utils.ts +++ b/typescript/packages/subsurface-viewer/src/layers/map/utils.ts @@ -44,8 +44,7 @@ function calcNormal( ox: number, oy: number, dx: number, - dy: number, - multZ: number + dy: number ) { if (!smoothShading) { return [1, 1, 1]; @@ -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; @@ -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); @@ -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]; @@ -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; @@ -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]; diff --git a/typescript/packages/subsurface-viewer/src/layers/map/vertex.glsl.ts b/typescript/packages/subsurface-viewer/src/layers/map/vertex.glsl.ts index cecf04760..11fa35277 100644 --- a/typescript/packages/subsurface-viewer/src/layers/map/vertex.glsl.ts +++ b/typescript/packages/subsurface-viewer/src/layers/map/vertex.glsl.ts @@ -20,14 +20,18 @@ 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; @@ -35,7 +39,7 @@ void main(void) { 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); diff --git a/typescript/packages/subsurface-viewer/src/layers/map/vertex_lines.glsl.ts b/typescript/packages/subsurface-viewer/src/layers/map/vertex_lines.glsl.ts index 286877acb..eedc8fdee 100644 --- a/typescript/packages/subsurface-viewer/src/layers/map/vertex_lines.glsl.ts +++ b/typescript/packages/subsurface-viewer/src/layers/map/vertex_lines.glsl.ts @@ -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)); } `; diff --git a/typescript/packages/subsurface-viewer/src/layers/triangle/fragment.fs.glsl.ts b/typescript/packages/subsurface-viewer/src/layers/triangle/fragment.fs.glsl.ts index 01c7fee9e..474bdec0b 100644 --- a/typescript/packages/subsurface-viewer/src/layers/triangle/fragment.fs.glsl.ts +++ b/typescript/packages/subsurface-viewer/src/layers/triangle/fragment.fs.glsl.ts @@ -40,7 +40,7 @@ void main(void) { color = color * vec4(c, c, c, 1.0); } - // Use normal lighting. This has no effect if "material" property is not set. + // Use two sided phong lighting. This has no effect if "material" property is not set. vec3 lightColor = getPhongLightColor(color.rgb, cameraPosition, position_commonspace.xyz, normal); gl_FragColor = vec4(lightColor, 1.0); DECKGL_FILTER_COLOR(gl_FragColor, geometry);