@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,69 +1,95 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
export const GOURAUD_VS = `\
|
|
4
|
+
export const GOURAUD_VS = /* glsl */ `\
|
|
6
5
|
uniform materialUniforms {
|
|
7
|
-
uniform float ambient;
|
|
8
|
-
uniform float diffuse;
|
|
9
|
-
uniform float shininess;
|
|
10
|
-
uniform vec3 specularColor;
|
|
6
|
+
uniform float ambient;
|
|
7
|
+
uniform float diffuse;
|
|
8
|
+
uniform float shininess;
|
|
9
|
+
uniform vec3 specularColor;
|
|
11
10
|
} material;
|
|
12
11
|
`;
|
|
13
|
-
export const GOURAUD_FS = `\
|
|
12
|
+
export const GOURAUD_FS = /* glsl */ `\
|
|
14
13
|
uniform materialUniforms {
|
|
15
|
-
uniform float ambient;
|
|
16
|
-
uniform float diffuse;
|
|
17
|
-
uniform float shininess;
|
|
18
|
-
uniform vec3 specularColor;
|
|
14
|
+
uniform float ambient;
|
|
15
|
+
uniform float diffuse;
|
|
16
|
+
uniform float shininess;
|
|
17
|
+
uniform vec3 specularColor;
|
|
19
18
|
} material;
|
|
19
|
+
|
|
20
20
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
21
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
22
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
23
|
-
float specular = 0.0;
|
|
24
|
-
if (lambertian > 0.0) {
|
|
25
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
26
|
-
specular = pow(specular_angle, material.shininess);
|
|
27
|
-
}
|
|
28
|
-
lambertian = max(lambertian, 0.0);
|
|
29
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
21
|
+
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
22
|
+
float lambertian = dot(light_direction, normal_worldspace);
|
|
23
|
+
float specular = 0.0;
|
|
24
|
+
if (lambertian > 0.0) {
|
|
25
|
+
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
26
|
+
specular = pow(specular_angle, material.shininess);
|
|
27
|
+
}
|
|
28
|
+
lambertian = max(lambertian, 0.0);
|
|
29
|
+
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
30
30
|
}
|
|
31
|
+
|
|
31
32
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
32
|
-
vec3 lightColor = surfaceColor;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
vec3 lightColor = surfaceColor;
|
|
34
|
+
|
|
35
|
+
if (lighting.enabled) {
|
|
36
|
+
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
37
|
+
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
38
|
+
|
|
39
|
+
if (lighting.lightType == 0) {
|
|
40
|
+
PointLight pointLight = lighting_getPointLight(0);
|
|
41
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
42
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
43
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
44
|
+
} else if (lighting.lightType == 1) {
|
|
45
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
46
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
47
|
+
}
|
|
48
|
+
/*
|
|
49
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
50
|
+
if (i >= lighting.pointLightCount) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
PointLight pointLight = lighting.pointLight[i];
|
|
54
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
55
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
56
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
60
|
+
if (i >= lighting.directionalLightCount) {
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
64
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
65
|
+
}
|
|
66
|
+
*/
|
|
67
|
+
}
|
|
68
|
+
return lightColor;
|
|
47
69
|
}
|
|
70
|
+
|
|
48
71
|
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
49
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
50
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
vec3 lightColor = vec3(0, 0, 0);
|
|
73
|
+
vec3 surfaceColor = vec3(0, 0, 0);
|
|
74
|
+
|
|
75
|
+
if (lighting.enabled) {
|
|
76
|
+
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
77
|
+
|
|
78
|
+
switch (lighting.lightType) {
|
|
79
|
+
case 0:
|
|
80
|
+
PointLight pointLight = lighting_getPointLight(0);
|
|
81
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
82
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
83
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
case 1:
|
|
87
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
88
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return lightColor;
|
|
67
93
|
}
|
|
68
94
|
`;
|
|
69
95
|
// TODO - handle multiple lights
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const lightingUniformsGLSL = "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";
|
|
2
2
|
//# sourceMappingURL=lighting-uniforms-glsl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-glsl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"lighting-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,6wCAoDhC,CAAC"}
|
|
@@ -1,41 +1,56 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
export const lightingUniforms = `\
|
|
4
|
+
export const lightingUniformsGLSL = /* glsl */ `\
|
|
6
5
|
precision highp int;
|
|
6
|
+
|
|
7
|
+
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
7
8
|
struct AmbientLight {
|
|
8
|
-
vec3 color;
|
|
9
|
+
vec3 color;
|
|
9
10
|
};
|
|
11
|
+
|
|
10
12
|
struct PointLight {
|
|
11
|
-
vec3 color;
|
|
12
|
-
vec3 position;
|
|
13
|
-
vec3 attenuation;
|
|
13
|
+
vec3 color;
|
|
14
|
+
vec3 position;
|
|
15
|
+
vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential
|
|
14
16
|
};
|
|
17
|
+
|
|
15
18
|
struct DirectionalLight {
|
|
16
|
-
vec3 color;
|
|
17
|
-
vec3 direction;
|
|
19
|
+
vec3 color;
|
|
20
|
+
vec3 direction;
|
|
18
21
|
};
|
|
22
|
+
|
|
19
23
|
uniform lightingUniforms {
|
|
20
|
-
int enabled;
|
|
21
|
-
int pointLightCount;
|
|
22
|
-
int directionalLightCount;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
vec3
|
|
28
|
-
vec3
|
|
24
|
+
int enabled;
|
|
25
|
+
int pointLightCount;
|
|
26
|
+
int directionalLightCount;
|
|
27
|
+
|
|
28
|
+
vec3 ambientColor;
|
|
29
|
+
|
|
30
|
+
int lightType;
|
|
31
|
+
vec3 lightColor;
|
|
32
|
+
vec3 lightDirection;
|
|
33
|
+
vec3 lightPosition;
|
|
34
|
+
vec3 lightAttenuation;
|
|
35
|
+
|
|
36
|
+
// AmbientLight ambientLight;
|
|
37
|
+
// PointLight pointLight[MAX_LIGHTS];
|
|
38
|
+
// DirectionalLight directionalLight[MAX_LIGHTS];
|
|
29
39
|
} lighting;
|
|
40
|
+
|
|
30
41
|
PointLight lighting_getPointLight(int index) {
|
|
31
|
-
return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
|
|
42
|
+
return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
|
|
32
43
|
}
|
|
44
|
+
|
|
33
45
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
34
|
-
return DirectionalLight(lighting.lightColor, lighting.lightDirection);
|
|
35
|
-
}
|
|
46
|
+
return DirectionalLight(lighting.lightColor, lighting.lightDirection);
|
|
47
|
+
}
|
|
48
|
+
|
|
36
49
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
37
|
-
return pointLight.attenuation.x
|
|
38
|
-
+ pointLight.attenuation.y * distance
|
|
39
|
-
+ pointLight.attenuation.z * distance * distance;
|
|
50
|
+
return pointLight.attenuation.x
|
|
51
|
+
+ pointLight.attenuation.y * distance
|
|
52
|
+
+ pointLight.attenuation.z * distance * distance;
|
|
40
53
|
}
|
|
54
|
+
|
|
55
|
+
// #endif
|
|
41
56
|
`;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const lightingUniformsWGSL = "// #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";
|
|
2
|
+
//# sourceMappingURL=lighting-uniforms-wgsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lighting-uniforms-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,4iDAoDhC,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export const lightingUniformsWGSL = /* wgsl */ `\
|
|
5
|
+
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
6
|
+
struct AmbientLight {
|
|
7
|
+
color: vec3<f32>,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
struct PointLight {
|
|
11
|
+
color: vec3<f32>,
|
|
12
|
+
position: vec3<f32>,
|
|
13
|
+
attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
struct DirectionalLight {
|
|
17
|
+
color: vec3<f32>,
|
|
18
|
+
direction: vec3<f32>,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
struct lightingUniforms {
|
|
22
|
+
enabled: i32,
|
|
23
|
+
poightCount: i32,
|
|
24
|
+
directionalLightCount: i32,
|
|
25
|
+
|
|
26
|
+
ambientColor: vec3<f32>,
|
|
27
|
+
|
|
28
|
+
// TODO - support multiple lights by uncommenting arrays below
|
|
29
|
+
lightType: i32,
|
|
30
|
+
lightColor: vec3<f32>,
|
|
31
|
+
lightDirection: vec3<f32>,
|
|
32
|
+
lightPosition: vec3<f32>,
|
|
33
|
+
lightAttenuation: vec3<f32>,
|
|
34
|
+
|
|
35
|
+
// AmbientLight ambientLight;
|
|
36
|
+
// PointLight pointLight[MAX_LIGHTS];
|
|
37
|
+
// DirectionalLight directionalLight[MAX_LIGHTS];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)
|
|
41
|
+
@binding(1) @group(0) var<uniform> lighting : lightingUniforms;
|
|
42
|
+
|
|
43
|
+
fn lighting_getPointLight(index: i32) -> PointLight {
|
|
44
|
+
return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
|
|
48
|
+
return DirectionalLight(lighting.lightColor, lighting.lightDirection);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
52
|
+
return pointLight.attenuation.x
|
|
53
|
+
+ pointLight.attenuation.y * distance
|
|
54
|
+
+ pointLight.attenuation.z * distance * distance;
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
@@ -47,6 +47,8 @@ export type LightingUniforms = {
|
|
|
47
47
|
};
|
|
48
48
|
/** UBO ready lighting module */
|
|
49
49
|
export declare const lighting: {
|
|
50
|
+
readonly props: LightingProps;
|
|
51
|
+
readonly uniforms: LightingUniforms;
|
|
50
52
|
readonly name: "lighting";
|
|
51
53
|
readonly defines: {
|
|
52
54
|
readonly MAX_LIGHTS: 5;
|
|
@@ -71,10 +73,9 @@ export declare const lighting: {
|
|
|
71
73
|
readonly lightDirection: readonly [1, 1, 1];
|
|
72
74
|
readonly lightAttenuation: readonly [1, 1, 1];
|
|
73
75
|
};
|
|
74
|
-
readonly
|
|
75
|
-
readonly
|
|
76
|
-
readonly
|
|
77
|
-
readonly uniforms: LightingUniforms;
|
|
76
|
+
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";
|
|
77
|
+
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";
|
|
78
|
+
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";
|
|
78
79
|
readonly getUniforms: typeof getUniforms;
|
|
79
80
|
};
|
|
80
81
|
declare function getUniforms(props?: LightingProps, prevUniforms?: Partial<LightingUniforms>): LightingUniforms;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAWhD,mCAAmC;AACnC,oBAAY,UAAU;IACpB,KAAK,IAAI;IACT,WAAW,IAAI;CAChB;AAED,4BAA4B;AAE5B,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAEjE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAChC,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAChC,SAAS,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACjC,KAAK,CAAC,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,kBAAkB;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,kBAAkB;IAClB,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,kBAAkB;IAClB,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,iBAAiB,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IAClC,aAAa,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACrC,cAAc,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;IACtC,gBAAgB,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC;CACzC,CAAC;AAEF,gCAAgC;AAChC,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoCgC,CAAC;AAEnE,iBAAS,WAAW,CAClB,KAAK,CAAC,EAAE,aAAa,EACrB,YAAY,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAC3C,gBAAgB,CAoClB"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import {
|
|
4
|
+
import { lightingUniformsGLSL } from "./lighting-uniforms-glsl.js";
|
|
5
|
+
import { lightingUniformsWGSL } from "./lighting-uniforms-wgsl.js";
|
|
5
6
|
/** Max number of supported lights (in addition to ambient light */
|
|
6
7
|
const MAX_LIGHTS = 5;
|
|
7
8
|
/** Whether to divide */
|
|
@@ -14,6 +15,8 @@ export var LIGHT_TYPE;
|
|
|
14
15
|
})(LIGHT_TYPE || (LIGHT_TYPE = {}));
|
|
15
16
|
/** UBO ready lighting module */
|
|
16
17
|
export const lighting = {
|
|
18
|
+
props: {},
|
|
19
|
+
uniforms: {},
|
|
17
20
|
name: 'lighting',
|
|
18
21
|
defines: {
|
|
19
22
|
MAX_LIGHTS
|
|
@@ -40,10 +43,9 @@ export const lighting = {
|
|
|
40
43
|
lightDirection: [1, 1, 1],
|
|
41
44
|
lightAttenuation: [1, 1, 1]
|
|
42
45
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
uniforms: {},
|
|
46
|
+
source: lightingUniformsWGSL,
|
|
47
|
+
vs: lightingUniformsGLSL,
|
|
48
|
+
fs: lightingUniformsGLSL,
|
|
47
49
|
getUniforms
|
|
48
50
|
};
|
|
49
51
|
function getUniforms(props, prevUniforms = {}) {
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Vector3Like, TypedArray } from '@math.gl/core';
|
|
2
2
|
export type DirlightProps = {
|
|
3
|
-
lightDirection?:
|
|
3
|
+
lightDirection?: Vector3Like | TypedArray;
|
|
4
4
|
};
|
|
5
5
|
export type DirlightUniforms = DirlightProps;
|
|
6
|
-
export declare const
|
|
7
|
-
export declare const FS_WGSL = "uniform dirlightUniforms {\n vec3 lightDirection;\n} dirlight;\n\n// Returns color attenuated by angle from light source\nfn dirlight_filterColor(color: vec4<f32>, dirlightInputs): vec4<f32> {\n const d: float = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));\n return vec4<f32>(color.rgb * d, color.a);\n}\n";
|
|
6
|
+
export declare const SOURCE_WGSL = " \nstruct dirlightUniforms {\n lightDirection: vec3<f32>,\n};\n\nalias DirlightNormal = vec3<f32>;\n\nstruct DirlightInputs {\n normal: DirlightNormal,\n};\n\n@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;\n\n// For vertex\nfn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {\n return normalize(normal);\n}\n\n// Returns color attenuated by angle from light source\nfn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {\n // TODO - fix default light direction\n // let lightDirection = dirlight.lightDirection;\n let lightDirection = vec3<f32>(1, 1, 1);\n let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));\n return vec4<f32>(color.rgb * d, color.a);\n}\n";
|
|
8
7
|
/**
|
|
9
8
|
* Cheap lighting - single directional light, single dot product, one uniform
|
|
10
9
|
*/
|
|
11
10
|
export declare const dirlight: {
|
|
11
|
+
readonly props: DirlightProps;
|
|
12
|
+
readonly uniforms: DirlightUniforms;
|
|
12
13
|
readonly name: "dirlight";
|
|
13
14
|
readonly dependencies: [];
|
|
14
|
-
readonly
|
|
15
|
-
readonly
|
|
15
|
+
readonly source: " \nstruct dirlightUniforms {\n lightDirection: vec3<f32>,\n};\n\nalias DirlightNormal = vec3<f32>;\n\nstruct DirlightInputs {\n normal: DirlightNormal,\n};\n\n@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;\n\n// For vertex\nfn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {\n return normalize(normal);\n}\n\n// Returns color attenuated by angle from light source\nfn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {\n // TODO - fix default light direction\n // let lightDirection = dirlight.lightDirection;\n let lightDirection = vec3<f32>(1, 1, 1);\n let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));\n return vec4<f32>(color.rgb * d, color.a);\n}\n";
|
|
16
|
+
readonly vs: "out vec3 dirlight_vNormal;\n\nvoid dirlight_setNormal(vec3 normal) {\n dirlight_vNormal = normalize(normal);\n}\n";
|
|
17
|
+
readonly fs: "uniform dirlightUniforms {\n vec3 lightDirection;\n} dirlight;\n\nin vec3 dirlight_vNormal;\n\n// Returns color attenuated by angle from light source\nvec4 dirlight_filterColor(vec4 color) {\n float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));\n return vec4(color.rgb * d, color.a);\n}\n";
|
|
16
18
|
readonly uniformTypes: {
|
|
17
19
|
readonly lightDirection: "vec3<f32>";
|
|
18
20
|
};
|
|
19
21
|
readonly defaultUniforms: {
|
|
20
22
|
readonly lightDirection: Float32Array;
|
|
21
23
|
};
|
|
22
|
-
readonly props: Required<DirlightProps>;
|
|
23
|
-
readonly uniforms: DirlightProps;
|
|
24
24
|
readonly getUniforms: typeof getUniforms;
|
|
25
25
|
};
|
|
26
26
|
declare function getUniforms(opts?: DirlightProps): DirlightUniforms;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dirlight.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/no-material/dirlight.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"dirlight.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/no-material/dirlight.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAE,UAAU,EAAC,MAAM,eAAe,CAAC;AAG3D,MAAM,MAAM,aAAa,GAAG;IAC1B,cAAc,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC;CAC3C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,aAAa,CAAC;AAG7C,eAAO,MAAM,WAAW,guBA0BvB,CAAC;AAwBF;;GAEG;AACH,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;CAqBgC,CAAC;AAEnE,iBAAS,WAAW,CAAC,IAAI,GAAE,aAAwC,GAAG,gBAAgB,CAOrF"}
|
|
@@ -1,47 +1,63 @@
|
|
|
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
|
// TODO
|
|
6
|
-
export const
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
export const SOURCE_WGSL = /* WGSL */ `\
|
|
6
|
+
struct dirlightUniforms {
|
|
7
|
+
lightDirection: vec3<f32>,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
alias DirlightNormal = vec3<f32>;
|
|
11
|
+
|
|
12
|
+
struct DirlightInputs {
|
|
13
|
+
normal: DirlightNormal,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;
|
|
17
|
+
|
|
18
|
+
// For vertex
|
|
19
|
+
fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {
|
|
20
|
+
return normalize(normal);
|
|
9
21
|
}
|
|
10
|
-
`;
|
|
11
|
-
// TODO
|
|
12
|
-
export const FS_WGSL = /* WGSL */ `\
|
|
13
|
-
uniform dirlightUniforms {
|
|
14
|
-
vec3 lightDirection;
|
|
15
|
-
} dirlight;
|
|
16
22
|
|
|
17
23
|
// Returns color attenuated by angle from light source
|
|
18
|
-
fn dirlight_filterColor(color: vec4<f32>,
|
|
19
|
-
|
|
24
|
+
fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
|
|
25
|
+
// TODO - fix default light direction
|
|
26
|
+
// let lightDirection = dirlight.lightDirection;
|
|
27
|
+
let lightDirection = vec3<f32>(1, 1, 1);
|
|
28
|
+
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
|
|
20
29
|
return vec4<f32>(color.rgb * d, color.a);
|
|
21
30
|
}
|
|
22
31
|
`;
|
|
23
|
-
const VS_GLSL = `\
|
|
32
|
+
const VS_GLSL = /* glsl */ `\
|
|
24
33
|
out vec3 dirlight_vNormal;
|
|
34
|
+
|
|
25
35
|
void dirlight_setNormal(vec3 normal) {
|
|
26
|
-
dirlight_vNormal = normalize(normal);
|
|
36
|
+
dirlight_vNormal = normalize(normal);
|
|
27
37
|
}
|
|
28
38
|
`;
|
|
29
|
-
const FS_GLSL = `\
|
|
39
|
+
const FS_GLSL = /* glsl */ `\
|
|
30
40
|
uniform dirlightUniforms {
|
|
31
|
-
vec3 lightDirection;
|
|
41
|
+
vec3 lightDirection;
|
|
32
42
|
} dirlight;
|
|
43
|
+
|
|
33
44
|
in vec3 dirlight_vNormal;
|
|
45
|
+
|
|
46
|
+
// Returns color attenuated by angle from light source
|
|
34
47
|
vec4 dirlight_filterColor(vec4 color) {
|
|
35
|
-
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
36
|
-
return vec4(color.rgb * d, color.a);
|
|
48
|
+
float d = abs(dot(dirlight_vNormal, normalize(dirlight.lightDirection)));
|
|
49
|
+
return vec4(color.rgb * d, color.a);
|
|
37
50
|
}
|
|
38
51
|
`;
|
|
39
52
|
/**
|
|
40
53
|
* Cheap lighting - single directional light, single dot product, one uniform
|
|
41
54
|
*/
|
|
42
55
|
export const dirlight = {
|
|
56
|
+
props: {},
|
|
57
|
+
uniforms: {},
|
|
43
58
|
name: 'dirlight',
|
|
44
59
|
dependencies: [],
|
|
60
|
+
source: SOURCE_WGSL,
|
|
45
61
|
vs: VS_GLSL,
|
|
46
62
|
fs: FS_GLSL,
|
|
47
63
|
// fragmentInputs: [
|
|
@@ -56,8 +72,6 @@ export const dirlight = {
|
|
|
56
72
|
defaultUniforms: {
|
|
57
73
|
lightDirection: new Float32Array([1, 1, 2])
|
|
58
74
|
},
|
|
59
|
-
props: {},
|
|
60
|
-
uniforms: {},
|
|
61
75
|
getUniforms
|
|
62
76
|
};
|
|
63
77
|
function getUniforms(opts = dirlight.defaultUniforms) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const fs: string;
|
|
1
|
+
export declare const fs = "precision highp float;\n\nuniform Projection {\n // Projection\n uniform vec3 u_Camera;\n};\n\nuniform pbrMaterial {\n // Material is unlit\n bool unlit;\n\n // Base color map\n bool baseColorMapEnabled;\n vec4 baseColorFactor;\n\n bool normalMapEnabled; \n float normalScale; // #ifdef HAS_NORMALMAP\n\n bool emissiveMapEnabled;\n vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP\n\n vec2 metallicRoughnessValues;\n bool metallicRoughnessMapEnabled;\n\n bool occlusionMapEnabled;\n float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP\n \n bool alphaCutoffEnabled;\n float alphaCutoff; // #ifdef ALPHA_CUTOFF\n \n // IBL\n bool IBLenabled;\n vec2 scaleIBLAmbient; // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n vec4 scaleDiffBaseMR;\n vec4 scaleFGDSpec;\n // #endif\n} u_pbrMaterial;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D u_BaseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D u_NormalSampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D u_EmissiveSampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D u_MetallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D u_OcclusionSampler;\n#endif\n#ifdef USE_IBL\nuniform samplerCube u_DiffuseEnvSampler;\nuniform samplerCube u_SpecularEnvSampler;\nuniform sampler2D u_brdfLUT;\n#endif\n\n// Inputs from vertex shader\n\nvarying vec3 pbr_vPosition;\nvarying vec2 pbr_vUV;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvarying mat3 pbr_vTBN;\n#else\nvarying vec3 pbr_vNormal;\n#endif\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n float NdotL; // cos angle between normal and light direction\n float NdotV; // cos angle between normal and view direction\n float NdotH; // cos angle between normal and half vector\n float LdotH; // cos angle between light direction and half vector\n float VdotH; // cos angle between view direction and half vector\n float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)\n float metalness; // metallic value at the surface\n vec3 reflectance0; // full reflectance color (normal incidence angle)\n vec3 reflectance90; // reflectance color at grazing angle\n float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])\n vec3 diffuseColor; // color contribution from diffuse lighting\n vec3 specularColor; // color contribution from specular lighting\n vec3 n; // normal at surface point\n vec3 v; // vector from surface point to camera\n};\n\nconst float M_PI = 3.141592653589793;\nconst float c_MinRoughness = 0.04;\n\nvec4 SRGBtoLINEAR(vec4 srgbIn)\n{\n#ifdef MANUAL_SRGB\n#ifdef SRGB_FAST_APPROXIMATION\n vec3 linOut = pow(srgbIn.xyz,vec3(2.2));\n#else // SRGB_FAST_APPROXIMATION\n vec3 bLess = step(vec3(0.04045),srgbIn.xyz);\n vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );\n#endif //SRGB_FAST_APPROXIMATION\n return vec4(linOut,srgbIn.w);;\n#else //MANUAL_SRGB\n return srgbIn;\n#endif //MANUAL_SRGB\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nvec3 getNormal()\n{\n // Retrieve the tangent space matrix\n#ifndef HAS_TANGENTS\n vec3 pos_dx = dFdx(pbr_vPosition);\n vec3 pos_dy = dFdy(pbr_vPosition);\n vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));\n vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));\n vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);\n\n#ifdef HAS_NORMALS\n vec3 ng = normalize(pbr_vNormal);\n#else\n vec3 ng = cross(pos_dx, pos_dy);\n#endif\n\n t = normalize(t - ng * dot(ng, t));\n vec3 b = normalize(cross(ng, t));\n mat3 tbn = mat3(t, b, ng);\n#else // HAS_TANGENTS\n mat3 tbn = pbr_vTBN;\n#endif\n\n#ifdef HAS_NORMALMAP\n vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;\n n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));\n#else\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n vec3 n = normalize(tbn[2].xyz);\n#endif\n\n return n;\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nvec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)\n{\n float mipCount = 9.0; // resolution of 512x512\n float lod = (pbrInfo.perceptualRoughness * mipCount);\n // retrieve a scale and bias to F0. See [1], Figure 3\n vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,\n vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;\n vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;\n\n#ifdef USE_TEX_LOD\n vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;\n#else\n vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;\n#endif\n\n vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;\n vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);\n\n // For presentation, this allows us to disable IBL terms\n diffuse *= u_pbrMaterial.scaleIBLAmbient.x;\n specular *= u_pbrMaterial.scaleIBLAmbient.y;\n\n return diffuse + specular;\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nvec3 diffuse(PBRInfo pbrInfo)\n{\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nvec3 specularReflection(PBRInfo pbrInfo)\n{\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfloat geometricOcclusion(PBRInfo pbrInfo)\n{\n float NdotL = pbrInfo.NdotL;\n float NdotV = pbrInfo.NdotV;\n float r = pbrInfo.alphaRoughness;\n\n float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfloat microfacetDistribution(PBRInfo pbrInfo)\n{\n float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nvoid PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {\n pbrInfo.NdotL = 1.0;\n pbrInfo.NdotH = 0.0;\n pbrInfo.LdotH = 0.0;\n pbrInfo.VdotH = 1.0;\n}\n\nvoid PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {\n vec3 n = pbrInfo.n;\n vec3 v = pbrInfo.v;\n vec3 l = normalize(lightDirection); // Vector from surface point to light\n vec3 h = normalize(l+v); // Half vector between both l and v\n\n pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);\n pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);\n pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);\n pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);\n}\n\nvoid PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {\n vec3 light_direction = normalize(pointLight.position - pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nvec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {\n // Calculate the shading terms for the microfacet specular shading model\n vec3 F = specularReflection(pbrInfo);\n float G = geometricOcclusion(pbrInfo);\n float D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nvec4 pbr_filterColor(vec4 colorUnused)\n{\n // The albedo may be defined from a base texture or a flat color\n#ifdef HAS_BASECOLORMAP\n vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;\n#else\n vec4 baseColor = u_pbrMaterial.baseColorFactor;\n#endif\n\n#ifdef ALPHA_CUTOFF\n if (baseColor.a < u_pbrMaterial.alphaCutoff) {\n discard;\n }\n#endif\n\n vec3 color = vec3(0, 0, 0);\n\n if(u_pbrMaterial.unlit){\n color.rgb = baseColor.rgb;\n }\n else{\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;\n float metallic = u_pbrMaterial.metallicRoughnessValues.x;\n#ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n#endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n float alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n vec3 f0 = vec3(0.04);\n vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n vec3 specularColor = mix(f0, baseColor.rgb, metallic);\n\n // Compute reflectance.\n float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflecance to 0%.\n float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n vec3 specularEnvironmentR0 = specularColor.rgb;\n vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;\n\n vec3 n = getNormal(); // normal at surface point\n vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera\n\n float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n vec3 reflection = -normalize(reflect(v, n));\n\n PBRInfo pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v\n );\n\n#ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);\n\n // Apply directional light\n for(int i = 0; i < lighting_uDirectionalLightCount; i++) {\n if (i < lighting_uDirectionalLightCount) {\n PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);\n color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);\n }\n }\n\n // Apply point light\n for(int i = 0; i < lighting_uPointLightCount; i++) {\n if (i < lighting_uPointLightCount) {\n PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);\n float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));\n color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);\n }\n }\n#endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n#ifdef USE_IBL\n if (u_pbrMateral.IBLEnabled) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n#endif\n\n // Apply optional PBR terms for additional (optional) shading\n#ifdef HAS_OCCLUSIONMAP\n if (u_pbrMaterial.occlusionMapEnabled) {\n float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;\n color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);\n }\n#endif\n\n#ifdef HAS_EMISSIVEMAP\n if (u_pbrMaterial.emmissiveMapEnabled) {\n vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;\n color += emissive;\n }\n#endif\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n#ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, u_ScaleFGDSpec.x);\n // color = mix(color, vec3(G), u_ScaleFGDSpec.y);\n // color = mix(color, vec3(D), u_ScaleFGDSpec.z);\n // color = mix(color, specContrib, u_ScaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);\n#endif\n\n }\n\n return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);\n}\n";
|
|
2
2
|
//# sourceMappingURL=pbr-fragment-glsl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-fragment-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-fragment-glsl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pbr-fragment-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-fragment-glsl.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,EAAE,o2cAsZd,CAAC"}
|