@luma.gl/shadertools 9.1.0-alpha.1 → 9.1.0-alpha.12
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.
- package/dist/dist.dev.js +1005 -487
- package/dist/dist.min.js +2489 -1625
- package/dist/index.cjs +2864 -1817
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +29 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -12
- package/dist/lib/glsl-utils/shader-utils.d.ts.map +1 -1
- package/dist/lib/glsl-utils/shader-utils.js +2 -3
- package/dist/lib/shader-assembler.d.ts +3 -4
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +3 -2
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +4 -3
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +46 -18
- package/dist/lib/shader-assembly/platform-defines.d.ts.map +1 -1
- package/dist/lib/shader-assembly/platform-defines.js +14 -6
- package/dist/lib/shader-module/shader-module-dependencies.d.ts +53 -0
- package/dist/lib/shader-module/shader-module-dependencies.d.ts.map +1 -0
- package/dist/lib/{shader-assembly/resolve-modules.js → shader-module/shader-module-dependencies.js} +38 -14
- package/dist/lib/shader-module/shader-module.d.ts +30 -12
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js +76 -6
- package/dist/lib/shader-module/shader-pass.d.ts +3 -2
- package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
- package/dist/module-injectors.d.ts +2 -2
- package/dist/module-injectors.d.ts.map +1 -1
- package/dist/module-injectors.js +13 -10
- package/dist/modules/engine/geometry/geometry.d.ts.map +1 -1
- package/dist/modules/engine/geometry/geometry.js +12 -8
- package/dist/modules/engine/picking/picking.d.ts +9 -9
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +103 -66
- package/dist/modules/engine/project/project.d.ts +2 -2
- package/dist/modules/engine/project/project.d.ts.map +1 -1
- package/dist/modules/engine/project/project.js +36 -22
- package/dist/modules/engine/transform/transform.d.ts.map +1 -1
- package/dist/modules/engine/transform/transform.js +28 -16
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +10 -7
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +2 -0
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +79 -53
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +38 -23
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts +2 -0
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js +56 -0
- package/dist/modules/lighting/lights/lighting.d.ts +5 -4
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +7 -5
- package/dist/modules/lighting/no-material/dirlight.d.ts +8 -8
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +34 -20
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +304 -181
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +72 -69
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +4 -2
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +38 -20
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +21 -16
- package/dist/modules/lighting/phong-material/phong-material.d.ts +14 -12
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +5 -3
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +82 -54
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +41 -0
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +130 -0
- package/dist/modules/math/fp32/fp32.d.ts.map +1 -1
- package/dist/modules/math/fp32/fp32.js +127 -100
- package/dist/modules/math/fp64/fp64-utils.d.ts +3 -3
- package/dist/modules/math/fp64/fp64-utils.d.ts.map +1 -1
- package/dist/modules/math/random/random.d.ts +1 -1
- package/dist/modules/math/random/random.d.ts.map +1 -1
- package/dist/modules/math/random/random.js +3 -3
- package/dist/modules/module-injectors.d.ts +2 -2
- package/dist/modules/module-injectors.d.ts.map +1 -1
- package/dist/modules/module-injectors.js +13 -10
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.js +16 -12
- package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/denoise.js +21 -17
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts +5 -2
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.js +29 -22
- package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/noise.js +14 -10
- package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/sepia.js +17 -12
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.js +12 -9
- package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/vignette.js +13 -10
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts +5 -2
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.js +40 -26
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts +5 -2
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.js +32 -19
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts +4 -1
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.js +2 -0
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.js +31 -27
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.js +19 -15
- package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts +8 -5
- package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/edgework.js +53 -42
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.js +41 -33
- package/dist/modules/postprocessing/image-fun-filters/ink.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/ink.js +27 -25
- package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts +2 -1
- package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/magnify.js +17 -16
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts +5 -2
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.js +24 -20
- package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts +5 -2
- package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/swirl.js +26 -22
- package/dist/modules/postprocessing/image-warp-filters/warp.d.ts +2 -1
- package/dist/modules/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/warp.js +9 -8
- package/dist/modules-webgl1/geometry/geometry.d.ts.map +1 -1
- package/dist/modules-webgl1/geometry/geometry.js +12 -8
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +2 -2
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/dirlight/dirlight.js +8 -5
- package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/lights/lights-glsl.js +19 -11
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +268 -157
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +16 -12
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +64 -55
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +113 -81
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +588 -433
- package/dist/modules-webgl1/project/project.d.ts +2 -2
- package/dist/modules-webgl1/project/project.d.ts.map +1 -1
- package/dist/modules-webgl1/project/project.js +5 -4
- package/package.json +5 -5
- package/src/index.ts +78 -32
- package/src/lib/glsl-utils/shader-utils.ts +1 -3
- package/src/lib/shader-assembler.ts +7 -8
- package/src/lib/shader-assembly/assemble-shaders.ts +55 -22
- package/src/lib/shader-assembly/platform-defines.ts +5 -6
- package/src/lib/shader-module/shader-module-dependencies.ts +111 -0
- package/src/lib/shader-module/shader-module.ts +134 -19
- package/src/lib/shader-module/shader-pass.ts +3 -2
- package/src/module-injectors.ts +2 -4
- package/src/modules/engine/geometry/geometry.ts +2 -3
- package/src/modules/engine/picking/picking.ts +12 -10
- package/src/modules/engine/project/project.ts +2 -3
- package/src/modules/engine/transform/transform.ts +1 -3
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +2 -4
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +1 -3
- package/src/modules/lighting/lights/lighting-uniforms-wgsl.ts +57 -0
- package/src/modules/lighting/lights/lighting.ts +9 -5
- package/src/modules/lighting/no-material/dirlight.ts +30 -19
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +1 -2
- package/src/modules/lighting/pbr-material/pbr-material.ts +44 -38
- package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +1 -3
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +1 -3
- package/src/modules/lighting/phong-material/phong-material.ts +6 -3
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -4
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +132 -0
- package/src/modules/math/fp32/fp32.ts +1 -2
- package/src/modules/math/fp64/fp64-utils.ts +3 -3
- package/src/modules/math/random/random.ts +1 -2
- package/src/modules/module-injectors.ts +2 -4
- package/src/modules/postprocessing/image-adjust-filters/brightnesscontrast.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/denoise.ts +7 -3
- package/src/modules/postprocessing/image-adjust-filters/huesaturation.ts +9 -4
- package/src/modules/postprocessing/image-adjust-filters/noise.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/sepia.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/vibrance.ts +5 -2
- package/src/modules/postprocessing/image-adjust-filters/vignette.ts +11 -4
- package/src/modules/postprocessing/image-blur-filters/tiltshift.ts +6 -2
- package/src/modules/postprocessing/image-blur-filters/triangleblur.ts +6 -2
- package/src/modules/postprocessing/image-blur-filters/zoomblur.ts +5 -0
- package/src/modules/postprocessing/image-fun-filters/colorhalftone.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/dotscreen.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/edgework.ts +10 -4
- package/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/ink.ts +8 -3
- package/src/modules/postprocessing/image-fun-filters/magnify.ts +3 -2
- package/src/modules/postprocessing/image-warp-filters/bulgepinch.ts +6 -2
- package/src/modules/postprocessing/image-warp-filters/swirl.ts +8 -2
- package/src/modules/postprocessing/image-warp-filters/warp.ts +3 -2
- package/src/modules-webgl1/geometry/geometry.ts +2 -3
- package/src/modules-webgl1/lighting/dirlight/dirlight.ts +3 -4
- package/src/modules-webgl1/lighting/lights/lights-glsl.ts +1 -3
- package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +1 -2
- package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +1 -3
- package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +1 -3
- package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +1 -3
- package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +1 -3
- package/src/modules-webgl1/project/project.ts +1 -2
- package/dist/lib/glsl-utils/highlight.d.ts +0 -6
- package/dist/lib/glsl-utils/highlight.d.ts.map +0 -1
- package/dist/lib/glsl-utils/highlight.js +0 -9
- package/dist/lib/shader-assembly/resolve-modules.d.ts +0 -40
- package/dist/lib/shader-assembly/resolve-modules.d.ts.map +0 -1
- package/dist/lib/shader-module/normalize-shader-module.d.ts +0 -3
- package/dist/lib/shader-module/normalize-shader-module.d.ts.map +0 -1
- package/dist/lib/shader-module/normalize-shader-module.js +0 -14
- package/dist/lib/shader-module/shader-module-instance.d.ts +0 -28
- package/dist/lib/shader-module/shader-module-instance.d.ts.map +0 -1
- package/dist/lib/shader-module/shader-module-instance.js +0 -126
- package/src/lib/glsl-utils/highlight.ts +0 -11
- package/src/lib/shader-assembly/resolve-modules.ts +0 -81
- package/src/lib/shader-module/normalize-shader-module.ts +0 -17
- package/src/lib/shader-module/shader-module-instance.ts +0 -167
|
@@ -1,100 +1,137 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
5
4
|
// cyan color
|
|
6
5
|
const DEFAULT_HIGHLIGHT_COLOR = new Float32Array([0, 1, 1, 1]);
|
|
7
|
-
const vs = `\
|
|
6
|
+
const vs = /* glsl */ `\
|
|
8
7
|
uniform pickingUniforms {
|
|
9
|
-
float isActive;
|
|
10
|
-
float isAttribute;
|
|
11
|
-
float isHighlightActive;
|
|
12
|
-
float useFloatColors;
|
|
13
|
-
vec3 highlightedObjectColor;
|
|
14
|
-
vec4 highlightColor;
|
|
8
|
+
float isActive;
|
|
9
|
+
float isAttribute;
|
|
10
|
+
float isHighlightActive;
|
|
11
|
+
float useFloatColors;
|
|
12
|
+
vec3 highlightedObjectColor;
|
|
13
|
+
vec4 highlightColor;
|
|
15
14
|
} picking;
|
|
15
|
+
|
|
16
16
|
out vec4 picking_vRGBcolor_Avalid;
|
|
17
|
+
|
|
18
|
+
// Normalize unsigned byte color to 0-1 range
|
|
17
19
|
vec3 picking_normalizeColor(vec3 color) {
|
|
18
|
-
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
20
|
+
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
19
21
|
}
|
|
22
|
+
|
|
23
|
+
// Normalize unsigned byte color to 0-1 range
|
|
20
24
|
vec4 picking_normalizeColor(vec4 color) {
|
|
21
|
-
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
25
|
+
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
22
26
|
}
|
|
27
|
+
|
|
23
28
|
bool picking_isColorZero(vec3 color) {
|
|
24
|
-
return dot(color, vec3(1.0)) < 0.00001;
|
|
29
|
+
return dot(color, vec3(1.0)) < 0.00001;
|
|
25
30
|
}
|
|
31
|
+
|
|
26
32
|
bool picking_isColorValid(vec3 color) {
|
|
27
|
-
return dot(color, vec3(1.0)) > 0.00001;
|
|
33
|
+
return dot(color, vec3(1.0)) > 0.00001;
|
|
28
34
|
}
|
|
35
|
+
|
|
36
|
+
// Check if this vertex is highlighted
|
|
29
37
|
bool isVertexHighlighted(vec3 vertexColor) {
|
|
30
|
-
vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
|
|
31
|
-
return
|
|
32
|
-
bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));
|
|
38
|
+
vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
|
|
39
|
+
return
|
|
40
|
+
bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));
|
|
33
41
|
}
|
|
42
|
+
|
|
43
|
+
// Set the current picking color
|
|
34
44
|
void picking_setPickingColor(vec3 pickingColor) {
|
|
35
|
-
pickingColor = picking_normalizeColor(pickingColor);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
picking_vRGBcolor_Avalid.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
pickingColor = picking_normalizeColor(pickingColor);
|
|
46
|
+
|
|
47
|
+
if (bool(picking.isActive)) {
|
|
48
|
+
// Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable
|
|
49
|
+
picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));
|
|
50
|
+
|
|
51
|
+
if (!bool(picking.isAttribute)) {
|
|
52
|
+
// Stores the picking color so that the fragment shader can render it during picking
|
|
53
|
+
picking_vRGBcolor_Avalid.rgb = pickingColor;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
// Do the comparison with selected item color in vertex shader as it should mean fewer compares
|
|
57
|
+
picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));
|
|
58
|
+
}
|
|
44
59
|
}
|
|
60
|
+
|
|
45
61
|
void picking_setPickingAttribute(float value) {
|
|
46
|
-
if (bool(picking.isAttribute)) {
|
|
47
|
-
picking_vRGBcolor_Avalid.r = value;
|
|
48
|
-
}
|
|
62
|
+
if (bool(picking.isAttribute)) {
|
|
63
|
+
picking_vRGBcolor_Avalid.r = value;
|
|
64
|
+
}
|
|
49
65
|
}
|
|
66
|
+
|
|
50
67
|
void picking_setPickingAttribute(vec2 value) {
|
|
51
|
-
if (bool(picking.isAttribute)) {
|
|
52
|
-
picking_vRGBcolor_Avalid.rg = value;
|
|
53
|
-
}
|
|
68
|
+
if (bool(picking.isAttribute)) {
|
|
69
|
+
picking_vRGBcolor_Avalid.rg = value;
|
|
70
|
+
}
|
|
54
71
|
}
|
|
72
|
+
|
|
55
73
|
void picking_setPickingAttribute(vec3 value) {
|
|
56
|
-
if (bool(picking.isAttribute)) {
|
|
57
|
-
picking_vRGBcolor_Avalid.rgb = value;
|
|
58
|
-
}
|
|
74
|
+
if (bool(picking.isAttribute)) {
|
|
75
|
+
picking_vRGBcolor_Avalid.rgb = value;
|
|
76
|
+
}
|
|
59
77
|
}
|
|
60
78
|
`;
|
|
61
|
-
const fs = `\
|
|
79
|
+
const fs = /* glsl */ `\
|
|
62
80
|
uniform pickingUniforms {
|
|
63
|
-
float isActive;
|
|
64
|
-
float isAttribute;
|
|
65
|
-
float isHighlightActive;
|
|
66
|
-
float useFloatColors;
|
|
67
|
-
vec3 highlightedObjectColor;
|
|
68
|
-
vec4 highlightColor;
|
|
81
|
+
float isActive;
|
|
82
|
+
float isAttribute;
|
|
83
|
+
float isHighlightActive;
|
|
84
|
+
float useFloatColors;
|
|
85
|
+
vec3 highlightedObjectColor;
|
|
86
|
+
vec4 highlightColor;
|
|
69
87
|
} picking;
|
|
88
|
+
|
|
70
89
|
in vec4 picking_vRGBcolor_Avalid;
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* Returns highlight color if this item is selected.
|
|
93
|
+
*/
|
|
71
94
|
vec4 picking_filterHighlightColor(vec4 color) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
// If we are still picking, we don't highlight
|
|
96
|
+
if (picking.isActive > 0.5) {
|
|
97
|
+
return color;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
bool selected = bool(picking_vRGBcolor_Avalid.a);
|
|
101
|
+
|
|
102
|
+
if (selected) {
|
|
103
|
+
// Blend in highlight color based on its alpha value
|
|
104
|
+
float highLightAlpha = picking.highlightColor.a;
|
|
105
|
+
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
106
|
+
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
107
|
+
|
|
108
|
+
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
109
|
+
return vec4(blendedRGB, blendedAlpha);
|
|
110
|
+
} else {
|
|
111
|
+
return color;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
* Returns picking color if picking enabled else unmodified argument.
|
|
117
|
+
*/
|
|
86
118
|
vec4 picking_filterPickingColor(vec4 color) {
|
|
87
|
-
if (bool(picking.isActive)) {
|
|
88
|
-
if (picking_vRGBcolor_Avalid.a == 0.0) {
|
|
89
|
-
discard;
|
|
90
|
-
}
|
|
91
|
-
return picking_vRGBcolor_Avalid;
|
|
92
|
-
}
|
|
93
|
-
return color;
|
|
94
|
-
}
|
|
119
|
+
if (bool(picking.isActive)) {
|
|
120
|
+
if (picking_vRGBcolor_Avalid.a == 0.0) {
|
|
121
|
+
discard;
|
|
122
|
+
}
|
|
123
|
+
return picking_vRGBcolor_Avalid;
|
|
124
|
+
}
|
|
125
|
+
return color;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* Returns picking color if picking is enabled if not
|
|
130
|
+
* highlight color if this item is selected, otherwise unmodified argument.
|
|
131
|
+
*/
|
|
95
132
|
vec4 picking_filterColor(vec4 color) {
|
|
96
|
-
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
97
|
-
return picking_filterPickingColor(highlightColor);
|
|
133
|
+
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
134
|
+
return picking_filterPickingColor(highlightColor);
|
|
98
135
|
}
|
|
99
136
|
`;
|
|
100
137
|
/**
|
|
@@ -105,6 +142,8 @@ return picking_filterPickingColor(highlightColor);
|
|
|
105
142
|
* primitives with the same picking color in non-instanced draw-calls
|
|
106
143
|
*/
|
|
107
144
|
export const picking = {
|
|
145
|
+
props: {},
|
|
146
|
+
uniforms: {},
|
|
108
147
|
name: 'picking',
|
|
109
148
|
uniformTypes: {
|
|
110
149
|
isActive: 'f32',
|
|
@@ -124,8 +163,6 @@ export const picking = {
|
|
|
124
163
|
},
|
|
125
164
|
vs,
|
|
126
165
|
fs,
|
|
127
|
-
props: {},
|
|
128
|
-
uniforms: {},
|
|
129
166
|
getUniforms
|
|
130
167
|
};
|
|
131
168
|
function getUniforms(opts = {}, prevUniforms) {
|
|
@@ -31,8 +31,8 @@ export declare const projection: {
|
|
|
31
31
|
readonly cameraPositionWorld: "vec3<f32>";
|
|
32
32
|
};
|
|
33
33
|
readonly getUniforms: typeof getUniforms;
|
|
34
|
-
readonly vs:
|
|
35
|
-
readonly fs:
|
|
34
|
+
readonly vs: "varying vec4 project_vPositionWorld;\nvarying vec3 project_vNormalWorld;\n\n// Project uniform block\nuniform Project {\n mat4 viewMatrix;\n mat4 projectionMatrix;\n mat4 viewProjectionMatrix;\n vec3 cameraPositionWorld;\n} project;\n\nstruct World {\n vec3 position;\n vec3 normal;\n};\n\nWorld world;\n\nvoid project_setPosition(vec4 position) {\n project_vPositionWorld = position;\n}\n\nvoid project_setNormal(vec3 normal) {\n project_vNormalWorld = normal;\n}\n\nvoid project_setPositionAndNormal_World(vec3 position, vec3 normal) {\n world.position = position;\n world.normal = normal;\n}\n\nvoid project_setPositionAndNormal_Model(vec3 position, vec3 normal, mat4 modelMatrix) {\n world.position = (modelMatrix * vec4(position, 1.)).xyz;\n world.normal = mat3(modelMatrix) * normal;\n}\n\nvec4 project_model_to_clipspace(vec4 position) {\n return project.viewProjectionMatrix * position;\n}\n\nvec4 project_model_to_clipspace_Model(vec3 position, mat4 modelMatrix) {\n return project.viewProjectionMatrix * modelMatrix * vec4(position, 1.);\n}\n\nvec4 project_world_to_clipspace(vec3 position) {\n return project.viewProjectionMatrix * vec4(position, 1.);\n}\n\nvec4 project_view_to_clipspace(vec3 position) {\n return project.projectionMatrix * vec4(position, 1.);\n}\n\nvec4 project_to_clipspace(vec3 position) {\n return project.viewProjectionMatrix * vec4(position, 1.);\n}\n";
|
|
35
|
+
readonly fs: "varying vec4 project_vPositionWorld;\nvarying vec3 project_vNormalWorld;\n\nvec4 project_getPosition_World() {\n return project_vPositionWorld;\n}\n\nvec3 project_getNormal_World() {\n return project_vNormalWorld;\n}\n";
|
|
36
36
|
};
|
|
37
37
|
export {};
|
|
38
38
|
//# sourceMappingURL=project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/project/project.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,IAAI,WAAW,EAAE,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/project/project.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,IAAI,WAAW,EAAE,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAK5E;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,CAAC;IAC7C,gBAAgB,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,CAAC;IACnD,mBAAmB,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,CAAC;CACvD,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,CAAC;IAC7C,gBAAgB,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,CAAC;IACnD,oBAAoB,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,CAAC;IACvD,mBAAmB,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,WAAW,CAAC,CAAC;CACvD,CAAC;AASF,iBAAS,WAAW,CAClB,IAAI,GAAE,eAAwC,EAC9C,YAAY,GAAE,kBAAuB,GACpC,kBAAkB,CAuBpB;AAmFD;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;CAY+C,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { Matrix4 } from '@math.gl/core';
|
|
5
|
-
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
6
5
|
const IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
7
6
|
const DEFAULT_MODULE_OPTIONS = {
|
|
8
7
|
viewMatrix: IDENTITY_MATRIX,
|
|
@@ -36,62 +35,77 @@ function getUniforms(opts = DEFAULT_MODULE_OPTIONS, prevUniforms = {}) {
|
|
|
36
35
|
* @note varyings must match vertex shader
|
|
37
36
|
* @note project module uses unprefixed uniforms to match conventions
|
|
38
37
|
*/
|
|
39
|
-
const vs = `\
|
|
38
|
+
const vs = /* glsl */ `\
|
|
40
39
|
varying vec4 project_vPositionWorld;
|
|
41
40
|
varying vec3 project_vNormalWorld;
|
|
41
|
+
|
|
42
|
+
// Project uniform block
|
|
42
43
|
uniform Project {
|
|
43
|
-
mat4 viewMatrix;
|
|
44
|
-
mat4 projectionMatrix;
|
|
45
|
-
mat4 viewProjectionMatrix;
|
|
46
|
-
vec3 cameraPositionWorld;
|
|
44
|
+
mat4 viewMatrix;
|
|
45
|
+
mat4 projectionMatrix;
|
|
46
|
+
mat4 viewProjectionMatrix;
|
|
47
|
+
vec3 cameraPositionWorld;
|
|
47
48
|
} project;
|
|
49
|
+
|
|
48
50
|
struct World {
|
|
49
|
-
vec3 position;
|
|
50
|
-
vec3 normal;
|
|
51
|
+
vec3 position;
|
|
52
|
+
vec3 normal;
|
|
51
53
|
};
|
|
54
|
+
|
|
52
55
|
World world;
|
|
56
|
+
|
|
53
57
|
void project_setPosition(vec4 position) {
|
|
54
|
-
project_vPositionWorld = position;
|
|
58
|
+
project_vPositionWorld = position;
|
|
55
59
|
}
|
|
60
|
+
|
|
56
61
|
void project_setNormal(vec3 normal) {
|
|
57
|
-
project_vNormalWorld = normal;
|
|
62
|
+
project_vNormalWorld = normal;
|
|
58
63
|
}
|
|
64
|
+
|
|
59
65
|
void project_setPositionAndNormal_World(vec3 position, vec3 normal) {
|
|
60
|
-
world.position = position;
|
|
61
|
-
world.normal = normal;
|
|
66
|
+
world.position = position;
|
|
67
|
+
world.normal = normal;
|
|
62
68
|
}
|
|
69
|
+
|
|
63
70
|
void project_setPositionAndNormal_Model(vec3 position, vec3 normal, mat4 modelMatrix) {
|
|
64
|
-
world.position = (modelMatrix * vec4(position, 1.)).xyz;
|
|
65
|
-
world.normal = mat3(modelMatrix) * normal;
|
|
71
|
+
world.position = (modelMatrix * vec4(position, 1.)).xyz;
|
|
72
|
+
world.normal = mat3(modelMatrix) * normal;
|
|
66
73
|
}
|
|
74
|
+
|
|
67
75
|
vec4 project_model_to_clipspace(vec4 position) {
|
|
68
|
-
return project.viewProjectionMatrix * position;
|
|
76
|
+
return project.viewProjectionMatrix * position;
|
|
69
77
|
}
|
|
78
|
+
|
|
70
79
|
vec4 project_model_to_clipspace_Model(vec3 position, mat4 modelMatrix) {
|
|
71
|
-
return project.viewProjectionMatrix * modelMatrix * vec4(position, 1.);
|
|
80
|
+
return project.viewProjectionMatrix * modelMatrix * vec4(position, 1.);
|
|
72
81
|
}
|
|
82
|
+
|
|
73
83
|
vec4 project_world_to_clipspace(vec3 position) {
|
|
74
|
-
return project.viewProjectionMatrix * vec4(position, 1.);
|
|
84
|
+
return project.viewProjectionMatrix * vec4(position, 1.);
|
|
75
85
|
}
|
|
86
|
+
|
|
76
87
|
vec4 project_view_to_clipspace(vec3 position) {
|
|
77
|
-
return project.projectionMatrix * vec4(position, 1.);
|
|
88
|
+
return project.projectionMatrix * vec4(position, 1.);
|
|
78
89
|
}
|
|
90
|
+
|
|
79
91
|
vec4 project_to_clipspace(vec3 position) {
|
|
80
|
-
return project.viewProjectionMatrix * vec4(position, 1.);
|
|
92
|
+
return project.viewProjectionMatrix * vec4(position, 1.);
|
|
81
93
|
}
|
|
82
94
|
`;
|
|
83
95
|
/**
|
|
84
96
|
* Functions to get the position and normal from the vertex shader
|
|
85
97
|
* @note varyings must match vertex shader
|
|
86
98
|
*/
|
|
87
|
-
const fs = `\
|
|
99
|
+
const fs = /* glsl */ `\
|
|
88
100
|
varying vec4 project_vPositionWorld;
|
|
89
101
|
varying vec3 project_vNormalWorld;
|
|
102
|
+
|
|
90
103
|
vec4 project_getPosition_World() {
|
|
91
|
-
return project_vPositionWorld;
|
|
104
|
+
return project_vPositionWorld;
|
|
92
105
|
}
|
|
106
|
+
|
|
93
107
|
vec3 project_getNormal_World() {
|
|
94
|
-
return project_vNormalWorld;
|
|
108
|
+
return project_vNormalWorld;
|
|
95
109
|
}
|
|
96
110
|
`;
|
|
97
111
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/transform/transform.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/transform/transform.ts"],"names":[],"mappings":"AA6CA,gDAAgD;AAChD,eAAO,MAAM,SAAS;;;CAGrB,CAAC"}
|
|
@@ -1,32 +1,44 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
const vs = `\
|
|
4
|
+
const vs = /* glsl */ `\
|
|
6
5
|
attribute float transform_elementID;
|
|
6
|
+
|
|
7
|
+
// returns half of pixel size, used to move the pixel position to center of the pixel.
|
|
7
8
|
vec2 transform_getPixelSizeHalf(vec2 size) {
|
|
8
|
-
return vec2(1.) / (2. * size);
|
|
9
|
+
return vec2(1.) / (2. * size);
|
|
9
10
|
}
|
|
11
|
+
|
|
12
|
+
// returns current elements pixel indeces [x, y],
|
|
13
|
+
// where x ranges in [0 to texSize-1] and y ranges in [0 to texSize-1]
|
|
10
14
|
vec2 transform_getPixelIndices(vec2 texSize, vec2 pixelSizeHalf) {
|
|
11
|
-
|
|
12
|
-
float
|
|
13
|
-
|
|
15
|
+
// Add safe offset (half of pixel height) before doing floor
|
|
16
|
+
float yIndex = floor((transform_elementID / texSize[0]) + pixelSizeHalf[1]);
|
|
17
|
+
float xIndex = transform_elementID - (yIndex * texSize[0]);
|
|
18
|
+
return vec2(xIndex, yIndex);
|
|
14
19
|
}
|
|
20
|
+
|
|
21
|
+
// returns current elementID's texture co-ordianate
|
|
15
22
|
vec2 transform_getTexCoord(vec2 size) {
|
|
16
|
-
vec2 pixelSizeHalf = transform_getPixelSizeHalf(size);
|
|
17
|
-
vec2 indices = transform_getPixelIndices(size, pixelSizeHalf);
|
|
18
|
-
vec2 coord = indices / size + pixelSizeHalf;
|
|
19
|
-
return coord;
|
|
23
|
+
vec2 pixelSizeHalf = transform_getPixelSizeHalf(size);
|
|
24
|
+
vec2 indices = transform_getPixelIndices(size, pixelSizeHalf);
|
|
25
|
+
vec2 coord = indices / size + pixelSizeHalf;
|
|
26
|
+
return coord;
|
|
20
27
|
}
|
|
28
|
+
|
|
29
|
+
// returns current elementID's position
|
|
21
30
|
vec2 transform_getPos(vec2 size) {
|
|
22
|
-
vec2 texCoord = transform_getTexCoord(size);
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
vec2 texCoord = transform_getTexCoord(size);
|
|
32
|
+
// Change from [0 1] range to [-1 1]
|
|
33
|
+
vec2 pos = (texCoord * (2.0, 2.0)) - (1., 1.);
|
|
34
|
+
return pos;
|
|
25
35
|
}
|
|
36
|
+
|
|
37
|
+
// returns current elementID's pixel value
|
|
26
38
|
vec4 transform_getInput(sampler2D texSampler, vec2 size) {
|
|
27
|
-
vec2 texCoord = transform_getTexCoord(size);
|
|
28
|
-
vec4 textureColor = texture2D(texSampler, texCoord);
|
|
29
|
-
return textureColor;
|
|
39
|
+
vec2 texCoord = transform_getTexCoord(size);
|
|
40
|
+
vec4 textureColor = texture2D(texSampler, texCoord);
|
|
41
|
+
return textureColor;
|
|
30
42
|
}
|
|
31
43
|
`;
|
|
32
44
|
/** Private shader module used by `Transform` */
|
|
@@ -8,13 +8,17 @@ export type GouraudMaterialUniforms = {
|
|
|
8
8
|
};
|
|
9
9
|
/** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
|
|
10
10
|
export declare const gouraudMaterial: {
|
|
11
|
+
readonly props: GouraudMaterialProps;
|
|
12
|
+
readonly uniforms: GouraudMaterialUniforms;
|
|
11
13
|
readonly name: "gouraud-lighting";
|
|
12
|
-
readonly vs:
|
|
13
|
-
readonly fs:
|
|
14
|
+
readonly vs: "uniform materialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n";
|
|
15
|
+
readonly fs: "uniform materialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n\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 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 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) {\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n PointLight pointLight = lighting_getPointLight(0);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n } else if (lighting.lightType == 1) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n /*\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.pointLightCount) {\n break;\n }\n PointLight pointLight = lighting.pointLight[i];\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.directionalLightCount) {\n break;\n }\n DirectionalLight directionalLight = lighting.directionalLight[i];\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n */\n }\n return lightColor;\n}\n\nvec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = vec3(0, 0, 0);\n vec3 surfaceColor = vec3(0, 0, 0);\n\n if (lighting.enabled) {\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0:\n PointLight pointLight = lighting_getPointLight(0);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n break;\n\n case 1:\n DirectionalLight directionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n break;\n }\n }\n return lightColor;\n}\n";
|
|
14
16
|
readonly defines: {
|
|
15
17
|
readonly LIGHTING_VERTEX: 1;
|
|
16
18
|
};
|
|
17
19
|
readonly dependencies: [{
|
|
20
|
+
readonly props: import("../lights/lighting").LightingProps;
|
|
21
|
+
readonly uniforms: import("../lights/lighting").LightingUniforms;
|
|
18
22
|
readonly name: "lighting";
|
|
19
23
|
readonly defines: {
|
|
20
24
|
readonly MAX_LIGHTS: 5;
|
|
@@ -39,11 +43,10 @@ export declare const gouraudMaterial: {
|
|
|
39
43
|
readonly lightDirection: readonly [1, 1, 1];
|
|
40
44
|
readonly lightAttenuation: readonly [1, 1, 1];
|
|
41
45
|
};
|
|
42
|
-
readonly
|
|
43
|
-
readonly
|
|
44
|
-
readonly
|
|
45
|
-
readonly
|
|
46
|
-
readonly getUniforms: (props?: import("../lights/lighting").LightingProps | undefined, prevUniforms?: Partial<import("../lights/lighting").LightingUniforms>) => import("../lights/lighting").LightingUniforms;
|
|
46
|
+
readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n poightCount: i32,\n directionalLightCount: i32,\n\n ambientColor: vec3<f32>,\n\n // TODO - support multiple lights by uncommenting arrays below\n lightType: i32,\n lightColor: vec3<f32>,\n lightDirection: vec3<f32>,\n lightPosition: vec3<f32>,\n lightAttenuation: vec3<f32>,\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n";
|
|
47
|
+
readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
48
|
+
readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int pointLightCount;\n int directionalLightCount;\n\n vec3 ambientColor;\n\n int lightType;\n vec3 lightColor;\n vec3 lightDirection;\n vec3 lightPosition;\n vec3 lightAttenuation;\n\n // AmbientLight ambientLight;\n // PointLight pointLight[MAX_LIGHTS];\n // DirectionalLight directionalLight[MAX_LIGHTS];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n return DirectionalLight(lighting.lightColor, lighting.lightDirection);\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
49
|
+
readonly getUniforms: (props?: import("../lights/lighting").LightingProps, prevUniforms?: Partial<import("../lights/lighting").LightingUniforms>) => import("../lights/lighting").LightingUniforms;
|
|
47
50
|
}];
|
|
48
51
|
readonly uniformTypes: {
|
|
49
52
|
readonly ambient: "f32";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAE3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,yIAAyI;AACzI,eAAO,MAAM,eAAe
|
|
1
|
+
{"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAE3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,yIAAyI;AACzI,eAAO,MAAM,eAAe;oBACb,oBAAoB;uBACjB,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAuBpB,oBAAoB,KAAG,uBAAuB;CAGa,CAAC"}
|
|
@@ -5,6 +5,8 @@ import { lighting } from "../lights/lighting.js";
|
|
|
5
5
|
import { GOURAUD_VS, GOURAUD_FS } from "./gouraud-shaders-glsl.js";
|
|
6
6
|
/** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
|
|
7
7
|
export const gouraudMaterial = {
|
|
8
|
+
props: {},
|
|
9
|
+
uniforms: {},
|
|
8
10
|
name: 'gouraud-lighting',
|
|
9
11
|
// Note these are switched between phong and gouraud
|
|
10
12
|
vs: GOURAUD_VS,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const GOURAUD_VS
|
|
2
|
-
export declare const GOURAUD_FS
|
|
1
|
+
export declare const GOURAUD_VS = "uniform materialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n";
|
|
2
|
+
export declare const GOURAUD_FS = "uniform materialUniforms {\n uniform float ambient;\n uniform float diffuse;\n uniform float shininess;\n uniform vec3 specularColor;\n} material;\n\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 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 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) {\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n PointLight pointLight = lighting_getPointLight(0);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n } else if (lighting.lightType == 1) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n /*\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.pointLightCount) {\n break;\n }\n PointLight pointLight = lighting.pointLight[i];\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n\n for (int i = 0; i < MAX_LIGHTS; i++) {\n if (i >= lighting.directionalLightCount) {\n break;\n }\n DirectionalLight directionalLight = lighting.directionalLight[i];\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n */\n }\n return lightColor;\n}\n\nvec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = vec3(0, 0, 0);\n vec3 surfaceColor = vec3(0, 0, 0);\n\n if (lighting.enabled) {\n vec3 view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0:\n PointLight pointLight = lighting_getPointLight(0);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n break;\n\n case 1:\n DirectionalLight directionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n break;\n }\n }\n return lightColor;\n}\n";
|
|
3
3
|
/**
|
|
4
4
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
5
5
|
if (i >= lighting.pointLightCount) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gouraud-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gouraud-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,8JAOtB,CAAC;AAEF,eAAO,MAAM,UAAU,ihHAkFtB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
|