@luma.gl/shaders 10.0.0-alpha.10 → 10.0.0-alpha.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +1923 -60
- package/dist/dist.min.js +1499 -148
- package/dist/glsl.cjs.map +1 -1
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.cjs +40 -0
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.d.ts +6 -0
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.d.ts.map +1 -0
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.js +15 -0
- package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.js.map +1 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.cjs +348 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.d.ts +188 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.d.ts.map +1 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.js +307 -0
- package/dist/modules/lighting/contact-shadow/contact-shadow.js.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.cjs +93 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.d.ts +35 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.d.ts.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.js +71 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.js.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap.cjs +89 -0
- package/dist/modules/lighting/lightmap/lightmap.d.ts +405 -0
- package/dist/modules/lighting/lightmap/lightmap.d.ts.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap.js +67 -0
- package/dist/modules/lighting/lightmap/lightmap.js.map +1 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.cjs +87 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.d.ts +21 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.js +61 -0
- package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.js.map +1 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.cjs +87 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.d.ts +21 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.js +61 -0
- package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.js.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.cjs +33 -11
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +33 -11
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.cjs +33 -11
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +33 -11
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +3 -3
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.cjs +97 -0
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.d.ts +15 -0
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.js +69 -0
- package/dist/modules/lighting/pbr-shadow/pbr-shadow.js.map +1 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.cjs +114 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.d.ts +15 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.js +88 -0
- package/dist/modules/lighting/pbr-surface/pbr-surface.js.map +1 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.cjs +379 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.d.ts +41 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.d.ts.map +1 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.js +345 -0
- package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.js.map +1 -0
- package/dist/modules/lighting/shadow/shadow-glsl.cjs +228 -0
- package/dist/modules/lighting/shadow/shadow-glsl.d.ts +3 -0
- package/dist/modules/lighting/shadow/shadow-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/shadow/shadow-glsl.js +204 -0
- package/dist/modules/lighting/shadow/shadow-glsl.js.map +1 -0
- package/dist/modules/lighting/shadow/shadow-types.cjs +15 -0
- package/dist/modules/lighting/shadow/shadow-types.d.ts +63 -0
- package/dist/modules/lighting/shadow/shadow-types.d.ts.map +1 -0
- package/dist/modules/lighting/shadow/shadow-types.js +5 -0
- package/dist/modules/lighting/shadow/shadow-types.js.map +1 -0
- package/dist/modules/lighting/shadow/shadow.cjs +458 -0
- package/dist/modules/lighting/shadow/shadow.d.ts +117 -0
- package/dist/modules/lighting/shadow/shadow.d.ts.map +1 -0
- package/dist/modules/lighting/shadow/shadow.js +450 -0
- package/dist/modules/lighting/shadow/shadow.js.map +1 -0
- package/dist/modules/lighting/unlit-material/unlit-material.cjs +60 -0
- package/dist/modules/lighting/unlit-material/unlit-material.d.ts +9 -0
- package/dist/modules/lighting/unlit-material/unlit-material.d.ts.map +1 -0
- package/dist/modules/lighting/unlit-material/unlit-material.js +40 -0
- package/dist/modules/lighting/unlit-material/unlit-material.js.map +1 -0
- package/dist/types/shader-type-decoder.cjs +12 -2
- package/dist/types/shader-type-decoder.d.ts +7 -7
- package/dist/types/shader-type-decoder.d.ts.map +1 -1
- package/dist/types/shader-type-decoder.js +13 -2
- package/dist/types/shader-type-decoder.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/wgsl.cjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +52 -0
- package/src/modules/lighting/clustered-light-grid/clustered-light-grid.ts +17 -0
- package/src/modules/lighting/contact-shadow/contact-shadow.ts +365 -0
- package/src/modules/lighting/lightmap/lightmap-filter.ts +73 -0
- package/src/modules/lighting/lightmap/lightmap.ts +76 -0
- package/src/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.ts +78 -0
- package/src/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.ts +78 -0
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +33 -11
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +33 -11
- package/src/modules/lighting/pbr-shadow/pbr-shadow.ts +85 -0
- package/src/modules/lighting/pbr-surface/pbr-surface.ts +103 -0
- package/src/modules/lighting/prefiltered-environment/prefiltered-environment.ts +370 -0
- package/src/modules/lighting/shadow/shadow-glsl.ts +204 -0
- package/src/modules/lighting/shadow/shadow-types.ts +68 -0
- package/src/modules/lighting/shadow/shadow.ts +536 -0
- package/src/modules/lighting/unlit-material/unlit-material.ts +44 -0
- package/src/types/shader-type-decoder.ts +22 -9
|
@@ -41,7 +41,7 @@ void pbr_setPositionNormalTangentUV(
|
|
|
41
41
|
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
42
42
|
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
43
43
|
#else // HAS_TANGENTS != 1
|
|
44
|
-
pbr_vNormal = normalize(vec3(pbrProjection.
|
|
44
|
+
pbr_vNormal = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
|
|
45
45
|
#endif
|
|
46
46
|
#endif
|
|
47
47
|
|
|
@@ -1047,7 +1047,9 @@ vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
|
|
|
1047
1047
|
}
|
|
1048
1048
|
|
|
1049
1049
|
// Visibility for the first four spotlights; environment and other lights are unaffected.
|
|
1050
|
-
|
|
1050
|
+
float pbr_ambientVisibility = 1.0;
|
|
1051
|
+
|
|
1052
|
+
vec4 pbr_filterColorWithShadows(vec4 vertexColor, float directionalVisibility, vec4 pointVisibility, vec4 spotVisibility)
|
|
1051
1053
|
{
|
|
1052
1054
|
vec2 baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
|
|
1053
1055
|
vec2 metallicRoughnessUV = getMaterialUV(
|
|
@@ -1143,7 +1145,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1143
1145
|
color.rgb = baseColor.rgb;
|
|
1144
1146
|
#ifdef HAS_LIGHTMAP
|
|
1145
1147
|
if (pbrMaterial.lightmapMapEnabled) {
|
|
1146
|
-
color *= lightmapIrradiance / M_PI;
|
|
1148
|
+
color *= lightmapIrradiance / M_PI * pbr_ambientVisibility;
|
|
1147
1149
|
#ifdef HAS_OCCLUSIONMAP
|
|
1148
1150
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
1149
1151
|
float ao = texture(pbr_occlusionSampler, occlusionUV).r;
|
|
@@ -1245,12 +1247,12 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1245
1247
|
|
|
1246
1248
|
#ifdef USE_LIGHTS
|
|
1247
1249
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
1248
|
-
color += calculateFinalColor(pbrInfo, lighting.ambientColor);
|
|
1250
|
+
color += calculateFinalColor(pbrInfo, lighting.ambientColor * pbr_ambientVisibility);
|
|
1249
1251
|
|
|
1250
1252
|
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
1251
1253
|
if (i < lighting.directionalLightCount) {
|
|
1252
1254
|
PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
1253
|
-
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
1255
|
+
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0));
|
|
1254
1256
|
}
|
|
1255
1257
|
}
|
|
1256
1258
|
|
|
@@ -1258,7 +1260,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1258
1260
|
if (i < lighting.pointLightCount) {
|
|
1259
1261
|
PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
|
|
1260
1262
|
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
1261
|
-
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
1263
|
+
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation);
|
|
1262
1264
|
}
|
|
1263
1265
|
}
|
|
1264
1266
|
|
|
@@ -1284,6 +1286,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1284
1286
|
}
|
|
1285
1287
|
#endif
|
|
1286
1288
|
|
|
1289
|
+
vec3 indirectBaseColor = color;
|
|
1287
1290
|
#ifdef USE_IBL
|
|
1288
1291
|
if (pbrMaterial.IBLenabled) {
|
|
1289
1292
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
@@ -1292,6 +1295,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1292
1295
|
|
|
1293
1296
|
// The pinned KHR_lightmap draft explicitly defines c_diff = (1 - metallic) * baseColor.
|
|
1294
1297
|
color += baseColor.rgb * (1.0 - metallic) * lightmapIrradiance / M_PI;
|
|
1298
|
+
color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
|
|
1295
1299
|
|
|
1296
1300
|
#ifdef HAS_OCCLUSIONMAP
|
|
1297
1301
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
@@ -1524,7 +1528,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1524
1528
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
1525
1529
|
color += calculateMaterialLightColor(
|
|
1526
1530
|
pbrInfo,
|
|
1527
|
-
lighting.ambientColor,
|
|
1531
|
+
lighting.ambientColor * pbr_ambientVisibility,
|
|
1528
1532
|
clearcoatNormal,
|
|
1529
1533
|
clearcoatFactor,
|
|
1530
1534
|
clearcoatRoughness,
|
|
@@ -1540,7 +1544,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1540
1544
|
PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
1541
1545
|
color += calculateMaterialLightColor(
|
|
1542
1546
|
pbrInfo,
|
|
1543
|
-
lighting_getDirectionalLight(i).color,
|
|
1547
|
+
lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0),
|
|
1544
1548
|
clearcoatNormal,
|
|
1545
1549
|
clearcoatFactor,
|
|
1546
1550
|
clearcoatRoughness,
|
|
@@ -1551,7 +1555,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1551
1555
|
);
|
|
1552
1556
|
color += calculateDiffuseTransmissionLight(
|
|
1553
1557
|
pbrInfo,
|
|
1554
|
-
lighting_getDirectionalLight(i).color,
|
|
1558
|
+
lighting_getDirectionalLight(i).color * (i == 0 ? clamp(directionalVisibility, 0.0, 1.0) : 1.0),
|
|
1555
1559
|
diffuseTransmissionColor,
|
|
1556
1560
|
diffuseTransmission,
|
|
1557
1561
|
multiscatterColor,
|
|
@@ -1567,7 +1571,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1567
1571
|
float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
|
|
1568
1572
|
color += calculateMaterialLightColor(
|
|
1569
1573
|
pbrInfo,
|
|
1570
|
-
lighting_getPointLight(i).color / attenuation,
|
|
1574
|
+
lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation,
|
|
1571
1575
|
clearcoatNormal,
|
|
1572
1576
|
clearcoatFactor,
|
|
1573
1577
|
clearcoatRoughness,
|
|
@@ -1578,7 +1582,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1578
1582
|
);
|
|
1579
1583
|
color += calculateDiffuseTransmissionLight(
|
|
1580
1584
|
pbrInfo,
|
|
1581
|
-
lighting_getPointLight(i).color / attenuation,
|
|
1585
|
+
lighting_getPointLight(i).color * (i < 4 ? clamp(pointVisibility[min(i, 3)], 0.0, 1.0) : 1.0) / attenuation,
|
|
1582
1586
|
diffuseTransmissionColor,
|
|
1583
1587
|
diffuseTransmission,
|
|
1584
1588
|
multiscatterColor,
|
|
@@ -1647,6 +1651,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1647
1651
|
}
|
|
1648
1652
|
#endif
|
|
1649
1653
|
|
|
1654
|
+
vec3 indirectBaseColor = color;
|
|
1650
1655
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
1651
1656
|
#ifdef USE_IBL
|
|
1652
1657
|
if (pbrMaterial.IBLenabled) {
|
|
@@ -1681,6 +1686,8 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1681
1686
|
(1.0 - diffuseTransmission) * baseLayerEnergy * lightmapIrradiance / M_PI;
|
|
1682
1687
|
#endif
|
|
1683
1688
|
|
|
1689
|
+
color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
|
|
1690
|
+
|
|
1684
1691
|
// Apply optional PBR terms for additional (optional) shading
|
|
1685
1692
|
#ifdef HAS_OCCLUSIONMAP
|
|
1686
1693
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
@@ -1742,6 +1749,21 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1742
1749
|
return vec4(applySceneColorManagement(color), alpha);
|
|
1743
1750
|
}
|
|
1744
1751
|
|
|
1752
|
+
// Depth-only passes use the same base-color alpha, vertex color and UV transform.
|
|
1753
|
+
void pbr_discardMaskedFragment(vec4 vertexColor) {
|
|
1754
|
+
#ifdef ALPHA_CUTOFF
|
|
1755
|
+
float alpha = pbrMaterial.baseColorFactor.a * vertexColor.a;
|
|
1756
|
+
#ifdef HAS_BASECOLORMAP
|
|
1757
|
+
alpha *= texture(pbr_baseColorSampler, getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform)).a;
|
|
1758
|
+
#endif
|
|
1759
|
+
if (alpha < pbrMaterial.alphaCutoff) {discard;}
|
|
1760
|
+
#endif
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility) {
|
|
1764
|
+
return pbr_filterColorWithShadows(vertexColor, 1.0, vec4(1.0), spotVisibility);
|
|
1765
|
+
}
|
|
1766
|
+
|
|
1745
1767
|
vec4 pbr_filterColor(vec4 vertexColor) {
|
|
1746
1768
|
return pbr_filterColorWithSpotShadows(vertexColor, vec4(1.0));
|
|
1747
1769
|
}
|
|
@@ -1268,7 +1268,9 @@ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
|
|
|
1268
1268
|
}
|
|
1269
1269
|
|
|
1270
1270
|
// Visibility for the first four spotlights; environment and other lights are unaffected.
|
|
1271
|
-
|
|
1271
|
+
var<private> pbr_ambientVisibility: f32 = 1.0;
|
|
1272
|
+
|
|
1273
|
+
fn pbr_filterColorWithShadows(vertexColor: vec4<f32>, directionalVisibility: f32, pointVisibility: vec4f, spotVisibility: vec4f) -> vec4<f32> {
|
|
1272
1274
|
let baseColorUV = getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform);
|
|
1273
1275
|
let metallicRoughnessUV = getMaterialUV(
|
|
1274
1276
|
pbrMaterial.metallicRoughnessUVSet,
|
|
@@ -1361,7 +1363,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1361
1363
|
color = baseColor.rgb;
|
|
1362
1364
|
#ifdef HAS_LIGHTMAP
|
|
1363
1365
|
if (pbrMaterial.lightmapMapEnabled != 0u) {
|
|
1364
|
-
color *= lightmapIrradiance / M_PI;
|
|
1366
|
+
color *= lightmapIrradiance / M_PI * pbr_ambientVisibility;
|
|
1365
1367
|
#ifdef HAS_OCCLUSIONMAP
|
|
1366
1368
|
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
1367
1369
|
let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, occlusionUV).r;
|
|
@@ -1464,12 +1466,12 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1464
1466
|
|
|
1465
1467
|
#ifdef USE_LIGHTS
|
|
1466
1468
|
PBRInfo_setAmbientLight(&pbrInfo);
|
|
1467
|
-
color += calculateFinalColor(pbrInfo, lighting.ambientColor);
|
|
1469
|
+
color += calculateFinalColor(pbrInfo, lighting.ambientColor * pbr_ambientVisibility);
|
|
1468
1470
|
|
|
1469
1471
|
for (var i = 0; i < lighting.directionalLightCount; i++) {
|
|
1470
1472
|
if (i < lighting.directionalLightCount) {
|
|
1471
1473
|
PBRInfo_setDirectionalLight(&pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
1472
|
-
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
1474
|
+
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color * select(1.0, clamp(directionalVisibility, 0.0, 1.0), i == 0));
|
|
1473
1475
|
}
|
|
1474
1476
|
}
|
|
1475
1477
|
|
|
@@ -1480,7 +1482,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1480
1482
|
lighting_getPointLight(i),
|
|
1481
1483
|
distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)
|
|
1482
1484
|
);
|
|
1483
|
-
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
1485
|
+
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color * select(1.0, clamp(pointVisibility[min(i, 3)], 0.0, 1.0), i < 4) / attenuation);
|
|
1484
1486
|
}
|
|
1485
1487
|
}
|
|
1486
1488
|
|
|
@@ -1509,7 +1511,8 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1509
1511
|
}
|
|
1510
1512
|
#endif
|
|
1511
1513
|
|
|
1512
|
-
|
|
1514
|
+
let indirectBaseColor = color;
|
|
1515
|
+
#ifdef USE_IBL
|
|
1513
1516
|
if (pbrMaterial.IBLenabled != 0) {
|
|
1514
1517
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
1515
1518
|
}
|
|
@@ -1517,6 +1520,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1517
1520
|
|
|
1518
1521
|
// The pinned KHR_lightmap draft explicitly defines c_diff = (1 - metallic) * baseColor.
|
|
1519
1522
|
color += baseColor.rgb * (1.0 - metallic) * lightmapIrradiance / M_PI;
|
|
1523
|
+
color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
|
|
1520
1524
|
|
|
1521
1525
|
#ifdef HAS_OCCLUSIONMAP
|
|
1522
1526
|
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
@@ -1815,7 +1819,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1815
1819
|
PBRInfo_setAmbientLight(&pbrInfo);
|
|
1816
1820
|
color += calculateMaterialLightColor(
|
|
1817
1821
|
pbrInfo,
|
|
1818
|
-
lighting.ambientColor,
|
|
1822
|
+
lighting.ambientColor * pbr_ambientVisibility,
|
|
1819
1823
|
clearcoatNormal,
|
|
1820
1824
|
clearcoatFactor,
|
|
1821
1825
|
clearcoatRoughness,
|
|
@@ -1831,7 +1835,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1831
1835
|
PBRInfo_setDirectionalLight(&pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
1832
1836
|
color += calculateMaterialLightColor(
|
|
1833
1837
|
pbrInfo,
|
|
1834
|
-
lighting_getDirectionalLight(i).color,
|
|
1838
|
+
lighting_getDirectionalLight(i).color * select(1.0, clamp(directionalVisibility, 0.0, 1.0), i == 0),
|
|
1835
1839
|
clearcoatNormal,
|
|
1836
1840
|
clearcoatFactor,
|
|
1837
1841
|
clearcoatRoughness,
|
|
@@ -1842,7 +1846,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1842
1846
|
);
|
|
1843
1847
|
color += calculateDiffuseTransmissionLight(
|
|
1844
1848
|
pbrInfo,
|
|
1845
|
-
lighting_getDirectionalLight(i).color,
|
|
1849
|
+
lighting_getDirectionalLight(i).color * select(1.0, clamp(directionalVisibility, 0.0, 1.0), i == 0),
|
|
1846
1850
|
diffuseTransmissionColor,
|
|
1847
1851
|
diffuseTransmission,
|
|
1848
1852
|
multiscatterColor,
|
|
@@ -1861,7 +1865,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1861
1865
|
);
|
|
1862
1866
|
color += calculateMaterialLightColor(
|
|
1863
1867
|
pbrInfo,
|
|
1864
|
-
lighting_getPointLight(i).color / attenuation,
|
|
1868
|
+
lighting_getPointLight(i).color * select(1.0, clamp(pointVisibility[min(i, 3)], 0.0, 1.0), i < 4) / attenuation,
|
|
1865
1869
|
clearcoatNormal,
|
|
1866
1870
|
clearcoatFactor,
|
|
1867
1871
|
clearcoatRoughness,
|
|
@@ -1872,7 +1876,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1872
1876
|
);
|
|
1873
1877
|
color += calculateDiffuseTransmissionLight(
|
|
1874
1878
|
pbrInfo,
|
|
1875
|
-
lighting_getPointLight(i).color / attenuation,
|
|
1879
|
+
lighting_getPointLight(i).color * select(1.0, clamp(pointVisibility[min(i, 3)], 0.0, 1.0), i < 4) / attenuation,
|
|
1876
1880
|
diffuseTransmissionColor,
|
|
1877
1881
|
diffuseTransmission,
|
|
1878
1882
|
multiscatterColor,
|
|
@@ -1941,6 +1945,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1941
1945
|
}
|
|
1942
1946
|
#endif
|
|
1943
1947
|
|
|
1948
|
+
let indirectBaseColor = color;
|
|
1944
1949
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
1945
1950
|
#ifdef USE_IBL
|
|
1946
1951
|
if (pbrMaterial.IBLenabled != 0) {
|
|
@@ -1975,6 +1980,8 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1975
1980
|
(1.0 - diffuseTransmission) * baseLayerEnergy * lightmapIrradiance / M_PI;
|
|
1976
1981
|
#endif
|
|
1977
1982
|
|
|
1983
|
+
color = indirectBaseColor + (color - indirectBaseColor) * pbr_ambientVisibility;
|
|
1984
|
+
|
|
1978
1985
|
// Apply optional PBR terms for additional (optional) shading
|
|
1979
1986
|
#ifdef HAS_OCCLUSIONMAP
|
|
1980
1987
|
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
@@ -2037,6 +2044,21 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
2037
2044
|
return vec4<f32>(applySceneColorManagement(color), alpha);
|
|
2038
2045
|
}
|
|
2039
2046
|
|
|
2047
|
+
// Depth-only passes use the same base-color alpha, vertex color and UV transform.
|
|
2048
|
+
fn pbr_discardMaskedFragment(vertexColor: vec4f) {
|
|
2049
|
+
#ifdef ALPHA_CUTOFF
|
|
2050
|
+
var alpha = pbrMaterial.baseColorFactor.a * vertexColor.a;
|
|
2051
|
+
#ifdef HAS_BASECOLORMAP
|
|
2052
|
+
alpha *= textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, getMaterialUV(pbrMaterial.baseColorUVSet, pbrMaterial.baseColorUVTransform)).a;
|
|
2053
|
+
#endif
|
|
2054
|
+
if (alpha < pbrMaterial.alphaCutoff) {discard;}
|
|
2055
|
+
#endif
|
|
2056
|
+
}
|
|
2057
|
+
|
|
2058
|
+
fn pbr_filterColorWithSpotShadows(vertexColor: vec4f, spotVisibility: vec4f) -> vec4f {
|
|
2059
|
+
return pbr_filterColorWithShadows(vertexColor, 1.0, vec4f(1.0), spotVisibility);
|
|
2060
|
+
}
|
|
2061
|
+
|
|
2040
2062
|
fn pbr_filterColor(vertexColor: vec4<f32>) -> vec4<f32> {
|
|
2041
2063
|
return pbr_filterColorWithSpotShadows(vertexColor, vec4f(1.0));
|
|
2042
2064
|
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import type {NumberArray16} from '@math.gl/core';
|
|
5
|
+
import type {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
|
+
import {pbrMaterial} from '../pbr-material/pbr-material';
|
|
7
|
+
import {shadow} from '../shadow/shadow';
|
|
8
|
+
|
|
9
|
+
export type PBRShadowProps = {
|
|
10
|
+
/** Receiver camera view matrix, used for directional cascade selection. */
|
|
11
|
+
viewMatrix?: Readonly<NumberArray16>;
|
|
12
|
+
/** Toggle receiving while retaining allocated maps and bindings. Defaults to true. */
|
|
13
|
+
enabled?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type PBRShadowUniforms = {
|
|
17
|
+
viewMatrix: Readonly<NumberArray16>;
|
|
18
|
+
enabled: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Applies shadow visibility to matching direct-light slots in the canonical PBR shader. */
|
|
22
|
+
export const pbrShadow: ShaderModule<PBRShadowProps, PBRShadowUniforms> = {
|
|
23
|
+
name: 'pbrShadow',
|
|
24
|
+
dependencies: [pbrMaterial, shadow],
|
|
25
|
+
bindingLayout: [{name: 'pbrShadow', group: 0}],
|
|
26
|
+
uniformTypes: {viewMatrix: 'mat4x4<f32>', enabled: 'i32'},
|
|
27
|
+
defaultUniforms: {
|
|
28
|
+
viewMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
|
|
29
|
+
enabled: 1
|
|
30
|
+
},
|
|
31
|
+
getUniforms(properties = {}) {
|
|
32
|
+
return {
|
|
33
|
+
...(properties.viewMatrix ? {viewMatrix: properties.viewMatrix} : {}),
|
|
34
|
+
...(properties.enabled === undefined ? {} : {enabled: Number(properties.enabled)})
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
source: /* wgsl */ `
|
|
38
|
+
struct PBRShadowUniforms {
|
|
39
|
+
viewMatrix: mat4x4f,
|
|
40
|
+
enabled: i32,
|
|
41
|
+
};
|
|
42
|
+
@group(0) @binding(auto) var<uniform> pbrShadow: PBRShadowUniforms;
|
|
43
|
+
fn pbrShadow_filterColorWithDirectionalContact(vertexColor: vec4f, worldPosition: vec3f, worldNormal: vec3f, contactVisibility: f32) -> vec4f {
|
|
44
|
+
var directionalVisibility = 1.0;
|
|
45
|
+
var pointVisibility = vec4f(1.0);
|
|
46
|
+
var spotVisibility = vec4f(1.0);
|
|
47
|
+
if (pbrShadow.enabled != 0) {
|
|
48
|
+
let normal = normalize(worldNormal);
|
|
49
|
+
let viewDepth = -(pbrShadow.viewMatrix * vec4f(worldPosition, 1.0)).z;
|
|
50
|
+
directionalVisibility = shadow_getDirectionalFactor(worldPosition, normal, viewDepth);
|
|
51
|
+
for (var index = 0; index < 4; index++) {
|
|
52
|
+
pointVisibility[index] = shadow_getPointFactor(index, worldPosition, normal);
|
|
53
|
+
spotVisibility[index] = shadow_getSpotFactor(index, worldPosition, normal);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return pbr_filterColorWithShadows(vertexColor, min(directionalVisibility, contactVisibility), pointVisibility, spotVisibility);
|
|
57
|
+
}
|
|
58
|
+
fn pbrShadow_filterColor(vertexColor: vec4f, worldPosition: vec3f, worldNormal: vec3f) -> vec4f {
|
|
59
|
+
return pbrShadow_filterColorWithDirectionalContact(vertexColor, worldPosition, worldNormal, 1.0);
|
|
60
|
+
}`,
|
|
61
|
+
|
|
62
|
+
fs: /* glsl */ `
|
|
63
|
+
layout(std140) uniform pbrShadowUniforms {
|
|
64
|
+
mat4 viewMatrix;
|
|
65
|
+
int enabled;
|
|
66
|
+
} pbrShadow;
|
|
67
|
+
vec4 pbrShadow_filterColorWithDirectionalContact(vec4 vertexColor, vec3 worldPosition, vec3 worldNormal, float contactVisibility) {
|
|
68
|
+
float directionalVisibility = 1.0;
|
|
69
|
+
vec4 pointVisibility = vec4(1.0);
|
|
70
|
+
vec4 spotVisibility = vec4(1.0);
|
|
71
|
+
if (pbrShadow.enabled != 0) {
|
|
72
|
+
vec3 normal = normalize(worldNormal);
|
|
73
|
+
float viewDepth = -(pbrShadow.viewMatrix * vec4(worldPosition, 1.0)).z;
|
|
74
|
+
directionalVisibility = shadow_getDirectionalFactor(worldPosition, normal, viewDepth);
|
|
75
|
+
for (int index = 0; index < 4; index++) {
|
|
76
|
+
pointVisibility[index] = shadow_getPointFactor(index, worldPosition, normal);
|
|
77
|
+
spotVisibility[index] = shadow_getSpotFactor(index, worldPosition, normal);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return pbr_filterColorWithShadows(vertexColor, min(directionalVisibility, contactVisibility), pointVisibility, spotVisibility);
|
|
81
|
+
}
|
|
82
|
+
vec4 pbrShadow_filterColor(vec4 vertexColor, vec3 worldPosition, vec3 worldNormal) {
|
|
83
|
+
return pbrShadow_filterColorWithDirectionalContact(vertexColor, worldPosition, worldNormal, 1.0);
|
|
84
|
+
}`
|
|
85
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
3
|
+
|
|
4
|
+
import type {NumberArray16} from '@math.gl/core';
|
|
5
|
+
import type {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
|
+
import {pbrMaterial} from '../pbr-material/pbr-material';
|
|
7
|
+
|
|
8
|
+
export type PBRSurfaceProps = {
|
|
9
|
+
/** Rigid world-to-view camera transform. Defaults to identity. */
|
|
10
|
+
viewMatrix?: Readonly<NumberArray16>;
|
|
11
|
+
/** Include canonical normal/bump maps instead of geometric normals. Defaults to false. */
|
|
12
|
+
useMaterialNormals?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type PBRSurfaceUniforms = {
|
|
16
|
+
viewMatrix: Readonly<NumberArray16>;
|
|
17
|
+
useMaterialNormals: number;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/** Encodes view-space PBR normals in RGB; alpha one marks covered surface pixels. */
|
|
21
|
+
export const pbrSurface: ShaderModule<PBRSurfaceProps, PBRSurfaceUniforms> = {
|
|
22
|
+
name: 'pbrSurface',
|
|
23
|
+
dependencies: [pbrMaterial],
|
|
24
|
+
bindingLayout: [{name: 'pbrSurface', group: 0}],
|
|
25
|
+
uniformTypes: {viewMatrix: 'mat4x4<f32>', useMaterialNormals: 'i32'},
|
|
26
|
+
defaultUniforms: {
|
|
27
|
+
viewMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
|
|
28
|
+
useMaterialNormals: 0
|
|
29
|
+
},
|
|
30
|
+
getUniforms(properties = {}) {
|
|
31
|
+
return {
|
|
32
|
+
...(properties.viewMatrix ? {viewMatrix: properties.viewMatrix} : {}),
|
|
33
|
+
...(properties.useMaterialNormals === undefined
|
|
34
|
+
? {}
|
|
35
|
+
: {useMaterialNormals: Number(properties.useMaterialNormals)})
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
source: /* wgsl */ `
|
|
39
|
+
struct PBRSurfaceUniforms {
|
|
40
|
+
viewMatrix: mat4x4f,
|
|
41
|
+
useMaterialNormals: i32,
|
|
42
|
+
};
|
|
43
|
+
@group(0) @binding(auto) var<uniform> pbrSurface: PBRSurfaceUniforms;
|
|
44
|
+
fn pbrSurface_getColor() -> vec4f {
|
|
45
|
+
#ifdef HAS_NORMALS
|
|
46
|
+
var normal = normalize(fragmentInputs.pbr_vNormal);
|
|
47
|
+
#ifdef DOUBLE_SIDED
|
|
48
|
+
if (!pbr_frontFacing) {normal = -normal;}
|
|
49
|
+
#endif
|
|
50
|
+
#else
|
|
51
|
+
var normal = normalize(cross(dpdy(fragmentInputs.pbr_vPosition), dpdx(fragmentInputs.pbr_vPosition)));
|
|
52
|
+
#endif
|
|
53
|
+
#ifdef HAS_NORMALMAP
|
|
54
|
+
if (pbrSurface.useMaterialNormals != 0) {
|
|
55
|
+
let coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
56
|
+
normal = getNormal(getTBN(coordinates), coordinates);
|
|
57
|
+
}
|
|
58
|
+
#else
|
|
59
|
+
#ifdef HAS_BUMPMAP
|
|
60
|
+
if (pbrSurface.useMaterialNormals != 0) {
|
|
61
|
+
let coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
62
|
+
normal = getNormal(getTBN(coordinates), coordinates);
|
|
63
|
+
}
|
|
64
|
+
#endif
|
|
65
|
+
#endif
|
|
66
|
+
let viewNormal = normalize((pbrSurface.viewMatrix * vec4f(normal, 0.0)).xyz);
|
|
67
|
+
return vec4f(viewNormal * 0.5 + vec3f(0.5), 1.0);
|
|
68
|
+
}`,
|
|
69
|
+
fs: /* glsl */ `
|
|
70
|
+
layout(std140) uniform pbrSurfaceUniforms {
|
|
71
|
+
mat4 viewMatrix;
|
|
72
|
+
int useMaterialNormals;
|
|
73
|
+
} pbrSurface;
|
|
74
|
+
vec4 pbrSurface_getColor() {
|
|
75
|
+
#ifdef HAS_NORMALS
|
|
76
|
+
#ifdef HAS_TANGENTS
|
|
77
|
+
vec3 normal = normalize(pbr_vTBN[2]);
|
|
78
|
+
#else
|
|
79
|
+
vec3 normal = normalize(pbr_vNormal);
|
|
80
|
+
#endif
|
|
81
|
+
#ifdef DOUBLE_SIDED
|
|
82
|
+
if (!gl_FrontFacing) normal = -normal;
|
|
83
|
+
#endif
|
|
84
|
+
#else
|
|
85
|
+
vec3 normal = normalize(cross(dFdx(pbr_vPosition), dFdy(pbr_vPosition)));
|
|
86
|
+
#endif
|
|
87
|
+
#ifdef HAS_NORMALMAP
|
|
88
|
+
if (pbrSurface.useMaterialNormals != 0) {
|
|
89
|
+
vec2 coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
90
|
+
normal = getNormal(getTBN(coordinates), coordinates);
|
|
91
|
+
}
|
|
92
|
+
#else
|
|
93
|
+
#ifdef HAS_BUMPMAP
|
|
94
|
+
if (pbrSurface.useMaterialNormals != 0) {
|
|
95
|
+
vec2 coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
|
|
96
|
+
normal = getNormal(getTBN(coordinates), coordinates);
|
|
97
|
+
}
|
|
98
|
+
#endif
|
|
99
|
+
#endif
|
|
100
|
+
vec3 viewNormal = normalize((pbrSurface.viewMatrix * vec4(normal, 0.0)).xyz);
|
|
101
|
+
return vec4(viewNormal * 0.5 + 0.5, 1.0);
|
|
102
|
+
}`
|
|
103
|
+
};
|