@pacem/pacem-3d 1.0.0-abel → 1.0.0-amaldi
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/browser/pacem-3d.js +343 -338
- package/dist/browser/pacem-3d.js.map +1 -1
- package/dist/browser/pacem-3d.min.js +5 -0
- package/dist/browser/pacem-3d.min.js.map +1 -1
- package/dist/bundle/pacem-3d.min.mjs +5 -0
- package/dist/bundle/pacem-3d.mjs +5 -0
- package/dist/bundle/pacem-3d.mjs.map +1 -1
- package/dist/esm/constants.js +5 -0
- package/dist/esm/converters.js +5 -0
- package/dist/esm/decorators.js +5 -0
- package/dist/esm/detector.js +5 -0
- package/dist/esm/geometry.js +5 -0
- package/dist/esm/index-components-drawing3d.js +5 -0
- package/dist/esm/index-components.js +5 -0
- package/dist/esm/index-drawing3d.js +5 -0
- package/dist/esm/index-iife.js +5 -0
- package/dist/esm/index-root.js +5 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/stage.js +5 -0
- package/dist/esm/types.js +5 -0
- package/package.json +1 -1
package/dist/browser/pacem-3d.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* @pacem/pacem-3d v1.0.0-amaldi (https://js.pacem.it)
|
|
3
|
+
* Pacem (https://pacem.it)
|
|
4
|
+
* Licensed under Apache-2.0
|
|
5
|
+
*/
|
|
1
6
|
(function (pacemFoundation, pacemCore, pacemNumerical) {
|
|
2
7
|
'use strict';
|
|
3
8
|
|
|
@@ -2295,35 +2300,35 @@
|
|
|
2295
2300
|
19, 3, 16, 19, 16, 17, 19, 18, 5, 19, 5, 1,
|
|
2296
2301
|
19, 1, 4, 18, 14, 10, 18, 10, 6, 18, 6, 5,
|
|
2297
2302
|
3, 2, 8, 3, 8, 12, 3, 12, 16];
|
|
2298
|
-
const textureCoordsString = `0.5 0.999501, 0.5 0.999501, 0.191292 0.808708, 0.5 0.690792,
|
|
2299
|
-
0.191292 0.808708, 0.191292 0.808708, 0.5 0.690792,
|
|
2300
|
-
0.808708 0.808708, 0.000499517 0.5, 0.309208 0.5, 0.5 0.309208,
|
|
2301
|
-
0.191292 0.191292, 0.191292 0.191292, 0.309208 0.5,
|
|
2302
|
-
0.191292 0.191292, 0.5 0.000499517, 0.5 0.309208, 0.808708 0.191292,
|
|
2303
|
-
0.000499517 0.5, 0.309208 0.5, 0.690792 0.5, 0.808708 0.808708,
|
|
2304
|
-
0.5 0.999501, 0.690792 0.5, 0.5 0.999501, 0.191292 0.808708,
|
|
2305
|
-
0.690792 0.5, 0.191292 0.808708, 0.309208 0.5, 0.309208 0.5,
|
|
2306
|
-
0.191292 0.191292, 0.5 0.000499517, 0.309208 0.5, 0.5 0.000499517,
|
|
2307
|
-
0.808708 0.191292, 0.309208 0.5, 0.808708 0.191292,
|
|
2308
|
-
0.690792 0.5, 0.191292 0.808708, 0.309208 0.5, 0.690792 0.5,
|
|
2309
|
-
0.191292 0.808708, 0.690792 0.5, 0.808708 0.808708,
|
|
2310
|
-
0.191292 0.808708, 0.808708 0.808708, 0.808708 0.808708,
|
|
2311
|
-
0.5 0.690792, 0.5 0.309208, 0.808708 0.808708, 0.5 0.309208,
|
|
2312
|
-
0.808708 0.191292, 0.808708 0.191292, 0.9995 0.5, 0.191292 0.191292,
|
|
2313
|
-
0.5 0.000499517, 0.808708 0.191292, 0.191292 0.191292,
|
|
2314
|
-
0.808708 0.191292, 0.690792 0.5, 0.191292 0.191292,
|
|
2315
|
-
0.690792 0.5, 0.191292 0.191292, 0.5 0.000499517, 0.808708 0.191292,
|
|
2316
|
-
0.191292 0.191292, 0.808708 0.191292, 0.690792 0.5,
|
|
2317
|
-
0.690792 0.5, 0.309208 0.5, 0.690792 0.5, 0.808708 0.808708,
|
|
2318
|
-
0.5 0.999501, 0.690792 0.5, 0.5 0.999501, 0.191292 0.808708,
|
|
2319
|
-
0.690792 0.5, 0.191292 0.808708, 0.5 0.000499517, 0.808708 0.191292,
|
|
2320
|
-
0.690792 0.5, 0.5 0.000499517, 0.690792 0.5, 0.309208 0.5,
|
|
2321
|
-
0.309208 0.5, 0.191292 0.191292, 0.9995 0.5, 0.808708 0.808708,
|
|
2322
|
-
0.5 0.690792, 0.9995 0.5, 0.5 0.690792, 0.5 0.309208,
|
|
2323
|
-
0.9995 0.5, 0.5 0.309208, 0.309208 0.5, 0.690792 0.5,
|
|
2324
|
-
0.808708 0.808708, 0.309208 0.5, 0.808708 0.808708,
|
|
2325
|
-
0.5 0.999501, 0.000499517 0.5, 0.5 0.309208, 0.000499517 0.5,
|
|
2326
|
-
0.5 0.690792, 0.5 0.690792, 0.000499517 0.5, 0.5 0.690792,
|
|
2303
|
+
const textureCoordsString = `0.5 0.999501, 0.5 0.999501, 0.191292 0.808708, 0.5 0.690792,
|
|
2304
|
+
0.191292 0.808708, 0.191292 0.808708, 0.5 0.690792,
|
|
2305
|
+
0.808708 0.808708, 0.000499517 0.5, 0.309208 0.5, 0.5 0.309208,
|
|
2306
|
+
0.191292 0.191292, 0.191292 0.191292, 0.309208 0.5,
|
|
2307
|
+
0.191292 0.191292, 0.5 0.000499517, 0.5 0.309208, 0.808708 0.191292,
|
|
2308
|
+
0.000499517 0.5, 0.309208 0.5, 0.690792 0.5, 0.808708 0.808708,
|
|
2309
|
+
0.5 0.999501, 0.690792 0.5, 0.5 0.999501, 0.191292 0.808708,
|
|
2310
|
+
0.690792 0.5, 0.191292 0.808708, 0.309208 0.5, 0.309208 0.5,
|
|
2311
|
+
0.191292 0.191292, 0.5 0.000499517, 0.309208 0.5, 0.5 0.000499517,
|
|
2312
|
+
0.808708 0.191292, 0.309208 0.5, 0.808708 0.191292,
|
|
2313
|
+
0.690792 0.5, 0.191292 0.808708, 0.309208 0.5, 0.690792 0.5,
|
|
2314
|
+
0.191292 0.808708, 0.690792 0.5, 0.808708 0.808708,
|
|
2315
|
+
0.191292 0.808708, 0.808708 0.808708, 0.808708 0.808708,
|
|
2316
|
+
0.5 0.690792, 0.5 0.309208, 0.808708 0.808708, 0.5 0.309208,
|
|
2317
|
+
0.808708 0.191292, 0.808708 0.191292, 0.9995 0.5, 0.191292 0.191292,
|
|
2318
|
+
0.5 0.000499517, 0.808708 0.191292, 0.191292 0.191292,
|
|
2319
|
+
0.808708 0.191292, 0.690792 0.5, 0.191292 0.191292,
|
|
2320
|
+
0.690792 0.5, 0.191292 0.191292, 0.5 0.000499517, 0.808708 0.191292,
|
|
2321
|
+
0.191292 0.191292, 0.808708 0.191292, 0.690792 0.5,
|
|
2322
|
+
0.690792 0.5, 0.309208 0.5, 0.690792 0.5, 0.808708 0.808708,
|
|
2323
|
+
0.5 0.999501, 0.690792 0.5, 0.5 0.999501, 0.191292 0.808708,
|
|
2324
|
+
0.690792 0.5, 0.191292 0.808708, 0.5 0.000499517, 0.808708 0.191292,
|
|
2325
|
+
0.690792 0.5, 0.5 0.000499517, 0.690792 0.5, 0.309208 0.5,
|
|
2326
|
+
0.309208 0.5, 0.191292 0.191292, 0.9995 0.5, 0.808708 0.808708,
|
|
2327
|
+
0.5 0.690792, 0.9995 0.5, 0.5 0.690792, 0.5 0.309208,
|
|
2328
|
+
0.9995 0.5, 0.5 0.309208, 0.309208 0.5, 0.690792 0.5,
|
|
2329
|
+
0.808708 0.808708, 0.309208 0.5, 0.808708 0.808708,
|
|
2330
|
+
0.5 0.999501, 0.000499517 0.5, 0.5 0.309208, 0.000499517 0.5,
|
|
2331
|
+
0.5 0.690792, 0.5 0.690792, 0.000499517 0.5, 0.5 0.690792,
|
|
2327
2332
|
0.191292 0.191292`;
|
|
2328
2333
|
const texIndices = [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
2329
2334
|
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
|
|
@@ -3444,35 +3449,35 @@
|
|
|
3444
3449
|
const opts = pacemCore.Utils.extend({}, DefaultBasicMaterialFragmentOptions, options);
|
|
3445
3450
|
const definitions = adaptWGSLStringArray$1(extensions.definitions), bindings = adaptWGSLStringArray$1(extensions.bindings), modifiers = adaptWGSLModifierStringArray$1(extensions.modifiers);
|
|
3446
3451
|
const color = VERTEX_COLOR_REFERENCE, lighting = LIGHTING_COLOR_REFERENCE, ambient = AMBIENT_COLOR_REFERENCE;
|
|
3447
|
-
return `// definitions
|
|
3448
|
-
|
|
3449
|
-
${definitions}
|
|
3450
|
-
|
|
3451
|
-
// bindings
|
|
3452
|
-
@group(${opts.storageMaterialGroupIndex}) @binding(${opts.storageMaterialBindingIndex}) var<storage, read> diffuseColor: vec4f;
|
|
3453
|
-
${bindings}
|
|
3454
|
-
|
|
3455
|
-
const empty = vec4f(0,0,0,0);
|
|
3456
|
-
const white = vec4f(1,1,1,1);
|
|
3457
|
-
|
|
3458
|
-
@fragment fn main (
|
|
3459
|
-
@builtin(position) position: vec4f, // clip-space position
|
|
3460
|
-
@location(${opts.outputNormalLocation}) normal: vec3f, // world-space normal
|
|
3461
|
-
@location(${opts.outputVertexLocation}) vertex: vec3f, // world-space position
|
|
3462
|
-
@location(${opts.outputUvLocation}) uv: vec2f,
|
|
3463
|
-
@location(${opts.outputVertexIndexLocation}) @interpolate(flat) index: u32, // vertex index,
|
|
3464
|
-
@location(${opts.outputRayIndexLocation}) ray: vec3f, // ray (eye-to-vertex) vector
|
|
3465
|
-
@location(${opts.outputInstanceIndexLocation}) @interpolate(flat) instance : u32, // instance index
|
|
3466
|
-
) -> @location(0) vec4f {
|
|
3467
|
-
var ${color} = diffuseColor;
|
|
3468
|
-
var ${ambient}: vec4f = empty;
|
|
3469
|
-
var ${lighting}: vec4f = empty;
|
|
3470
|
-
|
|
3471
|
-
// modifiers
|
|
3472
|
-
${modifiers}
|
|
3473
|
-
|
|
3474
|
-
${lighting} = select(white, ${lighting}, ${lighting}.a > 0);
|
|
3475
|
-
return ${color} * ${lighting} + ${ambient};
|
|
3452
|
+
return `// definitions
|
|
3453
|
+
|
|
3454
|
+
${definitions}
|
|
3455
|
+
|
|
3456
|
+
// bindings
|
|
3457
|
+
@group(${opts.storageMaterialGroupIndex}) @binding(${opts.storageMaterialBindingIndex}) var<storage, read> diffuseColor: vec4f;
|
|
3458
|
+
${bindings}
|
|
3459
|
+
|
|
3460
|
+
const empty = vec4f(0,0,0,0);
|
|
3461
|
+
const white = vec4f(1,1,1,1);
|
|
3462
|
+
|
|
3463
|
+
@fragment fn main (
|
|
3464
|
+
@builtin(position) position: vec4f, // clip-space position
|
|
3465
|
+
@location(${opts.outputNormalLocation}) normal: vec3f, // world-space normal
|
|
3466
|
+
@location(${opts.outputVertexLocation}) vertex: vec3f, // world-space position
|
|
3467
|
+
@location(${opts.outputUvLocation}) uv: vec2f,
|
|
3468
|
+
@location(${opts.outputVertexIndexLocation}) @interpolate(flat) index: u32, // vertex index,
|
|
3469
|
+
@location(${opts.outputRayIndexLocation}) ray: vec3f, // ray (eye-to-vertex) vector
|
|
3470
|
+
@location(${opts.outputInstanceIndexLocation}) @interpolate(flat) instance : u32, // instance index
|
|
3471
|
+
) -> @location(0) vec4f {
|
|
3472
|
+
var ${color} = diffuseColor;
|
|
3473
|
+
var ${ambient}: vec4f = empty;
|
|
3474
|
+
var ${lighting}: vec4f = empty;
|
|
3475
|
+
|
|
3476
|
+
// modifiers
|
|
3477
|
+
${modifiers}
|
|
3478
|
+
|
|
3479
|
+
${lighting} = select(white, ${lighting}, ${lighting}.a > 0);
|
|
3480
|
+
return ${color} * ${lighting} + ${ambient};
|
|
3476
3481
|
}`;
|
|
3477
3482
|
}
|
|
3478
3483
|
|
|
@@ -3501,30 +3506,30 @@ const white = vec4f(1,1,1,1);
|
|
|
3501
3506
|
function getLineMaterialFragmentWgsl(extensions = {}, options = DefaultLineMaterialFragmentOptions) {
|
|
3502
3507
|
const opts = pacemCore.Utils.extend({}, DefaultLineMaterialFragmentOptions, options);
|
|
3503
3508
|
const definitions = adaptWGSLStringArray(extensions.definitions), bindings = adaptWGSLStringArray(extensions.bindings), modifiers = adaptWGSLModifierStringArray(extensions.modifiers);
|
|
3504
|
-
return `// definitions
|
|
3505
|
-
${definitions}
|
|
3506
|
-
|
|
3507
|
-
// bindings
|
|
3508
|
-
@group(${options.storageMaterialGroupIndex}) @binding(${options.storageMaterialBindingIndex}) var<storage, read> vertexColors: array<vec4f>;
|
|
3509
|
-
${bindings}
|
|
3510
|
-
|
|
3511
|
-
fn getVertexColor(index: u32) -> vec4f {
|
|
3512
|
-
let numColors = arrayLength(&vertexColors);
|
|
3513
|
-
let vertexColorIndex = index % numColors;
|
|
3514
|
-
return vertexColors[vertexColorIndex];
|
|
3515
|
-
}
|
|
3516
|
-
|
|
3517
|
-
@fragment fn main (
|
|
3518
|
-
@builtin(position) position: vec4f, // clip-space position
|
|
3519
|
-
@location(${opts.outputInstanceIndexLocation}) @interpolate(flat) instance: u32, // instance index
|
|
3520
|
-
@location(${opts.outputVertexIndexLocation}) @interpolate(flat) index: u32 // vertex index
|
|
3521
|
-
) -> @location(0) vec4f {
|
|
3522
|
-
var output = getVertexColor(index);
|
|
3523
|
-
|
|
3524
|
-
// modifiers
|
|
3525
|
-
${modifiers}
|
|
3526
|
-
|
|
3527
|
-
return output;
|
|
3509
|
+
return `// definitions
|
|
3510
|
+
${definitions}
|
|
3511
|
+
|
|
3512
|
+
// bindings
|
|
3513
|
+
@group(${options.storageMaterialGroupIndex}) @binding(${options.storageMaterialBindingIndex}) var<storage, read> vertexColors: array<vec4f>;
|
|
3514
|
+
${bindings}
|
|
3515
|
+
|
|
3516
|
+
fn getVertexColor(index: u32) -> vec4f {
|
|
3517
|
+
let numColors = arrayLength(&vertexColors);
|
|
3518
|
+
let vertexColorIndex = index % numColors;
|
|
3519
|
+
return vertexColors[vertexColorIndex];
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
@fragment fn main (
|
|
3523
|
+
@builtin(position) position: vec4f, // clip-space position
|
|
3524
|
+
@location(${opts.outputInstanceIndexLocation}) @interpolate(flat) instance: u32, // instance index
|
|
3525
|
+
@location(${opts.outputVertexIndexLocation}) @interpolate(flat) index: u32 // vertex index
|
|
3526
|
+
) -> @location(0) vec4f {
|
|
3527
|
+
var output = getVertexColor(index);
|
|
3528
|
+
|
|
3529
|
+
// modifiers
|
|
3530
|
+
${modifiers}
|
|
3531
|
+
|
|
3532
|
+
return output;
|
|
3528
3533
|
}`;
|
|
3529
3534
|
}
|
|
3530
3535
|
|
|
@@ -3683,8 +3688,8 @@ fn getVertexColor(index: u32) -> vec4f {
|
|
|
3683
3688
|
if (!pacemCore.Utils.isNullOrEmpty(modifierInput)) {
|
|
3684
3689
|
const { name: modifierName, args: [arg0, arg1], body: modifierBody } = extractMeshVertexModifierFunctionComponents(modifierInput);
|
|
3685
3690
|
modifyInstructionInput = `${modifierName}(vertexInput, interaction)`;
|
|
3686
|
-
modifierFnInput = `fn ${modifierName} (${arg0}: ${WGSL_VERTEXINPUT_STRUCT_NAME}, ${arg1}: ${WGSL_INTERACTIONDATA_STRUCT_NAME}) -> ${WGSL_VERTEXINPUT_STRUCT_NAME} {
|
|
3687
|
-
${modifierBody}
|
|
3691
|
+
modifierFnInput = `fn ${modifierName} (${arg0}: ${WGSL_VERTEXINPUT_STRUCT_NAME}, ${arg1}: ${WGSL_INTERACTIONDATA_STRUCT_NAME}) -> ${WGSL_VERTEXINPUT_STRUCT_NAME} {
|
|
3692
|
+
${modifierBody}
|
|
3688
3693
|
}`;
|
|
3689
3694
|
}
|
|
3690
3695
|
// vertex output modifier?
|
|
@@ -3693,74 +3698,74 @@ fn getVertexColor(index: u32) -> vec4f {
|
|
|
3693
3698
|
if (!pacemCore.Utils.isNullOrEmpty(modifierOutput)) {
|
|
3694
3699
|
const { name: modifierName, args: [arg0, arg1], body: modifierBody } = extractMeshVertexModifierFunctionComponents(modifierOutput);
|
|
3695
3700
|
modifyInstructionOutput = `${modifierName}(output, interaction)`;
|
|
3696
|
-
modifierFnOutput = `fn ${modifierName} (${arg0}: ${WGSL_VERTEXINPUT_STRUCT_NAME}, ${arg1}: ${WGSL_INTERACTIONDATA_STRUCT_NAME}) -> ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3697
|
-
${modifierBody}
|
|
3701
|
+
modifierFnOutput = `fn ${modifierName} (${arg0}: ${WGSL_VERTEXINPUT_STRUCT_NAME}, ${arg1}: ${WGSL_INTERACTIONDATA_STRUCT_NAME}) -> ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3702
|
+
${modifierBody}
|
|
3698
3703
|
}`;
|
|
3699
3704
|
}
|
|
3700
3705
|
const opts = pacemCore.Utils.extend({}, DefaultMeshVertexOptions, options);
|
|
3701
|
-
return `struct ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3702
|
-
@builtin(position) position : vec4f, // clip space position
|
|
3703
|
-
@location(${opts.outputNormalLocation}) normal: vec3f, // world space normal
|
|
3704
|
-
@location(${opts.outputVertexLocation}) vertex : vec3f, // world space position
|
|
3705
|
-
@location(${opts.outputUvLocation}) uv : vec2f, // texture coordinates
|
|
3706
|
-
@location(${opts.outputVertexIndexLocation}) @interpolate(flat) index : u32, // vertex index
|
|
3707
|
-
@location(${opts.outputRayLocation}) ray : vec3f, // eye-to-point vector in world space
|
|
3708
|
-
@location(${opts.outputInstanceIndexLocation}) @interpolate(flat) instance : u32, // instance index
|
|
3709
|
-
}
|
|
3710
|
-
|
|
3711
|
-
struct ${WGSL_VERTEXINPUT_STRUCT_NAME} {
|
|
3712
|
-
@location(${opts.inputPositionLocation}) position: vec3f,
|
|
3713
|
-
@location(${opts.inputNormalLocation}) normal: vec3f,
|
|
3714
|
-
@location(${opts.inputUvLocation}) uv: vec2f,
|
|
3715
|
-
@builtin(vertex_index) index: u32,
|
|
3716
|
-
@builtin(instance_index) instance: u32,
|
|
3717
|
-
}
|
|
3718
|
-
|
|
3719
|
-
struct Transforms {
|
|
3720
|
-
world: mat4x4f,
|
|
3721
|
-
normal: mat3x3f,
|
|
3722
|
-
}
|
|
3723
|
-
|
|
3724
|
-
struct Camera {
|
|
3725
|
-
view: mat4x4f,
|
|
3726
|
-
projection: mat4x4f,
|
|
3727
|
-
position: vec3f,
|
|
3728
|
-
}
|
|
3729
|
-
|
|
3730
|
-
struct ${WGSL_INTERACTIONDATA_STRUCT_NAME} {
|
|
3731
|
-
// mouse coordinatges in NDC space ([-1,1], [-1,1])
|
|
3732
|
-
cursor: vec2f,
|
|
3733
|
-
// canvas size in pixels
|
|
3734
|
-
resolution: vec2f,
|
|
3735
|
-
// some phase timer (e.g. time since mouse down, or time since last click, etc.)
|
|
3736
|
-
time: f32,
|
|
3737
|
-
}
|
|
3738
|
-
|
|
3739
|
-
${modifierFnInput}
|
|
3740
|
-
|
|
3741
|
-
${modifierFnOutput}
|
|
3742
|
-
|
|
3743
|
-
@group(${opts.uniformWorldGroupIndex}) @binding(${opts.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;
|
|
3744
|
-
@group(${opts.uniformViewGroupIndex}) @binding(${opts.uniformViewBindingIndex}) var<uniform> camera: Camera;
|
|
3745
|
-
@group(${opts.uniformInteractionGroupIndex}) @binding(${opts.uniformInteractionBindingIndex}) var<uniform> interaction: ${WGSL_INTERACTIONDATA_STRUCT_NAME};
|
|
3746
|
-
|
|
3747
|
-
@vertex fn main(vertexInput: ${WGSL_VERTEXINPUT_STRUCT_NAME}) -> ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3748
|
-
let input = ${modifyInstructionInput};
|
|
3749
|
-
let position4 = vec4f(input.position, 1.0);
|
|
3750
|
-
let worldTransform = transforms.world;
|
|
3751
|
-
let viewProjectionTransform = camera.projection;
|
|
3752
|
-
let worldViewProjectionTransform = viewProjectionTransform * worldTransform;
|
|
3753
|
-
let worldPosition = (worldTransform * position4).xyz;
|
|
3754
|
-
let output = ${WGSL_VERTEXOUTPUT_STRUCT_NAME}(
|
|
3755
|
-
worldViewProjectionTransform * position4,
|
|
3756
|
-
transforms.normal * input.normal,
|
|
3757
|
-
worldPosition,
|
|
3758
|
-
input.uv,
|
|
3759
|
-
input.index,
|
|
3760
|
-
normalize(worldPosition - camera.position),
|
|
3761
|
-
input.instance
|
|
3762
|
-
);
|
|
3763
|
-
return ${modifyInstructionOutput};
|
|
3706
|
+
return `struct ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3707
|
+
@builtin(position) position : vec4f, // clip space position
|
|
3708
|
+
@location(${opts.outputNormalLocation}) normal: vec3f, // world space normal
|
|
3709
|
+
@location(${opts.outputVertexLocation}) vertex : vec3f, // world space position
|
|
3710
|
+
@location(${opts.outputUvLocation}) uv : vec2f, // texture coordinates
|
|
3711
|
+
@location(${opts.outputVertexIndexLocation}) @interpolate(flat) index : u32, // vertex index
|
|
3712
|
+
@location(${opts.outputRayLocation}) ray : vec3f, // eye-to-point vector in world space
|
|
3713
|
+
@location(${opts.outputInstanceIndexLocation}) @interpolate(flat) instance : u32, // instance index
|
|
3714
|
+
}
|
|
3715
|
+
|
|
3716
|
+
struct ${WGSL_VERTEXINPUT_STRUCT_NAME} {
|
|
3717
|
+
@location(${opts.inputPositionLocation}) position: vec3f,
|
|
3718
|
+
@location(${opts.inputNormalLocation}) normal: vec3f,
|
|
3719
|
+
@location(${opts.inputUvLocation}) uv: vec2f,
|
|
3720
|
+
@builtin(vertex_index) index: u32,
|
|
3721
|
+
@builtin(instance_index) instance: u32,
|
|
3722
|
+
}
|
|
3723
|
+
|
|
3724
|
+
struct Transforms {
|
|
3725
|
+
world: mat4x4f,
|
|
3726
|
+
normal: mat3x3f,
|
|
3727
|
+
}
|
|
3728
|
+
|
|
3729
|
+
struct Camera {
|
|
3730
|
+
view: mat4x4f,
|
|
3731
|
+
projection: mat4x4f,
|
|
3732
|
+
position: vec3f,
|
|
3733
|
+
}
|
|
3734
|
+
|
|
3735
|
+
struct ${WGSL_INTERACTIONDATA_STRUCT_NAME} {
|
|
3736
|
+
// mouse coordinatges in NDC space ([-1,1], [-1,1])
|
|
3737
|
+
cursor: vec2f,
|
|
3738
|
+
// canvas size in pixels
|
|
3739
|
+
resolution: vec2f,
|
|
3740
|
+
// some phase timer (e.g. time since mouse down, or time since last click, etc.)
|
|
3741
|
+
time: f32,
|
|
3742
|
+
}
|
|
3743
|
+
|
|
3744
|
+
${modifierFnInput}
|
|
3745
|
+
|
|
3746
|
+
${modifierFnOutput}
|
|
3747
|
+
|
|
3748
|
+
@group(${opts.uniformWorldGroupIndex}) @binding(${opts.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;
|
|
3749
|
+
@group(${opts.uniformViewGroupIndex}) @binding(${opts.uniformViewBindingIndex}) var<uniform> camera: Camera;
|
|
3750
|
+
@group(${opts.uniformInteractionGroupIndex}) @binding(${opts.uniformInteractionBindingIndex}) var<uniform> interaction: ${WGSL_INTERACTIONDATA_STRUCT_NAME};
|
|
3751
|
+
|
|
3752
|
+
@vertex fn main(vertexInput: ${WGSL_VERTEXINPUT_STRUCT_NAME}) -> ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3753
|
+
let input = ${modifyInstructionInput};
|
|
3754
|
+
let position4 = vec4f(input.position, 1.0);
|
|
3755
|
+
let worldTransform = transforms.world;
|
|
3756
|
+
let viewProjectionTransform = camera.projection;
|
|
3757
|
+
let worldViewProjectionTransform = viewProjectionTransform * worldTransform;
|
|
3758
|
+
let worldPosition = (worldTransform * position4).xyz;
|
|
3759
|
+
let output = ${WGSL_VERTEXOUTPUT_STRUCT_NAME}(
|
|
3760
|
+
worldViewProjectionTransform * position4,
|
|
3761
|
+
transforms.normal * input.normal,
|
|
3762
|
+
worldPosition,
|
|
3763
|
+
input.uv,
|
|
3764
|
+
input.index,
|
|
3765
|
+
normalize(worldPosition - camera.position),
|
|
3766
|
+
input.instance
|
|
3767
|
+
);
|
|
3768
|
+
return ${modifyInstructionOutput};
|
|
3764
3769
|
}`;
|
|
3765
3770
|
}
|
|
3766
3771
|
|
|
@@ -3778,160 +3783,160 @@ ${modifierFnOutput}
|
|
|
3778
3783
|
uniformWorldBindingIndex: UNIFORM_BINDING_INDEX_TRANSFORM,
|
|
3779
3784
|
};
|
|
3780
3785
|
function getVertexOutputStructDefinition(opts) {
|
|
3781
|
-
return `struct ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3782
|
-
@builtin(position) position : vec4f, // clip space position
|
|
3783
|
-
@location(${opts.outputInstanceIndexLocation}) @interpolate(flat) instance : u32, // instance index
|
|
3784
|
-
@location(${opts.outputVertexIndexLocation}) @interpolate(flat) index : u32, // vertex index
|
|
3786
|
+
return `struct ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3787
|
+
@builtin(position) position : vec4f, // clip space position
|
|
3788
|
+
@location(${opts.outputInstanceIndexLocation}) @interpolate(flat) instance : u32, // instance index
|
|
3789
|
+
@location(${opts.outputVertexIndexLocation}) @interpolate(flat) index : u32, // vertex index
|
|
3785
3790
|
}`;
|
|
3786
3791
|
}
|
|
3787
3792
|
function getDefaultLineVertexWgsl(options = DefaultLineVertexOptions) {
|
|
3788
3793
|
const opts = pacemCore.Utils.extend({}, DefaultLineVertexOptions, options);
|
|
3789
|
-
return `${getVertexOutputStructDefinition(opts)}
|
|
3790
|
-
|
|
3791
|
-
struct Transforms {
|
|
3792
|
-
world: mat4x4f,
|
|
3793
|
-
normal: mat3x3f,
|
|
3794
|
-
}
|
|
3795
|
-
|
|
3796
|
-
struct Camera {
|
|
3797
|
-
view: mat4x4f,
|
|
3798
|
-
projection: mat4x4f,
|
|
3799
|
-
position: vec3f
|
|
3800
|
-
}
|
|
3801
|
-
|
|
3802
|
-
@group(${opts.uniformWorldGroupIndex}) @binding(${opts.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;
|
|
3803
|
-
@group(${opts.uniformViewGroupIndex}) @binding(${opts.uniformViewBindingIndex}) var<uniform> camera: Camera;
|
|
3804
|
-
@group(${opts.storagePositionsGroupIndex}) @binding(${opts.storagePositionsBindingIndex}) var<storage, read> positions: array<f32>;
|
|
3805
|
-
|
|
3806
|
-
@vertex fn main(@builtin(instance_index) instance: u32,
|
|
3807
|
-
@builtin(vertex_index) index: u32) -> ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3808
|
-
|
|
3809
|
-
let x = positions[3u * index + 0u];
|
|
3810
|
-
let y = positions[3u * index + 1u];
|
|
3811
|
-
let z = positions[3u * index + 2u];
|
|
3812
|
-
let position4 = vec4f(x, y, z, 1.0);
|
|
3813
|
-
let worldTransform = transforms.world;
|
|
3814
|
-
let viewProjectionTransform = camera.projection;
|
|
3815
|
-
let worldViewProjectionTransform = viewProjectionTransform * worldTransform;
|
|
3816
|
-
let worldPosition = (worldTransform * position4).xyz;
|
|
3817
|
-
return ${WGSL_VERTEXOUTPUT_STRUCT_NAME}(
|
|
3818
|
-
worldViewProjectionTransform * position4,
|
|
3819
|
-
instance,
|
|
3820
|
-
index);
|
|
3794
|
+
return `${getVertexOutputStructDefinition(opts)}
|
|
3795
|
+
|
|
3796
|
+
struct Transforms {
|
|
3797
|
+
world: mat4x4f,
|
|
3798
|
+
normal: mat3x3f,
|
|
3799
|
+
}
|
|
3800
|
+
|
|
3801
|
+
struct Camera {
|
|
3802
|
+
view: mat4x4f,
|
|
3803
|
+
projection: mat4x4f,
|
|
3804
|
+
position: vec3f
|
|
3805
|
+
}
|
|
3806
|
+
|
|
3807
|
+
@group(${opts.uniformWorldGroupIndex}) @binding(${opts.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;
|
|
3808
|
+
@group(${opts.uniformViewGroupIndex}) @binding(${opts.uniformViewBindingIndex}) var<uniform> camera: Camera;
|
|
3809
|
+
@group(${opts.storagePositionsGroupIndex}) @binding(${opts.storagePositionsBindingIndex}) var<storage, read> positions: array<f32>;
|
|
3810
|
+
|
|
3811
|
+
@vertex fn main(@builtin(instance_index) instance: u32,
|
|
3812
|
+
@builtin(vertex_index) index: u32) -> ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3813
|
+
|
|
3814
|
+
let x = positions[3u * index + 0u];
|
|
3815
|
+
let y = positions[3u * index + 1u];
|
|
3816
|
+
let z = positions[3u * index + 2u];
|
|
3817
|
+
let position4 = vec4f(x, y, z, 1.0);
|
|
3818
|
+
let worldTransform = transforms.world;
|
|
3819
|
+
let viewProjectionTransform = camera.projection;
|
|
3820
|
+
let worldViewProjectionTransform = viewProjectionTransform * worldTransform;
|
|
3821
|
+
let worldPosition = (worldTransform * position4).xyz;
|
|
3822
|
+
return ${WGSL_VERTEXOUTPUT_STRUCT_NAME}(
|
|
3823
|
+
worldViewProjectionTransform * position4,
|
|
3824
|
+
instance,
|
|
3825
|
+
index);
|
|
3821
3826
|
}`;
|
|
3822
3827
|
}
|
|
3823
3828
|
function getFatLineVertexWgsl(options = DefaultLineVertexOptions) {
|
|
3824
3829
|
const opts = pacemCore.Utils.extend({}, DefaultLineVertexOptions, options);
|
|
3825
|
-
return `${getVertexOutputStructDefinition(opts)}
|
|
3826
|
-
|
|
3827
|
-
struct Transforms {
|
|
3828
|
-
world: mat4x4f,
|
|
3829
|
-
normal: mat3x3f,
|
|
3830
|
-
}
|
|
3831
|
-
|
|
3832
|
-
struct Camera {
|
|
3833
|
-
view: mat4x4f,
|
|
3834
|
-
projection: mat4x4f,
|
|
3835
|
-
position: vec3f
|
|
3836
|
-
}
|
|
3837
|
-
|
|
3838
|
-
struct Pixels {
|
|
3839
|
-
viewportWidth: f32,
|
|
3840
|
-
viewportHeight: f32,
|
|
3841
|
-
halfLineWidth: f32
|
|
3842
|
-
}
|
|
3843
|
-
|
|
3844
|
-
@group(${opts.uniformWorldGroupIndex}) @binding(${opts.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;
|
|
3845
|
-
@group(${opts.uniformViewGroupIndex}) @binding(${opts.uniformViewBindingIndex}) var<uniform> camera: Camera;
|
|
3846
|
-
@group(${opts.storagePositionsGroupIndex}) @binding(${opts.storagePositionsBindingIndex}) var<storage, read> positions: array<f32>;
|
|
3847
|
-
@group(${opts.uniformDimensionsGroupIndex}) @binding(${opts.uniformDimensionsBindingIndex}) var<uniform> dimensions: Pixels;
|
|
3848
|
-
|
|
3849
|
-
fn computeClipPosition(index: u32) -> vec4f {
|
|
3850
|
-
let x = positions[3u * index + 0u];
|
|
3851
|
-
let y = positions[3u * index + 1u];
|
|
3852
|
-
let z = positions[3u * index + 2u];
|
|
3853
|
-
let position4 = vec4f(x, y, z, 1.0);
|
|
3854
|
-
let worldTransform = transforms.world;
|
|
3855
|
-
let viewProjectionTransform = camera.projection;
|
|
3856
|
-
let worldViewProjectionTransform = viewProjectionTransform * worldTransform;
|
|
3857
|
-
return worldViewProjectionTransform * position4;
|
|
3858
|
-
}
|
|
3859
|
-
|
|
3860
|
-
fn computeOffsetPosition(p0: vec4f, p1: vec4f, index: u32) -> vec4f {
|
|
3861
|
-
|
|
3862
|
-
let viewportSize = vec2f(dimensions.viewportWidth, dimensions.viewportHeight);
|
|
3863
|
-
let normalizedSize = normalize(viewportSize);
|
|
3864
|
-
let halfThickness = dimensions.halfLineWidth / dimensions.viewportWidth;
|
|
3865
|
-
let p0ndc = p0.xyz / p0.w;
|
|
3866
|
-
let p1ndc = p1.xyz / p1.w;
|
|
3867
|
-
let dir = normalize((p1ndc - p0ndc).xy);
|
|
3868
|
-
let offsetX = halfThickness * 2.0 / normalizedSize.x;
|
|
3869
|
-
let offsetY = halfThickness * 2.0 / normalizedSize.y;
|
|
3870
|
-
|
|
3871
|
-
// perp
|
|
3872
|
-
let perp0 = vec2f(-dir.y * offsetX, dir.x * offsetY);
|
|
3873
|
-
let perp1 = perp0;
|
|
3874
|
-
|
|
3875
|
-
/*
|
|
3876
|
-
|
|
3877
|
-
position0-0 -----*----- position0-1
|
|
3878
|
-
|\\ |
|
|
3879
|
-
| \\ |
|
|
3880
|
-
| \\ |
|
|
3881
|
-
| \\ |
|
|
3882
|
-
| \\ |
|
|
3883
|
-
| \\ |
|
|
3884
|
-
| \\ |
|
|
3885
|
-
| \\|
|
|
3886
|
-
position1-0 -----*----- position1-1
|
|
3887
|
-
|
|
3888
|
-
indexes:
|
|
3889
|
-
------------
|
|
3890
|
-
p0-0 -> 0, 3
|
|
3891
|
-
p0-1 -> 5
|
|
3892
|
-
p1-0 -> 1
|
|
3893
|
-
p1-1 -> 2, 4
|
|
3894
|
-
*/
|
|
3895
|
-
|
|
3896
|
-
var outPos: vec2f;
|
|
3897
|
-
var w = p0.w;
|
|
3898
|
-
var z = p0.z;
|
|
3899
|
-
if (index == 0 || index == 3){
|
|
3900
|
-
outPos = p0ndc.xy - perp0;
|
|
3901
|
-
}
|
|
3902
|
-
else if (index == 1){
|
|
3903
|
-
outPos = p1ndc.xy - perp1;
|
|
3904
|
-
w = p1.w;
|
|
3905
|
-
z = p1.z;
|
|
3906
|
-
}
|
|
3907
|
-
else if (index == 5){
|
|
3908
|
-
outPos = p0ndc.xy + perp0;
|
|
3909
|
-
}
|
|
3910
|
-
else { //if (index == 2 || index == 4)
|
|
3911
|
-
outPos = p1ndc.xy + perp1;
|
|
3912
|
-
w = p1.w;
|
|
3913
|
-
z = p1.z;
|
|
3914
|
-
}
|
|
3915
|
-
|
|
3916
|
-
// return vec4f(outPos , 0, 1.0);
|
|
3917
|
-
return vec4f(outPos * w, z, w);
|
|
3918
|
-
}
|
|
3919
|
-
|
|
3920
|
-
@vertex fn main(@builtin(instance_index) instance: u32,
|
|
3921
|
-
@builtin(vertex_index) index: u32) -> ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3922
|
-
|
|
3923
|
-
// vertex index starting at 1
|
|
3924
|
-
let position0 = computeClipPosition(instance);
|
|
3925
|
-
let position1 = computeClipPosition(instance + 1);
|
|
3926
|
-
|
|
3927
|
-
// apply offset
|
|
3928
|
-
let position = computeOffsetPosition(position0, position1, index);
|
|
3929
|
-
|
|
3930
|
-
return ${WGSL_VERTEXOUTPUT_STRUCT_NAME}(
|
|
3931
|
-
position,
|
|
3932
|
-
instance,
|
|
3933
|
-
index
|
|
3934
|
-
);
|
|
3830
|
+
return `${getVertexOutputStructDefinition(opts)}
|
|
3831
|
+
|
|
3832
|
+
struct Transforms {
|
|
3833
|
+
world: mat4x4f,
|
|
3834
|
+
normal: mat3x3f,
|
|
3835
|
+
}
|
|
3836
|
+
|
|
3837
|
+
struct Camera {
|
|
3838
|
+
view: mat4x4f,
|
|
3839
|
+
projection: mat4x4f,
|
|
3840
|
+
position: vec3f
|
|
3841
|
+
}
|
|
3842
|
+
|
|
3843
|
+
struct Pixels {
|
|
3844
|
+
viewportWidth: f32,
|
|
3845
|
+
viewportHeight: f32,
|
|
3846
|
+
halfLineWidth: f32
|
|
3847
|
+
}
|
|
3848
|
+
|
|
3849
|
+
@group(${opts.uniformWorldGroupIndex}) @binding(${opts.uniformWorldBindingIndex}) var<uniform> transforms: Transforms;
|
|
3850
|
+
@group(${opts.uniformViewGroupIndex}) @binding(${opts.uniformViewBindingIndex}) var<uniform> camera: Camera;
|
|
3851
|
+
@group(${opts.storagePositionsGroupIndex}) @binding(${opts.storagePositionsBindingIndex}) var<storage, read> positions: array<f32>;
|
|
3852
|
+
@group(${opts.uniformDimensionsGroupIndex}) @binding(${opts.uniformDimensionsBindingIndex}) var<uniform> dimensions: Pixels;
|
|
3853
|
+
|
|
3854
|
+
fn computeClipPosition(index: u32) -> vec4f {
|
|
3855
|
+
let x = positions[3u * index + 0u];
|
|
3856
|
+
let y = positions[3u * index + 1u];
|
|
3857
|
+
let z = positions[3u * index + 2u];
|
|
3858
|
+
let position4 = vec4f(x, y, z, 1.0);
|
|
3859
|
+
let worldTransform = transforms.world;
|
|
3860
|
+
let viewProjectionTransform = camera.projection;
|
|
3861
|
+
let worldViewProjectionTransform = viewProjectionTransform * worldTransform;
|
|
3862
|
+
return worldViewProjectionTransform * position4;
|
|
3863
|
+
}
|
|
3864
|
+
|
|
3865
|
+
fn computeOffsetPosition(p0: vec4f, p1: vec4f, index: u32) -> vec4f {
|
|
3866
|
+
|
|
3867
|
+
let viewportSize = vec2f(dimensions.viewportWidth, dimensions.viewportHeight);
|
|
3868
|
+
let normalizedSize = normalize(viewportSize);
|
|
3869
|
+
let halfThickness = dimensions.halfLineWidth / dimensions.viewportWidth;
|
|
3870
|
+
let p0ndc = p0.xyz / p0.w;
|
|
3871
|
+
let p1ndc = p1.xyz / p1.w;
|
|
3872
|
+
let dir = normalize((p1ndc - p0ndc).xy);
|
|
3873
|
+
let offsetX = halfThickness * 2.0 / normalizedSize.x;
|
|
3874
|
+
let offsetY = halfThickness * 2.0 / normalizedSize.y;
|
|
3875
|
+
|
|
3876
|
+
// perp
|
|
3877
|
+
let perp0 = vec2f(-dir.y * offsetX, dir.x * offsetY);
|
|
3878
|
+
let perp1 = perp0;
|
|
3879
|
+
|
|
3880
|
+
/*
|
|
3881
|
+
|
|
3882
|
+
position0-0 -----*----- position0-1
|
|
3883
|
+
|\\ |
|
|
3884
|
+
| \\ |
|
|
3885
|
+
| \\ |
|
|
3886
|
+
| \\ |
|
|
3887
|
+
| \\ |
|
|
3888
|
+
| \\ |
|
|
3889
|
+
| \\ |
|
|
3890
|
+
| \\|
|
|
3891
|
+
position1-0 -----*----- position1-1
|
|
3892
|
+
|
|
3893
|
+
indexes:
|
|
3894
|
+
------------
|
|
3895
|
+
p0-0 -> 0, 3
|
|
3896
|
+
p0-1 -> 5
|
|
3897
|
+
p1-0 -> 1
|
|
3898
|
+
p1-1 -> 2, 4
|
|
3899
|
+
*/
|
|
3900
|
+
|
|
3901
|
+
var outPos: vec2f;
|
|
3902
|
+
var w = p0.w;
|
|
3903
|
+
var z = p0.z;
|
|
3904
|
+
if (index == 0 || index == 3){
|
|
3905
|
+
outPos = p0ndc.xy - perp0;
|
|
3906
|
+
}
|
|
3907
|
+
else if (index == 1){
|
|
3908
|
+
outPos = p1ndc.xy - perp1;
|
|
3909
|
+
w = p1.w;
|
|
3910
|
+
z = p1.z;
|
|
3911
|
+
}
|
|
3912
|
+
else if (index == 5){
|
|
3913
|
+
outPos = p0ndc.xy + perp0;
|
|
3914
|
+
}
|
|
3915
|
+
else { //if (index == 2 || index == 4)
|
|
3916
|
+
outPos = p1ndc.xy + perp1;
|
|
3917
|
+
w = p1.w;
|
|
3918
|
+
z = p1.z;
|
|
3919
|
+
}
|
|
3920
|
+
|
|
3921
|
+
// return vec4f(outPos , 0, 1.0);
|
|
3922
|
+
return vec4f(outPos * w, z, w);
|
|
3923
|
+
}
|
|
3924
|
+
|
|
3925
|
+
@vertex fn main(@builtin(instance_index) instance: u32,
|
|
3926
|
+
@builtin(vertex_index) index: u32) -> ${WGSL_VERTEXOUTPUT_STRUCT_NAME} {
|
|
3927
|
+
|
|
3928
|
+
// vertex index starting at 1
|
|
3929
|
+
let position0 = computeClipPosition(instance);
|
|
3930
|
+
let position1 = computeClipPosition(instance + 1);
|
|
3931
|
+
|
|
3932
|
+
// apply offset
|
|
3933
|
+
let position = computeOffsetPosition(position0, position1, index);
|
|
3934
|
+
|
|
3935
|
+
return ${WGSL_VERTEXOUTPUT_STRUCT_NAME}(
|
|
3936
|
+
position,
|
|
3937
|
+
instance,
|
|
3938
|
+
index
|
|
3939
|
+
);
|
|
3935
3940
|
}`;
|
|
3936
3941
|
}
|
|
3937
3942
|
|
|
@@ -3940,16 +3945,16 @@ fn computeOffsetPosition(p0: vec4f, p1: vec4f, index: u32) -> vec4f {
|
|
|
3940
3945
|
* Generate a WGSL piece of code that eases 3D picking using color strategy.
|
|
3941
3946
|
*/
|
|
3942
3947
|
function getColorPickingFragmentWgsl(groupIndex = UNIFORM_GROUP_INDEX_COLORPICKING) {
|
|
3943
|
-
return `struct ColorPicker {
|
|
3944
|
-
id: u32,
|
|
3945
|
-
};
|
|
3946
|
-
|
|
3947
|
-
@group(${groupIndex}) @binding(0) var<uniform> colorPicker: ColorPicker;
|
|
3948
|
-
|
|
3949
|
-
@fragment
|
|
3950
|
-
fn main(@builtin(position) position: vec4f) -> @location(0) u32 {
|
|
3951
|
-
return colorPicker.id;
|
|
3952
|
-
}
|
|
3948
|
+
return `struct ColorPicker {
|
|
3949
|
+
id: u32,
|
|
3950
|
+
};
|
|
3951
|
+
|
|
3952
|
+
@group(${groupIndex}) @binding(0) var<uniform> colorPicker: ColorPicker;
|
|
3953
|
+
|
|
3954
|
+
@fragment
|
|
3955
|
+
fn main(@builtin(position) position: vec4f) -> @location(0) u32 {
|
|
3956
|
+
return colorPicker.id;
|
|
3957
|
+
}
|
|
3953
3958
|
`;
|
|
3954
3959
|
}
|
|
3955
3960
|
|
|
@@ -3992,16 +3997,16 @@ fn computeOffsetPosition(p0: vec4f, p1: vec4f, index: u32) -> vec4f {
|
|
|
3992
3997
|
}
|
|
3993
3998
|
return {
|
|
3994
3999
|
// type definitions
|
|
3995
|
-
definitions: [`struct DirectionalLight {
|
|
3996
|
-
color: vec4f,
|
|
3997
|
-
direction: vec3f,
|
|
3998
|
-
intensity: f32
|
|
3999
|
-
}`, `fn computeDirectional(normal: vec3f, color: vec4f, light: DirectionalLight) -> vec4f {
|
|
4000
|
-
let n = normalize(normal);
|
|
4001
|
-
let d = normalize(light.direction);
|
|
4002
|
-
let factor = light.intensity * .5 * (1.0 + dot(n, -d));
|
|
4003
|
-
let output = color.rgb * light.color.rgb * factor;
|
|
4004
|
-
return vec4f(output, color.a);
|
|
4000
|
+
definitions: [`struct DirectionalLight {
|
|
4001
|
+
color: vec4f,
|
|
4002
|
+
direction: vec3f,
|
|
4003
|
+
intensity: f32
|
|
4004
|
+
}`, `fn computeDirectional(normal: vec3f, color: vec4f, light: DirectionalLight) -> vec4f {
|
|
4005
|
+
let n = normalize(normal);
|
|
4006
|
+
let d = normalize(light.direction);
|
|
4007
|
+
let factor = light.intensity * .5 * (1.0 + dot(n, -d));
|
|
4008
|
+
let output = color.rgb * light.color.rgb * factor;
|
|
4009
|
+
return vec4f(output, color.a);
|
|
4005
4010
|
}`],
|
|
4006
4011
|
// bindings
|
|
4007
4012
|
bindings: [`@group(${group}) @binding(${binding}) var<uniform> ${lightReference}: DirectionalLight;`],
|
|
@@ -4023,24 +4028,24 @@ fn computeOffsetPosition(p0: vec4f, p1: vec4f, index: u32) -> vec4f {
|
|
|
4023
4028
|
}
|
|
4024
4029
|
return {
|
|
4025
4030
|
// type definitions
|
|
4026
|
-
definitions: [`struct OmniLight {
|
|
4027
|
-
color: vec4f,
|
|
4028
|
-
position: vec3f,
|
|
4029
|
-
intensity: f32
|
|
4030
|
-
}`, `fn computeOmni(position: vec3f, normal: vec3f, ray: vec3f, color: vec4f, specularColor: vec4f, shininess: f32, light: OmniLight) -> vec4f {
|
|
4031
|
-
|
|
4032
|
-
// color
|
|
4033
|
-
let n = normalize(normal);
|
|
4034
|
-
let d = normalize(position - light.position);
|
|
4035
|
-
let factor = light.intensity * .5 * (1.0 + dot(n, -d));
|
|
4036
|
-
|
|
4037
|
-
// specular
|
|
4038
|
-
let r = normalize(ray);
|
|
4039
|
-
let halfVector = normalize(d + r);
|
|
4040
|
-
let specular = specularColor.rgb * shininess * dot(n, -halfVector);
|
|
4041
|
-
|
|
4042
|
-
let output = color.rgb * light.color.rgb * factor + specular;
|
|
4043
|
-
return vec4f(output, color.a);
|
|
4031
|
+
definitions: [`struct OmniLight {
|
|
4032
|
+
color: vec4f,
|
|
4033
|
+
position: vec3f,
|
|
4034
|
+
intensity: f32
|
|
4035
|
+
}`, `fn computeOmni(position: vec3f, normal: vec3f, ray: vec3f, color: vec4f, specularColor: vec4f, shininess: f32, light: OmniLight) -> vec4f {
|
|
4036
|
+
|
|
4037
|
+
// color
|
|
4038
|
+
let n = normalize(normal);
|
|
4039
|
+
let d = normalize(position - light.position);
|
|
4040
|
+
let factor = light.intensity * .5 * (1.0 + dot(n, -d));
|
|
4041
|
+
|
|
4042
|
+
// specular
|
|
4043
|
+
let r = normalize(ray);
|
|
4044
|
+
let halfVector = normalize(d + r);
|
|
4045
|
+
let specular = specularColor.rgb * shininess * dot(n, -halfVector);
|
|
4046
|
+
|
|
4047
|
+
let output = color.rgb * light.color.rgb * factor + specular;
|
|
4048
|
+
return vec4f(output, color.a);
|
|
4044
4049
|
}`],
|
|
4045
4050
|
// bindings
|
|
4046
4051
|
bindings: [`@group(${group}) @binding(${binding}) var<uniform> ${lightReference}: OmniLight;`],
|
|
@@ -4058,11 +4063,11 @@ fn computeOffsetPosition(p0: vec4f, p1: vec4f, index: u32) -> vec4f {
|
|
|
4058
4063
|
}
|
|
4059
4064
|
return {
|
|
4060
4065
|
// type definitions
|
|
4061
|
-
definitions: [`struct AmbientLight {
|
|
4062
|
-
color: vec4f,
|
|
4063
|
-
intensity: f32
|
|
4064
|
-
}`, `fn computeAmbient(color: vec4f, light: AmbientLight) -> vec4f {
|
|
4065
|
-
return vec4f(light.intensity * color.rgb * light.color.rgb, color.a);
|
|
4066
|
+
definitions: [`struct AmbientLight {
|
|
4067
|
+
color: vec4f,
|
|
4068
|
+
intensity: f32
|
|
4069
|
+
}`, `fn computeAmbient(color: vec4f, light: AmbientLight) -> vec4f {
|
|
4070
|
+
return vec4f(light.intensity * color.rgb * light.color.rgb, color.a);
|
|
4066
4071
|
}`],
|
|
4067
4072
|
// bindings
|
|
4068
4073
|
bindings: [`@group(${group}) @binding(${binding}) var<uniform> ${lightReference}: AmbientLight;`],
|