@luma.gl/shadertools 9.2.6 → 9.3.0-alpha.2
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 +209 -6100
- package/dist/dist.min.js +136 -80
- package/dist/index.cjs +128 -119
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +57 -0
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +82 -22
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +68 -2
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +33 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
- package/package.json +4 -5
- package/src/index.ts +9 -5
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +57 -0
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +82 -22
- package/src/modules/lighting/pbr-material/pbr-material.ts +88 -1
- package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts +0 -8
- package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +0 -1
- package/dist/lib/wgsl/get-shader-layout-wgsl.js +0 -95
- package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +0 -1
- package/src/lib/wgsl/get-shader-layout-wgsl.ts +0 -105
package/dist/index.cjs
CHANGED
|
@@ -45,7 +45,6 @@ __export(dist_exports, {
|
|
|
45
45
|
getPassthroughFS: () => getPassthroughFS,
|
|
46
46
|
getQualifierDetails: () => getQualifierDetails,
|
|
47
47
|
getShaderInfo: () => getShaderInfo,
|
|
48
|
-
getShaderLayoutFromWGSL: () => getShaderLayoutFromWGSL,
|
|
49
48
|
getShaderModuleDependencies: () => getShaderModuleDependencies,
|
|
50
49
|
getShaderModuleSource: () => getShaderModuleSource,
|
|
51
50
|
getShaderModuleUniforms: () => getShaderModuleUniforms,
|
|
@@ -310,15 +309,15 @@ function getShaderModuleUniforms(module2, props, oldUniforms) {
|
|
|
310
309
|
}
|
|
311
310
|
return getValidatedProperties(props, (_a = module2.instance) == null ? void 0 : _a.propValidators, module2.name);
|
|
312
311
|
}
|
|
313
|
-
function checkShaderModuleDeprecations(shaderModule, shaderSource,
|
|
312
|
+
function checkShaderModuleDeprecations(shaderModule, shaderSource, log2) {
|
|
314
313
|
var _a;
|
|
315
314
|
(_a = shaderModule.deprecations) == null ? void 0 : _a.forEach((def) => {
|
|
316
315
|
var _a2;
|
|
317
316
|
if ((_a2 = def.regex) == null ? void 0 : _a2.test(shaderSource)) {
|
|
318
317
|
if (def.deprecated) {
|
|
319
|
-
|
|
318
|
+
log2.deprecated(def.old, def.new)();
|
|
320
319
|
} else {
|
|
321
|
-
|
|
320
|
+
log2.removed(def.old, def.new)();
|
|
322
321
|
}
|
|
323
322
|
}
|
|
324
323
|
});
|
|
@@ -613,7 +612,7 @@ function assembleShaderWGSL(platformInfo, options) {
|
|
|
613
612
|
// defines = {},
|
|
614
613
|
hookFunctions = [],
|
|
615
614
|
inject = {},
|
|
616
|
-
log:
|
|
615
|
+
log: log2
|
|
617
616
|
} = options;
|
|
618
617
|
assert(typeof source3 === "string", "shader source must be a string");
|
|
619
618
|
const coreSource = source3;
|
|
@@ -643,8 +642,8 @@ function assembleShaderWGSL(platformInfo, options) {
|
|
|
643
642
|
}
|
|
644
643
|
const modulesToInject = modules;
|
|
645
644
|
for (const module2 of modulesToInject) {
|
|
646
|
-
if (
|
|
647
|
-
checkShaderModuleDeprecations(module2, coreSource,
|
|
645
|
+
if (log2) {
|
|
646
|
+
checkShaderModuleDeprecations(module2, coreSource, log2);
|
|
648
647
|
}
|
|
649
648
|
const moduleSource = getShaderModuleSource(module2, "wgsl");
|
|
650
649
|
assembledSource += moduleSource;
|
|
@@ -671,7 +670,7 @@ function assembleShaderWGSL(platformInfo, options) {
|
|
|
671
670
|
}
|
|
672
671
|
function assembleShaderGLSL(platformInfo, options) {
|
|
673
672
|
var _a;
|
|
674
|
-
const { source: source3, stage, language = "glsl", modules, defines = {}, hookFunctions = [], inject = {}, prologue = true, log:
|
|
673
|
+
const { source: source3, stage, language = "glsl", modules, defines = {}, hookFunctions = [], inject = {}, prologue = true, log: log2 } = options;
|
|
675
674
|
assert(typeof source3 === "string", "shader source must be a string");
|
|
676
675
|
const sourceVersion = language === "glsl" ? getShaderInfo(source3).version : -1;
|
|
677
676
|
const targetVersion = platformInfo.shaderLanguageVersion;
|
|
@@ -728,8 +727,8 @@ ${getApplicationDefines(allDefines)}
|
|
|
728
727
|
}
|
|
729
728
|
}
|
|
730
729
|
for (const module2 of modules) {
|
|
731
|
-
if (
|
|
732
|
-
checkShaderModuleDeprecations(module2, coreSource,
|
|
730
|
+
if (log2) {
|
|
731
|
+
checkShaderModuleDeprecations(module2, coreSource, log2);
|
|
733
732
|
}
|
|
734
733
|
const moduleSource = getShaderModuleSource(module2, stage);
|
|
735
734
|
assembledSource += moduleSource;
|
|
@@ -1135,97 +1134,15 @@ function generateShaderForModule(module2, options) {
|
|
|
1135
1134
|
}
|
|
1136
1135
|
}
|
|
1137
1136
|
|
|
1138
|
-
// dist/lib/wgsl/get-shader-layout-wgsl.js
|
|
1139
|
-
var import_core = require("@luma.gl/core");
|
|
1140
|
-
var import_wgsl_reflect = require("wgsl_reflect");
|
|
1141
|
-
function getShaderLayoutFromWGSL(source3) {
|
|
1142
|
-
var _a;
|
|
1143
|
-
const shaderLayout = { attributes: [], bindings: [] };
|
|
1144
|
-
let parsedWGSL;
|
|
1145
|
-
try {
|
|
1146
|
-
parsedWGSL = parseWGSL(source3);
|
|
1147
|
-
} catch (error) {
|
|
1148
|
-
import_core.log.error(error.message)();
|
|
1149
|
-
return shaderLayout;
|
|
1150
|
-
}
|
|
1151
|
-
for (const uniform of parsedWGSL.uniforms) {
|
|
1152
|
-
const members = [];
|
|
1153
|
-
for (const attribute of ((_a = uniform.type) == null ? void 0 : _a.members) || []) {
|
|
1154
|
-
members.push({
|
|
1155
|
-
name: attribute.name,
|
|
1156
|
-
type: getType(attribute.type)
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
shaderLayout.bindings.push({
|
|
1160
|
-
type: "uniform",
|
|
1161
|
-
name: uniform.name,
|
|
1162
|
-
group: uniform.group,
|
|
1163
|
-
location: uniform.binding,
|
|
1164
|
-
// @ts-expect-error TODO - unused for now but needs fixing
|
|
1165
|
-
members
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
for (const texture of parsedWGSL.textures) {
|
|
1169
|
-
shaderLayout.bindings.push({
|
|
1170
|
-
type: "texture",
|
|
1171
|
-
name: texture.name,
|
|
1172
|
-
group: texture.group,
|
|
1173
|
-
location: texture.binding
|
|
1174
|
-
});
|
|
1175
|
-
}
|
|
1176
|
-
for (const sampler of parsedWGSL.samplers) {
|
|
1177
|
-
shaderLayout.bindings.push({
|
|
1178
|
-
type: "sampler",
|
|
1179
|
-
name: sampler.name,
|
|
1180
|
-
group: sampler.group,
|
|
1181
|
-
location: sampler.binding
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
const vertex = parsedWGSL.entry.vertex[0];
|
|
1185
|
-
const attributeCount = (vertex == null ? void 0 : vertex.inputs.length) || 0;
|
|
1186
|
-
for (let i = 0; i < attributeCount; i++) {
|
|
1187
|
-
const wgslAttribute = vertex.inputs[i];
|
|
1188
|
-
if (wgslAttribute.locationType === "location") {
|
|
1189
|
-
const type = getType(wgslAttribute.type);
|
|
1190
|
-
shaderLayout.attributes.push({
|
|
1191
|
-
name: wgslAttribute.name,
|
|
1192
|
-
location: Number(wgslAttribute.location),
|
|
1193
|
-
type
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
}
|
|
1197
|
-
return shaderLayout;
|
|
1198
|
-
}
|
|
1199
|
-
function getType(type) {
|
|
1200
|
-
return (type == null ? void 0 : type.format) ? `${type.name}<${type.format.name}>` : type.name;
|
|
1201
|
-
}
|
|
1202
|
-
function parseWGSL(source3) {
|
|
1203
|
-
try {
|
|
1204
|
-
return new import_wgsl_reflect.WgslReflect(source3);
|
|
1205
|
-
} catch (error) {
|
|
1206
|
-
if (error instanceof Error) {
|
|
1207
|
-
throw error;
|
|
1208
|
-
}
|
|
1209
|
-
let message = "WGSL parse error";
|
|
1210
|
-
if (typeof error === "object" && (error == null ? void 0 : error.message)) {
|
|
1211
|
-
message += `: ${error.message} `;
|
|
1212
|
-
}
|
|
1213
|
-
if (typeof error === "object" && (error == null ? void 0 : error.token)) {
|
|
1214
|
-
message += error.token.line || "";
|
|
1215
|
-
}
|
|
1216
|
-
throw new Error(message, { cause: error });
|
|
1217
|
-
}
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
1137
|
// dist/modules/math/fp16/fp16-utils.js
|
|
1221
|
-
var
|
|
1138
|
+
var import_core = require("@math.gl/core");
|
|
1222
1139
|
var float16Tables = null;
|
|
1223
1140
|
var buffer = new ArrayBuffer(4);
|
|
1224
1141
|
var floatView = new Float32Array(buffer);
|
|
1225
1142
|
var uint32View = new Uint32Array(buffer);
|
|
1226
1143
|
function toHalfFloat(val) {
|
|
1227
1144
|
float16Tables ||= generateFloat16Tables();
|
|
1228
|
-
val = (0,
|
|
1145
|
+
val = (0, import_core.clamp)(val, -65504, 65504);
|
|
1229
1146
|
floatView[0] = val;
|
|
1230
1147
|
const f = uint32View[0];
|
|
1231
1148
|
const e = f >> 23 & 511;
|
|
@@ -2571,7 +2488,7 @@ function getUniforms(opts = {}, prevUniforms) {
|
|
|
2571
2488
|
}
|
|
2572
2489
|
|
|
2573
2490
|
// dist/modules/lighting/lights/lighting.js
|
|
2574
|
-
var
|
|
2491
|
+
var import_core2 = require("@luma.gl/core");
|
|
2575
2492
|
|
|
2576
2493
|
// dist/modules/lighting/lights/lighting-glsl.js
|
|
2577
2494
|
var lightingUniformsGLSL = (
|
|
@@ -2814,7 +2731,7 @@ function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLig
|
|
|
2814
2731
|
currentLight++;
|
|
2815
2732
|
}
|
|
2816
2733
|
if (currentLight > MAX_LIGHTS) {
|
|
2817
|
-
|
|
2734
|
+
import_core2.log.warn("MAX_LIGHTS exceeded")();
|
|
2818
2735
|
}
|
|
2819
2736
|
lightSourceUniforms.directionalLightCount = directionalLights.length;
|
|
2820
2737
|
lightSourceUniforms.pointLightCount = pointLights.length;
|
|
@@ -3212,6 +3129,40 @@ uniform pbrMaterialUniforms {
|
|
|
3212
3129
|
|
|
3213
3130
|
bool alphaCutoffEnabled;
|
|
3214
3131
|
float alphaCutoff; // #ifdef ALPHA_CUTOFF
|
|
3132
|
+
|
|
3133
|
+
vec3 specularColorFactor;
|
|
3134
|
+
float specularIntensityFactor;
|
|
3135
|
+
bool specularColorMapEnabled;
|
|
3136
|
+
bool specularIntensityMapEnabled;
|
|
3137
|
+
|
|
3138
|
+
float ior;
|
|
3139
|
+
|
|
3140
|
+
float transmissionFactor;
|
|
3141
|
+
bool transmissionMapEnabled;
|
|
3142
|
+
|
|
3143
|
+
float thicknessFactor;
|
|
3144
|
+
float attenuationDistance;
|
|
3145
|
+
vec3 attenuationColor;
|
|
3146
|
+
|
|
3147
|
+
float clearcoatFactor;
|
|
3148
|
+
float clearcoatRoughnessFactor;
|
|
3149
|
+
bool clearcoatMapEnabled;
|
|
3150
|
+
|
|
3151
|
+
vec3 sheenColorFactor;
|
|
3152
|
+
float sheenRoughnessFactor;
|
|
3153
|
+
bool sheenColorMapEnabled;
|
|
3154
|
+
|
|
3155
|
+
float iridescenceFactor;
|
|
3156
|
+
float iridescenceIor;
|
|
3157
|
+
vec2 iridescenceThicknessRange;
|
|
3158
|
+
bool iridescenceMapEnabled;
|
|
3159
|
+
|
|
3160
|
+
float anisotropyStrength;
|
|
3161
|
+
float anisotropyRotation;
|
|
3162
|
+
vec2 anisotropyDirection;
|
|
3163
|
+
bool anisotropyMapEnabled;
|
|
3164
|
+
|
|
3165
|
+
float emissiveStrength;
|
|
3215
3166
|
|
|
3216
3167
|
// IBL
|
|
3217
3168
|
bool IBLenabled;
|
|
@@ -3240,6 +3191,29 @@ uniform sampler2D pbr_metallicRoughnessSampler;
|
|
|
3240
3191
|
#ifdef HAS_OCCLUSIONMAP
|
|
3241
3192
|
uniform sampler2D pbr_occlusionSampler;
|
|
3242
3193
|
#endif
|
|
3194
|
+
#ifdef HAS_SPECULARCOLORMAP
|
|
3195
|
+
uniform sampler2D pbr_specularColorSampler;
|
|
3196
|
+
#endif
|
|
3197
|
+
#ifdef HAS_SPECULARINTENSITYMAP
|
|
3198
|
+
uniform sampler2D pbr_specularIntensitySampler;
|
|
3199
|
+
#endif
|
|
3200
|
+
#ifdef HAS_TRANSMISSIONMAP
|
|
3201
|
+
uniform sampler2D pbr_transmissionSampler;
|
|
3202
|
+
#endif
|
|
3203
|
+
#ifdef HAS_CLEARCOATMAP
|
|
3204
|
+
uniform sampler2D pbr_clearcoatSampler;
|
|
3205
|
+
uniform sampler2D pbr_clearcoatRoughnessSampler;
|
|
3206
|
+
#endif
|
|
3207
|
+
#ifdef HAS_SHEENCOLORMAP
|
|
3208
|
+
uniform sampler2D pbr_sheenColorSampler;
|
|
3209
|
+
uniform sampler2D pbr_sheenRoughnessSampler;
|
|
3210
|
+
#endif
|
|
3211
|
+
#ifdef HAS_IRIDESCENCEMAP
|
|
3212
|
+
uniform sampler2D pbr_iridescenceSampler;
|
|
3213
|
+
#endif
|
|
3214
|
+
#ifdef HAS_ANISOTROPYMAP
|
|
3215
|
+
uniform sampler2D pbr_anisotropySampler;
|
|
3216
|
+
#endif
|
|
3243
3217
|
#ifdef USE_IBL
|
|
3244
3218
|
uniform samplerCube pbr_diffuseEnvSampler;
|
|
3245
3219
|
uniform samplerCube pbr_specularEnvSampler;
|
|
@@ -3607,23 +3581,23 @@ var fragmentInputs: PBRFragmentInputs;
|
|
|
3607
3581
|
fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)
|
|
3608
3582
|
{
|
|
3609
3583
|
var pos: vec4f = pbrProjection.modelMatrix * position;
|
|
3610
|
-
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
3584
|
+
fragmentInputs.pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
3611
3585
|
|
|
3612
3586
|
#ifdef HAS_NORMALS
|
|
3613
3587
|
#ifdef HAS_TANGENTS
|
|
3614
3588
|
let normalW: vec3f = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
|
|
3615
3589
|
let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
|
|
3616
3590
|
let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;
|
|
3617
|
-
fragmentInputs
|
|
3591
|
+
fragmentInputs.pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
3618
3592
|
#else // HAS_TANGENTS != 1
|
|
3619
3593
|
fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
|
|
3620
3594
|
#endif
|
|
3621
3595
|
#endif
|
|
3622
3596
|
|
|
3623
3597
|
#ifdef HAS_UV
|
|
3624
|
-
pbr_vUV = uv;
|
|
3598
|
+
fragmentInputs.pbr_vUV = uv;
|
|
3625
3599
|
#else
|
|
3626
|
-
pbr_vUV = vec2(0.,0.);
|
|
3600
|
+
fragmentInputs.pbr_vUV = vec2(0.,0.);
|
|
3627
3601
|
#endif
|
|
3628
3602
|
}
|
|
3629
3603
|
|
|
@@ -3659,9 +3633,9 @@ struct pbrMaterialUniforms {
|
|
|
3659
3633
|
scaleDiffBaseMR: vec4f,
|
|
3660
3634
|
scaleFGDSpec: vec4f
|
|
3661
3635
|
// #endif
|
|
3662
|
-
}
|
|
3663
|
-
|
|
3664
|
-
@binding(2) @group(0) var<uniform>
|
|
3636
|
+
}
|
|
3637
|
+
|
|
3638
|
+
@binding(2) @group(0) var<uniform> pbrMaterial : pbrMaterialUniforms;
|
|
3665
3639
|
|
|
3666
3640
|
// Samplers
|
|
3667
3641
|
#ifdef HAS_BASECOLORMAP
|
|
@@ -3729,14 +3703,14 @@ fn getNormal() -> vec3f
|
|
|
3729
3703
|
{
|
|
3730
3704
|
// Retrieve the tangent space matrix
|
|
3731
3705
|
#ifndef HAS_TANGENTS
|
|
3732
|
-
var pos_dx: vec3f = dFdx(pbr_vPosition);
|
|
3733
|
-
var pos_dy: vec3f = dFdy(pbr_vPosition);
|
|
3734
|
-
var tex_dx: vec3f = dFdx(vec3(pbr_vUV, 0.0));
|
|
3735
|
-
var tex_dy: vec3f = dFdy(vec3(pbr_vUV, 0.0));
|
|
3706
|
+
var pos_dx: vec3f = dFdx(fragmentInputs.pbr_vPosition);
|
|
3707
|
+
var pos_dy: vec3f = dFdy(fragmentInputs.pbr_vPosition);
|
|
3708
|
+
var tex_dx: vec3f = dFdx(vec3(fragmentInputs.pbr_vUV, 0.0));
|
|
3709
|
+
var tex_dy: vec3f = dFdy(vec3(fragmentInputs.pbr_vUV, 0.0));
|
|
3736
3710
|
var t: vec3f = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
|
|
3737
3711
|
|
|
3738
3712
|
#ifdef HAS_NORMALS
|
|
3739
|
-
var ng: vec3f = normalize(pbr_vNormal);
|
|
3713
|
+
var ng: vec3f = normalize(fragmentInputs.pbr_vNormal);
|
|
3740
3714
|
#else
|
|
3741
3715
|
var ng: vec3f = cross(pos_dx, pos_dy);
|
|
3742
3716
|
#endif
|
|
@@ -3745,11 +3719,11 @@ fn getNormal() -> vec3f
|
|
|
3745
3719
|
var b: vec3f = normalize(cross(ng, t));
|
|
3746
3720
|
var tbn: mat3f = mat3f(t, b, ng);
|
|
3747
3721
|
#else // HAS_TANGENTS
|
|
3748
|
-
var tbn: mat3f = pbr_vTBN;
|
|
3722
|
+
var tbn: mat3f = fragmentInputs.pbr_vTBN;
|
|
3749
3723
|
#endif
|
|
3750
3724
|
|
|
3751
3725
|
#ifdef HAS_NORMALMAP
|
|
3752
|
-
vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
|
|
3726
|
+
vec3 n = texture(pbr_normalSampler, fragmentInputs.pbr_vUV).rgb;
|
|
3753
3727
|
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
3754
3728
|
#else
|
|
3755
3729
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
@@ -3793,7 +3767,7 @@ fn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f
|
|
|
3793
3767
|
// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
|
|
3794
3768
|
// See also [1], Equation 1
|
|
3795
3769
|
fn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {
|
|
3796
|
-
return pbrInfo.diffuseColor /
|
|
3770
|
+
return pbrInfo.diffuseColor / M_PI;
|
|
3797
3771
|
}
|
|
3798
3772
|
|
|
3799
3773
|
// The following equation models the Fresnel reflectance term of the spec equation (aka F())
|
|
@@ -3850,7 +3824,7 @@ fn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection:
|
|
|
3850
3824
|
}
|
|
3851
3825
|
|
|
3852
3826
|
fn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {
|
|
3853
|
-
let light_direction = normalize(pointLight.position - pbr_vPosition);
|
|
3827
|
+
let light_direction = normalize(pointLight.position - fragmentInputs.pbr_vPosition);
|
|
3854
3828
|
PBRInfo_setDirectionalLight(pbrInfo, light_direction);
|
|
3855
3829
|
}
|
|
3856
3830
|
|
|
@@ -3871,7 +3845,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3871
3845
|
// The albedo may be defined from a base texture or a flat color
|
|
3872
3846
|
var baseColor: vec4<f32>;
|
|
3873
3847
|
#ifdef HAS_BASECOLORMAP
|
|
3874
|
-
baseColor = SRGBtoLINEAR(textureSample(pbr_baseColorSampler, pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
|
|
3848
|
+
baseColor = SRGBtoLINEAR(textureSample(pbr_baseColorSampler, pbr_baseColorSampler, fragmentInputs.pbr_vUV)) * pbrMaterial.baseColorFactor;
|
|
3875
3849
|
#else
|
|
3876
3850
|
baseColor = pbrMaterial.baseColorFactor;
|
|
3877
3851
|
#endif
|
|
@@ -3895,7 +3869,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3895
3869
|
#ifdef HAS_METALROUGHNESSMAP
|
|
3896
3870
|
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
3897
3871
|
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
3898
|
-
let mrSample = textureSample(pbr_metallicRoughnessSampler, pbr_metallicRoughnessSampler, pbr_vUV);
|
|
3872
|
+
let mrSample = textureSample(pbr_metallicRoughnessSampler, pbr_metallicRoughnessSampler, fragmentInputs.pbr_vUV);
|
|
3899
3873
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
3900
3874
|
metallic = mrSample.b * metallic;
|
|
3901
3875
|
#endif
|
|
@@ -3922,7 +3896,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3922
3896
|
let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;
|
|
3923
3897
|
|
|
3924
3898
|
let n = getNormal(); // normal at surface point
|
|
3925
|
-
let v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
|
|
3899
|
+
let v = normalize(pbrProjection.camera - fragmentInputs.pbr_vPosition); // Vector from surface point to camera
|
|
3926
3900
|
|
|
3927
3901
|
let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
3928
3902
|
let reflection = -normalize(reflect(v, n));
|
|
@@ -3961,7 +3935,10 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3961
3935
|
for (var i = 0; i < lighting.pointLightCount; i++) {
|
|
3962
3936
|
if (i < lighting.pointLightCount) {
|
|
3963
3937
|
PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));
|
|
3964
|
-
let attenuation = getPointLightAttenuation(
|
|
3938
|
+
let attenuation = getPointLightAttenuation(
|
|
3939
|
+
lighting_getPointLight(i),
|
|
3940
|
+
distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)
|
|
3941
|
+
);
|
|
3965
3942
|
color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
|
|
3966
3943
|
}
|
|
3967
3944
|
}
|
|
@@ -3977,14 +3954,14 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
3977
3954
|
// Apply optional PBR terms for additional (optional) shading
|
|
3978
3955
|
#ifdef HAS_OCCLUSIONMAP
|
|
3979
3956
|
if (pbrMaterial.occlusionMapEnabled) {
|
|
3980
|
-
let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSampler, pbr_vUV).r;
|
|
3957
|
+
let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSampler, fragmentInputs.pbr_vUV).r;
|
|
3981
3958
|
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
3982
3959
|
}
|
|
3983
3960
|
#endif
|
|
3984
3961
|
|
|
3985
3962
|
#ifdef HAS_EMISSIVEMAP
|
|
3986
3963
|
if (pbrMaterial.emissiveMapEnabled) {
|
|
3987
|
-
let emissive = SRGBtoLINEAR(textureSample(pbr_emissiveSampler, pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
|
|
3964
|
+
let emissive = SRGBtoLINEAR(textureSample(pbr_emissiveSampler, pbr_emissiveSampler, fragmentInputs.pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
|
|
3988
3965
|
color += emissive;
|
|
3989
3966
|
}
|
|
3990
3967
|
#endif
|
|
@@ -4052,6 +4029,13 @@ var pbrMaterial = {
|
|
|
4052
4029
|
HAS_OCCLUSIONMAP: false,
|
|
4053
4030
|
HAS_BASECOLORMAP: false,
|
|
4054
4031
|
HAS_METALROUGHNESSMAP: false,
|
|
4032
|
+
HAS_SPECULARCOLORMAP: false,
|
|
4033
|
+
HAS_SPECULARINTENSITYMAP: false,
|
|
4034
|
+
HAS_TRANSMISSIONMAP: false,
|
|
4035
|
+
HAS_CLEARCOATMAP: false,
|
|
4036
|
+
HAS_SHEENCOLORMAP: false,
|
|
4037
|
+
HAS_IRIDESCENCEMAP: false,
|
|
4038
|
+
HAS_ANISOTROPYMAP: false,
|
|
4055
4039
|
ALPHA_CUTOFF: false,
|
|
4056
4040
|
USE_IBL: false,
|
|
4057
4041
|
PBR_DEBUG: false
|
|
@@ -4084,7 +4068,32 @@ var pbrMaterial = {
|
|
|
4084
4068
|
// debugging flags used for shader output of intermediate PBR variables
|
|
4085
4069
|
// #ifdef PBR_DEBUG
|
|
4086
4070
|
scaleDiffBaseMR: "vec4<f32>",
|
|
4087
|
-
scaleFGDSpec: "vec4<f32>"
|
|
4071
|
+
scaleFGDSpec: "vec4<f32>",
|
|
4072
|
+
specularColorFactor: "vec3<f32>",
|
|
4073
|
+
specularIntensityFactor: "f32",
|
|
4074
|
+
specularColorMapEnabled: "i32",
|
|
4075
|
+
specularIntensityMapEnabled: "i32",
|
|
4076
|
+
ior: "f32",
|
|
4077
|
+
transmissionFactor: "f32",
|
|
4078
|
+
transmissionMapEnabled: "i32",
|
|
4079
|
+
thicknessFactor: "f32",
|
|
4080
|
+
attenuationDistance: "f32",
|
|
4081
|
+
attenuationColor: "vec3<f32>",
|
|
4082
|
+
clearcoatFactor: "f32",
|
|
4083
|
+
clearcoatRoughnessFactor: "f32",
|
|
4084
|
+
clearcoatMapEnabled: "i32",
|
|
4085
|
+
sheenColorFactor: "vec3<f32>",
|
|
4086
|
+
sheenRoughnessFactor: "f32",
|
|
4087
|
+
sheenColorMapEnabled: "i32",
|
|
4088
|
+
iridescenceFactor: "f32",
|
|
4089
|
+
iridescenceIor: "f32",
|
|
4090
|
+
iridescenceThicknessRange: "vec2<f32>",
|
|
4091
|
+
iridescenceMapEnabled: "i32",
|
|
4092
|
+
anisotropyStrength: "f32",
|
|
4093
|
+
anisotropyRotation: "f32",
|
|
4094
|
+
anisotropyDirection: "vec2<f32>",
|
|
4095
|
+
anisotropyMapEnabled: "i32",
|
|
4096
|
+
emissiveStrength: "f32"
|
|
4088
4097
|
}
|
|
4089
4098
|
};
|
|
4090
4099
|
//# sourceMappingURL=index.cjs.map
|