@luma.gl/shadertools 9.1.4 → 9.1.6
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 +5908 -3435
- package/dist/dist.min.js +72 -71
- package/dist/index.cjs +38 -37
- package/dist/index.cjs.map +3 -3
- 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-material.js.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +4 -4
- package/package.json +3 -3
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +2 -0
- package/src/modules/lighting/lights/lighting-uniforms-wgsl.ts +1 -1
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,YAAY,EAAC,oDAAiD;
|
|
1
|
+
{"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAKtE,MAAM,MAAM,oBAAoB,GAAG;IACjC,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,EAAE,YAAY,CAAC,oBAAoB,CAgC9D,CAAC"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { lighting } from "../lights/lighting.js";
|
|
5
5
|
import { PHONG_VS, PHONG_FS } from "../phong-material/phong-shaders-glsl.js";
|
|
6
|
+
import { PHONG_WGSL } from "../phong-material/phong-shaders-wgsl.js";
|
|
6
7
|
/** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
|
|
7
8
|
export const gouraudMaterial = {
|
|
8
9
|
props: {},
|
|
@@ -10,6 +11,7 @@ export const gouraudMaterial = {
|
|
|
10
11
|
// Note these are switched between phong and gouraud
|
|
11
12
|
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
|
|
12
13
|
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
|
|
14
|
+
source: PHONG_WGSL.replaceAll('phongMaterial', 'gouraudMaterial'),
|
|
13
15
|
defines: {
|
|
14
16
|
LIGHTING_VERTEX: 1
|
|
15
17
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gouraud-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,gDAA6C;
|
|
1
|
+
{"version":3,"file":"gouraud-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,gDAA6C;AACxE,OAAO,EAAC,UAAU,EAAC,gDAA6C;AAUhE,yIAAyI;AACzI,MAAM,CAAC,MAAM,eAAe,GAAuC;IACjE,KAAK,EAAE,EAA0B;IAEjC,IAAI,EAAE,iBAAiB;IACvB,oDAAoD;IACpD,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,iBAAiB,CAAC;IACxD,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,iBAAiB,CAAC;IACxD,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAiB,CAAC;IACjE,OAAO,EAAE;QACP,eAAe,EAAE,CAAC;KACnB;IACD,YAAY,EAAE,CAAC,QAAQ,CAAC;IACxB,YAAY,EAAE;QACZ,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,WAAW;KAC3B;IACD,eAAe,EAAE;QACf,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,GAAG;QACZ,SAAS,EAAE,EAAE;QACb,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KAClC;IAED,WAAW,CAAC,KAA2B;QACrC,MAAM,QAAQ,GAAG,EAAC,GAAG,KAAK,EAAC,CAAC;QAC5B,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YAC3B,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAiB,CAAC;QACpF,CAAC;QACD,OAAO,EAAC,GAAG,eAAe,CAAC,eAAe,EAAE,GAAG,QAAQ,EAAC,CAAC;IAC3D,CAAC;CACF,CAAC"}
|
|
@@ -1,2 +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
|
|
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 pointLightCount: 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
2
|
//# sourceMappingURL=lighting-uniforms-wgsl.d.ts.map
|
|
@@ -1 +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,
|
|
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,gjDAoDhC,CAAC"}
|
|
@@ -99,7 +99,7 @@ export declare const lighting: {
|
|
|
99
99
|
readonly lightDirection2: readonly [1, 1, 1];
|
|
100
100
|
readonly lightAttenuation2: readonly [1, 0, 0];
|
|
101
101
|
};
|
|
102
|
-
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
|
|
102
|
+
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 pointLightCount: 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";
|
|
103
103
|
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 lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n default: \n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n }\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";
|
|
104
104
|
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 lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n default: \n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n }\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";
|
|
105
105
|
readonly getUniforms: typeof getUniforms;
|
|
@@ -85,7 +85,7 @@ export declare const pbrMaterial: {
|
|
|
85
85
|
readonly lightDirection2: readonly [1, 1, 1];
|
|
86
86
|
readonly lightAttenuation2: readonly [1, 0, 0];
|
|
87
87
|
};
|
|
88
|
-
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
|
|
88
|
+
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 pointLightCount: 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";
|
|
89
89
|
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 lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n default: \n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n }\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";
|
|
90
90
|
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 lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n default: \n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n }\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";
|
|
91
91
|
readonly getUniforms: (props?: import("../lights/lighting").LightingProps, prevUniforms?: Partial<import("../lights/lighting").LightingUniforms>) => import("../lights/lighting").LightingUniforms;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const PHONG_WGSL = "struct phongMaterialUniforms {\n ambient: f32,\n diffuse: f32,\n shininess: f32,\n specularColor: vec3<f32>,\n};\n\n@binding(2) @group(0) var<uniform>
|
|
1
|
+
export declare const PHONG_WGSL = "struct phongMaterialUniforms {\n ambient: f32,\n diffuse: f32,\n shininess: f32,\n specularColor: vec3<f32>,\n};\n\n@binding(2) @group(0) var<uniform> phongMaterial : phongMaterialUniforms;\n\nfn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {\n let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);\n var lambertian: f32 = dot(light_direction, normal_worldspace);\n var specular: f32 = 0.0;\n if (lambertian > 0.0) {\n let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);\n specular = pow(specular_angle, phongMaterial.shininess);\n }\n lambertian = max(lambertian, 0.0);\n return (lambertian * phongMaterial.diffuse * surfaceColor + specular * phongMaterial.specularColor) * color;\n}\n\nfn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {\n var lightColor: vec3<f32> = surfaceColor;\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);\n lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;\n\n if (lighting.lightType == 0) {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = 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 var directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n \n return lightColor;\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\nfn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{\n var lightColor = vec3<f32>(0, 0, 0);\n let surfaceColor = vec3<f32>(0, 0, 0);\n\n if (lighting.enabled == 0) {\n let view_direction = normalize(cameraPosition - position_worldspace);\n\n switch (lighting.lightType) {\n case 0, default: {\n let pointLight: PointLight = lighting_getPointLight(0);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);\n }\n case 1: {\n let directionalLight: DirectionalLight = lighting_getDirectionalLight(0);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);\n }\n }\n }\n return lightColor;\n}\n";
|
|
2
2
|
/**
|
|
3
3
|
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
4
4
|
if (i >= lighting.pointLightCount) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phong-shaders-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"phong-shaders-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,ywHAsFtB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
|
|
@@ -9,7 +9,7 @@ struct phongMaterialUniforms {
|
|
|
9
9
|
specularColor: vec3<f32>,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
@binding(2) @group(0) var<uniform>
|
|
12
|
+
@binding(2) @group(0) var<uniform> phongMaterial : phongMaterialUniforms;
|
|
13
13
|
|
|
14
14
|
fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
|
|
15
15
|
let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
|
|
@@ -17,10 +17,10 @@ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, v
|
|
|
17
17
|
var specular: f32 = 0.0;
|
|
18
18
|
if (lambertian > 0.0) {
|
|
19
19
|
let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
20
|
-
specular = pow(specular_angle,
|
|
20
|
+
specular = pow(specular_angle, phongMaterial.shininess);
|
|
21
21
|
}
|
|
22
22
|
lambertian = max(lambertian, 0.0);
|
|
23
|
-
return (lambertian *
|
|
23
|
+
return (lambertian * phongMaterial.diffuse * surfaceColor + specular * phongMaterial.specularColor) * color;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
@@ -31,7 +31,7 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
|
|
34
|
-
lightColor =
|
|
34
|
+
lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;
|
|
35
35
|
|
|
36
36
|
if (lighting.lightType == 0) {
|
|
37
37
|
let pointLight: PointLight = lighting_getPointLight(0);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.1.
|
|
3
|
+
"version": "9.1.6",
|
|
4
4
|
"description": "Shader module system for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@math.gl/core": "^4.1.0",
|
|
53
53
|
"@math.gl/types": "^4.1.0",
|
|
54
|
-
"wgsl_reflect": "^1.0
|
|
54
|
+
"wgsl_reflect": "^1.2.0"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "a0c83f5e6bdd9cdf59917ecf01ef958432c42b86"
|
|
57
57
|
}
|
|
@@ -6,6 +6,7 @@ import {NumberArray3} from '@math.gl/types';
|
|
|
6
6
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
7
7
|
import {lighting} from '../lights/lighting';
|
|
8
8
|
import {PHONG_VS, PHONG_FS} from '../phong-material/phong-shaders-glsl';
|
|
9
|
+
import {PHONG_WGSL} from '../phong-material/phong-shaders-wgsl';
|
|
9
10
|
|
|
10
11
|
export type GouraudMaterialProps = {
|
|
11
12
|
ambient?: number;
|
|
@@ -23,6 +24,7 @@ export const gouraudMaterial: ShaderModule<GouraudMaterialProps> = {
|
|
|
23
24
|
// Note these are switched between phong and gouraud
|
|
24
25
|
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
|
|
25
26
|
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
|
|
27
|
+
source: PHONG_WGSL.replaceAll('phongMaterial', 'gouraudMaterial'),
|
|
26
28
|
defines: {
|
|
27
29
|
LIGHTING_VERTEX: 1
|
|
28
30
|
},
|
|
@@ -10,7 +10,7 @@ struct phongMaterialUniforms {
|
|
|
10
10
|
specularColor: vec3<f32>,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
@binding(2) @group(0) var<uniform>
|
|
13
|
+
@binding(2) @group(0) var<uniform> phongMaterial : phongMaterialUniforms;
|
|
14
14
|
|
|
15
15
|
fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, view_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
|
|
16
16
|
let halfway_direction: vec3<f32> = normalize(light_direction + view_direction);
|
|
@@ -18,10 +18,10 @@ fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, v
|
|
|
18
18
|
var specular: f32 = 0.0;
|
|
19
19
|
if (lambertian > 0.0) {
|
|
20
20
|
let specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
21
|
-
specular = pow(specular_angle,
|
|
21
|
+
specular = pow(specular_angle, phongMaterial.shininess);
|
|
22
22
|
}
|
|
23
23
|
lambertian = max(lambertian, 0.0);
|
|
24
|
-
return (lambertian *
|
|
24
|
+
return (lambertian * phongMaterial.diffuse * surfaceColor + specular * phongMaterial.specularColor) * color;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
@@ -32,7 +32,7 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
|
|
35
|
-
lightColor =
|
|
35
|
+
lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;
|
|
36
36
|
|
|
37
37
|
if (lighting.lightType == 0) {
|
|
38
38
|
let pointLight: PointLight = lighting_getPointLight(0);
|