@luma.gl/engine 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/animation/node-animation-binding.cjs +10 -0
- package/dist/animation/node-animation-binding.d.ts +1 -1
- package/dist/animation/node-animation-binding.d.ts.map +1 -1
- package/dist/animation/node-animation-binding.js +10 -0
- package/dist/animation/node-animation-binding.js.map +1 -1
- package/dist/dist.dev.js +457 -206
- package/dist/dist.min.js +58 -58
- package/dist/gltf/gltf/animations/animations.d.ts +1 -1
- package/dist/gltf/gltf/animations/animations.d.ts.map +1 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.cjs +80 -12
- package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts +8 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.d.ts.map +1 -1
- package/dist/gltf/gltf/create-scenegraph-from-gltf.js +82 -14
- package/dist/gltf/gltf/create-scenegraph-from-gltf.js.map +1 -1
- package/dist/gltf/gltf/gltf-billboard.cjs +6 -1
- package/dist/gltf/gltf/gltf-billboard.d.ts.map +1 -1
- package/dist/gltf/gltf/gltf-billboard.js +6 -1
- package/dist/gltf/gltf/gltf-billboard.js.map +1 -1
- package/dist/gltf/gltf/gltf-extension-support.cjs +2 -2
- package/dist/gltf/gltf/gltf-extension-support.js +2 -2
- package/dist/gltf/gltf/gltf-extension-support.js.map +1 -1
- package/dist/gltf/index.cjs +2 -0
- package/dist/gltf/index.cjs.map +3 -3
- package/dist/gltf/index.d.ts +1 -1
- package/dist/gltf/index.d.ts.map +1 -1
- package/dist/gltf/index.js +1 -1
- package/dist/gltf/index.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-animations.cjs +8 -5
- package/dist/gltf/parsers/parse-gltf-animations.js +20 -5
- package/dist/gltf/parsers/parse-gltf-animations.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-lights.cjs +36 -72
- package/dist/gltf/parsers/parse-gltf-lights.d.ts +6 -2
- package/dist/gltf/parsers/parse-gltf-lights.d.ts.map +1 -1
- package/dist/gltf/parsers/parse-gltf-lights.js +34 -91
- package/dist/gltf/parsers/parse-gltf-lights.js.map +1 -1
- package/dist/gltf/parsers/parse-gltf-metadata.cjs +60 -0
- package/dist/gltf/parsers/parse-gltf-metadata.d.ts +5 -0
- package/dist/gltf/parsers/parse-gltf-metadata.d.ts.map +1 -0
- package/dist/gltf/parsers/parse-gltf-metadata.js +39 -0
- package/dist/gltf/parsers/parse-gltf-metadata.js.map +1 -0
- package/dist/gltf/parsers/parse-gltf.cjs +4 -1
- package/dist/gltf/parsers/parse-gltf.d.ts +4 -0
- package/dist/gltf/parsers/parse-gltf.d.ts.map +1 -1
- package/dist/gltf/parsers/parse-gltf.js +3 -0
- package/dist/gltf/parsers/parse-gltf.js.map +1 -1
- package/dist/gltf/pbr/pbr-environment.cjs +21 -3
- package/dist/gltf/pbr/pbr-environment.d.ts +3 -0
- package/dist/gltf/pbr/pbr-environment.d.ts.map +1 -1
- package/dist/gltf/pbr/pbr-environment.js +19 -1
- package/dist/gltf/pbr/pbr-environment.js.map +1 -1
- package/dist/graph/models/index.cjs.map +1 -1
- package/dist/graph/models/path/path-attribute-model.cjs +1 -1
- package/dist/graph/models/path/path-attribute-model.js +1 -1
- package/dist/graph/models/path/path-attribute-model.js.map +1 -1
- package/dist/graph/models/path/path-storage-model.cjs +1 -1
- package/dist/graph/models/path/path-storage-model.js +1 -1
- package/dist/graph/models/path/path-storage-model.js.map +1 -1
- package/dist/graph/physics/index.cjs.map +1 -1
- package/dist/graph/tables/index.cjs.map +1 -1
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lighting/ambient-occlusion-pass.cjs +126 -0
- package/dist/lighting/ambient-occlusion-pass.d.ts +31 -0
- package/dist/lighting/ambient-occlusion-pass.d.ts.map +1 -0
- package/dist/lighting/ambient-occlusion-pass.js +108 -0
- package/dist/lighting/ambient-occlusion-pass.js.map +1 -0
- package/dist/lighting/clustered-light-grid.cjs +378 -0
- package/dist/lighting/clustered-light-grid.d.ts +94 -0
- package/dist/lighting/clustered-light-grid.d.ts.map +1 -0
- package/dist/lighting/clustered-light-grid.js +370 -0
- package/dist/lighting/clustered-light-grid.js.map +1 -0
- package/dist/lighting/contact-shadow-composite.cjs +80 -0
- package/dist/lighting/contact-shadow-composite.d.ts +6 -0
- package/dist/lighting/contact-shadow-composite.d.ts.map +1 -0
- package/dist/lighting/contact-shadow-composite.js +59 -0
- package/dist/lighting/contact-shadow-composite.js.map +1 -0
- package/dist/lighting/contact-shadow-pass.cjs +102 -0
- package/dist/lighting/contact-shadow-pass.d.ts +23 -0
- package/dist/lighting/contact-shadow-pass.d.ts.map +1 -0
- package/dist/lighting/contact-shadow-pass.js +85 -0
- package/dist/lighting/contact-shadow-pass.js.map +1 -0
- package/dist/lighting/index.cjs +118 -0
- package/dist/lighting/index.cjs.map +6 -0
- package/dist/lighting/index.d.ts +31 -0
- package/dist/lighting/index.d.ts.map +1 -0
- package/dist/lighting/index.js +20 -0
- package/dist/lighting/index.js.map +1 -0
- package/dist/lighting/lightmap-baker.cjs +238 -0
- package/dist/lighting/lightmap-baker.d.ts +62 -0
- package/dist/lighting/lightmap-baker.d.ts.map +1 -0
- package/dist/lighting/lightmap-baker.js +236 -0
- package/dist/lighting/lightmap-baker.js.map +1 -0
- package/dist/lighting/lightmap-data.cjs +117 -0
- package/dist/lighting/lightmap-data.d.ts +20 -0
- package/dist/lighting/lightmap-data.d.ts.map +1 -0
- package/dist/lighting/lightmap-data.js +110 -0
- package/dist/lighting/lightmap-data.js.map +1 -0
- package/dist/lighting/lightmap-environment.cjs +61 -0
- package/dist/lighting/lightmap-environment.d.ts +18 -0
- package/dist/lighting/lightmap-environment.d.ts.map +1 -0
- package/dist/lighting/lightmap-environment.js +46 -0
- package/dist/lighting/lightmap-environment.js.map +1 -0
- package/dist/lighting/pbr-environment.cjs +45 -0
- package/dist/lighting/pbr-environment.d.ts +25 -0
- package/dist/lighting/pbr-environment.d.ts.map +1 -0
- package/dist/lighting/pbr-environment.js +30 -0
- package/dist/lighting/pbr-environment.js.map +1 -0
- package/dist/lighting/pbr-material.cjs +75 -0
- package/dist/lighting/pbr-material.d.ts +33 -0
- package/dist/lighting/pbr-material.d.ts.map +1 -0
- package/dist/lighting/pbr-material.js +52 -0
- package/dist/lighting/pbr-material.js.map +1 -0
- package/dist/lighting/pbr-model.cjs +579 -0
- package/dist/lighting/pbr-model.d.ts +45 -0
- package/dist/lighting/pbr-model.d.ts.map +1 -0
- package/dist/lighting/pbr-model.js +545 -0
- package/dist/lighting/pbr-model.js.map +1 -0
- package/dist/lighting/pbr-surface-pass.cjs +116 -0
- package/dist/lighting/pbr-surface-pass.d.ts +35 -0
- package/dist/lighting/pbr-surface-pass.d.ts.map +1 -0
- package/dist/lighting/pbr-surface-pass.js +98 -0
- package/dist/lighting/pbr-surface-pass.js.map +1 -0
- package/dist/lighting/prefiltered-environment.cjs +275 -0
- package/dist/lighting/prefiltered-environment.d.ts +56 -0
- package/dist/lighting/prefiltered-environment.d.ts.map +1 -0
- package/dist/lighting/prefiltered-environment.js +264 -0
- package/dist/lighting/prefiltered-environment.js.map +1 -0
- package/dist/lighting/shadow-map-renderer.cjs +631 -0
- package/dist/lighting/shadow-map-renderer.d.ts +92 -0
- package/dist/lighting/shadow-map-renderer.d.ts.map +1 -0
- package/dist/lighting/shadow-map-renderer.js +622 -0
- package/dist/lighting/shadow-map-renderer.js.map +1 -0
- package/dist/lighting/shadow-quality.cjs +58 -0
- package/dist/lighting/shadow-quality.d.ts +13 -0
- package/dist/lighting/shadow-quality.d.ts.map +1 -0
- package/dist/lighting/shadow-quality.js +37 -0
- package/dist/lighting/shadow-quality.js.map +1 -0
- package/dist/material/material.cjs +3 -0
- package/dist/material/material.d.ts +2 -0
- package/dist/material/material.d.ts.map +1 -1
- package/dist/material/material.js +3 -0
- package/dist/material/material.js.map +1 -1
- package/dist/model/gpu-vector-model.cjs +11 -1
- package/dist/model/gpu-vector-model.d.ts +4 -2
- package/dist/model/gpu-vector-model.d.ts.map +1 -1
- package/dist/model/gpu-vector-model.js +12 -1
- package/dist/model/gpu-vector-model.js.map +1 -1
- package/dist/scenegraph/controllers/punctual-light-controller.cjs +121 -0
- package/dist/scenegraph/controllers/punctual-light-controller.d.ts +31 -0
- package/dist/scenegraph/controllers/punctual-light-controller.d.ts.map +1 -0
- package/dist/scenegraph/controllers/punctual-light-controller.js +117 -0
- package/dist/scenegraph/controllers/punctual-light-controller.js.map +1 -0
- package/dist/scenegraph/scene-metadata.cjs +43 -0
- package/dist/scenegraph/scene-metadata.d.ts +9 -0
- package/dist/scenegraph/scene-metadata.d.ts.map +1 -0
- package/dist/scenegraph/scene-metadata.js +21 -0
- package/dist/scenegraph/scene-metadata.js.map +1 -0
- package/dist/scenegraph/scenegraph-interaction.cjs +99 -0
- package/dist/scenegraph/scenegraph-interaction.d.ts +47 -0
- package/dist/scenegraph/scenegraph-interaction.d.ts.map +1 -0
- package/dist/scenegraph/scenegraph-interaction.js +79 -0
- package/dist/scenegraph/scenegraph-interaction.js.map +1 -0
- package/dist/scenegraph/scenegraph-node.cjs +10 -0
- package/dist/scenegraph/scenegraph-node.d.ts +10 -0
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +10 -0
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- package/dist/text/experimental.cjs.map +1 -1
- package/dist/text/fonts/atlas/text-utils.cjs +1 -1
- package/dist/text/fonts/atlas/text-utils.js +1 -1
- package/dist/text/fonts/atlas/text-utils.js.map +1 -1
- package/dist/text/fonts/index.cjs.map +1 -1
- package/dist/text/index.cjs.map +1 -1
- package/dist/text/text-2d/models/text-attribute-model.cjs +1 -1
- package/dist/text/text-2d/models/text-attribute-model.js +1 -1
- package/dist/text/text-2d/models/text-attribute-model.js.map +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.cjs +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.js +1 -1
- package/dist/text/text-2d/models/text-dictionary-model.js.map +1 -1
- package/dist/text/text-2d/models/text-storage-model.cjs +1 -1
- package/dist/text/text-2d/models/text-storage-model.js +1 -1
- package/dist/text/text-2d/models/text-storage-model.js.map +1 -1
- package/package.json +13 -8
- package/src/animation/node-animation-binding.ts +18 -1
- package/src/gltf/gltf/animations/animations.ts +8 -1
- package/src/gltf/gltf/create-scenegraph-from-gltf.ts +98 -17
- package/src/gltf/gltf/gltf-billboard.ts +6 -1
- package/src/gltf/gltf/gltf-extension-support.ts +2 -2
- package/src/gltf/index.ts +1 -0
- package/src/gltf/parsers/parse-gltf-animations.ts +22 -8
- package/src/gltf/parsers/parse-gltf-lights.ts +42 -130
- package/src/gltf/parsers/parse-gltf-metadata.ts +40 -0
- package/src/gltf/parsers/parse-gltf.ts +5 -0
- package/src/gltf/pbr/pbr-environment.ts +27 -1
- package/src/graph/models/path/path-attribute-model.ts +1 -1
- package/src/graph/models/path/path-storage-model.ts +1 -1
- package/src/index.ts +16 -0
- package/src/lighting/ambient-occlusion-pass.ts +130 -0
- package/src/lighting/clustered-light-grid.ts +481 -0
- package/src/lighting/contact-shadow-composite.ts +67 -0
- package/src/lighting/contact-shadow-pass.ts +107 -0
- package/src/lighting/index.ts +107 -0
- package/src/lighting/lightmap-baker.ts +306 -0
- package/src/lighting/lightmap-data.ts +138 -0
- package/src/lighting/lightmap-environment.ts +70 -0
- package/src/lighting/pbr-environment.ts +55 -0
- package/src/lighting/pbr-material.ts +85 -0
- package/src/lighting/pbr-model.ts +608 -0
- package/src/lighting/pbr-surface-pass.ts +122 -0
- package/src/lighting/prefiltered-environment.ts +354 -0
- package/src/lighting/shadow-map-renderer.ts +918 -0
- package/src/lighting/shadow-quality.ts +50 -0
- package/src/material/material.ts +3 -0
- package/src/model/gpu-vector-model.ts +18 -3
- package/src/scenegraph/controllers/punctual-light-controller.ts +172 -0
- package/src/scenegraph/scene-metadata.ts +23 -0
- package/src/scenegraph/scenegraph-interaction.ts +131 -0
- package/src/scenegraph/scenegraph-node.ts +12 -0
- package/src/text/fonts/atlas/text-utils.ts +1 -1
- package/src/text/text-2d/models/text-attribute-model.ts +1 -1
- package/src/text/text-2d/models/text-dictionary-model.ts +1 -1
- package/src/text/text-2d/models/text-storage-model.ts +1 -1
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
3
|
+
import { assert } from '@luma.gl/core';
|
|
4
|
+
import { Model } from "../model/model.js";
|
|
5
|
+
import { pbrMaterial, lightmapBake, pbrScene, pbrShadow, pbrSurface, pbrContactShadow, pbrAmbientOcclusion, skin } from '@luma.gl/shaders';
|
|
6
|
+
/** Builds mesh entry points; default source has no scene-specific resources or identifiers. */
|
|
7
|
+
export function getPBRModelWGSL(hooks = {}) {
|
|
8
|
+
return /* wgsl */ `
|
|
9
|
+
struct PBRModelVertexInputs {
|
|
10
|
+
@location(0) positions: vec3f,
|
|
11
|
+
#ifdef HAS_NORMALS
|
|
12
|
+
@location(1) normals: vec3f,
|
|
13
|
+
#endif
|
|
14
|
+
#ifdef HAS_TANGENTS
|
|
15
|
+
@location(2) TANGENT: vec4f,
|
|
16
|
+
#endif
|
|
17
|
+
#ifdef HAS_UV
|
|
18
|
+
@location(3) texCoords: vec2f,
|
|
19
|
+
#endif
|
|
20
|
+
#ifdef HAS_UV_1
|
|
21
|
+
@location(4) texCoords1: vec2f,
|
|
22
|
+
#endif
|
|
23
|
+
#ifdef HAS_SKIN
|
|
24
|
+
@location(5) JOINTS_0: vec4u,
|
|
25
|
+
@location(6) WEIGHTS_0: vec4f,
|
|
26
|
+
#endif
|
|
27
|
+
#ifdef HAS_COLORS
|
|
28
|
+
#ifdef HAS_RGBA_COLORS
|
|
29
|
+
@location(7) colors: vec4f,
|
|
30
|
+
#else
|
|
31
|
+
@location(7) colors: vec3f,
|
|
32
|
+
#endif
|
|
33
|
+
#endif
|
|
34
|
+
${hooks.vertexInputs ?? ''}
|
|
35
|
+
#ifdef HAS_INSTANCING
|
|
36
|
+
@location(8) instanceModelMatrixCol0: vec4f,
|
|
37
|
+
@location(9) instanceModelMatrixCol1: vec4f,
|
|
38
|
+
@location(10) instanceModelMatrixCol2: vec4f,
|
|
39
|
+
@location(11) instanceModelMatrixCol3: vec4f,
|
|
40
|
+
#endif
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
struct PBRModelFragmentInputs {
|
|
44
|
+
@builtin(position) position: vec4f,
|
|
45
|
+
@location(0) pbrPosition: vec3f,
|
|
46
|
+
@location(1) pbrUV0: vec2f,
|
|
47
|
+
@location(2) pbrUV1: vec2f,
|
|
48
|
+
@location(3) pbrNormal: vec3f,
|
|
49
|
+
@location(4) pbrColor: vec4f,
|
|
50
|
+
${hooks.fragmentInputs ?? ''}
|
|
51
|
+
#ifdef HAS_TANGENTS
|
|
52
|
+
@location(5) pbrTangent: vec4f,
|
|
53
|
+
#endif
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
fn getPBRInstanceNormalMatrix(matrix: mat3x3f) -> mat3x3f {
|
|
57
|
+
let firstCofactor = cross(matrix[1], matrix[2]);
|
|
58
|
+
let inverseDeterminant = 1.0 / dot(matrix[0], firstCofactor);
|
|
59
|
+
return mat3x3f(
|
|
60
|
+
firstCofactor,
|
|
61
|
+
cross(matrix[2], matrix[0]),
|
|
62
|
+
cross(matrix[0], matrix[1])
|
|
63
|
+
) * inverseDeterminant;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@vertex
|
|
67
|
+
fn vertexMain(inputs: PBRModelVertexInputs) -> PBRModelFragmentInputs {
|
|
68
|
+
var outputs: PBRModelFragmentInputs;
|
|
69
|
+
var position = vec4f(inputs.positions, 1.0);
|
|
70
|
+
var normal = vec3f(0.0, 0.0, 1.0);
|
|
71
|
+
var tangent = vec4f(1.0, 0.0, 0.0, 1.0);
|
|
72
|
+
var textureCoordinates = vec2f(0.0);
|
|
73
|
+
var secondTextureCoordinates = vec2f(0.0);
|
|
74
|
+
var vertexColor = vec4f(1.0);
|
|
75
|
+
|
|
76
|
+
#ifdef HAS_NORMALS
|
|
77
|
+
normal = inputs.normals;
|
|
78
|
+
#endif
|
|
79
|
+
#ifdef HAS_UV
|
|
80
|
+
textureCoordinates = inputs.texCoords;
|
|
81
|
+
#endif
|
|
82
|
+
#ifdef HAS_UV_1
|
|
83
|
+
secondTextureCoordinates = inputs.texCoords1;
|
|
84
|
+
#endif
|
|
85
|
+
#ifdef HAS_TANGENTS
|
|
86
|
+
tangent = inputs.TANGENT;
|
|
87
|
+
#endif
|
|
88
|
+
#ifdef HAS_COLORS
|
|
89
|
+
#ifdef HAS_RGBA_COLORS
|
|
90
|
+
vertexColor = inputs.colors;
|
|
91
|
+
#else
|
|
92
|
+
vertexColor = vec4f(inputs.colors, 1.0);
|
|
93
|
+
#endif
|
|
94
|
+
#endif
|
|
95
|
+
|
|
96
|
+
#ifdef HAS_SKIN
|
|
97
|
+
let skinMatrix = getSkinMatrix(inputs.WEIGHTS_0, inputs.JOINTS_0);
|
|
98
|
+
position = skinMatrix * position;
|
|
99
|
+
normal = normalize(getPBRInstanceNormalMatrix(mat3x3f(skinMatrix[0].xyz, skinMatrix[1].xyz, skinMatrix[2].xyz)) * normal);
|
|
100
|
+
#ifdef HAS_TANGENTS
|
|
101
|
+
tangent = vec4f(normalize((skinMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w * sign(determinant(mat3x3f(skinMatrix[0].xyz, skinMatrix[1].xyz, skinMatrix[2].xyz))));
|
|
102
|
+
#endif
|
|
103
|
+
#endif
|
|
104
|
+
|
|
105
|
+
#ifdef HAS_INSTANCING
|
|
106
|
+
var instanceMatrix = mat4x4f(
|
|
107
|
+
inputs.instanceModelMatrixCol0,
|
|
108
|
+
inputs.instanceModelMatrixCol1,
|
|
109
|
+
inputs.instanceModelMatrixCol2,
|
|
110
|
+
inputs.instanceModelMatrixCol3
|
|
111
|
+
);
|
|
112
|
+
${hooks.instanceTransform ?? ''} position = instanceMatrix * position;
|
|
113
|
+
let instanceNormalMatrix = getPBRInstanceNormalMatrix(mat3x3f(
|
|
114
|
+
instanceMatrix[0].xyz, instanceMatrix[1].xyz, instanceMatrix[2].xyz
|
|
115
|
+
));
|
|
116
|
+
normal = normalize(instanceNormalMatrix * normal);
|
|
117
|
+
#ifdef HAS_TANGENTS
|
|
118
|
+
tangent = vec4f(normalize((instanceMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w * sign(determinant(mat3x3f(instanceMatrix[0].xyz, instanceMatrix[1].xyz, instanceMatrix[2].xyz))));
|
|
119
|
+
#endif
|
|
120
|
+
#endif
|
|
121
|
+
let worldPosition = pbrProjection.modelMatrix * position;
|
|
122
|
+
normal = normalize((pbrProjection.normalMatrix * vec4f(normal, 0.0)).xyz);
|
|
123
|
+
#ifdef HAS_TANGENTS
|
|
124
|
+
tangent = vec4f(normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w * sign(determinant(mat3x3f(pbrProjection.modelMatrix[0].xyz, pbrProjection.modelMatrix[1].xyz, pbrProjection.modelMatrix[2].xyz))));
|
|
125
|
+
#endif
|
|
126
|
+
outputs.position = pbrProjection.modelViewProjectionMatrix * position;
|
|
127
|
+
#ifdef PBR_LIGHTMAP_PASS
|
|
128
|
+
let atlasUV = (lightmapBake.uvTransform * vec3f(select(textureCoordinates, secondTextureCoordinates, lightmapBake.uvSet == 1), 1.0)).xy;
|
|
129
|
+
outputs.position = vec4f(atlasUV.x * 2.0 - 1.0, 1.0 - atlasUV.y * 2.0, 0.0, 1.0);
|
|
130
|
+
#endif
|
|
131
|
+
${hooks.vertexOutput ?? ''}
|
|
132
|
+
outputs.pbrPosition = worldPosition.xyz / worldPosition.w;
|
|
133
|
+
outputs.pbrUV0 = textureCoordinates;
|
|
134
|
+
outputs.pbrUV1 = secondTextureCoordinates;
|
|
135
|
+
outputs.pbrNormal = normal;
|
|
136
|
+
outputs.pbrColor = vertexColor;
|
|
137
|
+
#ifdef HAS_TANGENTS
|
|
138
|
+
outputs.pbrTangent = tangent;
|
|
139
|
+
#endif
|
|
140
|
+
return outputs;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
${hooks.fragmentDeclarations ?? ''}
|
|
144
|
+
@fragment
|
|
145
|
+
fn fragmentMain(inputs: PBRModelFragmentInputs, @builtin(front_facing) frontFacing: bool)
|
|
146
|
+
${hooks.fragmentReturnType ??
|
|
147
|
+
`#ifndef PBR_SHADOW_PASS
|
|
148
|
+
-> @location(0) vec4f
|
|
149
|
+
#endif`}
|
|
150
|
+
{
|
|
151
|
+
#ifdef DOUBLE_SIDED
|
|
152
|
+
pbr_frontFacing = frontFacing;
|
|
153
|
+
#endif
|
|
154
|
+
fragmentInputs.pbr_vPosition = inputs.pbrPosition;
|
|
155
|
+
fragmentInputs.pbr_vUV0 = inputs.pbrUV0;
|
|
156
|
+
fragmentInputs.pbr_vUV1 = inputs.pbrUV1;
|
|
157
|
+
fragmentInputs.pbr_vNormal = inputs.pbrNormal;
|
|
158
|
+
#ifdef HAS_TANGENTS
|
|
159
|
+
let tangent = normalize(inputs.pbrTangent.xyz);
|
|
160
|
+
let bitangent = normalize(cross(inputs.pbrNormal, tangent)) * inputs.pbrTangent.w;
|
|
161
|
+
fragmentInputs.pbr_vTBN = mat3x3f(tangent, bitangent, inputs.pbrNormal);
|
|
162
|
+
#endif
|
|
163
|
+
${hooks.fragmentBody ??
|
|
164
|
+
`
|
|
165
|
+
#ifdef PBR_LIGHTMAP_PASS
|
|
166
|
+
pbr_discardMaskedFragment(inputs.pbrColor);
|
|
167
|
+
var directionalVisibility = 1.0;
|
|
168
|
+
var pointVisibility = vec4f(1.0);
|
|
169
|
+
var spotVisibility = vec4f(1.0);
|
|
170
|
+
let normal = normalize(inputs.pbrNormal);
|
|
171
|
+
#ifdef PBR_RECEIVE_SHADOWS
|
|
172
|
+
if (pbrShadow.enabled != 0) {
|
|
173
|
+
let viewDepth = -(pbrShadow.viewMatrix * vec4f(inputs.pbrPosition, 1.0)).z;
|
|
174
|
+
directionalVisibility = shadow_getDirectionalFactor(inputs.pbrPosition, normal, viewDepth);
|
|
175
|
+
for (var index = 0; index < 4; index++) {
|
|
176
|
+
pointVisibility[index] = shadow_getPointFactor(index, inputs.pbrPosition, normal);
|
|
177
|
+
spotVisibility[index] = shadow_getSpotFactor(index, inputs.pbrPosition, normal);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
#endif
|
|
181
|
+
return vec4f(lightmap_getIrradiance(inputs.pbrPosition, normal, directionalVisibility, pointVisibility, spotVisibility), lightmapBake.chartId);
|
|
182
|
+
#else
|
|
183
|
+
#ifdef PBR_SHADOW_PASS
|
|
184
|
+
pbr_discardMaskedFragment(inputs.pbrColor);
|
|
185
|
+
#else
|
|
186
|
+
#ifdef PBR_SURFACE_PASS
|
|
187
|
+
pbr_discardMaskedFragment(inputs.pbrColor);
|
|
188
|
+
return pbrSurface_getColor();
|
|
189
|
+
#else
|
|
190
|
+
#ifdef DEBUG_NORMALS
|
|
191
|
+
return vec4f(normalize(inputs.pbrNormal) * 0.5 + vec3f(0.5), 1.0);
|
|
192
|
+
#else
|
|
193
|
+
#ifdef DEBUG_DEPTH
|
|
194
|
+
return vec4f(vec3f(inputs.position.z), 1.0);
|
|
195
|
+
#else
|
|
196
|
+
#ifdef PBR_RECEIVE_AMBIENT_OCCLUSION
|
|
197
|
+
pbrAmbientOcclusion_setFactor(inputs.position.xy);
|
|
198
|
+
#endif
|
|
199
|
+
#ifdef PBR_RECEIVE_SHADOWS
|
|
200
|
+
#ifdef HAS_NORMALS
|
|
201
|
+
let shadowNormal = inputs.pbrNormal;
|
|
202
|
+
#else
|
|
203
|
+
let shadowNormal = normalize(cross(dpdy(inputs.pbrPosition), dpdx(inputs.pbrPosition)));
|
|
204
|
+
#endif
|
|
205
|
+
#ifdef PBR_RECEIVE_CONTACT_SHADOWS
|
|
206
|
+
return pbrShadow_filterColorWithDirectionalContact(inputs.pbrColor, inputs.pbrPosition, shadowNormal, pbrContactShadow_getFactor(inputs.position.xy));
|
|
207
|
+
#else
|
|
208
|
+
return pbrShadow_filterColor(inputs.pbrColor, inputs.pbrPosition, shadowNormal);
|
|
209
|
+
#endif
|
|
210
|
+
#else
|
|
211
|
+
#ifdef PBR_RECEIVE_CONTACT_SHADOWS
|
|
212
|
+
return pbrContactShadow_filterColor(inputs.pbrColor, inputs.position.xy);
|
|
213
|
+
#else
|
|
214
|
+
return pbr_filterColor(inputs.pbrColor);
|
|
215
|
+
#endif
|
|
216
|
+
#endif
|
|
217
|
+
#endif
|
|
218
|
+
#endif
|
|
219
|
+
#endif
|
|
220
|
+
#endif
|
|
221
|
+
#endif
|
|
222
|
+
`}
|
|
223
|
+
}
|
|
224
|
+
`;
|
|
225
|
+
}
|
|
226
|
+
export const PBR_MODEL_WGSL_SHADER = /* @__PURE__ */ getPBRModelWGSL();
|
|
227
|
+
const PBR_VERTEX_SHADER = /* glsl */ `#version 300 es
|
|
228
|
+
in vec3 positions;
|
|
229
|
+
#ifdef HAS_NORMALS
|
|
230
|
+
in vec3 normals;
|
|
231
|
+
#endif
|
|
232
|
+
#ifdef HAS_TANGENTS
|
|
233
|
+
in vec4 TANGENT;
|
|
234
|
+
#endif
|
|
235
|
+
#ifdef HAS_UV
|
|
236
|
+
in vec2 texCoords;
|
|
237
|
+
#endif
|
|
238
|
+
#ifdef HAS_UV_1
|
|
239
|
+
in vec2 texCoords1;
|
|
240
|
+
#endif
|
|
241
|
+
#ifdef HAS_SKIN
|
|
242
|
+
in uvec4 JOINTS_0;
|
|
243
|
+
in vec4 WEIGHTS_0;
|
|
244
|
+
#endif
|
|
245
|
+
#ifdef HAS_COLORS
|
|
246
|
+
#ifdef HAS_RGBA_COLORS
|
|
247
|
+
in vec4 colors;
|
|
248
|
+
#else
|
|
249
|
+
in vec3 colors;
|
|
250
|
+
#endif
|
|
251
|
+
#endif
|
|
252
|
+
#ifdef HAS_INSTANCING
|
|
253
|
+
in vec4 instanceModelMatrixCol0;
|
|
254
|
+
in vec4 instanceModelMatrixCol1;
|
|
255
|
+
in vec4 instanceModelMatrixCol2;
|
|
256
|
+
in vec4 instanceModelMatrixCol3;
|
|
257
|
+
#endif
|
|
258
|
+
out vec4 sceneVertexColor;
|
|
259
|
+
|
|
260
|
+
void main(void) {
|
|
261
|
+
vec4 position = vec4(positions, 1.0);
|
|
262
|
+
vec4 normal = vec4(0.0, 0.0, 1.0, 0.0);
|
|
263
|
+
vec4 tangent = vec4(1.0, 0.0, 0.0, 1.0);
|
|
264
|
+
vec2 textureCoordinates = vec2(0.0);
|
|
265
|
+
vec2 secondTextureCoordinates = vec2(0.0);
|
|
266
|
+
sceneVertexColor = vec4(1.0);
|
|
267
|
+
|
|
268
|
+
#ifdef HAS_NORMALS
|
|
269
|
+
normal = vec4(normals, 0.0);
|
|
270
|
+
#endif
|
|
271
|
+
#ifdef HAS_TANGENTS
|
|
272
|
+
tangent = TANGENT;
|
|
273
|
+
#endif
|
|
274
|
+
#ifdef HAS_UV
|
|
275
|
+
textureCoordinates = texCoords;
|
|
276
|
+
#endif
|
|
277
|
+
#ifdef HAS_UV_1
|
|
278
|
+
secondTextureCoordinates = texCoords1;
|
|
279
|
+
#endif
|
|
280
|
+
#ifdef HAS_COLORS
|
|
281
|
+
#ifdef HAS_RGBA_COLORS
|
|
282
|
+
sceneVertexColor = colors;
|
|
283
|
+
#else
|
|
284
|
+
sceneVertexColor = vec4(colors, 1.0);
|
|
285
|
+
#endif
|
|
286
|
+
#endif
|
|
287
|
+
|
|
288
|
+
#ifdef HAS_SKIN
|
|
289
|
+
mat4 skinMatrix = getSkinMatrix(WEIGHTS_0, JOINTS_0);
|
|
290
|
+
position = skinMatrix * position;
|
|
291
|
+
normal = vec4(transpose(inverse(mat3(skinMatrix))) * normal.xyz, 0.0);
|
|
292
|
+
tangent = vec4((skinMatrix * vec4(tangent.xyz, 0.0)).xyz, tangent.w * sign(determinant(mat3(skinMatrix))));
|
|
293
|
+
#endif
|
|
294
|
+
|
|
295
|
+
#ifdef HAS_INSTANCING
|
|
296
|
+
mat4 instanceMatrix = mat4(
|
|
297
|
+
instanceModelMatrixCol0,
|
|
298
|
+
instanceModelMatrixCol1,
|
|
299
|
+
instanceModelMatrixCol2,
|
|
300
|
+
instanceModelMatrixCol3
|
|
301
|
+
);
|
|
302
|
+
position = instanceMatrix * position;
|
|
303
|
+
normal = vec4(normalize(transpose(inverse(mat3(instanceMatrix))) * normal.xyz), 0.0);
|
|
304
|
+
tangent = vec4(normalize(mat3(instanceMatrix) * tangent.xyz), tangent.w * sign(determinant(mat3(instanceMatrix))));
|
|
305
|
+
#endif
|
|
306
|
+
|
|
307
|
+
tangent.w *= sign(determinant(mat3(pbrProjection.modelMatrix)));
|
|
308
|
+
pbr_setPositionNormalTangentUV(
|
|
309
|
+
position,
|
|
310
|
+
normal,
|
|
311
|
+
tangent,
|
|
312
|
+
textureCoordinates,
|
|
313
|
+
secondTextureCoordinates
|
|
314
|
+
);
|
|
315
|
+
gl_Position = pbrProjection.modelViewProjectionMatrix * position;
|
|
316
|
+
#ifdef PBR_LIGHTMAP_PASS
|
|
317
|
+
vec2 atlasUV = (lightmapBake.uvTransform * vec3(lightmapBake.uvSet == 1 ? secondTextureCoordinates : textureCoordinates, 1.0)).xy;
|
|
318
|
+
gl_Position = vec4(atlasUV * 2.0 - 1.0, 0.0, 1.0);
|
|
319
|
+
#endif
|
|
320
|
+
#ifdef PBR_SHADOW_PASS
|
|
321
|
+
// ShadowMapRenderer light projections use [0, 1] depth on both backends.
|
|
322
|
+
gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;
|
|
323
|
+
#endif
|
|
324
|
+
}
|
|
325
|
+
`;
|
|
326
|
+
const PBR_FRAGMENT_SHADER = /* glsl */ `#version 300 es
|
|
327
|
+
in vec4 sceneVertexColor;
|
|
328
|
+
#ifndef PBR_SHADOW_PASS
|
|
329
|
+
out vec4 fragmentColor;
|
|
330
|
+
#endif
|
|
331
|
+
|
|
332
|
+
void main(void) {
|
|
333
|
+
#ifdef PBR_LIGHTMAP_PASS
|
|
334
|
+
pbr_discardMaskedFragment(sceneVertexColor);
|
|
335
|
+
#ifdef HAS_TANGENTS
|
|
336
|
+
vec3 normal = normalize(pbr_vTBN[2]);
|
|
337
|
+
#else
|
|
338
|
+
vec3 normal = normalize(pbr_vNormal);
|
|
339
|
+
#endif
|
|
340
|
+
float directionalVisibility = 1.0;
|
|
341
|
+
vec4 pointVisibility = vec4(1.0);
|
|
342
|
+
vec4 spotVisibility = vec4(1.0);
|
|
343
|
+
#ifdef PBR_RECEIVE_SHADOWS
|
|
344
|
+
if (pbrShadow.enabled != 0) {
|
|
345
|
+
float viewDepth = -(pbrShadow.viewMatrix * vec4(pbr_vPosition, 1.0)).z;
|
|
346
|
+
directionalVisibility = shadow_getDirectionalFactor(pbr_vPosition, normal, viewDepth);
|
|
347
|
+
for (int index = 0; index < 4; index++) {
|
|
348
|
+
pointVisibility[index] = shadow_getPointFactor(index, pbr_vPosition, normal);
|
|
349
|
+
spotVisibility[index] = shadow_getSpotFactor(index, pbr_vPosition, normal);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
#endif
|
|
353
|
+
fragmentColor = vec4(lightmap_getIrradiance(pbr_vPosition, normal, directionalVisibility, pointVisibility, spotVisibility), lightmapBake.chartId);
|
|
354
|
+
#else
|
|
355
|
+
#ifdef PBR_SHADOW_PASS
|
|
356
|
+
pbr_discardMaskedFragment(sceneVertexColor);
|
|
357
|
+
#else
|
|
358
|
+
#ifdef PBR_SURFACE_PASS
|
|
359
|
+
pbr_discardMaskedFragment(sceneVertexColor);
|
|
360
|
+
fragmentColor = pbrSurface_getColor();
|
|
361
|
+
#else
|
|
362
|
+
#ifdef DEBUG_NORMALS
|
|
363
|
+
#ifdef HAS_TANGENTS
|
|
364
|
+
fragmentColor = vec4(normalize(pbr_vTBN[2]) * 0.5 + 0.5, 1.0);
|
|
365
|
+
#else
|
|
366
|
+
#ifdef HAS_NORMALS
|
|
367
|
+
fragmentColor = vec4(normalize(pbr_vNormal) * 0.5 + 0.5, 1.0);
|
|
368
|
+
#else
|
|
369
|
+
fragmentColor = vec4(0.5, 0.5, 1.0, 1.0);
|
|
370
|
+
#endif
|
|
371
|
+
#endif
|
|
372
|
+
#else
|
|
373
|
+
#ifdef DEBUG_DEPTH
|
|
374
|
+
fragmentColor = vec4(vec3(gl_FragCoord.z), 1.0);
|
|
375
|
+
#else
|
|
376
|
+
#ifdef PBR_RECEIVE_AMBIENT_OCCLUSION
|
|
377
|
+
pbrAmbientOcclusion_setFactor(gl_FragCoord.xy);
|
|
378
|
+
#endif
|
|
379
|
+
#ifdef PBR_RECEIVE_SHADOWS
|
|
380
|
+
#ifdef HAS_NORMALS
|
|
381
|
+
#ifdef HAS_TANGENTS
|
|
382
|
+
vec3 shadowNormal = pbr_vTBN[2];
|
|
383
|
+
#else
|
|
384
|
+
vec3 shadowNormal = pbr_vNormal;
|
|
385
|
+
#endif
|
|
386
|
+
#else
|
|
387
|
+
vec3 shadowNormal = normalize(cross(dFdx(pbr_vPosition), dFdy(pbr_vPosition)));
|
|
388
|
+
#endif
|
|
389
|
+
#ifdef PBR_RECEIVE_CONTACT_SHADOWS
|
|
390
|
+
fragmentColor = pbrShadow_filterColorWithDirectionalContact(sceneVertexColor, pbr_vPosition, shadowNormal, pbrContactShadow_getFactor(gl_FragCoord.xy));
|
|
391
|
+
#else
|
|
392
|
+
fragmentColor = pbrShadow_filterColor(sceneVertexColor, pbr_vPosition, shadowNormal);
|
|
393
|
+
#endif
|
|
394
|
+
#else
|
|
395
|
+
#ifdef PBR_RECEIVE_CONTACT_SHADOWS
|
|
396
|
+
fragmentColor = pbrContactShadow_filterColor(sceneVertexColor, gl_FragCoord.xy);
|
|
397
|
+
#else
|
|
398
|
+
fragmentColor = pbr_filterColor(sceneVertexColor);
|
|
399
|
+
#endif
|
|
400
|
+
#endif
|
|
401
|
+
#endif
|
|
402
|
+
#endif
|
|
403
|
+
#endif
|
|
404
|
+
#endif
|
|
405
|
+
#endif
|
|
406
|
+
}
|
|
407
|
+
`;
|
|
408
|
+
/** Creates a standalone WebGPU/WebGL PBR model with a borrowed material. */
|
|
409
|
+
export function createPBRModel(device, options) {
|
|
410
|
+
const { receiveShadows = false, receiveContactShadows = false, receiveAmbientOcclusion = false, ...modelOptions } = options;
|
|
411
|
+
const shaderModules = [
|
|
412
|
+
pbrScene,
|
|
413
|
+
pbrMaterial,
|
|
414
|
+
...(receiveShadows ? [pbrShadow] : []),
|
|
415
|
+
...(receiveContactShadows ? [pbrContactShadow] : []),
|
|
416
|
+
...(receiveAmbientOcclusion ? [pbrAmbientOcclusion] : []),
|
|
417
|
+
...(options.defines?.['PBR_SURFACE_PASS'] ? [pbrSurface] : []),
|
|
418
|
+
...(options.modules || [])
|
|
419
|
+
];
|
|
420
|
+
const modules = shaderModules.filter((module, moduleIndex) => shaderModules.findIndex(candidate => candidate.name === module.name) === moduleIndex);
|
|
421
|
+
const geometryDefines = getPBRGeometryDefines(options.geometry);
|
|
422
|
+
const hasSkin = Boolean(options.defines?.['HAS_SKIN'] ?? geometryDefines['HAS_SKIN']);
|
|
423
|
+
if (hasSkin && !modules.some(module => module.name === skin.name)) {
|
|
424
|
+
modules.push(skin);
|
|
425
|
+
}
|
|
426
|
+
const model = new Model(device, {
|
|
427
|
+
source: PBR_MODEL_WGSL_SHADER,
|
|
428
|
+
vs: PBR_VERTEX_SHADER,
|
|
429
|
+
fs: PBR_FRAGMENT_SHADER,
|
|
430
|
+
...modelOptions,
|
|
431
|
+
modules,
|
|
432
|
+
defines: {
|
|
433
|
+
USE_SCENE_COLOR_MANAGEMENT: true,
|
|
434
|
+
PBR_RECEIVE_SHADOWS: receiveShadows,
|
|
435
|
+
PBR_RECEIVE_CONTACT_SHADOWS: receiveContactShadows,
|
|
436
|
+
PBR_RECEIVE_AMBIENT_OCCLUSION: receiveAmbientOcclusion,
|
|
437
|
+
...geometryDefines,
|
|
438
|
+
...getPBRTextureDefines(options.material.getResourceBindings()),
|
|
439
|
+
...options.defines
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
if (!options.shaderInputs) {
|
|
443
|
+
const identity = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
444
|
+
model.shaderInputs.setProps({
|
|
445
|
+
pbrProjection: {
|
|
446
|
+
modelMatrix: identity.slice(),
|
|
447
|
+
modelViewProjectionMatrix: identity.slice(),
|
|
448
|
+
normalMatrix: identity.slice(),
|
|
449
|
+
camera: [0, 0, 1]
|
|
450
|
+
},
|
|
451
|
+
pbrScene: { toneMapMode: 0, outputEncoding: 0 }
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
return model;
|
|
455
|
+
}
|
|
456
|
+
/** Creates a depth-only caster sharing PBR geometry, transforms, skinning and alpha cutouts.
|
|
457
|
+
* Supply the zero-to-one light projection returned by ShadowMapRenderer on both backends.
|
|
458
|
+
* The material is borrowed; caster and visible models may share it.
|
|
459
|
+
*/
|
|
460
|
+
export function createPBRShadowModel(device, options) {
|
|
461
|
+
return createPBRModel(device, {
|
|
462
|
+
colorAttachmentFormats: [],
|
|
463
|
+
depthStencilAttachmentFormat: 'depth32float',
|
|
464
|
+
...options,
|
|
465
|
+
receiveShadows: false,
|
|
466
|
+
receiveContactShadows: false,
|
|
467
|
+
receiveAmbientOcclusion: false,
|
|
468
|
+
defines: { ...options.defines, PBR_SHADOW_PASS: true },
|
|
469
|
+
parameters: { depthWriteEnabled: true, depthCompare: 'less-equal', ...options.parameters }
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
/** Creates a camera-space depth/normal model with the shared PBR vertex and alpha-cutout paths. */
|
|
473
|
+
export function createPBRSurfaceModel(device, options) {
|
|
474
|
+
return createPBRModel(device, {
|
|
475
|
+
colorAttachmentFormats: ['rgba8unorm'],
|
|
476
|
+
depthStencilAttachmentFormat: 'depth32float',
|
|
477
|
+
...options,
|
|
478
|
+
receiveShadows: false,
|
|
479
|
+
receiveContactShadows: false,
|
|
480
|
+
receiveAmbientOcclusion: false,
|
|
481
|
+
defines: { ...options.defines, PBR_SHADOW_PASS: false, PBR_SURFACE_PASS: true },
|
|
482
|
+
parameters: { depthWriteEnabled: true, depthCompare: 'less-equal', ...options.parameters }
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
/** Returns shader features implied by canonical CPU geometry attributes. */
|
|
486
|
+
export function getPBRGeometryDefines(geometry) {
|
|
487
|
+
const attributes = geometry && 'attributes' in geometry ? geometry.attributes : {};
|
|
488
|
+
const colors = attributes['COLOR_0'] || attributes['colors'];
|
|
489
|
+
return {
|
|
490
|
+
HAS_NORMALS: Boolean(attributes['NORMAL'] || attributes['normals']),
|
|
491
|
+
HAS_TANGENTS: Boolean(attributes['TANGENT'] || attributes['tangents']),
|
|
492
|
+
HAS_UV: Boolean(attributes['TEXCOORD_0'] || attributes['texCoords']),
|
|
493
|
+
HAS_UV_1: Boolean(attributes['TEXCOORD_1'] || attributes['texCoords1']),
|
|
494
|
+
HAS_SKIN: Boolean(attributes['JOINTS_0'] && attributes['WEIGHTS_0']),
|
|
495
|
+
HAS_COLORS: Boolean(colors),
|
|
496
|
+
HAS_RGBA_COLORS: Boolean(colors && 'size' in colors && colors.size === 4)
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
/** Returns feature-specialized shader defines for texture bindings present on one PBR material. */
|
|
500
|
+
export function getPBRTextureDefines(bindings) {
|
|
501
|
+
return {
|
|
502
|
+
HAS_BASECOLORMAP: Boolean(bindings['pbr_baseColorSampler']),
|
|
503
|
+
HAS_NORMALMAP: Boolean(bindings['pbr_normalSampler']),
|
|
504
|
+
HAS_LIGHTMAP: Boolean(bindings['pbr_lightmapSampler']),
|
|
505
|
+
HAS_EMISSIVEMAP: Boolean(bindings['pbr_emissiveSampler']),
|
|
506
|
+
HAS_METALROUGHNESSMAP: Boolean(bindings['pbr_metallicRoughnessSampler']),
|
|
507
|
+
HAS_OCCLUSIONMAP: Boolean(bindings['pbr_occlusionSampler']),
|
|
508
|
+
HAS_SPECULARCOLORMAP: Boolean(bindings['pbr_specularColorSampler']),
|
|
509
|
+
HAS_SPECULARINTENSITYMAP: Boolean(bindings['pbr_specularIntensitySampler']),
|
|
510
|
+
HAS_TRANSMISSIONMAP: Boolean(bindings['pbr_transmissionSampler']),
|
|
511
|
+
HAS_THICKNESSMAP: Boolean(bindings['pbr_thicknessSampler']),
|
|
512
|
+
HAS_CLEARCOATMAP: Boolean(bindings['pbr_clearcoatSampler']),
|
|
513
|
+
HAS_CLEARCOATROUGHNESSMAP: Boolean(bindings['pbr_clearcoatRoughnessSampler']),
|
|
514
|
+
HAS_CLEARCOATNORMALMAP: Boolean(bindings['pbr_clearcoatNormalSampler']),
|
|
515
|
+
HAS_SHEENCOLORMAP: Boolean(bindings['pbr_sheenColorSampler']),
|
|
516
|
+
HAS_SHEENROUGHNESSMAP: Boolean(bindings['pbr_sheenRoughnessSampler']),
|
|
517
|
+
HAS_IRIDESCENCEMAP: Boolean(bindings['pbr_iridescenceSampler']),
|
|
518
|
+
HAS_IRIDESCENCETHICKNESSMAP: Boolean(bindings['pbr_iridescenceThicknessSampler']),
|
|
519
|
+
HAS_ANISOTROPYMAP: Boolean(bindings['pbr_anisotropySampler']),
|
|
520
|
+
HAS_BUMPMAP: Boolean(bindings['pbr_bumpSampler']),
|
|
521
|
+
HAS_DIFFUSETRANSMISSIONMAP: Boolean(bindings['pbr_diffuseTransmissionSampler']),
|
|
522
|
+
HAS_DIFFUSETRANSMISSIONCOLORMAP: Boolean(bindings['pbr_diffuseTransmissionColorSampler']),
|
|
523
|
+
HAS_MULTISCATTERCOLORMAP: Boolean(bindings['pbr_multiscatterColorSampler'])
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
/** Creates a borrowed-material bake model; output is linear irradiance E with chart ID in alpha. */
|
|
527
|
+
export function createPBRLightmapModel(device, options) {
|
|
528
|
+
const features = { ...getPBRGeometryDefines(options.geometry), ...options.defines };
|
|
529
|
+
// Bake surfaces require geometric normals and the selected atlas UV attributes.
|
|
530
|
+
assert(features['HAS_NORMALS'] && (features['HAS_UV'] || features['HAS_UV_1']));
|
|
531
|
+
return createPBRModel(device, {
|
|
532
|
+
colorAttachmentFormats: ['rgba16float'],
|
|
533
|
+
...options,
|
|
534
|
+
modules: [lightmapBake, ...(options.modules || [])],
|
|
535
|
+
receiveContactShadows: false,
|
|
536
|
+
receiveAmbientOcclusion: false,
|
|
537
|
+
defines: { ...options.defines, HAS_LIGHTMAP: false, USE_IBL: false, PBR_LIGHTMAP_PASS: true },
|
|
538
|
+
parameters: {
|
|
539
|
+
...options.parameters,
|
|
540
|
+
depthWriteEnabled: false,
|
|
541
|
+
cullMode: 'none'
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
//# sourceMappingURL=pbr-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbr-model.js","sourceRoot":"","sources":["../../src/lighting/pbr-model.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAAC,MAAM,EAAc,MAAM,eAAe,CAAC;AAElD,OAAO,EAAC,KAAK,EAAkB,0BAAuB;AACtD,OAAO,EACL,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,mBAAmB,EACnB,IAAI,EACL,MAAM,kBAAkB,CAAC;AAa1B,+FAA+F;AAC/F,MAAM,UAAU,eAAe,CAAC,QAA6B,EAAE;IAC7D,OAAO,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BlB,KAAK,CAAC,YAAY,IAAI,EAAE;;;;;;;;;;;;;;;;EAgBxB,KAAK,CAAC,cAAc,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GAAG,OAAO,CAAC,UAAU;YACrB,iBAAiB,EAAE,KAAK;YACxB,QAAQ,EAAE,MAAM;SACjB;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var pbr_surface_pass_exports = {};
|
|
19
|
+
__export(pbr_surface_pass_exports, {
|
|
20
|
+
PBRSurfacePass: () => PBRSurfacePass
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(pbr_surface_pass_exports);
|
|
23
|
+
var import_core = require("@luma.gl/core");
|
|
24
|
+
class PBRSurfacePass {
|
|
25
|
+
device;
|
|
26
|
+
resources;
|
|
27
|
+
destroyed = false;
|
|
28
|
+
constructor(device, props) {
|
|
29
|
+
this.device = device;
|
|
30
|
+
this.resources = createSurfaceResources(device, props);
|
|
31
|
+
}
|
|
32
|
+
get width() {
|
|
33
|
+
return this.resources.width;
|
|
34
|
+
}
|
|
35
|
+
get height() {
|
|
36
|
+
return this.resources.height;
|
|
37
|
+
}
|
|
38
|
+
/** Borrowed rgba8unorm encoded view normals; alpha zero denotes background. */
|
|
39
|
+
get normalTexture() {
|
|
40
|
+
return this.resources.normalTexture;
|
|
41
|
+
}
|
|
42
|
+
/** Borrowed depth32float hardware depth in [0,1], cleared to one. */
|
|
43
|
+
get depthTexture() {
|
|
44
|
+
return this.resources.depthTexture;
|
|
45
|
+
}
|
|
46
|
+
get framebuffer() {
|
|
47
|
+
return this.resources.framebuffer;
|
|
48
|
+
}
|
|
49
|
+
/** Replaces and destroys old attachments only when dimensions change. Rebind consumers afterward. */
|
|
50
|
+
resize(props) {
|
|
51
|
+
(0, import_core.assert)(!this.destroyed);
|
|
52
|
+
if (props.width === this.width && props.height === this.height)
|
|
53
|
+
return;
|
|
54
|
+
const resources = createSurfaceResources(this.device, props);
|
|
55
|
+
destroySurfaceResources(this.resources);
|
|
56
|
+
this.resources = resources;
|
|
57
|
+
}
|
|
58
|
+
/** Records camera-surface draws and ends the pass even if a callback throws. Never submits. */
|
|
59
|
+
render(options) {
|
|
60
|
+
var _a;
|
|
61
|
+
(0, import_core.assert)(!this.destroyed);
|
|
62
|
+
const view = { width: this.width, height: this.height, framebuffer: this.framebuffer };
|
|
63
|
+
(_a = options.prepareSurfaces) == null ? void 0 : _a.call(options, view);
|
|
64
|
+
const renderPass = this.device.beginRenderPass({
|
|
65
|
+
framebuffer: this.framebuffer,
|
|
66
|
+
clearColor: [0.5, 0.5, 1, 0],
|
|
67
|
+
clearDepth: 1
|
|
68
|
+
});
|
|
69
|
+
try {
|
|
70
|
+
renderPass.setParameters({ viewport: [0, 0, this.width, this.height] });
|
|
71
|
+
options.drawSurfaces({ ...view, renderPass });
|
|
72
|
+
} finally {
|
|
73
|
+
renderPass.end();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
destroy() {
|
|
77
|
+
if (this.destroyed)
|
|
78
|
+
return;
|
|
79
|
+
this.destroyed = true;
|
|
80
|
+
destroySurfaceResources(this.resources);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function createSurfaceResources(device, props) {
|
|
84
|
+
const { width, height } = props;
|
|
85
|
+
(0, import_core.assert)(Number.isInteger(width) && width > 0 && Number.isInteger(height) && height > 0);
|
|
86
|
+
let normalTexture;
|
|
87
|
+
let depthTexture;
|
|
88
|
+
let framebuffer;
|
|
89
|
+
try {
|
|
90
|
+
const usage = import_core.Texture.RENDER_ATTACHMENT | import_core.Texture.SAMPLE | import_core.Texture.COPY_SRC;
|
|
91
|
+
const sampler = { minFilter: "nearest", magFilter: "nearest" };
|
|
92
|
+
normalTexture = device.createTexture({ width, height, format: "rgba8unorm", usage, sampler });
|
|
93
|
+
depthTexture = device.createTexture({ width, height, format: "depth32float", usage, sampler });
|
|
94
|
+
framebuffer = device.createFramebuffer({
|
|
95
|
+
width,
|
|
96
|
+
height,
|
|
97
|
+
colorAttachments: [normalTexture],
|
|
98
|
+
depthStencilAttachment: depthTexture
|
|
99
|
+
});
|
|
100
|
+
return { width, height, normalTexture, depthTexture, framebuffer };
|
|
101
|
+
} catch (error) {
|
|
102
|
+
framebuffer == null ? void 0 : framebuffer.destroy();
|
|
103
|
+
depthTexture == null ? void 0 : depthTexture.destroy();
|
|
104
|
+
normalTexture == null ? void 0 : normalTexture.destroy();
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function destroySurfaceResources(resources) {
|
|
109
|
+
resources.framebuffer.destroy();
|
|
110
|
+
resources.depthTexture.destroy();
|
|
111
|
+
resources.normalTexture.destroy();
|
|
112
|
+
}
|
|
113
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
114
|
+
0 && (module.exports = {
|
|
115
|
+
PBRSurfacePass
|
|
116
|
+
});
|