@luma.gl/shadertools 9.1.0-alpha.10 → 9.1.0-alpha.13
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 +195 -10
- package/dist/dist.min.js +241 -80
- package/dist/index.cjs +196 -10
- package/dist/index.cjs.map +3 -3
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +9 -8
- package/dist/lib/shader-module/shader-module-dependencies.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module-dependencies.js +1 -1
- package/dist/lib/shader-module/shader-module.d.ts +2 -2
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.d.ts +5 -5
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- 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 +1 -1
- 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 +1 -0
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +5 -3
- package/dist/modules/lighting/no-material/dirlight.d.ts +4 -4
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +22 -11
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +1 -0
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.d.ts +2 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +2 -0
- 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/fp64/fp64-utils.d.ts +3 -3
- package/dist/modules/math/fp64/fp64-utils.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +2 -2
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/lib/shader-assembly/assemble-shaders.ts +9 -8
- package/src/lib/shader-module/shader-module-dependencies.ts +1 -2
- package/src/lib/shader-module/shader-module.ts +10 -6
- package/src/modules/engine/picking/picking.ts +5 -5
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +1 -1
- package/src/modules/lighting/lights/lighting-uniforms-wgsl.ts +57 -0
- package/src/modules/lighting/lights/lighting.ts +5 -3
- package/src/modules/lighting/no-material/dirlight.ts +24 -14
- package/src/modules/lighting/phong-material/phong-material.ts +2 -0
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +132 -0
- package/src/modules/math/fp64/fp64-utils.ts +3 -3
- package/src/modules-webgl1/lighting/dirlight/dirlight.ts +2 -2
package/dist/dist.dev.js
CHANGED
|
@@ -683,14 +683,14 @@ ${DECLARATION_INJECT_MARKER}
|
|
|
683
683
|
mainInjections[key] = [injection];
|
|
684
684
|
}
|
|
685
685
|
}
|
|
686
|
-
const modulesToInject =
|
|
686
|
+
const modulesToInject = modules;
|
|
687
687
|
for (const module of modulesToInject) {
|
|
688
688
|
if (log2) {
|
|
689
689
|
checkShaderModuleDeprecations(module, coreSource, log2);
|
|
690
690
|
}
|
|
691
|
-
const moduleSource = getShaderModuleSource(module,
|
|
691
|
+
const moduleSource = getShaderModuleSource(module, "wgsl");
|
|
692
692
|
assembledSource += moduleSource;
|
|
693
|
-
const injections = module.injections[stage];
|
|
693
|
+
const injections = module.injections?.[stage] || {};
|
|
694
694
|
for (const key in injections) {
|
|
695
695
|
const match = /^(v|f)s:#([\w-]+)$/.exec(key);
|
|
696
696
|
if (match) {
|
|
@@ -857,12 +857,16 @@ ${getApplicationDefines(allDefines)}
|
|
|
857
857
|
throw new Error("Shader module must have a name");
|
|
858
858
|
}
|
|
859
859
|
const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, "_");
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
#define MODULE_${moduleName}
|
|
863
|
-
${moduleSource}
|
|
860
|
+
let source = `// ----- MODULE ${module.name} ---------------
|
|
864
861
|
|
|
865
862
|
`;
|
|
863
|
+
if (stage !== "wgsl") {
|
|
864
|
+
source += `#define MODULE_${moduleName}
|
|
865
|
+
`;
|
|
866
|
+
}
|
|
867
|
+
source += `${moduleSource}
|
|
868
|
+
`;
|
|
869
|
+
return source;
|
|
866
870
|
}
|
|
867
871
|
|
|
868
872
|
// src/lib/preprocessor/preprocessor.ts
|
|
@@ -6845,7 +6849,7 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
6845
6849
|
}
|
|
6846
6850
|
|
|
6847
6851
|
// src/modules/lighting/lights/lighting-uniforms-glsl.ts
|
|
6848
|
-
var
|
|
6852
|
+
var lightingUniformsGLSL = (
|
|
6849
6853
|
/* glsl */
|
|
6850
6854
|
`precision highp int;
|
|
6851
6855
|
|
|
@@ -6901,6 +6905,63 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
6901
6905
|
`
|
|
6902
6906
|
);
|
|
6903
6907
|
|
|
6908
|
+
// src/modules/lighting/lights/lighting-uniforms-wgsl.ts
|
|
6909
|
+
var lightingUniformsWGSL = (
|
|
6910
|
+
/* wgsl */
|
|
6911
|
+
`// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
6912
|
+
struct AmbientLight {
|
|
6913
|
+
color: vec3<f32>,
|
|
6914
|
+
};
|
|
6915
|
+
|
|
6916
|
+
struct PointLight {
|
|
6917
|
+
color: vec3<f32>,
|
|
6918
|
+
position: vec3<f32>,
|
|
6919
|
+
attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
|
|
6920
|
+
};
|
|
6921
|
+
|
|
6922
|
+
struct DirectionalLight {
|
|
6923
|
+
color: vec3<f32>,
|
|
6924
|
+
direction: vec3<f32>,
|
|
6925
|
+
};
|
|
6926
|
+
|
|
6927
|
+
struct lightingUniforms {
|
|
6928
|
+
enabled: i32,
|
|
6929
|
+
poightCount: i32,
|
|
6930
|
+
directionalLightCount: i32,
|
|
6931
|
+
|
|
6932
|
+
ambientColor: vec3<f32>,
|
|
6933
|
+
|
|
6934
|
+
// TODO - support multiple lights by uncommenting arrays below
|
|
6935
|
+
lightType: i32,
|
|
6936
|
+
lightColor: vec3<f32>,
|
|
6937
|
+
lightDirection: vec3<f32>,
|
|
6938
|
+
lightPosition: vec3<f32>,
|
|
6939
|
+
lightAttenuation: vec3<f32>,
|
|
6940
|
+
|
|
6941
|
+
// AmbientLight ambientLight;
|
|
6942
|
+
// PointLight pointLight[MAX_LIGHTS];
|
|
6943
|
+
// DirectionalLight directionalLight[MAX_LIGHTS];
|
|
6944
|
+
};
|
|
6945
|
+
|
|
6946
|
+
// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)
|
|
6947
|
+
@binding(1) @group(0) var<uniform> lighting : lightingUniforms;
|
|
6948
|
+
|
|
6949
|
+
fn lighting_getPointLight(index: i32) -> PointLight {
|
|
6950
|
+
return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
|
|
6951
|
+
}
|
|
6952
|
+
|
|
6953
|
+
fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
|
|
6954
|
+
return DirectionalLight(lighting.lightColor, lighting.lightDirection);
|
|
6955
|
+
}
|
|
6956
|
+
|
|
6957
|
+
fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
6958
|
+
return pointLight.attenuation.x
|
|
6959
|
+
+ pointLight.attenuation.y * distance
|
|
6960
|
+
+ pointLight.attenuation.z * distance * distance;
|
|
6961
|
+
}
|
|
6962
|
+
`
|
|
6963
|
+
);
|
|
6964
|
+
|
|
6904
6965
|
// src/modules/lighting/lights/lighting.ts
|
|
6905
6966
|
var MAX_LIGHTS = 5;
|
|
6906
6967
|
var COLOR_FACTOR = 255;
|
|
@@ -6939,8 +7000,9 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
6939
7000
|
lightDirection: [1, 1, 1],
|
|
6940
7001
|
lightAttenuation: [1, 1, 1]
|
|
6941
7002
|
},
|
|
6942
|
-
|
|
6943
|
-
|
|
7003
|
+
source: lightingUniformsWGSL,
|
|
7004
|
+
vs: lightingUniformsGLSL,
|
|
7005
|
+
fs: lightingUniformsGLSL,
|
|
6944
7006
|
getUniforms: getUniforms2
|
|
6945
7007
|
};
|
|
6946
7008
|
function getUniforms2(props, prevUniforms = {}) {
|
|
@@ -7021,6 +7083,36 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
7021
7083
|
}
|
|
7022
7084
|
|
|
7023
7085
|
// src/modules/lighting/no-material/dirlight.ts
|
|
7086
|
+
var SOURCE_WGSL = (
|
|
7087
|
+
/* WGSL */
|
|
7088
|
+
`
|
|
7089
|
+
struct dirlightUniforms {
|
|
7090
|
+
lightDirection: vec3<f32>,
|
|
7091
|
+
};
|
|
7092
|
+
|
|
7093
|
+
alias DirlightNormal = vec3<f32>;
|
|
7094
|
+
|
|
7095
|
+
struct DirlightInputs {
|
|
7096
|
+
normal: DirlightNormal,
|
|
7097
|
+
};
|
|
7098
|
+
|
|
7099
|
+
@binding(1) @group(0) var<uniform> dirlight : dirlightUniforms;
|
|
7100
|
+
|
|
7101
|
+
// For vertex
|
|
7102
|
+
fn dirlight_setNormal(normal: vec3<f32>) -> DirlightNormal {
|
|
7103
|
+
return normalize(normal);
|
|
7104
|
+
}
|
|
7105
|
+
|
|
7106
|
+
// Returns color attenuated by angle from light source
|
|
7107
|
+
fn dirlight_filterColor(color: vec4<f32>, inputs: DirlightInputs) -> vec4<f32> {
|
|
7108
|
+
// TODO - fix default light direction
|
|
7109
|
+
// let lightDirection = dirlight.lightDirection;
|
|
7110
|
+
let lightDirection = vec3<f32>(1, 1, 1);
|
|
7111
|
+
let d: f32 = abs(dot(inputs.normal, normalize(lightDirection)));
|
|
7112
|
+
return vec4<f32>(color.rgb * d, color.a);
|
|
7113
|
+
}
|
|
7114
|
+
`
|
|
7115
|
+
);
|
|
7024
7116
|
var VS_GLSL = (
|
|
7025
7117
|
/* glsl */
|
|
7026
7118
|
`out vec3 dirlight_vNormal;
|
|
@@ -7050,6 +7142,7 @@ vec4 dirlight_filterColor(vec4 color) {
|
|
|
7050
7142
|
uniforms: {},
|
|
7051
7143
|
name: "dirlight",
|
|
7052
7144
|
dependencies: [],
|
|
7145
|
+
source: SOURCE_WGSL,
|
|
7053
7146
|
vs: VS_GLSL,
|
|
7054
7147
|
fs: FS_GLSL,
|
|
7055
7148
|
// fragmentInputs: [
|
|
@@ -7200,6 +7293,97 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
7200
7293
|
}
|
|
7201
7294
|
};
|
|
7202
7295
|
|
|
7296
|
+
// src/modules/lighting/phong-material/phong-shaders-wgsl.ts
|
|
7297
|
+
var PHONG_WGSL = (
|
|
7298
|
+
/* wgsl */
|
|
7299
|
+
`struct phongMaterialUniforms {
|
|
7300
|
+
ambient: f32,
|
|
7301
|
+
diffuse: f32,
|
|
7302
|
+
shininess: f32,
|
|
7303
|
+
specularColor: vec3<f32>,
|
|
7304
|
+
};
|
|
7305
|
+
|
|
7306
|
+
@binding(2) @group(0) var<uniform> material : phongMaterialUniforms;
|
|
7307
|
+
|
|
7308
|
+
fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
|
|
7309
|
+
let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
|
|
7310
|
+
var lambertian: f32 = dot(light_direction, normal_worldspace);
|
|
7311
|
+
var specular: f32 = 0.0;
|
|
7312
|
+
if (lambertian > 0.0) {
|
|
7313
|
+
let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
7314
|
+
specular = pow(specular_angle, material.shininess);
|
|
7315
|
+
}
|
|
7316
|
+
lambertian = max(lambertian, 0.0);
|
|
7317
|
+
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
7318
|
+
}
|
|
7319
|
+
|
|
7320
|
+
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
7321
|
+
var lightColor: vec3<f32> = surfaceColor;
|
|
7322
|
+
|
|
7323
|
+
if (lighting.enabled == 0) {
|
|
7324
|
+
return lightColor;
|
|
7325
|
+
}
|
|
7326
|
+
|
|
7327
|
+
let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
|
|
7328
|
+
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
7329
|
+
|
|
7330
|
+
if (lighting.lightType == 0) {
|
|
7331
|
+
let pointLight: PointLight = lighting_getPointLight(0);
|
|
7332
|
+
let light_position_worldspace: vec3<f32> = pointLight.position;
|
|
7333
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
7334
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
7335
|
+
} else if (lighting.lightType == 1) {
|
|
7336
|
+
var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
|
|
7337
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
7338
|
+
}
|
|
7339
|
+
|
|
7340
|
+
return lightColor;
|
|
7341
|
+
/*
|
|
7342
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
7343
|
+
if (i >= lighting.pointLightCount) {
|
|
7344
|
+
break;
|
|
7345
|
+
}
|
|
7346
|
+
PointLight pointLight = lighting.pointLight[i];
|
|
7347
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
7348
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
7349
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
7350
|
+
}
|
|
7351
|
+
|
|
7352
|
+
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
7353
|
+
if (i >= lighting.directionalLightCount) {
|
|
7354
|
+
break;
|
|
7355
|
+
}
|
|
7356
|
+
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
7357
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
7358
|
+
}
|
|
7359
|
+
*/
|
|
7360
|
+
}
|
|
7361
|
+
|
|
7362
|
+
fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{
|
|
7363
|
+
var lightColor = vec3<f32>(0, 0, 0);
|
|
7364
|
+
let surfaceColor = vec3<f32>(0, 0, 0);
|
|
7365
|
+
|
|
7366
|
+
if (lighting.enabled == 0) {
|
|
7367
|
+
let view_direction = normalize(cameraPosition - position_worldspace);
|
|
7368
|
+
|
|
7369
|
+
switch (lighting.lightType) {
|
|
7370
|
+
case 0, default: {
|
|
7371
|
+
let pointLight: PointLight = lighting_getPointLight(0);
|
|
7372
|
+
let light_position_worldspace: vec3<f32> = pointLight.position;
|
|
7373
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
7374
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
7375
|
+
}
|
|
7376
|
+
case 1: {
|
|
7377
|
+
let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);
|
|
7378
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
7379
|
+
}
|
|
7380
|
+
}
|
|
7381
|
+
}
|
|
7382
|
+
return lightColor;
|
|
7383
|
+
}
|
|
7384
|
+
`
|
|
7385
|
+
);
|
|
7386
|
+
|
|
7203
7387
|
// src/modules/lighting/phong-material/phong-shaders-glsl.ts
|
|
7204
7388
|
var PHONG_VS = (
|
|
7205
7389
|
/* glsl */
|
|
@@ -7307,6 +7491,7 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
7307
7491
|
name: "phong-lighting",
|
|
7308
7492
|
dependencies: [lighting],
|
|
7309
7493
|
// Note these are switched between phong and gouraud
|
|
7494
|
+
source: PHONG_WGSL,
|
|
7310
7495
|
vs: PHONG_VS,
|
|
7311
7496
|
fs: PHONG_FS,
|
|
7312
7497
|
defines: {
|