@webviz/subsurface-viewer 1.18.3 → 1.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import type { NumberArray3 } from "@math.gl/types";
2
2
  import type { ShaderModule } from "@luma.gl/shadertools";
3
3
  export type PhongMaterialProps = {
4
+ unlit?: boolean;
4
5
  ambient?: number;
5
6
  diffuse?: number;
6
7
  /** Specularity exponent */
@@ -1,36 +1,39 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- import { lighting } from "@luma.gl/shadertools";
4
+ import { floatColors, lighting } from "@luma.gl/shadertools";
5
+ //import {PHONG_WGSL} from './phong-shaders-wgsl';
5
6
  import { PHONG_VS, PHONG_FS } from "./phong-shaders-glsl";
7
+ const DEFAULT_SPECULAR_COLOR = [38.25, 38.25, 38.25];
6
8
  /** In Phong shading, the normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. */
7
9
  export const phongMaterial = {
8
10
  name: "phongMaterial",
9
- dependencies: [lighting],
11
+ firstBindingSlot: 0,
12
+ bindingLayout: [{ name: "phongMaterial", group: 3 }],
13
+ dependencies: [lighting, floatColors],
10
14
  // Note these are switched between phong and gouraud
15
+ //source: PHONG_WGSL,
11
16
  vs: PHONG_VS,
12
17
  fs: PHONG_FS,
13
18
  defines: {
14
19
  LIGHTING_FRAGMENT: true,
15
20
  },
16
21
  uniformTypes: {
22
+ unlit: "i32",
17
23
  ambient: "f32",
18
24
  diffuse: "f32",
19
25
  shininess: "f32",
20
26
  specularColor: "vec3<f32>",
21
27
  },
22
28
  defaultUniforms: {
29
+ unlit: false,
23
30
  ambient: 0.35,
24
31
  diffuse: 0.6,
25
32
  shininess: 32,
26
- specularColor: [0.15, 0.15, 0.15],
33
+ specularColor: DEFAULT_SPECULAR_COLOR,
27
34
  },
28
35
  getUniforms(props) {
29
- const uniforms = { ...props };
30
- if (uniforms.specularColor) {
31
- uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
32
- }
33
- return { ...phongMaterial.defaultUniforms, ...uniforms };
36
+ return { ...phongMaterial.defaultUniforms, ...props };
34
37
  },
35
38
  };
36
39
  //# sourceMappingURL=phong-material.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"phong-material.js","sourceRoot":"","sources":["../../../../src/layers/shader_modules/phong-lighting/phong-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AASpC,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAU1D,wIAAwI;AACxI,MAAM,CAAC,MAAM,aAAa,GAAqC;IAC3D,IAAI,EAAE,eAAe;IACrB,YAAY,EAAE,CAAC,QAAQ,CAAC;IACxB,oDAAoD;IACpD,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE;QACL,iBAAiB,EAAE,IAAI;KAC1B;IACD,YAAY,EAAE;QACV,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,WAAW;KAC7B;IACD,eAAe,EAAE;QACb,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,GAAG;QACZ,SAAS,EAAE,EAAE;QACb,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KACpC;IACD,WAAW,CAAC,KAA0B;QAClC,MAAM,QAAQ,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;QAC9B,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YACzB,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAC/C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,CACD,CAAC;QACtB,CAAC;QACD,OAAO,EAAE,GAAG,aAAa,CAAC,eAAe,EAAE,GAAG,QAAQ,EAAE,CAAC;IAC7D,CAAC;CACJ,CAAC"}
1
+ {"version":3,"file":"phong-material.js","sourceRoot":"","sources":["../../../../src/layers/shader_modules/phong-lighting/phong-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AASpC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC7D,kDAAkD;AAClD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAW1D,MAAM,sBAAsB,GAAiB,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAEnE,wIAAwI;AACxI,MAAM,CAAC,MAAM,aAAa,GAAqC;IAC3D,IAAI,EAAE,eAAe;IACrB,gBAAgB,EAAE,CAAC;IACnB,aAAa,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;IACpD,YAAY,EAAE,CAAC,QAAQ,EAAE,WAAW,CAAC;IACrC,oDAAoD;IACpD,qBAAqB;IACrB,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,QAAQ;IACZ,OAAO,EAAE;QACL,iBAAiB,EAAE,IAAI;KAC1B;IACD,YAAY,EAAE;QACV,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,WAAW;KAC7B;IACD,eAAe,EAAE;QACb,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,GAAG;QACZ,SAAS,EAAE,EAAE;QACb,aAAa,EAAE,sBAAsB;KACxC;IACD,WAAW,CAAC,KAA0B;QAClC,OAAO,EAAE,GAAG,aAAa,CAAC,eAAe,EAAE,GAAG,KAAK,EAAE,CAAC;IAC1D,CAAC;CACJ,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const PHONG_VS = "uniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n";
2
- export declare const PHONG_FS = "#define MAX_LIGHTS 3\n\nuniform phongMaterialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n\n// Note modified for two sided lighting.\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {\n vec3 halfway_direction = normalize(light_direction + view_direction); \n\n float lambertian = abs(dot(light_direction, normal_worldspace));\n float specular_angle = abs(dot(normal_worldspace, halfway_direction));\n\n float specular = pow(specular_angle, material.shininess); \n return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;\n}\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n for (int i = 0; i < lighting.pointLightCount; i++) {\n PointLight pointLight = lighting_getPointLight(i);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);\n }\n\n int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);\n for (int i = lighting.pointLightCount; i < totalLights; i++) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(i);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\n}\n";
1
+ export declare const PHONG_VS = "layout(std140) uniform phongMaterialUniforms {\n uniform bool unlit;\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n";
2
+ export declare const PHONG_FS = "layout(std140) uniform phongMaterialUniforms {\n uniform bool unlit;\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n\n// Note modified for two sided lighting.\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {\n vec3 halfway_direction = normalize(light_direction + view_direction);\n\n // initial code\n // float lambertian = dot(light_direction, normal_worldspace);\n // float specular = 0.0;\n // if (lambertian > 0.0) {\n // float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n // specular = pow(specular_angle, material.shininess);\n // }\n // lambertian = max(lambertian, 0.0);\n \n // new code for two sided lighting\n float lambertian = abs(dot(light_direction, normal_worldspace));\n float specular_angle = abs(dot(normal_worldspace, halfway_direction));\n float specular = pow(specular_angle, material.shininess);\n\n return (lambertian * material.diffuse * surfaceColor + specular * floatColors_normalize(material.specularColor)) * color;\n}\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = surfaceColor;\n\n if (material.unlit) {\n return surfaceColor;\n }\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n for (int i = 0; i < lighting.pointLightCount; i++) {\n PointLight pointLight = lighting_getPointLight(i);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);\n }\n\n for (int i = 0; i < lighting.spotLightCount; i++) {\n SpotLight spotLight = lighting_getSpotLight(i);\n vec3 light_position_worldspace = spotLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, spotLight.color / light_attenuation);\n }\n\n for (int i = 0; i < lighting.directionalLightCount; i++) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(i);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\n}\n";
@@ -1,8 +1,13 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
+ // Webviz note: Copied this module from luma.gl.
5
+ // https://github.com/visgl/luma.gl branch 9.3-release
6
+ // Modified imports and commented PHONG_WGSL in file "phong-material.ts".
7
+ // Modified function "lighting_getLightColor" in file "phong-shaders-glsl.ts" to get two sided phong lighting.
4
8
  export const PHONG_VS = /* glsl */ `\
5
- uniform phongMaterialUniforms {
9
+ layout(std140) uniform phongMaterialUniforms {
10
+ uniform bool unlit;
6
11
  uniform float ambient;
7
12
  uniform float diffuse;
8
13
  uniform float shininess;
@@ -10,9 +15,8 @@ uniform phongMaterialUniforms {
10
15
  } material;
11
16
  `;
12
17
  export const PHONG_FS = /* glsl */ `\
13
- #define MAX_LIGHTS 3
14
-
15
- uniform phongMaterialUniforms {
18
+ layout(std140) uniform phongMaterialUniforms {
19
+ uniform bool unlit;
16
20
  uniform float ambient;
17
21
  uniform float diffuse;
18
22
  uniform float shininess;
@@ -21,18 +25,32 @@ uniform phongMaterialUniforms {
21
25
 
22
26
  // Note modified for two sided lighting.
23
27
  vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
24
- vec3 halfway_direction = normalize(light_direction + view_direction);
28
+ vec3 halfway_direction = normalize(light_direction + view_direction);
25
29
 
30
+ // initial code
31
+ // float lambertian = dot(light_direction, normal_worldspace);
32
+ // float specular = 0.0;
33
+ // if (lambertian > 0.0) {
34
+ // float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
35
+ // specular = pow(specular_angle, material.shininess);
36
+ // }
37
+ // lambertian = max(lambertian, 0.0);
38
+
39
+ // new code for two sided lighting
26
40
  float lambertian = abs(dot(light_direction, normal_worldspace));
27
41
  float specular_angle = abs(dot(normal_worldspace, halfway_direction));
42
+ float specular = pow(specular_angle, material.shininess);
28
43
 
29
- float specular = pow(specular_angle, material.shininess);
30
- return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
44
+ return (lambertian * material.diffuse * surfaceColor + specular * floatColors_normalize(material.specularColor)) * color;
31
45
  }
32
46
 
33
47
  vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
34
48
  vec3 lightColor = surfaceColor;
35
49
 
50
+ if (material.unlit) {
51
+ return surfaceColor;
52
+ }
53
+
36
54
  if (lighting.enabled == 0) {
37
55
  return lightColor;
38
56
  }
@@ -48,8 +66,15 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
48
66
  lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
49
67
  }
50
68
 
51
- int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
52
- for (int i = lighting.pointLightCount; i < totalLights; i++) {
69
+ for (int i = 0; i < lighting.spotLightCount; i++) {
70
+ SpotLight spotLight = lighting_getSpotLight(i);
71
+ vec3 light_position_worldspace = spotLight.position;
72
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
73
+ float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
74
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, spotLight.color / light_attenuation);
75
+ }
76
+
77
+ for (int i = 0; i < lighting.directionalLightCount; i++) {
53
78
  DirectionalLight directionalLight = lighting_getDirectionalLight(i);
54
79
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
55
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"phong-shaders-glsl.js","sourceRoot":"","sources":["../../../../src/layers/shader_modules/phong-lighting/phong-shaders-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;;;;;;;CAOlC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+ClC,CAAC"}
1
+ {"version":3,"file":"phong-shaders-glsl.js","sourceRoot":"","sources":["../../../../src/layers/shader_modules/phong-lighting/phong-shaders-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,gDAAgD;AAChD,sDAAsD;AACtD,yEAAyE;AACzE,8GAA8G;AAE9G,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;;;;;;;;CAQlC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmElC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webviz/subsurface-viewer",
3
- "version": "1.18.3",
3
+ "version": "1.18.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },