@luma.gl/shadertools 9.1.0-alpha.15 → 9.1.0-alpha.17
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 +322 -389
- package/dist/dist.min.js +229 -336
- package/dist/index.cjs +321 -391
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/shader-module/shader-module.d.ts +25 -15
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js +18 -4
- package/dist/lib/shader-module/shader-pass.d.ts +4 -2
- package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
- package/dist/lib/utils/uniform-types.d.ts +11 -0
- package/dist/lib/utils/uniform-types.d.ts.map +1 -0
- package/dist/lib/utils/uniform-types.js +1 -0
- package/dist/module-injectors.d.ts +1 -1
- package/dist/module-injectors.d.ts.map +1 -1
- package/dist/module-injectors.js +5 -5
- package/dist/modules/engine/picking/picking.d.ts +7 -7
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +2 -2
- package/dist/modules/engine/project/project.d.ts +9 -8
- package/dist/modules/engine/project/project.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +3 -57
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +9 -6
- 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 +35 -12
- package/dist/modules/lighting/lights/lighting.d.ts +55 -29
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +47 -35
- package/dist/modules/lighting/no-material/dirlight.d.ts +3 -3
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +1 -1
- 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 +56 -60
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +56 -98
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +14 -22
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.js +24 -0
- 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 +8 -16
- package/dist/modules/lighting/phong-material/phong-material.d.ts +5 -59
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +6 -4
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +1 -40
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +8 -87
- package/dist/modules/module-injectors.d.ts +1 -1
- package/dist/modules/module-injectors.d.ts.map +1 -1
- package/dist/modules/module-injectors.js +5 -5
- package/dist/modules-webgl1/project/project.d.ts +6 -4
- package/dist/modules-webgl1/project/project.d.ts.map +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.d.ts +2 -2
- package/dist/passes/postprocessing/fxaa/fxaa.d.ts.map +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.js +2 -2
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +7 -4
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +7 -4
- package/dist/passes/postprocessing/image-adjust-filters/denoise.d.ts +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/denoise.js +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +2 -3
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +2 -3
- package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts +2 -2
- package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/noise.js +2 -6
- package/dist/passes/postprocessing/image-adjust-filters/sepia.d.ts +2 -2
- package/dist/passes/postprocessing/image-adjust-filters/sepia.js +2 -2
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +5 -2
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +5 -2
- package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts +6 -2
- package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/vignette.js +6 -6
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +3 -3
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.js +1 -1
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +2 -2
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.js +1 -1
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +2 -2
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.js +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +3 -3
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.js +2 -2
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +3 -3
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.js +2 -2
- package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +16 -12
- package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/edgework.js +25 -13
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +2 -2
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.js +1 -1
- package/dist/passes/postprocessing/image-fun-filters/ink.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/ink.js +1 -1
- package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +3 -3
- package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/magnify.js +1 -1
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +2 -2
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.js +1 -1
- package/dist/passes/postprocessing/image-warp-filters/swirl.d.ts +1 -1
- package/dist/passes/postprocessing/image-warp-filters/swirl.js +1 -1
- package/package.json +3 -3
- package/src/index.ts +9 -3
- package/src/lib/shader-module/shader-module.ts +51 -21
- package/src/lib/shader-module/shader-pass.ts +7 -4
- package/src/lib/utils/uniform-types.ts +66 -0
- package/src/module-injectors.ts +5 -5
- package/src/modules/engine/picking/README.md +9 -9
- package/src/modules/engine/picking/picking.ts +9 -9
- package/src/modules/engine/project/project.ts +10 -9
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +14 -12
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +35 -12
- package/src/modules/lighting/lights/lighting.ts +84 -54
- package/src/modules/lighting/no-material/dirlight.ts +3 -3
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +56 -60
- package/src/modules/lighting/pbr-material/pbr-material.ts +40 -74
- package/src/modules/lighting/pbr-material/pbr-projection.ts +39 -0
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +8 -16
- package/src/modules/lighting/phong-material/phong-material.ts +12 -12
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -88
- package/src/modules/module-injectors.ts +5 -5
- package/src/modules-webgl1/project/project.ts +8 -7
- package/src/passes/postprocessing/fxaa/fxaa.ts +3 -3
- package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +7 -4
- package/src/passes/postprocessing/image-adjust-filters/denoise.ts +1 -1
- package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +2 -3
- package/src/passes/postprocessing/image-adjust-filters/noise.ts +2 -6
- package/src/passes/postprocessing/image-adjust-filters/sepia.ts +2 -2
- package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +5 -2
- package/src/passes/postprocessing/image-adjust-filters/vignette.ts +6 -6
- package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +3 -3
- package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +2 -2
- package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +2 -2
- package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +3 -3
- package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +3 -3
- package/src/passes/postprocessing/image-fun-filters/edgework.ts +27 -16
- package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +2 -2
- package/src/passes/postprocessing/image-fun-filters/ink.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/magnify.ts +3 -3
- package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +2 -2
- package/src/passes/postprocessing/image-warp-filters/swirl.ts +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +0 -42
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +0 -134
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -137
package/dist/index.cjs
CHANGED
|
@@ -172,20 +172,20 @@ var MODULE_INJECTORS_VS = (
|
|
|
172
172
|
var MODULE_INJECTORS_FS = (
|
|
173
173
|
/* glsl */
|
|
174
174
|
`#ifdef MODULE_MATERIAL
|
|
175
|
-
|
|
175
|
+
fragColor = material_filterColor(fragColor);
|
|
176
176
|
#endif
|
|
177
177
|
|
|
178
178
|
#ifdef MODULE_LIGHTING
|
|
179
|
-
|
|
179
|
+
fragColor = lighting_filterColor(fragColor);
|
|
180
180
|
#endif
|
|
181
181
|
|
|
182
182
|
#ifdef MODULE_FOG
|
|
183
|
-
|
|
183
|
+
fragColor = fog_filterColor(fragColor);
|
|
184
184
|
#endif
|
|
185
185
|
|
|
186
186
|
#ifdef MODULE_PICKING
|
|
187
|
-
|
|
188
|
-
|
|
187
|
+
fragColor = picking_filterHighlightColor(fragColor);
|
|
188
|
+
fragColor = picking_filterPickingColor(fragColor);
|
|
189
189
|
#endif
|
|
190
190
|
|
|
191
191
|
#ifdef MODULE_LOGDEPTH
|
|
@@ -303,7 +303,7 @@ function initializeShaderModule(module2) {
|
|
|
303
303
|
}
|
|
304
304
|
initializeShaderModules(module2.dependencies || []);
|
|
305
305
|
const {
|
|
306
|
-
|
|
306
|
+
propTypes = {},
|
|
307
307
|
deprecations = [],
|
|
308
308
|
// defines = {},
|
|
309
309
|
inject = {}
|
|
@@ -312,29 +312,40 @@ function initializeShaderModule(module2) {
|
|
|
312
312
|
normalizedInjections: normalizeInjections(inject),
|
|
313
313
|
parsedDeprecations: parseDeprecationDefinitions(deprecations)
|
|
314
314
|
};
|
|
315
|
-
if (
|
|
316
|
-
instance.propValidators = makePropValidators(
|
|
315
|
+
if (propTypes) {
|
|
316
|
+
instance.propValidators = makePropValidators(propTypes);
|
|
317
317
|
}
|
|
318
318
|
module2.instance = instance;
|
|
319
|
+
let defaultProps = {};
|
|
320
|
+
if (propTypes) {
|
|
321
|
+
defaultProps = Object.entries(propTypes).reduce((obj, [key, propType]) => {
|
|
322
|
+
const value = propType == null ? void 0 : propType.value;
|
|
323
|
+
if (value) {
|
|
324
|
+
obj[key] = value;
|
|
325
|
+
}
|
|
326
|
+
return obj;
|
|
327
|
+
}, {});
|
|
328
|
+
}
|
|
329
|
+
module2.defaultUniforms = { ...module2.defaultUniforms, ...defaultProps };
|
|
319
330
|
}
|
|
320
331
|
function getShaderModuleUniforms(module2, props, oldUniforms) {
|
|
321
332
|
var _a;
|
|
322
333
|
initializeShaderModule(module2);
|
|
323
334
|
const uniforms = oldUniforms || { ...module2.defaultUniforms };
|
|
324
|
-
if (module2.getUniforms) {
|
|
335
|
+
if (props && module2.getUniforms) {
|
|
325
336
|
return module2.getUniforms(props, uniforms);
|
|
326
337
|
}
|
|
327
338
|
return getValidatedProperties(props, (_a = module2.instance) == null ? void 0 : _a.propValidators, module2.name);
|
|
328
339
|
}
|
|
329
|
-
function checkShaderModuleDeprecations(shaderModule, shaderSource,
|
|
340
|
+
function checkShaderModuleDeprecations(shaderModule, shaderSource, log3) {
|
|
330
341
|
var _a;
|
|
331
342
|
(_a = shaderModule.deprecations) == null ? void 0 : _a.forEach((def) => {
|
|
332
343
|
var _a2;
|
|
333
344
|
if ((_a2 = def.regex) == null ? void 0 : _a2.test(shaderSource)) {
|
|
334
345
|
if (def.deprecated) {
|
|
335
|
-
|
|
346
|
+
log3.deprecated(def.old, def.new)();
|
|
336
347
|
} else {
|
|
337
|
-
|
|
348
|
+
log3.removed(def.old, def.new)();
|
|
338
349
|
}
|
|
339
350
|
}
|
|
340
351
|
});
|
|
@@ -629,7 +640,7 @@ function assembleShaderWGSL(platformInfo, options) {
|
|
|
629
640
|
// defines = {},
|
|
630
641
|
hookFunctions = [],
|
|
631
642
|
inject = {},
|
|
632
|
-
log:
|
|
643
|
+
log: log3
|
|
633
644
|
} = options;
|
|
634
645
|
assert(typeof source2 === "string", "shader source must be a string");
|
|
635
646
|
const coreSource = source2;
|
|
@@ -659,8 +670,8 @@ function assembleShaderWGSL(platformInfo, options) {
|
|
|
659
670
|
}
|
|
660
671
|
const modulesToInject = modules;
|
|
661
672
|
for (const module2 of modulesToInject) {
|
|
662
|
-
if (
|
|
663
|
-
checkShaderModuleDeprecations(module2, coreSource,
|
|
673
|
+
if (log3) {
|
|
674
|
+
checkShaderModuleDeprecations(module2, coreSource, log3);
|
|
664
675
|
}
|
|
665
676
|
const moduleSource = getShaderModuleSource(module2, "wgsl");
|
|
666
677
|
assembledSource += moduleSource;
|
|
@@ -687,7 +698,7 @@ function assembleShaderWGSL(platformInfo, options) {
|
|
|
687
698
|
}
|
|
688
699
|
function assembleShaderGLSL(platformInfo, options) {
|
|
689
700
|
var _a;
|
|
690
|
-
const { id, source: source2, stage, language = "glsl", modules, defines = {}, hookFunctions = [], inject = {}, prologue = true, log:
|
|
701
|
+
const { id, source: source2, stage, language = "glsl", modules, defines = {}, hookFunctions = [], inject = {}, prologue = true, log: log3 } = options;
|
|
691
702
|
assert(typeof source2 === "string", "shader source must be a string");
|
|
692
703
|
const sourceVersion = language === "glsl" ? getShaderInfo(source2).version : -1;
|
|
693
704
|
const targetVersion = platformInfo.shaderLanguageVersion;
|
|
@@ -745,8 +756,8 @@ ${getApplicationDefines(allDefines)}
|
|
|
745
756
|
}
|
|
746
757
|
}
|
|
747
758
|
for (const module2 of modules) {
|
|
748
|
-
if (
|
|
749
|
-
checkShaderModuleDeprecations(module2, coreSource,
|
|
759
|
+
if (log3) {
|
|
760
|
+
checkShaderModuleDeprecations(module2, coreSource, log3);
|
|
750
761
|
}
|
|
751
762
|
const moduleSource = getShaderModuleSource(module2, stage);
|
|
752
763
|
assembledSource += moduleSource;
|
|
@@ -1507,7 +1518,7 @@ var fp32 = {
|
|
|
1507
1518
|
};
|
|
1508
1519
|
|
|
1509
1520
|
// dist/modules/engine/picking/picking.js
|
|
1510
|
-
var DEFAULT_HIGHLIGHT_COLOR =
|
|
1521
|
+
var DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
|
|
1511
1522
|
var vs = (
|
|
1512
1523
|
/* glsl */
|
|
1513
1524
|
`uniform pickingUniforms {
|
|
@@ -1660,7 +1671,7 @@ var picking = {
|
|
|
1660
1671
|
isAttribute: false,
|
|
1661
1672
|
isHighlightActive: false,
|
|
1662
1673
|
useFloatColors: true,
|
|
1663
|
-
highlightedObjectColor:
|
|
1674
|
+
highlightedObjectColor: [0, 0, 0],
|
|
1664
1675
|
highlightColor: DEFAULT_HIGHLIGHT_COLOR
|
|
1665
1676
|
},
|
|
1666
1677
|
vs,
|
|
@@ -1694,6 +1705,9 @@ function getUniforms(opts = {}, prevUniforms) {
|
|
|
1694
1705
|
return uniforms;
|
|
1695
1706
|
}
|
|
1696
1707
|
|
|
1708
|
+
// dist/modules/lighting/lights/lighting.js
|
|
1709
|
+
var import_core3 = require("@luma.gl/core");
|
|
1710
|
+
|
|
1697
1711
|
// dist/modules/lighting/lights/lighting-uniforms-glsl.js
|
|
1698
1712
|
var lightingUniformsGLSL = (
|
|
1699
1713
|
/* glsl */
|
|
@@ -1717,28 +1731,51 @@ struct DirectionalLight {
|
|
|
1717
1731
|
|
|
1718
1732
|
uniform lightingUniforms {
|
|
1719
1733
|
int enabled;
|
|
1720
|
-
int
|
|
1734
|
+
int lightType;
|
|
1735
|
+
|
|
1721
1736
|
int directionalLightCount;
|
|
1737
|
+
int pointLightCount;
|
|
1722
1738
|
|
|
1723
1739
|
vec3 ambientColor;
|
|
1724
1740
|
|
|
1725
|
-
|
|
1726
|
-
vec3
|
|
1727
|
-
vec3
|
|
1728
|
-
vec3
|
|
1729
|
-
vec3 lightAttenuation;
|
|
1741
|
+
vec3 lightColor0;
|
|
1742
|
+
vec3 lightPosition0;
|
|
1743
|
+
vec3 lightDirection0;
|
|
1744
|
+
vec3 lightAttenuation0;
|
|
1730
1745
|
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1746
|
+
vec3 lightColor1;
|
|
1747
|
+
vec3 lightPosition1;
|
|
1748
|
+
vec3 lightDirection1;
|
|
1749
|
+
vec3 lightAttenuation1;
|
|
1750
|
+
|
|
1751
|
+
vec3 lightColor2;
|
|
1752
|
+
vec3 lightPosition2;
|
|
1753
|
+
vec3 lightDirection2;
|
|
1754
|
+
vec3 lightAttenuation2;
|
|
1734
1755
|
} lighting;
|
|
1735
1756
|
|
|
1736
1757
|
PointLight lighting_getPointLight(int index) {
|
|
1737
|
-
|
|
1758
|
+
switch (index) {
|
|
1759
|
+
case 0:
|
|
1760
|
+
return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
|
|
1761
|
+
case 1:
|
|
1762
|
+
return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
|
|
1763
|
+
case 2:
|
|
1764
|
+
default:
|
|
1765
|
+
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
1766
|
+
}
|
|
1738
1767
|
}
|
|
1739
1768
|
|
|
1740
1769
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
1741
|
-
|
|
1770
|
+
switch (index) {
|
|
1771
|
+
case 0:
|
|
1772
|
+
return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
|
|
1773
|
+
case 1:
|
|
1774
|
+
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
1775
|
+
case 2:
|
|
1776
|
+
default:
|
|
1777
|
+
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
1778
|
+
}
|
|
1742
1779
|
}
|
|
1743
1780
|
|
|
1744
1781
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
@@ -1809,7 +1846,7 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
|
1809
1846
|
);
|
|
1810
1847
|
|
|
1811
1848
|
// dist/modules/lighting/lights/lighting.js
|
|
1812
|
-
var MAX_LIGHTS =
|
|
1849
|
+
var MAX_LIGHTS = 3;
|
|
1813
1850
|
var COLOR_FACTOR = 255;
|
|
1814
1851
|
var LIGHT_TYPE;
|
|
1815
1852
|
(function(LIGHT_TYPE2) {
|
|
@@ -1825,31 +1862,44 @@ var lighting = {
|
|
|
1825
1862
|
},
|
|
1826
1863
|
uniformTypes: {
|
|
1827
1864
|
enabled: "i32",
|
|
1828
|
-
ambientLightColor: "vec3<f32>",
|
|
1829
|
-
numberOfLights: "i32",
|
|
1830
|
-
// , array: MAX_LIGHTS,
|
|
1831
1865
|
lightType: "i32",
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1866
|
+
directionalLightCount: "i32",
|
|
1867
|
+
pointLightCount: "i32",
|
|
1868
|
+
ambientLightColor: "vec3<f32>",
|
|
1869
|
+
// TODO define as arrays once we have appropriate uniformTypes
|
|
1870
|
+
lightColor0: "vec3<f32>",
|
|
1871
|
+
lightPosition0: "vec3<f32>",
|
|
1837
1872
|
// TODO - could combine direction and attenuation
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1873
|
+
lightDirection0: "vec3<f32>",
|
|
1874
|
+
lightAttenuation0: "vec3<f32>",
|
|
1875
|
+
lightColor1: "vec3<f32>",
|
|
1876
|
+
lightPosition1: "vec3<f32>",
|
|
1877
|
+
lightDirection1: "vec3<f32>",
|
|
1878
|
+
lightAttenuation1: "vec3<f32>",
|
|
1879
|
+
lightColor2: "vec3<f32>",
|
|
1880
|
+
lightPosition2: "vec3<f32>",
|
|
1881
|
+
lightDirection2: "vec3<f32>",
|
|
1882
|
+
lightAttenuation2: "vec3<f32>"
|
|
1842
1883
|
},
|
|
1843
1884
|
defaultUniforms: {
|
|
1844
1885
|
enabled: 1,
|
|
1845
|
-
ambientLightColor: [0.1, 0.1, 0.1],
|
|
1846
|
-
numberOfLights: 0,
|
|
1847
1886
|
lightType: LIGHT_TYPE.POINT,
|
|
1848
|
-
|
|
1849
|
-
|
|
1887
|
+
directionalLightCount: 0,
|
|
1888
|
+
pointLightCount: 0,
|
|
1889
|
+
ambientLightColor: [0.1, 0.1, 0.1],
|
|
1890
|
+
lightColor0: [1, 1, 1],
|
|
1891
|
+
lightPosition0: [1, 1, 2],
|
|
1850
1892
|
// TODO - could combine direction and attenuation
|
|
1851
|
-
|
|
1852
|
-
|
|
1893
|
+
lightDirection0: [1, 1, 1],
|
|
1894
|
+
lightAttenuation0: [1, 0, 0],
|
|
1895
|
+
lightColor1: [1, 1, 1],
|
|
1896
|
+
lightPosition1: [1, 1, 2],
|
|
1897
|
+
lightDirection1: [1, 1, 1],
|
|
1898
|
+
lightAttenuation1: [1, 0, 0],
|
|
1899
|
+
lightColor2: [1, 1, 1],
|
|
1900
|
+
lightPosition2: [1, 1, 2],
|
|
1901
|
+
lightDirection2: [1, 1, 1],
|
|
1902
|
+
lightAttenuation2: [1, 0, 0]
|
|
1853
1903
|
},
|
|
1854
1904
|
source: lightingUniformsWGSL,
|
|
1855
1905
|
vs: lightingUniformsGLSL,
|
|
@@ -1880,30 +1930,29 @@ function getUniforms2(props, prevUniforms = {}) {
|
|
|
1880
1930
|
return uniforms;
|
|
1881
1931
|
}
|
|
1882
1932
|
function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLights = [] }) {
|
|
1883
|
-
const lightSourceUniforms = {
|
|
1884
|
-
// lightType: new Array(MAX_LIGHTS).fill(0),
|
|
1885
|
-
// lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
1886
|
-
// lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
1887
|
-
// lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
|
|
1888
|
-
// lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
|
|
1889
|
-
};
|
|
1933
|
+
const lightSourceUniforms = {};
|
|
1890
1934
|
lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
|
|
1891
1935
|
let currentLight = 0;
|
|
1892
1936
|
for (const pointLight of pointLights) {
|
|
1893
1937
|
lightSourceUniforms.lightType = LIGHT_TYPE.POINT;
|
|
1894
|
-
|
|
1895
|
-
lightSourceUniforms
|
|
1896
|
-
lightSourceUniforms
|
|
1938
|
+
const i = currentLight;
|
|
1939
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
|
|
1940
|
+
lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
|
|
1941
|
+
lightSourceUniforms[`lightAttenuation${i}`] = pointLight.attenuation || [1, 0, 0];
|
|
1897
1942
|
currentLight++;
|
|
1898
1943
|
}
|
|
1899
1944
|
for (const directionalLight of directionalLights) {
|
|
1900
1945
|
lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;
|
|
1901
|
-
|
|
1902
|
-
lightSourceUniforms
|
|
1903
|
-
lightSourceUniforms
|
|
1946
|
+
const i = currentLight;
|
|
1947
|
+
lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
|
|
1948
|
+
lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
|
|
1904
1949
|
currentLight++;
|
|
1905
1950
|
}
|
|
1906
|
-
|
|
1951
|
+
if (currentLight > MAX_LIGHTS) {
|
|
1952
|
+
import_core3.log.warn("MAX_LIGHTS exceeded")();
|
|
1953
|
+
}
|
|
1954
|
+
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
1955
|
+
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
1907
1956
|
return lightSourceUniforms;
|
|
1908
1957
|
}
|
|
1909
1958
|
function extractLightTypes(lights2) {
|
|
@@ -2003,7 +2052,7 @@ var dirlight = {
|
|
|
2003
2052
|
lightDirection: "vec3<f32>"
|
|
2004
2053
|
},
|
|
2005
2054
|
defaultUniforms: {
|
|
2006
|
-
lightDirection:
|
|
2055
|
+
lightDirection: [1, 1, 2]
|
|
2007
2056
|
},
|
|
2008
2057
|
getUniforms: getUniforms3
|
|
2009
2058
|
};
|
|
@@ -2015,10 +2064,10 @@ function getUniforms3(opts = dirlight.defaultUniforms) {
|
|
|
2015
2064
|
return uniforms;
|
|
2016
2065
|
}
|
|
2017
2066
|
|
|
2018
|
-
// dist/modules/lighting/
|
|
2019
|
-
var
|
|
2067
|
+
// dist/modules/lighting/phong-material/phong-shaders-glsl.js
|
|
2068
|
+
var PHONG_VS = (
|
|
2020
2069
|
/* glsl */
|
|
2021
|
-
`uniform
|
|
2070
|
+
`uniform phongMaterialUniforms {
|
|
2022
2071
|
uniform float ambient;
|
|
2023
2072
|
uniform float diffuse;
|
|
2024
2073
|
uniform float shininess;
|
|
@@ -2026,9 +2075,9 @@ var GOURAUD_VS = (
|
|
|
2026
2075
|
} material;
|
|
2027
2076
|
`
|
|
2028
2077
|
);
|
|
2029
|
-
var
|
|
2078
|
+
var PHONG_FS = (
|
|
2030
2079
|
/* glsl */
|
|
2031
|
-
`uniform
|
|
2080
|
+
`uniform phongMaterialUniforms {
|
|
2032
2081
|
uniform float ambient;
|
|
2033
2082
|
uniform float diffuse;
|
|
2034
2083
|
uniform float shininess;
|
|
@@ -2050,63 +2099,27 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
|
|
|
2050
2099
|
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
2051
2100
|
vec3 lightColor = surfaceColor;
|
|
2052
2101
|
|
|
2053
|
-
if (lighting.enabled) {
|
|
2054
|
-
|
|
2055
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
2056
|
-
|
|
2057
|
-
if (lighting.lightType == 0) {
|
|
2058
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
2059
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
2060
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
2061
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
2062
|
-
} else if (lighting.lightType == 1) {
|
|
2063
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
2064
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
2065
|
-
}
|
|
2066
|
-
/*
|
|
2067
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
2068
|
-
if (i >= lighting.pointLightCount) {
|
|
2069
|
-
break;
|
|
2070
|
-
}
|
|
2071
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
2072
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
2073
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
2074
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
2075
|
-
}
|
|
2076
|
-
|
|
2077
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
2078
|
-
if (i >= lighting.directionalLightCount) {
|
|
2079
|
-
break;
|
|
2080
|
-
}
|
|
2081
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
2082
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
2083
|
-
}
|
|
2084
|
-
*/
|
|
2102
|
+
if (lighting.enabled == 0) {
|
|
2103
|
+
return lightColor;
|
|
2085
2104
|
}
|
|
2086
|
-
return lightColor;
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
2090
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
2091
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
2092
2105
|
|
|
2093
|
-
|
|
2094
|
-
|
|
2106
|
+
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
2107
|
+
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
2095
2108
|
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2109
|
+
for (int i = 0; i < lighting.pointLightCount; i++) {
|
|
2110
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
2111
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
2112
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
2113
|
+
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
|
|
2114
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
|
|
2115
|
+
}
|
|
2103
2116
|
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
}
|
|
2117
|
+
int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
|
|
2118
|
+
for (int i = lighting.pointLightCount; i < totalLights; i++) {
|
|
2119
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(i);
|
|
2120
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
2109
2121
|
}
|
|
2122
|
+
|
|
2110
2123
|
return lightColor;
|
|
2111
2124
|
}
|
|
2112
2125
|
`
|
|
@@ -2115,11 +2128,10 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
|
|
|
2115
2128
|
// dist/modules/lighting/gouraud-material/gouraud-material.js
|
|
2116
2129
|
var gouraudMaterial = {
|
|
2117
2130
|
props: {},
|
|
2118
|
-
|
|
2119
|
-
name: "gouraud-lighting",
|
|
2131
|
+
name: "gouraudMaterial",
|
|
2120
2132
|
// Note these are switched between phong and gouraud
|
|
2121
|
-
vs:
|
|
2122
|
-
fs:
|
|
2133
|
+
vs: PHONG_FS.replace("phongMaterial", "gouraudMaterial"),
|
|
2134
|
+
fs: PHONG_VS.replace("phongMaterial", "gouraudMaterial"),
|
|
2123
2135
|
defines: {
|
|
2124
2136
|
LIGHTING_VERTEX: 1
|
|
2125
2137
|
},
|
|
@@ -2137,7 +2149,11 @@ var gouraudMaterial = {
|
|
|
2137
2149
|
specularColor: [0.15, 0.15, 0.15]
|
|
2138
2150
|
},
|
|
2139
2151
|
getUniforms(props) {
|
|
2140
|
-
|
|
2152
|
+
const uniforms = { ...props };
|
|
2153
|
+
if (uniforms.specularColor) {
|
|
2154
|
+
uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
|
|
2155
|
+
}
|
|
2156
|
+
return { ...gouraudMaterial.defaultUniforms, ...uniforms };
|
|
2141
2157
|
}
|
|
2142
2158
|
};
|
|
2143
2159
|
|
|
@@ -2232,111 +2248,9 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
|
|
|
2232
2248
|
`
|
|
2233
2249
|
);
|
|
2234
2250
|
|
|
2235
|
-
// dist/modules/lighting/phong-material/phong-shaders-glsl.js
|
|
2236
|
-
var PHONG_VS = (
|
|
2237
|
-
/* glsl */
|
|
2238
|
-
`uniform phongMaterialUniforms {
|
|
2239
|
-
uniform float ambient;
|
|
2240
|
-
uniform float diffuse;
|
|
2241
|
-
uniform float shininess;
|
|
2242
|
-
uniform vec3 specularColor;
|
|
2243
|
-
} material;
|
|
2244
|
-
`
|
|
2245
|
-
);
|
|
2246
|
-
var PHONG_FS = (
|
|
2247
|
-
/* glsl */
|
|
2248
|
-
`uniform phongMaterialUniforms {
|
|
2249
|
-
uniform float ambient;
|
|
2250
|
-
uniform float diffuse;
|
|
2251
|
-
uniform float shininess;
|
|
2252
|
-
uniform vec3 specularColor;
|
|
2253
|
-
} material;
|
|
2254
|
-
|
|
2255
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
|
|
2256
|
-
vec3 halfway_direction = normalize(light_direction + view_direction);
|
|
2257
|
-
float lambertian = dot(light_direction, normal_worldspace);
|
|
2258
|
-
float specular = 0.0;
|
|
2259
|
-
if (lambertian > 0.0) {
|
|
2260
|
-
float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
|
|
2261
|
-
specular = pow(specular_angle, material.shininess);
|
|
2262
|
-
}
|
|
2263
|
-
lambertian = max(lambertian, 0.0);
|
|
2264
|
-
return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
|
|
2265
|
-
}
|
|
2266
|
-
|
|
2267
|
-
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
2268
|
-
vec3 lightColor = surfaceColor;
|
|
2269
|
-
|
|
2270
|
-
if (lighting.enabled == 0) {
|
|
2271
|
-
return lightColor;
|
|
2272
|
-
}
|
|
2273
|
-
|
|
2274
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
2275
|
-
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
2276
|
-
|
|
2277
|
-
if (lighting.lightType == 0) {
|
|
2278
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
2279
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
2280
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
2281
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
2282
|
-
} else if (lighting.lightType == 1) {
|
|
2283
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
2284
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
/*
|
|
2288
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
2289
|
-
if (i >= lighting.pointLightCount) {
|
|
2290
|
-
break;
|
|
2291
|
-
}
|
|
2292
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
2293
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
2294
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
2295
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
2296
|
-
}
|
|
2297
|
-
|
|
2298
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
2299
|
-
if (i >= lighting.directionalLightCount) {
|
|
2300
|
-
break;
|
|
2301
|
-
}
|
|
2302
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
2303
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
2304
|
-
}
|
|
2305
|
-
*/
|
|
2306
|
-
return lightColor;
|
|
2307
|
-
}
|
|
2308
|
-
|
|
2309
|
-
vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
2310
|
-
vec3 lightColor = vec3(0, 0, 0);
|
|
2311
|
-
vec3 surfaceColor = vec3(0, 0, 0);
|
|
2312
|
-
|
|
2313
|
-
if (lighting.enabled == 0) {
|
|
2314
|
-
vec3 view_direction = normalize(cameraPosition - position_worldspace);
|
|
2315
|
-
|
|
2316
|
-
switch (lighting.lightType) {
|
|
2317
|
-
case 0:
|
|
2318
|
-
PointLight pointLight = lighting_getPointLight(0);
|
|
2319
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
2320
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
2321
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
2322
|
-
break;
|
|
2323
|
-
|
|
2324
|
-
case 1:
|
|
2325
|
-
DirectionalLight directionalLight = lighting_getDirectionalLight(0);
|
|
2326
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
2327
|
-
break;
|
|
2328
|
-
}
|
|
2329
|
-
}
|
|
2330
|
-
return lightColor;
|
|
2331
|
-
}
|
|
2332
|
-
`
|
|
2333
|
-
);
|
|
2334
|
-
|
|
2335
2251
|
// dist/modules/lighting/phong-material/phong-material.js
|
|
2336
2252
|
var phongMaterial = {
|
|
2337
|
-
|
|
2338
|
-
uniforms: {},
|
|
2339
|
-
name: "phong-lighting",
|
|
2253
|
+
name: "phongMaterial",
|
|
2340
2254
|
dependencies: [lighting],
|
|
2341
2255
|
// Note these are switched between phong and gouraud
|
|
2342
2256
|
source: PHONG_WGSL,
|
|
@@ -2358,45 +2272,41 @@ var phongMaterial = {
|
|
|
2358
2272
|
specularColor: [0.15, 0.15, 0.15]
|
|
2359
2273
|
},
|
|
2360
2274
|
getUniforms(props) {
|
|
2361
|
-
|
|
2275
|
+
const uniforms = { ...props };
|
|
2276
|
+
if (uniforms.specularColor) {
|
|
2277
|
+
uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
|
|
2278
|
+
}
|
|
2279
|
+
return { ...phongMaterial.defaultUniforms, ...uniforms };
|
|
2362
2280
|
}
|
|
2363
2281
|
};
|
|
2364
2282
|
|
|
2365
2283
|
// dist/modules/lighting/pbr-material/pbr-vertex-glsl.js
|
|
2366
2284
|
var vs2 = (
|
|
2367
2285
|
/* glsl */
|
|
2368
|
-
`
|
|
2369
|
-
|
|
2370
|
-
mat4 u_ModelMatrix;
|
|
2371
|
-
mat4 u_NormalMatrix;
|
|
2372
|
-
// Projection
|
|
2373
|
-
vec3 u_Camera;
|
|
2374
|
-
}
|
|
2375
|
-
|
|
2376
|
-
varying vec3 pbr_vPosition;
|
|
2377
|
-
varying vec2 pbr_vUV;
|
|
2286
|
+
`out vec3 pbr_vPosition;
|
|
2287
|
+
out vec2 pbr_vUV;
|
|
2378
2288
|
|
|
2379
2289
|
#ifdef HAS_NORMALS
|
|
2380
2290
|
# ifdef HAS_TANGENTS
|
|
2381
|
-
|
|
2291
|
+
out mat3 pbr_vTBN;
|
|
2382
2292
|
# else
|
|
2383
|
-
|
|
2293
|
+
out vec3 pbr_vNormal;
|
|
2384
2294
|
# endif
|
|
2385
2295
|
#endif
|
|
2386
2296
|
|
|
2387
2297
|
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
2388
2298
|
{
|
|
2389
|
-
vec4 pos =
|
|
2299
|
+
vec4 pos = pbrProjection.modelMatrix * position;
|
|
2390
2300
|
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
2391
2301
|
|
|
2392
2302
|
#ifdef HAS_NORMALS
|
|
2393
2303
|
#ifdef HAS_TANGENTS
|
|
2394
|
-
vec3 normalW = normalize(vec3(
|
|
2395
|
-
vec3 tangentW = normalize(vec3(
|
|
2304
|
+
vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
|
|
2305
|
+
vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
|
|
2396
2306
|
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
2397
2307
|
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
2398
2308
|
#else // HAS_TANGENTS != 1
|
|
2399
|
-
pbr_vNormal = normalize(vec3(
|
|
2309
|
+
pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
|
|
2400
2310
|
#endif
|
|
2401
2311
|
#endif
|
|
2402
2312
|
|
|
@@ -2414,12 +2324,7 @@ var fs3 = (
|
|
|
2414
2324
|
/* glsl */
|
|
2415
2325
|
`precision highp float;
|
|
2416
2326
|
|
|
2417
|
-
uniform
|
|
2418
|
-
// Projection
|
|
2419
|
-
uniform vec3 u_Camera;
|
|
2420
|
-
};
|
|
2421
|
-
|
|
2422
|
-
uniform pbrMaterial {
|
|
2327
|
+
uniform pbrMaterialUniforms {
|
|
2423
2328
|
// Material is unlit
|
|
2424
2329
|
bool unlit;
|
|
2425
2330
|
|
|
@@ -2451,40 +2356,40 @@ uniform pbrMaterial {
|
|
|
2451
2356
|
vec4 scaleDiffBaseMR;
|
|
2452
2357
|
vec4 scaleFGDSpec;
|
|
2453
2358
|
// #endif
|
|
2454
|
-
}
|
|
2359
|
+
} pbrMaterial;
|
|
2455
2360
|
|
|
2456
2361
|
// Samplers
|
|
2457
2362
|
#ifdef HAS_BASECOLORMAP
|
|
2458
|
-
uniform sampler2D
|
|
2363
|
+
uniform sampler2D pbr_baseColorSampler;
|
|
2459
2364
|
#endif
|
|
2460
2365
|
#ifdef HAS_NORMALMAP
|
|
2461
|
-
uniform sampler2D
|
|
2366
|
+
uniform sampler2D pbr_normalSampler;
|
|
2462
2367
|
#endif
|
|
2463
2368
|
#ifdef HAS_EMISSIVEMAP
|
|
2464
|
-
uniform sampler2D
|
|
2369
|
+
uniform sampler2D pbr_emissiveSampler;
|
|
2465
2370
|
#endif
|
|
2466
2371
|
#ifdef HAS_METALROUGHNESSMAP
|
|
2467
|
-
uniform sampler2D
|
|
2372
|
+
uniform sampler2D pbr_metallicRoughnessSampler;
|
|
2468
2373
|
#endif
|
|
2469
2374
|
#ifdef HAS_OCCLUSIONMAP
|
|
2470
|
-
uniform sampler2D
|
|
2375
|
+
uniform sampler2D pbr_occlusionSampler;
|
|
2471
2376
|
#endif
|
|
2472
2377
|
#ifdef USE_IBL
|
|
2473
|
-
uniform samplerCube
|
|
2474
|
-
uniform samplerCube
|
|
2475
|
-
uniform sampler2D
|
|
2378
|
+
uniform samplerCube pbr_diffuseEnvSampler;
|
|
2379
|
+
uniform samplerCube pbr_specularEnvSampler;
|
|
2380
|
+
uniform sampler2D pbr_brdfLUT;
|
|
2476
2381
|
#endif
|
|
2477
2382
|
|
|
2478
2383
|
// Inputs from vertex shader
|
|
2479
2384
|
|
|
2480
|
-
|
|
2481
|
-
|
|
2385
|
+
in vec3 pbr_vPosition;
|
|
2386
|
+
in vec2 pbr_vUV;
|
|
2482
2387
|
|
|
2483
2388
|
#ifdef HAS_NORMALS
|
|
2484
2389
|
#ifdef HAS_TANGENTS
|
|
2485
|
-
|
|
2390
|
+
in mat3 pbr_vTBN;
|
|
2486
2391
|
#else
|
|
2487
|
-
|
|
2392
|
+
in vec3 pbr_vNormal;
|
|
2488
2393
|
#endif
|
|
2489
2394
|
#endif
|
|
2490
2395
|
|
|
@@ -2552,8 +2457,8 @@ vec3 getNormal()
|
|
|
2552
2457
|
#endif
|
|
2553
2458
|
|
|
2554
2459
|
#ifdef HAS_NORMALMAP
|
|
2555
|
-
vec3 n =
|
|
2556
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(
|
|
2460
|
+
vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
|
|
2461
|
+
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
2557
2462
|
#else
|
|
2558
2463
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
2559
2464
|
vec3 n = normalize(tbn[2].xyz);
|
|
@@ -2571,22 +2476,22 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
|
|
|
2571
2476
|
float mipCount = 9.0; // resolution of 512x512
|
|
2572
2477
|
float lod = (pbrInfo.perceptualRoughness * mipCount);
|
|
2573
2478
|
// retrieve a scale and bias to F0. See [1], Figure 3
|
|
2574
|
-
vec3 brdf = SRGBtoLINEAR(
|
|
2479
|
+
vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
|
|
2575
2480
|
vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
|
|
2576
|
-
vec3 diffuseLight = SRGBtoLINEAR(
|
|
2481
|
+
vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
|
|
2577
2482
|
|
|
2578
2483
|
#ifdef USE_TEX_LOD
|
|
2579
|
-
vec3 specularLight = SRGBtoLINEAR(
|
|
2484
|
+
vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
|
|
2580
2485
|
#else
|
|
2581
|
-
vec3 specularLight = SRGBtoLINEAR(
|
|
2486
|
+
vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
|
|
2582
2487
|
#endif
|
|
2583
2488
|
|
|
2584
2489
|
vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
|
|
2585
2490
|
vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
|
|
2586
2491
|
|
|
2587
2492
|
// For presentation, this allows us to disable IBL terms
|
|
2588
|
-
diffuse *=
|
|
2589
|
-
specular *=
|
|
2493
|
+
diffuse *= pbrMaterial.scaleIBLAmbient.x;
|
|
2494
|
+
specular *= pbrMaterial.scaleIBLAmbient.y;
|
|
2590
2495
|
|
|
2591
2496
|
return diffuse + specular;
|
|
2592
2497
|
}
|
|
@@ -2678,32 +2583,32 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2678
2583
|
{
|
|
2679
2584
|
// The albedo may be defined from a base texture or a flat color
|
|
2680
2585
|
#ifdef HAS_BASECOLORMAP
|
|
2681
|
-
vec4 baseColor = SRGBtoLINEAR(
|
|
2586
|
+
vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
|
|
2682
2587
|
#else
|
|
2683
|
-
vec4 baseColor =
|
|
2588
|
+
vec4 baseColor = pbrMaterial.baseColorFactor;
|
|
2684
2589
|
#endif
|
|
2685
2590
|
|
|
2686
2591
|
#ifdef ALPHA_CUTOFF
|
|
2687
|
-
if (baseColor.a <
|
|
2592
|
+
if (baseColor.a < pbrMaterial.alphaCutoff) {
|
|
2688
2593
|
discard;
|
|
2689
2594
|
}
|
|
2690
2595
|
#endif
|
|
2691
2596
|
|
|
2692
2597
|
vec3 color = vec3(0, 0, 0);
|
|
2693
2598
|
|
|
2694
|
-
if(
|
|
2599
|
+
if(pbrMaterial.unlit){
|
|
2695
2600
|
color.rgb = baseColor.rgb;
|
|
2696
2601
|
}
|
|
2697
2602
|
else{
|
|
2698
2603
|
// Metallic and Roughness material properties are packed together
|
|
2699
2604
|
// In glTF, these factors can be specified by fixed scalar values
|
|
2700
2605
|
// or from a metallic-roughness map
|
|
2701
|
-
float perceptualRoughness =
|
|
2702
|
-
float metallic =
|
|
2606
|
+
float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
|
|
2607
|
+
float metallic = pbrMaterial.metallicRoughnessValues.x;
|
|
2703
2608
|
#ifdef HAS_METALROUGHNESSMAP
|
|
2704
2609
|
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
2705
2610
|
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
2706
|
-
vec4 mrSample =
|
|
2611
|
+
vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
|
|
2707
2612
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
2708
2613
|
metallic = mrSample.b * metallic;
|
|
2709
2614
|
#endif
|
|
@@ -2730,7 +2635,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2730
2635
|
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
2731
2636
|
|
|
2732
2637
|
vec3 n = getNormal(); // normal at surface point
|
|
2733
|
-
vec3 v = normalize(
|
|
2638
|
+
vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
|
|
2734
2639
|
|
|
2735
2640
|
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
2736
2641
|
vec3 reflection = -normalize(reflect(v, n));
|
|
@@ -2752,47 +2657,48 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2752
2657
|
v
|
|
2753
2658
|
);
|
|
2754
2659
|
|
|
2660
|
+
|
|
2755
2661
|
#ifdef USE_LIGHTS
|
|
2756
2662
|
// Apply ambient light
|
|
2757
2663
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
2758
|
-
color += calculateFinalColor(pbrInfo,
|
|
2664
|
+
color += calculateFinalColor(pbrInfo, lighting.ambientColor);
|
|
2759
2665
|
|
|
2760
2666
|
// Apply directional light
|
|
2761
|
-
for(int i = 0; i <
|
|
2762
|
-
if (i <
|
|
2763
|
-
PBRInfo_setDirectionalLight(pbrInfo,
|
|
2764
|
-
color += calculateFinalColor(pbrInfo,
|
|
2667
|
+
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
2668
|
+
if (i < lighting.directionalLightCount) {
|
|
2669
|
+
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
2670
|
+
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
2765
2671
|
}
|
|
2766
2672
|
}
|
|
2767
2673
|
|
|
2768
2674
|
// Apply point light
|
|
2769
|
-
for(int i = 0; i <
|
|
2770
|
-
if (i <
|
|
2771
|
-
PBRInfo_setPointLight(pbrInfo,
|
|
2772
|
-
float attenuation = getPointLightAttenuation(
|
|
2773
|
-
color += calculateFinalColor(pbrInfo,
|
|
2675
|
+
for(int i = 0; i < lighting.pointLightCount; i++) {
|
|
2676
|
+
if (i < lighting.pointLightCount) {
|
|
2677
|
+
PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
|
|
2678
|
+
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
2679
|
+
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
2774
2680
|
}
|
|
2775
2681
|
}
|
|
2776
2682
|
#endif
|
|
2777
2683
|
|
|
2778
2684
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
2779
2685
|
#ifdef USE_IBL
|
|
2780
|
-
if (
|
|
2686
|
+
if (pbrMaterial.IBLenabled) {
|
|
2781
2687
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
2782
2688
|
}
|
|
2783
2689
|
#endif
|
|
2784
2690
|
|
|
2785
|
-
|
|
2691
|
+
// Apply optional PBR terms for additional (optional) shading
|
|
2786
2692
|
#ifdef HAS_OCCLUSIONMAP
|
|
2787
|
-
if (
|
|
2788
|
-
float ao =
|
|
2789
|
-
color = mix(color, color * ao,
|
|
2693
|
+
if (pbrMaterial.occlusionMapEnabled) {
|
|
2694
|
+
float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
|
|
2695
|
+
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
2790
2696
|
}
|
|
2791
2697
|
#endif
|
|
2792
2698
|
|
|
2793
2699
|
#ifdef HAS_EMISSIVEMAP
|
|
2794
|
-
if (
|
|
2795
|
-
vec3 emissive = SRGBtoLINEAR(
|
|
2700
|
+
if (pbrMaterial.emissiveMapEnabled) {
|
|
2701
|
+
vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
|
|
2796
2702
|
color += emissive;
|
|
2797
2703
|
}
|
|
2798
2704
|
#endif
|
|
@@ -2802,15 +2708,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2802
2708
|
#ifdef PBR_DEBUG
|
|
2803
2709
|
// TODO: Figure out how to debug multiple lights
|
|
2804
2710
|
|
|
2805
|
-
// color = mix(color, F,
|
|
2806
|
-
// color = mix(color, vec3(G),
|
|
2807
|
-
// color = mix(color, vec3(D),
|
|
2808
|
-
// color = mix(color, specContrib,
|
|
2711
|
+
// color = mix(color, F, pbr_scaleFGDSpec.x);
|
|
2712
|
+
// color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
|
|
2713
|
+
// color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
|
|
2714
|
+
// color = mix(color, specContrib, pbr_scaleFGDSpec.w);
|
|
2809
2715
|
|
|
2810
|
-
// color = mix(color, diffuseContrib,
|
|
2811
|
-
color = mix(color, baseColor.rgb,
|
|
2812
|
-
color = mix(color, vec3(metallic),
|
|
2813
|
-
color = mix(color, vec3(perceptualRoughness),
|
|
2716
|
+
// color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
|
|
2717
|
+
color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
|
|
2718
|
+
color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
|
|
2719
|
+
color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
|
|
2814
2720
|
#endif
|
|
2815
2721
|
|
|
2816
2722
|
}
|
|
@@ -2820,25 +2726,52 @@ vec4 pbr_filterColor(vec4 colorUnused)
|
|
|
2820
2726
|
`
|
|
2821
2727
|
);
|
|
2822
2728
|
|
|
2729
|
+
// dist/modules/lighting/pbr-material/pbr-projection.js
|
|
2730
|
+
var uniformBlock = (
|
|
2731
|
+
/* glsl */
|
|
2732
|
+
`uniform pbrProjectionUniforms {
|
|
2733
|
+
mat4 modelViewProjectionMatrix;
|
|
2734
|
+
mat4 modelMatrix;
|
|
2735
|
+
mat4 normalMatrix;
|
|
2736
|
+
vec3 camera;
|
|
2737
|
+
} pbrProjection;
|
|
2738
|
+
`
|
|
2739
|
+
);
|
|
2740
|
+
var pbrProjection = {
|
|
2741
|
+
name: "pbrProjection",
|
|
2742
|
+
vs: uniformBlock,
|
|
2743
|
+
fs: uniformBlock,
|
|
2744
|
+
// TODO why is this needed?
|
|
2745
|
+
getUniforms: (props) => props,
|
|
2746
|
+
uniformTypes: {
|
|
2747
|
+
modelViewProjectionMatrix: "mat4x4<f32>",
|
|
2748
|
+
modelMatrix: "mat4x4<f32>",
|
|
2749
|
+
normalMatrix: "mat4x4<f32>",
|
|
2750
|
+
camera: "vec3<i32>"
|
|
2751
|
+
}
|
|
2752
|
+
};
|
|
2753
|
+
|
|
2823
2754
|
// dist/modules/lighting/pbr-material/pbr-material.js
|
|
2824
2755
|
var pbrMaterial = {
|
|
2825
2756
|
props: {},
|
|
2826
2757
|
uniforms: {},
|
|
2827
|
-
name: "
|
|
2828
|
-
dependencies: [lighting],
|
|
2758
|
+
name: "pbrMaterial",
|
|
2759
|
+
dependencies: [lighting, pbrProjection],
|
|
2829
2760
|
vs: vs2,
|
|
2830
2761
|
fs: fs3,
|
|
2831
2762
|
defines: {
|
|
2832
|
-
LIGHTING_FRAGMENT: 1
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2763
|
+
LIGHTING_FRAGMENT: 1
|
|
2764
|
+
// TODO defining these as 0 breaks shader
|
|
2765
|
+
// HAS_NORMALMAP: 0
|
|
2766
|
+
// HAS_EMISSIVEMAP: 0,
|
|
2767
|
+
// HAS_OCCLUSIONMAP: 0,
|
|
2768
|
+
// HAS_BASECOLORMAP: 0,
|
|
2769
|
+
// HAS_METALROUGHNESSMAP: 0,
|
|
2770
|
+
// ALPHA_CUTOFF: 0
|
|
2771
|
+
// USE_IBL: 0
|
|
2772
|
+
// PBR_DEBUG: 0
|
|
2841
2773
|
},
|
|
2774
|
+
getUniforms: (props) => props,
|
|
2842
2775
|
uniformTypes: {
|
|
2843
2776
|
// Material is unlit
|
|
2844
2777
|
unlit: "i32",
|
|
@@ -2867,25 +2800,6 @@ var pbrMaterial = {
|
|
|
2867
2800
|
// #ifdef PBR_DEBUG
|
|
2868
2801
|
scaleDiffBaseMR: "vec4<f32>",
|
|
2869
2802
|
scaleFGDSpec: "vec4<f32>"
|
|
2870
|
-
},
|
|
2871
|
-
bindings: {
|
|
2872
|
-
baseColorSampler: { type: "texture", location: 8 },
|
|
2873
|
-
// #ifdef HAS_BASECOLORMAP
|
|
2874
|
-
normalSampler: { type: "texture", location: 9 },
|
|
2875
|
-
// #ifdef HAS_NORMALMAP
|
|
2876
|
-
emissiveSampler: { type: "texture", location: 10 },
|
|
2877
|
-
// #ifdef HAS_EMISSIVEMAP
|
|
2878
|
-
metallicRoughnessSampler: { type: "texture", location: 11 },
|
|
2879
|
-
// #ifdef HAS_METALROUGHNESSMAP
|
|
2880
|
-
occlusionSampler: { type: "texture", location: 12 },
|
|
2881
|
-
// #ifdef HAS_OCCLUSIONMAP
|
|
2882
|
-
// IBL Samplers
|
|
2883
|
-
diffuseEnvSampler: { type: "texture", location: 13 },
|
|
2884
|
-
// #ifdef USE_IBL (samplerCube)
|
|
2885
|
-
specularEnvSampler: { type: "texture", location: 14 },
|
|
2886
|
-
// #ifdef USE_IBL (samplerCube)
|
|
2887
|
-
brdfLUT: { type: "texture", location: 15 }
|
|
2888
|
-
// #ifdef USE_IBL
|
|
2889
2803
|
}
|
|
2890
2804
|
};
|
|
2891
2805
|
|
|
@@ -2900,7 +2814,7 @@ var source = (
|
|
|
2900
2814
|
// Binding 0:1 is reserved for shader passes
|
|
2901
2815
|
@binding(1) @group(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
|
|
2902
2816
|
|
|
2903
|
-
fn
|
|
2817
|
+
fn brightnessContrast_filterColor_ext(color: vec4<f32>, texSize: vec2<f32>, texCoords: vec2<f32>) -> vec4<f32> {
|
|
2904
2818
|
color.rgb += brightnessContrast.brightness;
|
|
2905
2819
|
if (brightnessContrast.contrast > 0.0) {
|
|
2906
2820
|
color.rgb = (color.rgb - 0.5) / (1.0 - brightnessContrast.contrast) + 0.5;
|
|
@@ -2928,20 +2842,23 @@ vec4 brightnessContrast_filterColor(vec4 color) {
|
|
|
2928
2842
|
return color;
|
|
2929
2843
|
}
|
|
2930
2844
|
|
|
2931
|
-
vec4
|
|
2845
|
+
vec4 brightnessContrast_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
2932
2846
|
return brightnessContrast_filterColor(color);
|
|
2933
2847
|
}
|
|
2934
2848
|
`
|
|
2935
2849
|
);
|
|
2936
2850
|
var brightnessContrast = {
|
|
2937
2851
|
props: {},
|
|
2938
|
-
uniforms: {},
|
|
2939
2852
|
name: "brightnessContrast",
|
|
2940
2853
|
uniformTypes: {
|
|
2941
2854
|
brightness: "f32",
|
|
2942
2855
|
contrast: "f32"
|
|
2943
2856
|
},
|
|
2944
|
-
|
|
2857
|
+
defaultUniforms: {
|
|
2858
|
+
brightness: 0,
|
|
2859
|
+
contrast: 0
|
|
2860
|
+
},
|
|
2861
|
+
propTypes: {
|
|
2945
2862
|
brightness: { format: "f32", value: 0, min: -1, max: 1 },
|
|
2946
2863
|
contrast: { format: "f32", value: 0, min: -1, max: 1 }
|
|
2947
2864
|
},
|
|
@@ -2984,7 +2901,7 @@ var denoise = {
|
|
|
2984
2901
|
uniformTypes: {
|
|
2985
2902
|
strength: "f32"
|
|
2986
2903
|
},
|
|
2987
|
-
|
|
2904
|
+
propTypes: {
|
|
2988
2905
|
strength: { format: "f32", value: 0.5, min: 0, max: 1 }
|
|
2989
2906
|
// strength: {..., adjust: (strength: number): number => 0.53 + 200 * Math.pow(1 - strength, 4) // TODO - JS preprocessing
|
|
2990
2907
|
},
|
|
@@ -3023,21 +2940,20 @@ vec4 hueSaturation_filterColor(vec4 color) {
|
|
|
3023
2940
|
return color;
|
|
3024
2941
|
}
|
|
3025
2942
|
|
|
3026
|
-
vec4
|
|
2943
|
+
vec4 hueSaturation_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3027
2944
|
return hueSaturation_filterColor(color);
|
|
3028
2945
|
}
|
|
3029
2946
|
`
|
|
3030
2947
|
);
|
|
3031
2948
|
var hueSaturation = {
|
|
3032
2949
|
props: {},
|
|
3033
|
-
uniforms: {},
|
|
3034
2950
|
name: "hueSaturation",
|
|
3035
2951
|
fs: fs6,
|
|
3036
2952
|
uniformTypes: {
|
|
3037
2953
|
hue: "f32",
|
|
3038
2954
|
saturation: "f32"
|
|
3039
2955
|
},
|
|
3040
|
-
|
|
2956
|
+
propTypes: {
|
|
3041
2957
|
hue: { value: 0, min: -1, max: 1 },
|
|
3042
2958
|
saturation: { value: 0, min: -1, max: 1 }
|
|
3043
2959
|
},
|
|
@@ -3055,17 +2971,13 @@ float rand(vec2 co) {
|
|
|
3055
2971
|
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
|
|
3056
2972
|
}
|
|
3057
2973
|
|
|
3058
|
-
vec4
|
|
2974
|
+
vec4 noise_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3059
2975
|
float diff = (rand(texCoord) - 0.5) * noise.amount;
|
|
3060
2976
|
color.r += diff;
|
|
3061
2977
|
color.g += diff;
|
|
3062
2978
|
color.b += diff;
|
|
3063
2979
|
return color;
|
|
3064
2980
|
}
|
|
3065
|
-
|
|
3066
|
-
vec4 noise_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3067
|
-
return noise_filterColor(color, texCoord);
|
|
3068
|
-
}
|
|
3069
2981
|
`
|
|
3070
2982
|
);
|
|
3071
2983
|
var noise = {
|
|
@@ -3075,7 +2987,7 @@ var noise = {
|
|
|
3075
2987
|
uniformTypes: {
|
|
3076
2988
|
amount: "f32"
|
|
3077
2989
|
},
|
|
3078
|
-
|
|
2990
|
+
propTypes: {
|
|
3079
2991
|
amount: { value: 0.5, min: 0, max: 1 }
|
|
3080
2992
|
},
|
|
3081
2993
|
fs: fs7,
|
|
@@ -3102,7 +3014,7 @@ vec4 sepia_filterColor(vec4 color) {
|
|
|
3102
3014
|
return color;
|
|
3103
3015
|
}
|
|
3104
3016
|
|
|
3105
|
-
vec4
|
|
3017
|
+
vec4 sepia_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3106
3018
|
return sepia_filterColor(color);
|
|
3107
3019
|
}
|
|
3108
3020
|
`
|
|
@@ -3114,7 +3026,7 @@ var sepia = {
|
|
|
3114
3026
|
uniformTypes: {
|
|
3115
3027
|
amount: "f32"
|
|
3116
3028
|
},
|
|
3117
|
-
|
|
3029
|
+
propTypes: {
|
|
3118
3030
|
amount: { value: 0.5, min: 0, max: 1 }
|
|
3119
3031
|
},
|
|
3120
3032
|
fs: fs8,
|
|
@@ -3136,7 +3048,7 @@ vec4 vibrance_filterColor(vec4 color) {
|
|
|
3136
3048
|
return color;
|
|
3137
3049
|
}
|
|
3138
3050
|
|
|
3139
|
-
vec4
|
|
3051
|
+
vec4 vibrance_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3140
3052
|
return vibrance_filterColor(color);
|
|
3141
3053
|
}
|
|
3142
3054
|
`
|
|
@@ -3145,7 +3057,10 @@ var vibrance = {
|
|
|
3145
3057
|
props: {},
|
|
3146
3058
|
uniforms: {},
|
|
3147
3059
|
name: "vibrance",
|
|
3148
|
-
|
|
3060
|
+
uniformTypes: {
|
|
3061
|
+
amount: "f32"
|
|
3062
|
+
},
|
|
3063
|
+
propTypes: {
|
|
3149
3064
|
amount: { value: 0, min: -1, max: 1 }
|
|
3150
3065
|
},
|
|
3151
3066
|
fs: fs9,
|
|
@@ -3160,15 +3075,11 @@ var fs10 = (
|
|
|
3160
3075
|
float amount;
|
|
3161
3076
|
} vignette;
|
|
3162
3077
|
|
|
3163
|
-
vec4
|
|
3078
|
+
vec4 vignette_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3164
3079
|
float dist = distance(texCoord, vec2(0.5, 0.5));
|
|
3165
3080
|
float ratio = smoothstep(0.8, vignette.radius * 0.799, dist * (vignette.amount + vignette.radius));
|
|
3166
3081
|
return color.rgba * ratio + (1.0 - ratio)*vec4(0.0, 0.0, 0.0, 1.0);
|
|
3167
3082
|
}
|
|
3168
|
-
|
|
3169
|
-
vec4 vignette_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3170
|
-
return vignette_filterColor(color, texCoord);
|
|
3171
|
-
}
|
|
3172
3083
|
`
|
|
3173
3084
|
);
|
|
3174
3085
|
var vignette = {
|
|
@@ -3179,7 +3090,11 @@ var vignette = {
|
|
|
3179
3090
|
radius: "f32",
|
|
3180
3091
|
amount: "f32"
|
|
3181
3092
|
},
|
|
3182
|
-
|
|
3093
|
+
defaultUniforms: {
|
|
3094
|
+
radius: 0.5,
|
|
3095
|
+
amount: 0.5
|
|
3096
|
+
},
|
|
3097
|
+
propTypes: {
|
|
3183
3098
|
radius: { value: 0.5, min: 0, max: 1 },
|
|
3184
3099
|
amount: { value: 0.5, min: 0, max: 1 }
|
|
3185
3100
|
},
|
|
@@ -3247,7 +3162,7 @@ var tiltShift = {
|
|
|
3247
3162
|
end: "vec2<f32>",
|
|
3248
3163
|
invert: "i32"
|
|
3249
3164
|
},
|
|
3250
|
-
|
|
3165
|
+
propTypes: {
|
|
3251
3166
|
blurRadius: { value: 15, min: 0, max: 50 },
|
|
3252
3167
|
gradientRadius: { value: 200, min: 0, max: 400 },
|
|
3253
3168
|
start: { value: [0, 0] },
|
|
@@ -3307,7 +3222,7 @@ var triangleBlur = {
|
|
|
3307
3222
|
radius: "f32",
|
|
3308
3223
|
delta: "vec2<f32>"
|
|
3309
3224
|
},
|
|
3310
|
-
|
|
3225
|
+
propTypes: {
|
|
3311
3226
|
radius: { value: 20, min: 0, softMax: 100 },
|
|
3312
3227
|
delta: { value: [1, 0], private: true }
|
|
3313
3228
|
},
|
|
@@ -3362,7 +3277,7 @@ var zoomBlur = {
|
|
|
3362
3277
|
center: "vec2<f32>",
|
|
3363
3278
|
strength: "f32"
|
|
3364
3279
|
},
|
|
3365
|
-
|
|
3280
|
+
propTypes: {
|
|
3366
3281
|
center: { value: [0.5, 0.5] },
|
|
3367
3282
|
strength: { value: 0.3, min: 0, softMax: 1 }
|
|
3368
3283
|
},
|
|
@@ -3390,7 +3305,7 @@ float pattern(float angle, float scale, vec2 texSize, vec2 texCoord) {
|
|
|
3390
3305
|
return (sin(point.x) * sin(point.y)) * 4.0;
|
|
3391
3306
|
}
|
|
3392
3307
|
|
|
3393
|
-
vec4
|
|
3308
|
+
vec4 colorHalftone_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3394
3309
|
float scale = 3.1514 / colorHalftone.size;
|
|
3395
3310
|
vec3 cmy = 1.0 - color.rgb;
|
|
3396
3311
|
float k = min(cmy.x, min(cmy.y, cmy.z));
|
|
@@ -3419,7 +3334,7 @@ var colorHalftone = {
|
|
|
3419
3334
|
angle: "f32",
|
|
3420
3335
|
size: "f32"
|
|
3421
3336
|
},
|
|
3422
|
-
|
|
3337
|
+
propTypes: {
|
|
3423
3338
|
center: { value: [0.5, 0.5] },
|
|
3424
3339
|
angle: { value: 1.1, softMin: 0, softMax: Math.PI / 2 },
|
|
3425
3340
|
size: { value: 4, min: 1, softMin: 3, softMax: 20 }
|
|
@@ -3449,7 +3364,7 @@ float pattern(vec2 texSize, vec2 texCoord) {
|
|
|
3449
3364
|
return (sin(point.x) * sin(point.y)) * 4.0;
|
|
3450
3365
|
}
|
|
3451
3366
|
|
|
3452
|
-
vec4
|
|
3367
|
+
vec4 dotScreen_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
3453
3368
|
float average = (color.r + color.g + color.b) / 3.0;
|
|
3454
3369
|
return vec4(vec3(average * 10.0 - 5.0 + pattern(texSize, texCoord)), color.a);
|
|
3455
3370
|
}
|
|
@@ -3464,7 +3379,7 @@ var dotScreen = {
|
|
|
3464
3379
|
angle: "f32",
|
|
3465
3380
|
size: "f32"
|
|
3466
3381
|
},
|
|
3467
|
-
|
|
3382
|
+
propTypes: {
|
|
3468
3383
|
center: { value: [0.5, 0.5] },
|
|
3469
3384
|
angle: { value: 1.1, softMin: 0, softMax: Math.PI / 2 },
|
|
3470
3385
|
size: { value: 3, min: 1, softMin: 3, softMax: 20 }
|
|
@@ -3478,11 +3393,11 @@ var fs16 = (
|
|
|
3478
3393
|
/* glsl */
|
|
3479
3394
|
`uniform edgeWorkUniforms {
|
|
3480
3395
|
float radius;
|
|
3481
|
-
|
|
3396
|
+
int mode;
|
|
3482
3397
|
} edgeWork;
|
|
3483
3398
|
|
|
3484
|
-
vec4
|
|
3485
|
-
vec2 relativeDelta = edgeWork.radius *
|
|
3399
|
+
vec4 edgeWork_sampleColorRGB(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) {
|
|
3400
|
+
vec2 relativeDelta = edgeWork.radius * delta / texSize;
|
|
3486
3401
|
|
|
3487
3402
|
vec2 color = vec2(0.0);
|
|
3488
3403
|
vec2 total = vec2(0.0);
|
|
@@ -3506,8 +3421,8 @@ vec4 edgeWork_sampleColor1(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
3506
3421
|
return vec4(color / total, 0.0, 1.0);
|
|
3507
3422
|
}
|
|
3508
3423
|
|
|
3509
|
-
vec4
|
|
3510
|
-
vec2 relativeDelta = edgeWork.radius *
|
|
3424
|
+
vec4 edgeWork_sampleColorXY(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) {
|
|
3425
|
+
vec2 relativeDelta = edgeWork.radius * delta / texSize;
|
|
3511
3426
|
|
|
3512
3427
|
vec2 color = vec2(0.0);
|
|
3513
3428
|
vec2 total = vec2(0.0);
|
|
@@ -3530,6 +3445,16 @@ vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
3530
3445
|
float c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
|
|
3531
3446
|
return vec4(c, c, c, 1.0);
|
|
3532
3447
|
}
|
|
3448
|
+
|
|
3449
|
+
vec4 edgeWork_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
3450
|
+
switch (edgeWork.mode) {
|
|
3451
|
+
case 0:
|
|
3452
|
+
return edgeWork_sampleColorRGB(source, texSize, texCoord, vec2(1., 0.));
|
|
3453
|
+
case 1:
|
|
3454
|
+
default:
|
|
3455
|
+
return edgeWork_sampleColorXY(source, texSize, texCoord, vec2(0., 1.));
|
|
3456
|
+
}
|
|
3457
|
+
}
|
|
3533
3458
|
`
|
|
3534
3459
|
);
|
|
3535
3460
|
var edgeWork = {
|
|
@@ -3538,20 +3463,22 @@ var edgeWork = {
|
|
|
3538
3463
|
name: "edgeWork",
|
|
3539
3464
|
dependencies: [random],
|
|
3540
3465
|
fs: fs16,
|
|
3541
|
-
|
|
3466
|
+
uniformTypes: {
|
|
3467
|
+
radius: "f32",
|
|
3468
|
+
mode: "i32"
|
|
3469
|
+
},
|
|
3470
|
+
propTypes: {
|
|
3542
3471
|
radius: { value: 2, min: 1, softMax: 50 },
|
|
3543
|
-
|
|
3472
|
+
mode: { value: 0, private: true }
|
|
3544
3473
|
},
|
|
3545
3474
|
passes: [
|
|
3546
3475
|
{
|
|
3547
|
-
|
|
3548
|
-
|
|
3549
|
-
uniformPropTypes: { delta: [1, 0] }
|
|
3476
|
+
sampler: true,
|
|
3477
|
+
uniforms: { mode: 0 }
|
|
3550
3478
|
},
|
|
3551
3479
|
{
|
|
3552
|
-
|
|
3553
|
-
|
|
3554
|
-
uniformPropTypes: { delta: [0, 1] }
|
|
3480
|
+
sampler: true,
|
|
3481
|
+
uniforms: { mode: 1 }
|
|
3555
3482
|
}
|
|
3556
3483
|
]
|
|
3557
3484
|
};
|
|
@@ -3611,7 +3538,7 @@ var hexagonalPixelate = {
|
|
|
3611
3538
|
center: "vec2<f32>",
|
|
3612
3539
|
scale: "f32"
|
|
3613
3540
|
},
|
|
3614
|
-
|
|
3541
|
+
propTypes: {
|
|
3615
3542
|
center: { value: [0.5, 0.5], hint: "screenspace" },
|
|
3616
3543
|
scale: { value: 10, min: 1, softMin: 5, softMax: 50 }
|
|
3617
3544
|
},
|
|
@@ -3659,7 +3586,7 @@ var ink = {
|
|
|
3659
3586
|
uniformTypes: {
|
|
3660
3587
|
strength: "f32"
|
|
3661
3588
|
},
|
|
3662
|
-
|
|
3589
|
+
propTypes: {
|
|
3663
3590
|
strength: { value: 0.25, min: 0, softMax: 1 }
|
|
3664
3591
|
},
|
|
3665
3592
|
passes: [{ sampler: true }]
|
|
@@ -3699,7 +3626,7 @@ var magnify = {
|
|
|
3699
3626
|
borderWidthPixels: "f32",
|
|
3700
3627
|
borderColor: "vec4<f32>"
|
|
3701
3628
|
},
|
|
3702
|
-
|
|
3629
|
+
propTypes: {
|
|
3703
3630
|
// range 0 to 1
|
|
3704
3631
|
screenXY: { value: [0, 0] },
|
|
3705
3632
|
radiusPixels: 200,
|
|
@@ -3775,7 +3702,7 @@ var bulgePinch = {
|
|
|
3775
3702
|
radius: "f32",
|
|
3776
3703
|
strength: "f32"
|
|
3777
3704
|
},
|
|
3778
|
-
|
|
3705
|
+
propTypes: {
|
|
3779
3706
|
center: { value: [0.5, 0.5] },
|
|
3780
3707
|
radius: { value: 200, min: 1, softMax: 600 },
|
|
3781
3708
|
strength: { value: 0.5, min: -1, max: 1 }
|
|
@@ -3828,7 +3755,7 @@ var swirl = {
|
|
|
3828
3755
|
radius: "f32",
|
|
3829
3756
|
angle: "f32"
|
|
3830
3757
|
},
|
|
3831
|
-
|
|
3758
|
+
propTypes: {
|
|
3832
3759
|
center: { value: [0.5, 0.5] },
|
|
3833
3760
|
radius: { value: 200, min: 1, softMax: 600 },
|
|
3834
3761
|
angle: { value: 3, softMin: -25, softMax: 25 }
|
|
@@ -3837,7 +3764,9 @@ var swirl = {
|
|
|
3837
3764
|
};
|
|
3838
3765
|
|
|
3839
3766
|
// dist/passes/postprocessing/fxaa/fxaa.js
|
|
3840
|
-
var fs23 =
|
|
3767
|
+
var fs23 = (
|
|
3768
|
+
/* glsl */
|
|
3769
|
+
`
|
|
3841
3770
|
#define FXAA_QUALITY_PRESET 29
|
|
3842
3771
|
|
|
3843
3772
|
#if (FXAA_QUALITY_PRESET == 10)
|
|
@@ -4417,10 +4346,11 @@ vec4 fxaa_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
4417
4346
|
fxaa_QualityEdgeThresholdMin
|
|
4418
4347
|
);
|
|
4419
4348
|
}
|
|
4420
|
-
|
|
4349
|
+
`
|
|
4350
|
+
);
|
|
4421
4351
|
var fxaa = {
|
|
4422
4352
|
name: "fxaa",
|
|
4423
|
-
|
|
4353
|
+
propTypes: {},
|
|
4424
4354
|
fs: fs23,
|
|
4425
4355
|
passes: [{ sampler: true }],
|
|
4426
4356
|
getUniforms: (props) => props
|
|
@@ -5338,7 +5268,7 @@ var geometry = {
|
|
|
5338
5268
|
};
|
|
5339
5269
|
|
|
5340
5270
|
// dist/modules-webgl1/project/project.js
|
|
5341
|
-
var
|
|
5271
|
+
var import_core4 = require("@math.gl/core");
|
|
5342
5272
|
var IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
5343
5273
|
var DEFAULT_MODULE_OPTIONS = {
|
|
5344
5274
|
modelMatrix: IDENTITY_MATRIX,
|
|
@@ -5361,7 +5291,7 @@ function getUniforms5(opts = DEFAULT_MODULE_OPTIONS, prevUniforms = {}) {
|
|
|
5361
5291
|
uniforms.cameraPositionWorld = opts.cameraPositionWorld;
|
|
5362
5292
|
}
|
|
5363
5293
|
if (opts.projectionMatrix !== void 0 && opts.viewMatrix !== void 0) {
|
|
5364
|
-
uniforms.viewProjectionMatrix = new
|
|
5294
|
+
uniforms.viewProjectionMatrix = new import_core4.Matrix4(opts.projectionMatrix).multiplyRight(opts.viewMatrix);
|
|
5365
5295
|
}
|
|
5366
5296
|
return uniforms;
|
|
5367
5297
|
}
|