@luma.gl/shadertools 9.3.0-alpha.2 → 9.3.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +2114 -198
- package/dist/dist.min.js +315 -184
- package/dist/index.cjs +463 -199
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
- package/dist/lib/preprocessor/preprocessor.js +33 -7
- package/dist/lib/preprocessor/preprocessor.js.map +1 -1
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +8 -1
- package/dist/lib/shader-assembler.js.map +1 -1
- package/dist/lib/shader-module/shader-module.d.ts +1 -1
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/utils/assert.d.ts.map +1 -1
- package/dist/lib/utils/assert.js +3 -1
- package/dist/lib/utils/assert.js.map +1 -1
- package/dist/modules/engine/skin/skin.d.ts +29 -0
- package/dist/modules/engine/skin/skin.d.ts.map +1 -0
- package/dist/modules/engine/skin/skin.js +88 -0
- package/dist/modules/engine/skin/skin.js.map +1 -0
- package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.js +20 -2
- package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.js +63 -13
- package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +27 -3
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +32 -6
- package/dist/modules/lighting/lights/lighting.js.map +1 -1
- 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 +106 -79
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +20 -4
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js +12 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +40 -76
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
- package/dist/modules/math/random/random.d.ts +1 -1
- package/dist/modules/math/random/random.d.ts.map +1 -1
- package/dist/modules/math/random/random.js +2 -3
- package/dist/modules/math/random/random.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/lib/preprocessor/preprocessor.ts +40 -7
- package/src/lib/shader-assembler.ts +8 -1
- package/src/lib/shader-module/shader-module.ts +1 -1
- package/src/lib/utils/assert.ts +3 -1
- package/src/modules/engine/skin/skin.ts +116 -0
- package/src/modules/lighting/lights/lighting-glsl.ts +20 -2
- package/src/modules/lighting/lights/lighting-wgsl.ts +63 -13
- package/src/modules/lighting/lights/lighting.ts +45 -9
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +106 -79
- package/src/modules/lighting/pbr-material/pbr-projection.ts +13 -1
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +40 -77
- package/src/modules/math/random/random.ts +2 -3
|
@@ -134,51 +134,55 @@ export const source = /* wgsl */ `\
|
|
|
134
134
|
struct PBRFragmentInputs {
|
|
135
135
|
pbr_vPosition: vec3f,
|
|
136
136
|
pbr_vUV: vec2f,
|
|
137
|
-
pbr_vTBN:
|
|
137
|
+
pbr_vTBN: mat3x3f,
|
|
138
138
|
pbr_vNormal: vec3f
|
|
139
139
|
};
|
|
140
140
|
|
|
141
|
-
var fragmentInputs: PBRFragmentInputs;
|
|
141
|
+
var<private> fragmentInputs: PBRFragmentInputs;
|
|
142
142
|
|
|
143
143
|
fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)
|
|
144
144
|
{
|
|
145
145
|
var pos: vec4f = pbrProjection.modelMatrix * position;
|
|
146
|
-
fragmentInputs.pbr_vPosition =
|
|
146
|
+
fragmentInputs.pbr_vPosition = pos.xyz / pos.w;
|
|
147
|
+
fragmentInputs.pbr_vNormal = vec3f(0.0, 0.0, 1.0);
|
|
148
|
+
fragmentInputs.pbr_vTBN = mat3x3f(
|
|
149
|
+
vec3f(1.0, 0.0, 0.0),
|
|
150
|
+
vec3f(0.0, 1.0, 0.0),
|
|
151
|
+
vec3f(0.0, 0.0, 1.0)
|
|
152
|
+
);
|
|
153
|
+
fragmentInputs.pbr_vUV = vec2f(0.0, 0.0);
|
|
147
154
|
|
|
148
155
|
#ifdef HAS_NORMALS
|
|
156
|
+
let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);
|
|
157
|
+
fragmentInputs.pbr_vNormal = normalW;
|
|
149
158
|
#ifdef HAS_TANGENTS
|
|
150
|
-
let
|
|
151
|
-
let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
|
|
159
|
+
let tangentW: vec3f = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);
|
|
152
160
|
let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;
|
|
153
|
-
fragmentInputs.pbr_vTBN =
|
|
154
|
-
#else // HAS_TANGENTS != 1
|
|
155
|
-
fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
|
|
161
|
+
fragmentInputs.pbr_vTBN = mat3x3f(tangentW, bitangentW, normalW);
|
|
156
162
|
#endif
|
|
157
163
|
#endif
|
|
158
164
|
|
|
159
165
|
#ifdef HAS_UV
|
|
160
166
|
fragmentInputs.pbr_vUV = uv;
|
|
161
|
-
#else
|
|
162
|
-
fragmentInputs.pbr_vUV = vec2(0.,0.);
|
|
163
167
|
#endif
|
|
164
168
|
}
|
|
165
169
|
|
|
166
170
|
struct pbrMaterialUniforms {
|
|
167
171
|
// Material is unlit
|
|
168
|
-
unlit:
|
|
172
|
+
unlit: u32,
|
|
169
173
|
|
|
170
174
|
// Base color map
|
|
171
|
-
baseColorMapEnabled:
|
|
175
|
+
baseColorMapEnabled: u32,
|
|
172
176
|
baseColorFactor: vec4f,
|
|
173
177
|
|
|
174
|
-
normalMapEnabled :
|
|
178
|
+
normalMapEnabled : u32,
|
|
175
179
|
normalScale: f32, // #ifdef HAS_NORMALMAP
|
|
176
180
|
|
|
177
|
-
emissiveMapEnabled:
|
|
181
|
+
emissiveMapEnabled: u32,
|
|
178
182
|
emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP
|
|
179
183
|
|
|
180
184
|
metallicRoughnessValues: vec2f,
|
|
181
|
-
metallicRoughnessMapEnabled:
|
|
185
|
+
metallicRoughnessMapEnabled: u32,
|
|
182
186
|
|
|
183
187
|
occlusionMapEnabled: i32,
|
|
184
188
|
occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP
|
|
@@ -193,7 +197,7 @@ struct pbrMaterialUniforms {
|
|
|
193
197
|
// debugging flags used for shader output of intermediate PBR variables
|
|
194
198
|
// #ifdef PBR_DEBUG
|
|
195
199
|
scaleDiffBaseMR: vec4f,
|
|
196
|
-
scaleFGDSpec: vec4f
|
|
200
|
+
scaleFGDSpec: vec4f,
|
|
197
201
|
// #endif
|
|
198
202
|
}
|
|
199
203
|
|
|
@@ -201,24 +205,32 @@ struct pbrMaterialUniforms {
|
|
|
201
205
|
|
|
202
206
|
// Samplers
|
|
203
207
|
#ifdef HAS_BASECOLORMAP
|
|
204
|
-
|
|
208
|
+
@binding(3) @group(0) var pbr_baseColorSampler: texture_2d<f32>;
|
|
209
|
+
@binding(4) @group(0) var pbr_baseColorSamplerSampler: sampler;
|
|
205
210
|
#endif
|
|
206
211
|
#ifdef HAS_NORMALMAP
|
|
207
|
-
|
|
212
|
+
@binding(5) @group(0) var pbr_normalSampler: texture_2d<f32>;
|
|
213
|
+
@binding(6) @group(0) var pbr_normalSamplerSampler: sampler;
|
|
208
214
|
#endif
|
|
209
215
|
#ifdef HAS_EMISSIVEMAP
|
|
210
|
-
|
|
216
|
+
@binding(7) @group(0) var pbr_emissiveSampler: texture_2d<f32>;
|
|
217
|
+
@binding(8) @group(0) var pbr_emissiveSamplerSampler: sampler;
|
|
211
218
|
#endif
|
|
212
219
|
#ifdef HAS_METALROUGHNESSMAP
|
|
213
|
-
|
|
220
|
+
@binding(9) @group(0) var pbr_metallicRoughnessSampler: texture_2d<f32>;
|
|
221
|
+
@binding(10) @group(0) var pbr_metallicRoughnessSamplerSampler: sampler;
|
|
214
222
|
#endif
|
|
215
223
|
#ifdef HAS_OCCLUSIONMAP
|
|
216
|
-
|
|
224
|
+
@binding(11) @group(0) var pbr_occlusionSampler: texture_2d<f32>;
|
|
225
|
+
@binding(12) @group(0) var pbr_occlusionSamplerSampler: sampler;
|
|
217
226
|
#endif
|
|
218
227
|
#ifdef USE_IBL
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
228
|
+
@binding(13) @group(0) var pbr_diffuseEnvSampler: texture_cube<f32>;
|
|
229
|
+
@binding(14) @group(0) var pbr_diffuseEnvSamplerSampler: sampler;
|
|
230
|
+
@binding(15) @group(0) var pbr_specularEnvSampler: texture_cube<f32>;
|
|
231
|
+
@binding(16) @group(0) var pbr_specularEnvSamplerSampler: sampler;
|
|
232
|
+
@binding(17) @group(0) var pbr_BrdfLUT: texture_2d<f32>;
|
|
233
|
+
@binding(18) @group(0) var pbr_BrdfLUTSampler: sampler;
|
|
222
234
|
#endif
|
|
223
235
|
|
|
224
236
|
// Encapsulate the various inputs used by the various functions in the shading equation
|
|
@@ -246,17 +258,19 @@ const c_MinRoughness = 0.04;
|
|
|
246
258
|
|
|
247
259
|
fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
|
|
248
260
|
{
|
|
261
|
+
var linOut: vec3f = srgbIn.xyz;
|
|
249
262
|
#ifdef MANUAL_SRGB
|
|
263
|
+
let bLess: vec3f = step(vec3f(0.04045), srgbIn.xyz);
|
|
264
|
+
linOut = mix(
|
|
265
|
+
srgbIn.xyz / vec3f(12.92),
|
|
266
|
+
pow((srgbIn.xyz + vec3f(0.055)) / vec3f(1.055), vec3f(2.4)),
|
|
267
|
+
bLess
|
|
268
|
+
);
|
|
250
269
|
#ifdef SRGB_FAST_APPROXIMATION
|
|
251
|
-
|
|
252
|
-
#
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
#endif //SRGB_FAST_APPROXIMATION
|
|
256
|
-
return vec4f(linOut,srgbIn.w);;
|
|
257
|
-
#else //MANUAL_SRGB
|
|
258
|
-
return srgbIn;
|
|
259
|
-
#endif //MANUAL_SRGB
|
|
270
|
+
linOut = pow(srgbIn.xyz, vec3f(2.2));
|
|
271
|
+
#endif
|
|
272
|
+
#endif
|
|
273
|
+
return vec4f(linOut, srgbIn.w);
|
|
260
274
|
}
|
|
261
275
|
|
|
262
276
|
// Find the normal for this fragment, pulling either from a predefined normal map
|
|
@@ -264,32 +278,28 @@ fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
|
|
|
264
278
|
fn getNormal() -> vec3f
|
|
265
279
|
{
|
|
266
280
|
// Retrieve the tangent space matrix
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
var
|
|
272
|
-
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);
|
|
281
|
+
let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);
|
|
282
|
+
let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);
|
|
283
|
+
let tex_dx: vec3f = dpdx(vec3f(fragmentInputs.pbr_vUV, 0.0));
|
|
284
|
+
let tex_dy: vec3f = dpdy(vec3f(fragmentInputs.pbr_vUV, 0.0));
|
|
285
|
+
var t: vec3f = (tex_dy.y * pos_dx - tex_dx.y * pos_dy) / (tex_dx.x * tex_dy.y - tex_dy.x * tex_dx.y);
|
|
273
286
|
|
|
274
|
-
#ifdef HAS_NORMALS
|
|
275
|
-
var ng: vec3f = normalize(fragmentInputs.pbr_vNormal);
|
|
276
|
-
#else
|
|
277
287
|
var ng: vec3f = cross(pos_dx, pos_dy);
|
|
288
|
+
#ifdef HAS_NORMALS
|
|
289
|
+
ng = normalize(fragmentInputs.pbr_vNormal);
|
|
278
290
|
#endif
|
|
279
|
-
|
|
280
291
|
t = normalize(t - ng * dot(ng, t));
|
|
281
292
|
var b: vec3f = normalize(cross(ng, t));
|
|
282
|
-
var tbn:
|
|
283
|
-
#
|
|
284
|
-
|
|
293
|
+
var tbn: mat3x3f = mat3x3f(t, b, ng);
|
|
294
|
+
#ifdef HAS_TANGENTS
|
|
295
|
+
tbn = fragmentInputs.pbr_vTBN;
|
|
285
296
|
#endif
|
|
286
297
|
|
|
287
|
-
#ifdef HAS_NORMALMAP
|
|
288
|
-
vec3 n = texture(pbr_normalSampler, fragmentInputs.pbr_vUV).rgb;
|
|
289
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
290
|
-
#else
|
|
291
298
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
292
|
-
|
|
299
|
+
var n: vec3f = normalize(tbn[2].xyz);
|
|
300
|
+
#ifdef HAS_NORMALMAP
|
|
301
|
+
n = textureSample(pbr_normalSampler, pbr_normalSamplerSampler, fragmentInputs.pbr_vUV).rgb;
|
|
302
|
+
n = normalize(tbn * ((2.0 * n - 1.0) * vec3f(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
293
303
|
#endif
|
|
294
304
|
|
|
295
305
|
return n;
|
|
@@ -299,27 +309,37 @@ fn getNormal() -> vec3f
|
|
|
299
309
|
// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
|
|
300
310
|
// See our README.md on Environment Maps [3] for additional discussion.
|
|
301
311
|
#ifdef USE_IBL
|
|
302
|
-
fn getIBLContribution(PBRInfo
|
|
312
|
+
fn getIBLContribution(pbrInfo: PBRInfo, n: vec3f, reflection: vec3f) -> vec3f
|
|
303
313
|
{
|
|
304
|
-
|
|
305
|
-
|
|
314
|
+
let mipCount: f32 = 9.0; // resolution of 512x512
|
|
315
|
+
let lod: f32 = pbrInfo.perceptualRoughness * mipCount;
|
|
306
316
|
// retrieve a scale and bias to F0. See [1], Figure 3
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
317
|
+
let brdf = SRGBtoLINEAR(
|
|
318
|
+
textureSample(
|
|
319
|
+
pbr_BrdfLUT,
|
|
320
|
+
pbr_BrdfLUTSampler,
|
|
321
|
+
vec2f(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness)
|
|
322
|
+
)
|
|
323
|
+
).rgb;
|
|
324
|
+
let diffuseLight =
|
|
325
|
+
SRGBtoLINEAR(textureSample(pbr_diffuseEnvSampler, pbr_diffuseEnvSamplerSampler, n)).rgb;
|
|
326
|
+
let specularLightDefault =
|
|
327
|
+
SRGBtoLINEAR(textureSample(pbr_specularEnvSampler, pbr_specularEnvSamplerSampler, reflection)).rgb;
|
|
328
|
+
var specularLight = specularLightDefault;
|
|
311
329
|
#ifdef USE_TEX_LOD
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
330
|
+
specularLight = SRGBtoLINEAR(
|
|
331
|
+
textureSampleLevel(
|
|
332
|
+
pbr_specularEnvSampler,
|
|
333
|
+
pbr_specularEnvSamplerSampler,
|
|
334
|
+
reflection,
|
|
335
|
+
lod
|
|
336
|
+
)
|
|
337
|
+
).rgb;
|
|
315
338
|
#endif
|
|
316
339
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
// For presentation, this allows us to disable IBL terms
|
|
321
|
-
diffuse *= pbrMaterial.scaleIBLAmbient.x;
|
|
322
|
-
specular *= pbrMaterial.scaleIBLAmbient.y;
|
|
340
|
+
let diffuse = diffuseLight * pbrInfo.diffuseColor * pbrMaterial.scaleIBLAmbient.x;
|
|
341
|
+
let specular =
|
|
342
|
+
specularLight * (pbrInfo.specularColor * brdf.x + brdf.y) * pbrMaterial.scaleIBLAmbient.y;
|
|
323
343
|
|
|
324
344
|
return diffuse + specular;
|
|
325
345
|
}
|
|
@@ -363,7 +383,7 @@ fn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {
|
|
|
363
383
|
fn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {
|
|
364
384
|
let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
|
|
365
385
|
let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
|
|
366
|
-
return roughnessSq / (
|
|
386
|
+
return roughnessSq / (M_PI * f * f);
|
|
367
387
|
}
|
|
368
388
|
|
|
369
389
|
fn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {
|
|
@@ -405,11 +425,11 @@ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
|
|
|
405
425
|
|
|
406
426
|
fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
407
427
|
// The albedo may be defined from a base texture or a flat color
|
|
408
|
-
var baseColor: vec4<f32
|
|
428
|
+
var baseColor: vec4<f32> = pbrMaterial.baseColorFactor;
|
|
409
429
|
#ifdef HAS_BASECOLORMAP
|
|
410
|
-
baseColor = SRGBtoLINEAR(
|
|
411
|
-
|
|
412
|
-
|
|
430
|
+
baseColor = SRGBtoLINEAR(
|
|
431
|
+
textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, fragmentInputs.pbr_vUV)
|
|
432
|
+
) * pbrMaterial.baseColorFactor;
|
|
413
433
|
#endif
|
|
414
434
|
|
|
415
435
|
#ifdef ALPHA_CUTOFF
|
|
@@ -420,7 +440,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
420
440
|
|
|
421
441
|
var color = vec3<f32>(0.0, 0.0, 0.0);
|
|
422
442
|
|
|
423
|
-
if (pbrMaterial.unlit) {
|
|
443
|
+
if (pbrMaterial.unlit != 0u) {
|
|
424
444
|
color = baseColor.rgb;
|
|
425
445
|
} else {
|
|
426
446
|
// Metallic and Roughness material properties are packed together
|
|
@@ -431,7 +451,11 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
431
451
|
#ifdef HAS_METALROUGHNESSMAP
|
|
432
452
|
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
433
453
|
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
434
|
-
let mrSample = textureSample(
|
|
454
|
+
let mrSample = textureSample(
|
|
455
|
+
pbr_metallicRoughnessSampler,
|
|
456
|
+
pbr_metallicRoughnessSamplerSampler,
|
|
457
|
+
fragmentInputs.pbr_vUV
|
|
458
|
+
);
|
|
435
459
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
436
460
|
metallic = mrSample.b * metallic;
|
|
437
461
|
#endif
|
|
@@ -508,22 +532,25 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
508
532
|
|
|
509
533
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
510
534
|
#ifdef USE_IBL
|
|
511
|
-
if (pbrMaterial.IBLenabled) {
|
|
535
|
+
if (pbrMaterial.IBLenabled != 0) {
|
|
512
536
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
513
537
|
}
|
|
514
538
|
#endif
|
|
515
539
|
|
|
516
540
|
// Apply optional PBR terms for additional (optional) shading
|
|
517
541
|
#ifdef HAS_OCCLUSIONMAP
|
|
518
|
-
if (pbrMaterial.occlusionMapEnabled) {
|
|
519
|
-
let ao =
|
|
542
|
+
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
543
|
+
let ao =
|
|
544
|
+
textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, fragmentInputs.pbr_vUV).r;
|
|
520
545
|
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
521
546
|
}
|
|
522
547
|
#endif
|
|
523
548
|
|
|
524
549
|
#ifdef HAS_EMISSIVEMAP
|
|
525
|
-
if (pbrMaterial.emissiveMapEnabled) {
|
|
526
|
-
let emissive = SRGBtoLINEAR(
|
|
550
|
+
if (pbrMaterial.emissiveMapEnabled != 0u) {
|
|
551
|
+
let emissive = SRGBtoLINEAR(
|
|
552
|
+
textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, fragmentInputs.pbr_vUV)
|
|
553
|
+
).rgb * pbrMaterial.emissiveFactor;
|
|
527
554
|
color += emissive;
|
|
528
555
|
}
|
|
529
556
|
#endif
|
|
@@ -15,6 +15,17 @@ uniform pbrProjectionUniforms {
|
|
|
15
15
|
} pbrProjection;
|
|
16
16
|
`;
|
|
17
17
|
|
|
18
|
+
const wgslUniformBlock = /* wgsl */ `\
|
|
19
|
+
struct pbrProjectionUniforms {
|
|
20
|
+
modelViewProjectionMatrix: mat4x4<f32>,
|
|
21
|
+
modelMatrix: mat4x4<f32>,
|
|
22
|
+
normalMatrix: mat4x4<f32>,
|
|
23
|
+
camera: vec3<f32>
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
@binding(0) @group(0) var<uniform> pbrProjection: pbrProjectionUniforms;
|
|
27
|
+
`;
|
|
28
|
+
|
|
18
29
|
export type PBRProjectionProps = {
|
|
19
30
|
modelViewProjectionMatrix: NumberArray16;
|
|
20
31
|
modelMatrix: NumberArray16;
|
|
@@ -24,6 +35,7 @@ export type PBRProjectionProps = {
|
|
|
24
35
|
|
|
25
36
|
export const pbrProjection: ShaderModule<PBRProjectionProps> = {
|
|
26
37
|
name: 'pbrProjection',
|
|
38
|
+
source: wgslUniformBlock,
|
|
27
39
|
vs: uniformBlock,
|
|
28
40
|
fs: uniformBlock,
|
|
29
41
|
// TODO why is this needed?
|
|
@@ -32,6 +44,6 @@ export const pbrProjection: ShaderModule<PBRProjectionProps> = {
|
|
|
32
44
|
modelViewProjectionMatrix: 'mat4x4<f32>',
|
|
33
45
|
modelMatrix: 'mat4x4<f32>',
|
|
34
46
|
normalMatrix: 'mat4x4<f32>',
|
|
35
|
-
camera: 'vec3<
|
|
47
|
+
camera: 'vec3<f32>'
|
|
36
48
|
}
|
|
37
49
|
};
|
|
@@ -34,99 +34,62 @@ fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, p
|
|
|
34
34
|
let view_direction: vec3<f32> = normalize(cameraPosition - position_worldspace);
|
|
35
35
|
lightColor = phongMaterial.ambient * surfaceColor * lighting.ambientColor;
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
let pointLight: PointLight
|
|
37
|
+
for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
|
|
38
|
+
let pointLight: PointLight = lighting_getPointLight(i);
|
|
39
39
|
let light_position_worldspace: vec3<f32> = pointLight.position;
|
|
40
40
|
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
PointLight pointLight = lighting.pointLight[i];
|
|
54
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
55
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
56
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
41
|
+
let light_attenuation = getPointLightAttenuation(
|
|
42
|
+
pointLight,
|
|
43
|
+
distance(light_position_worldspace, position_worldspace)
|
|
44
|
+
);
|
|
45
|
+
lightColor += lighting_getLightColor(
|
|
46
|
+
surfaceColor,
|
|
47
|
+
light_direction,
|
|
48
|
+
view_direction,
|
|
49
|
+
normal_worldspace,
|
|
50
|
+
pointLight.color / light_attenuation
|
|
51
|
+
);
|
|
57
52
|
}
|
|
58
53
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
DirectionalLight directionalLight = lighting.directionalLight[i];
|
|
54
|
+
let totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
|
|
55
|
+
for (var i: i32 = lighting.pointLightCount; i < totalLights; i++) {
|
|
56
|
+
let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
|
|
64
57
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
65
|
-
}
|
|
66
|
-
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return lightColor;
|
|
67
61
|
}
|
|
68
62
|
|
|
69
63
|
fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32>{
|
|
70
64
|
var lightColor = vec3<f32>(0, 0, 0);
|
|
71
65
|
let surfaceColor = vec3<f32>(0, 0, 0);
|
|
72
66
|
|
|
73
|
-
if (lighting.enabled
|
|
67
|
+
if (lighting.enabled != 0) {
|
|
74
68
|
let view_direction = normalize(cameraPosition - position_worldspace);
|
|
75
69
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
|
|
71
|
+
let pointLight: PointLight = lighting_getPointLight(i);
|
|
72
|
+
let light_position_worldspace: vec3<f32> = pointLight.position;
|
|
73
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
74
|
+
let light_attenuation = getPointLightAttenuation(
|
|
75
|
+
pointLight,
|
|
76
|
+
distance(light_position_worldspace, position_worldspace)
|
|
77
|
+
);
|
|
78
|
+
lightColor += lighting_getLightColor(
|
|
79
|
+
surfaceColor,
|
|
80
|
+
light_direction,
|
|
81
|
+
view_direction,
|
|
82
|
+
normal_worldspace,
|
|
83
|
+
pointLight.color / light_attenuation
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
|
|
88
|
+
for (var i: i32 = lighting.pointLightCount; i < totalLights; i++) {
|
|
89
|
+
let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
|
|
85
90
|
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
86
|
-
}
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
return lightColor;
|
|
90
94
|
}
|
|
91
95
|
`;
|
|
92
|
-
|
|
93
|
-
// TODO - handle multiple lights
|
|
94
|
-
/**
|
|
95
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
96
|
-
if (i >= lighting.pointLightCount) {
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
100
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
101
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
102
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
106
|
-
if (i >= lighting.directionalLightCount) {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
110
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
115
|
-
if (i >= lighting.pointLightCount) {
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
PointLight pointLight = lighting_getPointLight(i);
|
|
119
|
-
vec3 light_position_worldspace = pointLight.position;
|
|
120
|
-
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
121
|
-
lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
for (int i = 0; i < MAX_LIGHTS; i++) {
|
|
125
|
-
if (i >= lighting.directionalLightCount) {
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
PointLight pointLight = lighting_getDirectionalLight(i);
|
|
129
|
-
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
*/
|
|
@@ -5,9 +5,8 @@
|
|
|
5
5
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
6
|
|
|
7
7
|
const source = /* wgsl */ `\
|
|
8
|
-
fn random(scale: vec3f, seed:
|
|
9
|
-
|
|
10
|
-
return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
|
|
8
|
+
fn random(scale: vec3f, seed: f32) -> f32 {
|
|
9
|
+
return fract(sin(dot(scale + vec3f(seed), vec3f(12.9898, 78.233, 151.7182))) * 43758.5453 + seed);
|
|
11
10
|
}
|
|
12
11
|
`;
|
|
13
12
|
|