@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
|
@@ -52,6 +52,14 @@ export type LightingUniforms = {
|
|
|
52
52
|
lightPosition2: Readonly<NumberArray3>;
|
|
53
53
|
lightDirection2: Readonly<NumberArray3>;
|
|
54
54
|
lightAttenuation2: Readonly<NumberArray3>;
|
|
55
|
+
lightColor3: Readonly<NumberArray3>;
|
|
56
|
+
lightPosition3: Readonly<NumberArray3>;
|
|
57
|
+
lightDirection3: Readonly<NumberArray3>;
|
|
58
|
+
lightAttenuation3: Readonly<NumberArray3>;
|
|
59
|
+
lightColor4: Readonly<NumberArray3>;
|
|
60
|
+
lightPosition4: Readonly<NumberArray3>;
|
|
61
|
+
lightDirection4: Readonly<NumberArray3>;
|
|
62
|
+
lightAttenuation4: Readonly<NumberArray3>;
|
|
55
63
|
};
|
|
56
64
|
/** UBO ready lighting module */
|
|
57
65
|
export declare const lighting: {
|
|
@@ -77,6 +85,14 @@ export declare const lighting: {
|
|
|
77
85
|
readonly lightPosition2: "vec3<f32>";
|
|
78
86
|
readonly lightDirection2: "vec3<f32>";
|
|
79
87
|
readonly lightAttenuation2: "vec3<f32>";
|
|
88
|
+
readonly lightColor3: "vec3<f32>";
|
|
89
|
+
readonly lightPosition3: "vec3<f32>";
|
|
90
|
+
readonly lightDirection3: "vec3<f32>";
|
|
91
|
+
readonly lightAttenuation3: "vec3<f32>";
|
|
92
|
+
readonly lightColor4: "vec3<f32>";
|
|
93
|
+
readonly lightPosition4: "vec3<f32>";
|
|
94
|
+
readonly lightDirection4: "vec3<f32>";
|
|
95
|
+
readonly lightAttenuation4: "vec3<f32>";
|
|
80
96
|
};
|
|
81
97
|
readonly defaultUniforms: {
|
|
82
98
|
readonly enabled: 1;
|
|
@@ -96,10 +112,18 @@ export declare const lighting: {
|
|
|
96
112
|
readonly lightPosition2: readonly [1, 1, 2];
|
|
97
113
|
readonly lightDirection2: readonly [1, 1, 1];
|
|
98
114
|
readonly lightAttenuation2: readonly [1, 0, 0];
|
|
115
|
+
readonly lightColor3: readonly [1, 1, 1];
|
|
116
|
+
readonly lightPosition3: readonly [1, 1, 2];
|
|
117
|
+
readonly lightDirection3: readonly [1, 1, 1];
|
|
118
|
+
readonly lightAttenuation3: readonly [1, 0, 0];
|
|
119
|
+
readonly lightColor4: readonly [1, 1, 1];
|
|
120
|
+
readonly lightPosition4: readonly [1, 1, 2];
|
|
121
|
+
readonly lightDirection4: readonly [1, 1, 1];
|
|
122
|
+
readonly lightAttenuation4: readonly [1, 0, 0];
|
|
99
123
|
};
|
|
100
|
-
readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n
|
|
101
|
-
readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.
|
|
102
|
-
readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n default: \n return PointLight(lighting.
|
|
124
|
+
readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nconst MAX_LIGHTS: i32 = 5;\n\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n lightType: i32,\n\n directionalLightCount: i32,\n pointLightCount: i32,\n\n ambientColor: vec3<f32>,\n\n lightColor0: vec3<f32>,\n lightPosition0: vec3<f32>,\n lightDirection0: vec3<f32>,\n lightAttenuation0: vec3<f32>,\n\n lightColor1: vec3<f32>,\n lightPosition1: vec3<f32>,\n lightDirection1: vec3<f32>,\n lightAttenuation1: vec3<f32>,\n\n lightColor2: vec3<f32>,\n lightPosition2: vec3<f32>,\n lightDirection2: vec3<f32>,\n lightAttenuation2: vec3<f32>,\n\n lightColor3: vec3<f32>,\n lightPosition3: vec3<f32>,\n lightDirection3: vec3<f32>,\n lightAttenuation3: vec3<f32>,\n\n lightColor4: vec3<f32>,\n lightPosition4: vec3<f32>,\n lightDirection4: vec3<f32>,\n lightAttenuation4: vec3<f32>,\n};\n\n// Binding 0:1 is reserved for lighting (Note: could go into separate bind group as it is stable across draw calls)\n@binding(1) @group(0) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n switch (index) {\n case 0: {\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n }\n case 1: {\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n }\n case 2: {\n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n }\n case 3: {\n return PointLight(lighting.lightColor3, lighting.lightPosition3, lighting.lightAttenuation3);\n }\n case 4, default: {\n return PointLight(lighting.lightColor4, lighting.lightPosition4, lighting.lightAttenuation4);\n }\n }\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n switch (index) {\n case 0: {\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n }\n case 1: {\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n }\n case 2: {\n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n }\n case 3: {\n return DirectionalLight(lighting.lightColor3, lighting.lightDirection3);\n }\n case 4, default: {\n return DirectionalLight(lighting.lightColor4, lighting.lightDirection4);\n }\n }\n} \n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n";
|
|
125
|
+
readonly vs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n\n vec3 lightColor3;\n vec3 lightPosition3;\n vec3 lightDirection3;\n vec3 lightAttenuation3;\n\n vec3 lightColor4;\n vec3 lightPosition4;\n vec3 lightDirection4;\n vec3 lightAttenuation4;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n case 3:\n return PointLight(lighting.lightColor3, lighting.lightPosition3, lighting.lightAttenuation3);\n case 4:\n default: \n return PointLight(lighting.lightColor4, lighting.lightPosition4, lighting.lightAttenuation4);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n case 3:\n return DirectionalLight(lighting.lightColor3, lighting.lightDirection3);\n case 4:\n default: \n return DirectionalLight(lighting.lightColor4, lighting.lightDirection4);\n }\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
126
|
+
readonly fs: "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nuniform lightingUniforms {\n int enabled;\n int lightType;\n\n int directionalLightCount;\n int pointLightCount;\n\n vec3 ambientColor;\n\n vec3 lightColor0;\n vec3 lightPosition0;\n vec3 lightDirection0;\n vec3 lightAttenuation0;\n\n vec3 lightColor1;\n vec3 lightPosition1;\n vec3 lightDirection1;\n vec3 lightAttenuation1;\n\n vec3 lightColor2;\n vec3 lightPosition2;\n vec3 lightDirection2;\n vec3 lightAttenuation2;\n\n vec3 lightColor3;\n vec3 lightPosition3;\n vec3 lightDirection3;\n vec3 lightAttenuation3;\n\n vec3 lightColor4;\n vec3 lightPosition4;\n vec3 lightDirection4;\n vec3 lightAttenuation4;\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n switch (index) {\n case 0:\n return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);\n case 1:\n return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);\n case 2:\n return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);\n case 3:\n return PointLight(lighting.lightColor3, lighting.lightPosition3, lighting.lightAttenuation3);\n case 4:\n default: \n return PointLight(lighting.lightColor4, lighting.lightPosition4, lighting.lightAttenuation4);\n }\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n switch (index) {\n case 0:\n return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);\n case 1:\n return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);\n case 2:\n return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);\n case 3:\n return DirectionalLight(lighting.lightColor3, lighting.lightDirection3);\n case 4:\n default: \n return DirectionalLight(lighting.lightColor4, lighting.lightDirection4);\n }\n} \n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\n// #endif\n";
|
|
103
127
|
readonly getUniforms: typeof getUniforms;
|
|
104
128
|
};
|
|
105
129
|
declare function getUniforms(props?: LightingProps, prevUniforms?: Partial<LightingUniforms>): LightingUniforms;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAQhD,mCAAmC;AAEnC,oBAAY,UAAU;IACpB,KAAK,IAAI;IACT,WAAW,IAAI;CAChB;AAED,4BAA4B;AAE5B,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAEjE,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,CAAC,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,OAAO,CAAC;IACd,QAAQ,EAAE,QAAQ,CAA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cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC1C,WAAW,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpC,cAAc,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACvC,eAAe,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;IACxC,iBAAiB,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;CAC3C,CAAC;AAEF,gCAAgC;AAChC,eAAO,MAAM,QAAQ;oBACN,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgFoC,CAAC;AAEvE,iBAAS,WAAW,CAClB,KAAK,CAAC,EAAE,aAAa,EACrB,YAAY,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAC3C,gBAAgB,CAoClB"}
|
|
@@ -42,7 +42,15 @@ export const lighting = {
|
|
|
42
42
|
lightColor2: 'vec3<f32>',
|
|
43
43
|
lightPosition2: 'vec3<f32>',
|
|
44
44
|
lightDirection2: 'vec3<f32>',
|
|
45
|
-
lightAttenuation2: 'vec3<f32>'
|
|
45
|
+
lightAttenuation2: 'vec3<f32>',
|
|
46
|
+
lightColor3: 'vec3<f32>',
|
|
47
|
+
lightPosition3: 'vec3<f32>',
|
|
48
|
+
lightDirection3: 'vec3<f32>',
|
|
49
|
+
lightAttenuation3: 'vec3<f32>',
|
|
50
|
+
lightColor4: 'vec3<f32>',
|
|
51
|
+
lightPosition4: 'vec3<f32>',
|
|
52
|
+
lightDirection4: 'vec3<f32>',
|
|
53
|
+
lightAttenuation4: 'vec3<f32>'
|
|
46
54
|
},
|
|
47
55
|
defaultUniforms: {
|
|
48
56
|
enabled: 1,
|
|
@@ -62,7 +70,15 @@ export const lighting = {
|
|
|
62
70
|
lightColor2: [1, 1, 1],
|
|
63
71
|
lightPosition2: [1, 1, 2],
|
|
64
72
|
lightDirection2: [1, 1, 1],
|
|
65
|
-
lightAttenuation2: [1, 0, 0]
|
|
73
|
+
lightAttenuation2: [1, 0, 0],
|
|
74
|
+
lightColor3: [1, 1, 1],
|
|
75
|
+
lightPosition3: [1, 1, 2],
|
|
76
|
+
lightDirection3: [1, 1, 1],
|
|
77
|
+
lightAttenuation3: [1, 0, 0],
|
|
78
|
+
lightColor4: [1, 1, 1],
|
|
79
|
+
lightPosition4: [1, 1, 2],
|
|
80
|
+
lightDirection4: [1, 1, 1],
|
|
81
|
+
lightAttenuation4: [1, 0, 0]
|
|
66
82
|
},
|
|
67
83
|
source: lightingUniformsWGSL,
|
|
68
84
|
vs: lightingUniformsGLSL,
|
|
@@ -103,26 +119,36 @@ function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLig
|
|
|
103
119
|
const lightSourceUniforms = {};
|
|
104
120
|
lightSourceUniforms.ambientColor = convertColor(ambientLight);
|
|
105
121
|
let currentLight = 0;
|
|
122
|
+
let pointLightCount = 0;
|
|
123
|
+
let directionalLightCount = 0;
|
|
106
124
|
for (const pointLight of pointLights) {
|
|
125
|
+
if (currentLight >= MAX_LIGHTS) {
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
107
128
|
lightSourceUniforms.lightType = LIGHT_TYPE.POINT;
|
|
108
129
|
const i = currentLight;
|
|
109
130
|
lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
|
|
110
131
|
lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
|
|
111
132
|
lightSourceUniforms[`lightAttenuation${i}`] = pointLight.attenuation || [1, 0, 0];
|
|
112
133
|
currentLight++;
|
|
134
|
+
pointLightCount++;
|
|
113
135
|
}
|
|
114
136
|
for (const directionalLight of directionalLights) {
|
|
137
|
+
if (currentLight >= MAX_LIGHTS) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
115
140
|
lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;
|
|
116
141
|
const i = currentLight;
|
|
117
142
|
lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
|
|
118
143
|
lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
|
|
119
144
|
currentLight++;
|
|
145
|
+
directionalLightCount++;
|
|
120
146
|
}
|
|
121
|
-
if (
|
|
122
|
-
log.warn(
|
|
147
|
+
if (pointLights.length + directionalLights.length > MAX_LIGHTS) {
|
|
148
|
+
log.warn(`MAX_LIGHTS exceeded, truncating to ${MAX_LIGHTS}`)();
|
|
123
149
|
}
|
|
124
|
-
lightSourceUniforms.directionalLightCount =
|
|
125
|
-
lightSourceUniforms.pointLightCount =
|
|
150
|
+
lightSourceUniforms.directionalLightCount = directionalLightCount;
|
|
151
|
+
lightSourceUniforms.pointLightCount = pointLightCount;
|
|
126
152
|
return lightSourceUniforms;
|
|
127
153
|
}
|
|
128
154
|
function extractLightTypes(lights) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AAElC,OAAO,EAAC,oBAAoB,EAAC,2BAAwB;AACrD,OAAO,EAAC,oBAAoB,EAAC,2BAAwB;AAGrD,mEAAmE;AACnE,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,wBAAwB;AACxB,MAAM,YAAY,GAAG,KAAK,CAAC;AAE3B,mCAAmC;AACnC,qCAAqC;AACrC,MAAM,CAAN,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,6CAAS,CAAA;IACT,yDAAe,CAAA;AACjB,CAAC,EAHW,UAAU,KAAV,UAAU,QAGrB;
|
|
1
|
+
{"version":3,"file":"lighting.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+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AAM;YACR,QAAQ;YACR,2BAA2B;YAC3B,4BAA4B;QAC9B,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,uEAAuE;AACvE,SAAS,YAAY,CACnB,WAAiE,EAAE;IAEnE,MAAM,EAAC,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,SAAS,GAAG,GAAG,EAAC,GAAG,QAAQ,CAAC;IACtD,OAAO,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,YAAY,CAAiB,CAAC;AACxF,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare const pbrMaterialUniforms = "uniform Projection {\n // Projection\n vec3 u_Camera;\n};\n\nuniform pbrMaterialUniforms {\n // Material is unlit\n bool unlit;\n\n // Base color map\n bool baseColorMapEnabled;\n vec4 baseColorFactor;\n\n bool normalMapEnabled; \n float normalScale; // #ifdef HAS_NORMALMAP\n\n bool emissiveMapEnabled;\n vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP\n\n vec2 metallicRoughnessValues;\n bool metallicRoughnessMapEnabled;\n\n bool occlusionMapEnabled;\n float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP\n \n bool alphaCutoffEnabled;\n float alphaCutoff; // #ifdef ALPHA_CUTOFF\n\n vec3 specularColorFactor;\n float specularIntensityFactor;\n bool specularColorMapEnabled;\n bool specularIntensityMapEnabled;\n\n float ior;\n\n float transmissionFactor;\n bool transmissionMapEnabled;\n\n float thicknessFactor;\n float attenuationDistance;\n vec3 attenuationColor;\n\n float clearcoatFactor;\n float clearcoatRoughnessFactor;\n bool clearcoatMapEnabled;\n\n vec3 sheenColorFactor;\n float sheenRoughnessFactor;\n bool sheenColorMapEnabled;\n\n float iridescenceFactor;\n float iridescenceIor;\n vec2 iridescenceThicknessRange;\n bool iridescenceMapEnabled;\n\n float anisotropyStrength;\n float anisotropyRotation;\n vec2 anisotropyDirection;\n bool anisotropyMapEnabled;\n\n float emissiveStrength;\n \n // IBL\n bool IBLenabled;\n vec2 scaleIBLAmbient; // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n vec4 scaleDiffBaseMR;\n vec4 scaleFGDSpec;\n // #endif\n};\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D u_BaseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D u_NormalSampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D u_EmissiveSampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D u_MetallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D u_OcclusionSampler;\n#endif\n#ifdef HAS_SPECULARCOLORMAP\nuniform sampler2D u_SpecularColorSampler;\n#endif\n#ifdef HAS_SPECULARINTENSITYMAP\nuniform sampler2D u_SpecularIntensitySampler;\n#endif\n#ifdef HAS_TRANSMISSIONMAP\nuniform sampler2D u_TransmissionSampler;\n#endif\n#ifdef HAS_CLEARCOATMAP\nuniform sampler2D u_ClearcoatSampler;\nuniform sampler2D u_ClearcoatRoughnessSampler;\n#endif\n#ifdef HAS_SHEENCOLORMAP\nuniform sampler2D u_SheenColorSampler;\nuniform sampler2D u_SheenRoughnessSampler;\n#endif\n#ifdef HAS_IRIDESCENCEMAP\nuniform sampler2D u_IridescenceSampler;\n#endif\n#ifdef HAS_ANISOTROPYMAP\nuniform sampler2D u_AnisotropySampler;\n#endif\n#ifdef USE_IBL\nuniform samplerCube u_DiffuseEnvSampler;\nuniform samplerCube u_SpecularEnvSampler;\nuniform sampler2D u_brdfLUT;\n#endif\n\n";
|
|
2
|
-
export declare const source = "struct PBRFragmentInputs {\n pbr_vPosition: vec3f,\n pbr_vUV: vec2f,\n pbr_vTBN: mat3f,\n pbr_vNormal: vec3f\n};\n\nvar fragmentInputs: PBRFragmentInputs;\n\nfn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)\n{\n var pos: vec4f = pbrProjection.modelMatrix * position;\n fragmentInputs.pbr_vPosition = vec3(pos.xyz) / pos.w;\n\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\n let normalW: vec3f = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));\n let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));\n let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;\n fragmentInputs.pbr_vTBN = mat3(tangentW, bitangentW, normalW);\n#else // HAS_TANGENTS != 1\n fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));\n#endif\n#endif\n\n#ifdef HAS_UV\n fragmentInputs.pbr_vUV = uv;\n#else\n fragmentInputs.pbr_vUV = vec2(0.,0.);\n#endif\n}\n\nstruct pbrMaterialUniforms {\n // Material is unlit\n unlit: uint32,\n\n // Base color map\n baseColorMapEnabled: uint32,\n baseColorFactor: vec4f,\n\n normalMapEnabled : uint32,\n normalScale: f32, // #ifdef HAS_NORMALMAP\n\n emissiveMapEnabled: uint32,\n emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP\n\n metallicRoughnessValues: vec2f,\n metallicRoughnessMapEnabled: uint32,\n\n occlusionMapEnabled: i32,\n occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP\n \n alphaCutoffEnabled: i32,\n alphaCutoff: f32, // #ifdef ALPHA_CUTOFF\n \n // IBL\n IBLenabled: i32,\n scaleIBLAmbient: vec2f, // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n scaleDiffBaseMR: vec4f,\n scaleFGDSpec: vec4f\n // #endif\n}\n\n@binding(2) @group(0) var<uniform> pbrMaterial : pbrMaterialUniforms;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\nuniform sampler2D pbr_baseColorSampler;\n#endif\n#ifdef HAS_NORMALMAP\nuniform sampler2D pbr_normalSampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\nuniform sampler2D pbr_emissiveSampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\nuniform sampler2D pbr_metallicRoughnessSampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\nuniform sampler2D pbr_occlusionSampler;\n#endif\n#ifdef USE_IBL\nuniform samplerCube pbr_diffuseEnvSampler;\nuniform samplerCube pbr_specularEnvSampler;\nuniform sampler2D pbr_brdfLUT;\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n NdotL: f32, // cos angle between normal and light direction\n NdotV: f32, // cos angle between normal and view direction\n NdotH: f32, // cos angle between normal and half vector\n LdotH: f32, // cos angle between light direction and half vector\n VdotH: f32, // cos angle between view direction and half vector\n perceptualRoughness: f32, // roughness value, as authored by the model creator (input to shader)\n metalness: f32, // metallic value at the surface\n reflectance0: vec3f, // full reflectance color (normal incidence angle)\n reflectance90: vec3f, // reflectance color at grazing angle\n alphaRoughness: f32, // roughness mapped to a more linear change in the roughness (proposed by [2])\n diffuseColor: vec3f, // color contribution from diffuse lighting\n specularColor: vec3f, // color contribution from specular lighting\n n: vec3f, // normal at surface point\n v: vec3f, // vector from surface point to camera\n};\n\nconst M_PI = 3.141592653589793;\nconst c_MinRoughness = 0.04;\n\nfn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f\n{\n#ifdef MANUAL_SRGB\n#ifdef SRGB_FAST_APPROXIMATION\n var linOut: vec3f = pow(srgbIn.xyz,vec3(2.2));\n#else // SRGB_FAST_APPROXIMATION\n var bLess: vec3f = step(vec3(0.04045),srgbIn.xyz);\n var linOut: vec3f = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );\n#endif //SRGB_FAST_APPROXIMATION\n return vec4f(linOut,srgbIn.w);;\n#else //MANUAL_SRGB\n return srgbIn;\n#endif //MANUAL_SRGB\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nfn getNormal() -> vec3f\n{\n // Retrieve the tangent space matrix\n#ifndef HAS_TANGENTS\n var pos_dx: vec3f = dFdx(fragmentInputs.pbr_vPosition);\n var pos_dy: vec3f = dFdy(fragmentInputs.pbr_vPosition);\n var tex_dx: vec3f = dFdx(vec3(fragmentInputs.pbr_vUV, 0.0));\n var tex_dy: vec3f = dFdy(vec3(fragmentInputs.pbr_vUV, 0.0));\n 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);\n\n#ifdef HAS_NORMALS\n var ng: vec3f = normalize(fragmentInputs.pbr_vNormal);\n#else\n var ng: vec3f = cross(pos_dx, pos_dy);\n#endif\n\n t = normalize(t - ng * dot(ng, t));\n var b: vec3f = normalize(cross(ng, t));\n var tbn: mat3f = mat3f(t, b, ng);\n#else // HAS_TANGENTS\n var tbn: mat3f = fragmentInputs.pbr_vTBN;\n#endif\n\n#ifdef HAS_NORMALMAP\n vec3 n = texture(pbr_normalSampler, fragmentInputs.pbr_vUV).rgb;\n n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));\n#else\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n vec3 n = normalize(tbn[2].xyz);\n#endif\n\n return n;\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nfn getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection) -> vec3f\n{\n float mipCount = 9.0; // resolution of 512x512\n float lod = (pbrInfo.perceptualRoughness * mipCount);\n // retrieve a scale and bias to F0. See [1], Figure 3\n vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,\n vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;\n vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;\n\n#ifdef USE_TEX_LOD\n vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;\n#else\n vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;\n#endif\n\n vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;\n vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);\n\n // For presentation, this allows us to disable IBL terms\n diffuse *= pbrMaterial.scaleIBLAmbient.x;\n specular *= pbrMaterial.scaleIBLAmbient.y;\n\n return diffuse + specular;\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nfn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nfn specularReflection(pbrInfo: PBRInfo) -> vec3<f32> {\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {\n let NdotL: f32 = pbrInfo.NdotL;\n let NdotV: f32 = pbrInfo.NdotV;\n let r: f32 = pbrInfo.alphaRoughness;\n\n let attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n let attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {\n let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (PI * f * f);\n}\n\nfn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {\n (*pbrInfo).NdotL = 1.0;\n (*pbrInfo).NdotH = 0.0;\n (*pbrInfo).LdotH = 0.0;\n (*pbrInfo).VdotH = 1.0;\n}\n\nfn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection: vec3<f32>) {\n let n = (*pbrInfo).n;\n let v = (*pbrInfo).v;\n let l = normalize(lightDirection); // Vector from surface point to light\n let h = normalize(l + v); // Half vector between both l and v\n\n (*pbrInfo).NdotL = clamp(dot(n, l), 0.001, 1.0);\n (*pbrInfo).NdotH = clamp(dot(n, h), 0.0, 1.0);\n (*pbrInfo).LdotH = clamp(dot(l, h), 0.0, 1.0);\n (*pbrInfo).VdotH = clamp(dot(v, h), 0.0, 1.0);\n}\n\nfn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {\n let light_direction = normalize(pointLight.position - fragmentInputs.pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nfn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {\n // Calculate the shading terms for the microfacet specular shading model\n let F = specularReflection(pbrInfo);\n let G = geometricOcclusion(pbrInfo);\n let D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n let diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n let specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nfn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {\n // The albedo may be defined from a base texture or a flat color\n var baseColor: vec4<f32>;\n #ifdef HAS_BASECOLORMAP\n baseColor = SRGBtoLINEAR(textureSample(pbr_baseColorSampler, pbr_baseColorSampler, fragmentInputs.pbr_vUV)) * pbrMaterial.baseColorFactor;\n #else\n baseColor = pbrMaterial.baseColorFactor;\n #endif\n\n #ifdef ALPHA_CUTOFF\n if (baseColor.a < pbrMaterial.alphaCutoff) {\n discard;\n }\n #endif\n\n var color = vec3<f32>(0.0, 0.0, 0.0);\n\n if (pbrMaterial.unlit) {\n color = baseColor.rgb;\n } else {\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n var perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;\n var metallic = pbrMaterial.metallicRoughnessValues.x;\n #ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n let mrSample = textureSample(pbr_metallicRoughnessSampler, pbr_metallicRoughnessSampler, fragmentInputs.pbr_vUV);\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n #endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n let alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n let f0 = vec3<f32>(0.04);\n var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n let specularColor = mix(f0, baseColor.rgb, metallic);\n\n // Compute reflectance.\n let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflectance to 0%.\n let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n let specularEnvironmentR0 = specularColor;\n let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;\n\n let n = getNormal(); // normal at surface point\n let v = normalize(pbrProjection.camera - fragmentInputs.pbr_vPosition); // Vector from surface point to camera\n\n let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n let reflection = -normalize(reflect(v, n));\n\n var pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v\n );\n\n #ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(&pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting.ambientColor);\n\n // Apply directional light\n for (var i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);\n }\n }\n\n // Apply point light\n for (var i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));\n let attenuation = getPointLightAttenuation(\n lighting_getPointLight(i),\n distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)\n );\n color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);\n }\n }\n #endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n #ifdef USE_IBL\n if (pbrMaterial.IBLenabled) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n #endif\n\n // Apply optional PBR terms for additional (optional) shading\n #ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled) {\n let ao = textureSample(pbr_occlusionSampler, pbr_occlusionSampler, fragmentInputs.pbr_vUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n #endif\n\n #ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled) {\n let emissive = SRGBtoLINEAR(textureSample(pbr_emissiveSampler, pbr_emissiveSampler, fragmentInputs.pbr_vUV)).rgb * pbrMaterial.emissiveFactor;\n color += emissive;\n }\n #endif\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n #ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, pbr_scaleFGDSpec.x);\n // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);\n // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);\n // color = mix(color, specContrib, pbr_scaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n #endif\n }\n\n return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);\n}\n";
|
|
2
|
+
export declare const source = "struct PBRFragmentInputs {\n pbr_vPosition: vec3f,\n pbr_vUV: vec2f,\n pbr_vTBN: mat3x3f,\n pbr_vNormal: vec3f\n};\n\nvar<private> fragmentInputs: PBRFragmentInputs;\n\nfn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)\n{\n var pos: vec4f = pbrProjection.modelMatrix * position;\n fragmentInputs.pbr_vPosition = pos.xyz / pos.w;\n fragmentInputs.pbr_vNormal = vec3f(0.0, 0.0, 1.0);\n fragmentInputs.pbr_vTBN = mat3x3f(\n vec3f(1.0, 0.0, 0.0),\n vec3f(0.0, 1.0, 0.0),\n vec3f(0.0, 0.0, 1.0)\n );\n fragmentInputs.pbr_vUV = vec2f(0.0, 0.0);\n\n#ifdef HAS_NORMALS\n let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);\n fragmentInputs.pbr_vNormal = normalW;\n#ifdef HAS_TANGENTS\n let tangentW: vec3f = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);\n let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;\n fragmentInputs.pbr_vTBN = mat3x3f(tangentW, bitangentW, normalW);\n#endif\n#endif\n\n#ifdef HAS_UV\n fragmentInputs.pbr_vUV = uv;\n#endif\n}\n\nstruct pbrMaterialUniforms {\n // Material is unlit\n unlit: u32,\n\n // Base color map\n baseColorMapEnabled: u32,\n baseColorFactor: vec4f,\n\n normalMapEnabled : u32,\n normalScale: f32, // #ifdef HAS_NORMALMAP\n\n emissiveMapEnabled: u32,\n emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP\n\n metallicRoughnessValues: vec2f,\n metallicRoughnessMapEnabled: u32,\n\n occlusionMapEnabled: i32,\n occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP\n \n alphaCutoffEnabled: i32,\n alphaCutoff: f32, // #ifdef ALPHA_CUTOFF\n \n // IBL\n IBLenabled: i32,\n scaleIBLAmbient: vec2f, // #ifdef USE_IBL\n \n // debugging flags used for shader output of intermediate PBR variables\n // #ifdef PBR_DEBUG\n scaleDiffBaseMR: vec4f,\n scaleFGDSpec: vec4f,\n // #endif\n}\n\n@binding(2) @group(0) var<uniform> pbrMaterial : pbrMaterialUniforms;\n\n// Samplers\n#ifdef HAS_BASECOLORMAP\n@binding(3) @group(0) var pbr_baseColorSampler: texture_2d<f32>;\n@binding(4) @group(0) var pbr_baseColorSamplerSampler: sampler;\n#endif\n#ifdef HAS_NORMALMAP\n@binding(5) @group(0) var pbr_normalSampler: texture_2d<f32>;\n@binding(6) @group(0) var pbr_normalSamplerSampler: sampler;\n#endif\n#ifdef HAS_EMISSIVEMAP\n@binding(7) @group(0) var pbr_emissiveSampler: texture_2d<f32>;\n@binding(8) @group(0) var pbr_emissiveSamplerSampler: sampler;\n#endif\n#ifdef HAS_METALROUGHNESSMAP\n@binding(9) @group(0) var pbr_metallicRoughnessSampler: texture_2d<f32>;\n@binding(10) @group(0) var pbr_metallicRoughnessSamplerSampler: sampler;\n#endif\n#ifdef HAS_OCCLUSIONMAP\n@binding(11) @group(0) var pbr_occlusionSampler: texture_2d<f32>;\n@binding(12) @group(0) var pbr_occlusionSamplerSampler: sampler;\n#endif\n#ifdef USE_IBL\n@binding(13) @group(0) var pbr_diffuseEnvSampler: texture_cube<f32>;\n@binding(14) @group(0) var pbr_diffuseEnvSamplerSampler: sampler;\n@binding(15) @group(0) var pbr_specularEnvSampler: texture_cube<f32>;\n@binding(16) @group(0) var pbr_specularEnvSamplerSampler: sampler;\n@binding(17) @group(0) var pbr_BrdfLUT: texture_2d<f32>;\n@binding(18) @group(0) var pbr_BrdfLUTSampler: sampler;\n#endif\n\n// Encapsulate the various inputs used by the various functions in the shading equation\n// We store values in this struct to simplify the integration of alternative implementations\n// of the shading terms, outlined in the Readme.MD Appendix.\nstruct PBRInfo {\n NdotL: f32, // cos angle between normal and light direction\n NdotV: f32, // cos angle between normal and view direction\n NdotH: f32, // cos angle between normal and half vector\n LdotH: f32, // cos angle between light direction and half vector\n VdotH: f32, // cos angle between view direction and half vector\n perceptualRoughness: f32, // roughness value, as authored by the model creator (input to shader)\n metalness: f32, // metallic value at the surface\n reflectance0: vec3f, // full reflectance color (normal incidence angle)\n reflectance90: vec3f, // reflectance color at grazing angle\n alphaRoughness: f32, // roughness mapped to a more linear change in the roughness (proposed by [2])\n diffuseColor: vec3f, // color contribution from diffuse lighting\n specularColor: vec3f, // color contribution from specular lighting\n n: vec3f, // normal at surface point\n v: vec3f, // vector from surface point to camera\n};\n\nconst M_PI = 3.141592653589793;\nconst c_MinRoughness = 0.04;\n\nfn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f\n{\n var linOut: vec3f = srgbIn.xyz;\n#ifdef MANUAL_SRGB\n let bLess: vec3f = step(vec3f(0.04045), srgbIn.xyz);\n linOut = mix(\n srgbIn.xyz / vec3f(12.92),\n pow((srgbIn.xyz + vec3f(0.055)) / vec3f(1.055), vec3f(2.4)),\n bLess\n );\n#ifdef SRGB_FAST_APPROXIMATION\n linOut = pow(srgbIn.xyz, vec3f(2.2));\n#endif\n#endif\n return vec4f(linOut, srgbIn.w);\n}\n\n// Find the normal for this fragment, pulling either from a predefined normal map\n// or from the interpolated mesh normal and tangent attributes.\nfn getNormal() -> vec3f\n{\n // Retrieve the tangent space matrix\n let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);\n let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);\n let tex_dx: vec3f = dpdx(vec3f(fragmentInputs.pbr_vUV, 0.0));\n let tex_dy: vec3f = dpdy(vec3f(fragmentInputs.pbr_vUV, 0.0));\n 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);\n\n var ng: vec3f = cross(pos_dx, pos_dy);\n#ifdef HAS_NORMALS\n ng = normalize(fragmentInputs.pbr_vNormal);\n#endif\n t = normalize(t - ng * dot(ng, t));\n var b: vec3f = normalize(cross(ng, t));\n var tbn: mat3x3f = mat3x3f(t, b, ng);\n#ifdef HAS_TANGENTS\n tbn = fragmentInputs.pbr_vTBN;\n#endif\n\n // The tbn matrix is linearly interpolated, so we need to re-normalize\n var n: vec3f = normalize(tbn[2].xyz);\n#ifdef HAS_NORMALMAP\n n = textureSample(pbr_normalSampler, pbr_normalSamplerSampler, fragmentInputs.pbr_vUV).rgb;\n n = normalize(tbn * ((2.0 * n - 1.0) * vec3f(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));\n#endif\n\n return n;\n}\n\n// Calculation of the lighting contribution from an optional Image Based Light source.\n// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].\n// See our README.md on Environment Maps [3] for additional discussion.\n#ifdef USE_IBL\nfn getIBLContribution(pbrInfo: PBRInfo, n: vec3f, reflection: vec3f) -> vec3f\n{\n let mipCount: f32 = 9.0; // resolution of 512x512\n let lod: f32 = pbrInfo.perceptualRoughness * mipCount;\n // retrieve a scale and bias to F0. See [1], Figure 3\n let brdf = SRGBtoLINEAR(\n textureSample(\n pbr_BrdfLUT,\n pbr_BrdfLUTSampler,\n vec2f(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness)\n )\n ).rgb;\n let diffuseLight =\n SRGBtoLINEAR(textureSample(pbr_diffuseEnvSampler, pbr_diffuseEnvSamplerSampler, n)).rgb;\n let specularLightDefault =\n SRGBtoLINEAR(textureSample(pbr_specularEnvSampler, pbr_specularEnvSamplerSampler, reflection)).rgb;\n var specularLight = specularLightDefault;\n#ifdef USE_TEX_LOD\n specularLight = SRGBtoLINEAR(\n textureSampleLevel(\n pbr_specularEnvSampler,\n pbr_specularEnvSamplerSampler,\n reflection,\n lod\n )\n ).rgb;\n#endif\n\n let diffuse = diffuseLight * pbrInfo.diffuseColor * pbrMaterial.scaleIBLAmbient.x;\n let specular =\n specularLight * (pbrInfo.specularColor * brdf.x + brdf.y) * pbrMaterial.scaleIBLAmbient.y;\n\n return diffuse + specular;\n}\n#endif\n\n// Basic Lambertian diffuse\n// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog\n// See also [1], Equation 1\nfn diffuse(pbrInfo: PBRInfo) -> vec3<f32> {\n return pbrInfo.diffuseColor / M_PI;\n}\n\n// The following equation models the Fresnel reflectance term of the spec equation (aka F())\n// Implementation of fresnel from [4], Equation 15\nfn specularReflection(pbrInfo: PBRInfo) -> vec3<f32> {\n return pbrInfo.reflectance0 +\n (pbrInfo.reflectance90 - pbrInfo.reflectance0) *\n pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);\n}\n\n// This calculates the specular geometric attenuation (aka G()),\n// where rougher material will reflect less light back to the viewer.\n// This implementation is based on [1] Equation 4, and we adopt their modifications to\n// alphaRoughness as input as originally proposed in [2].\nfn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {\n let NdotL: f32 = pbrInfo.NdotL;\n let NdotV: f32 = pbrInfo.NdotV;\n let r: f32 = pbrInfo.alphaRoughness;\n\n let attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));\n let attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));\n return attenuationL * attenuationV;\n}\n\n// The following equation(s) model the distribution of microfacet normals across\n// the area being drawn (aka D())\n// Implementation from \"Average Irregularity Representation of a Roughened Surface\n// for Ray Reflection\" by T. S. Trowbridge, and K. P. Reitz\n// Follows the distribution function recommended in the SIGGRAPH 2013 course notes\n// from EPIC Games [1], Equation 3.\nfn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {\n let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;\n let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;\n return roughnessSq / (M_PI * f * f);\n}\n\nfn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {\n (*pbrInfo).NdotL = 1.0;\n (*pbrInfo).NdotH = 0.0;\n (*pbrInfo).LdotH = 0.0;\n (*pbrInfo).VdotH = 1.0;\n}\n\nfn PBRInfo_setDirectionalLight(pbrInfo: ptr<function, PBRInfo>, lightDirection: vec3<f32>) {\n let n = (*pbrInfo).n;\n let v = (*pbrInfo).v;\n let l = normalize(lightDirection); // Vector from surface point to light\n let h = normalize(l + v); // Half vector between both l and v\n\n (*pbrInfo).NdotL = clamp(dot(n, l), 0.001, 1.0);\n (*pbrInfo).NdotH = clamp(dot(n, h), 0.0, 1.0);\n (*pbrInfo).LdotH = clamp(dot(l, h), 0.0, 1.0);\n (*pbrInfo).VdotH = clamp(dot(v, h), 0.0, 1.0);\n}\n\nfn PBRInfo_setPointLight(pbrInfo: ptr<function, PBRInfo>, pointLight: PointLight) {\n let light_direction = normalize(pointLight.position - fragmentInputs.pbr_vPosition);\n PBRInfo_setDirectionalLight(pbrInfo, light_direction);\n}\n\nfn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {\n // Calculate the shading terms for the microfacet specular shading model\n let F = specularReflection(pbrInfo);\n let G = geometricOcclusion(pbrInfo);\n let D = microfacetDistribution(pbrInfo);\n\n // Calculation of analytical lighting contribution\n let diffuseContrib = (1.0 - F) * diffuse(pbrInfo);\n let specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);\n // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)\n return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);\n}\n\nfn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {\n // The albedo may be defined from a base texture or a flat color\n var baseColor: vec4<f32> = pbrMaterial.baseColorFactor;\n #ifdef HAS_BASECOLORMAP\n baseColor = SRGBtoLINEAR(\n textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, fragmentInputs.pbr_vUV)\n ) * pbrMaterial.baseColorFactor;\n #endif\n\n #ifdef ALPHA_CUTOFF\n if (baseColor.a < pbrMaterial.alphaCutoff) {\n discard;\n }\n #endif\n\n var color = vec3<f32>(0.0, 0.0, 0.0);\n\n if (pbrMaterial.unlit != 0u) {\n color = baseColor.rgb;\n } else {\n // Metallic and Roughness material properties are packed together\n // In glTF, these factors can be specified by fixed scalar values\n // or from a metallic-roughness map\n var perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;\n var metallic = pbrMaterial.metallicRoughnessValues.x;\n #ifdef HAS_METALROUGHNESSMAP\n // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.\n // This layout intentionally reserves the 'r' channel for (optional) occlusion map data\n let mrSample = textureSample(\n pbr_metallicRoughnessSampler,\n pbr_metallicRoughnessSamplerSampler,\n fragmentInputs.pbr_vUV\n );\n perceptualRoughness = mrSample.g * perceptualRoughness;\n metallic = mrSample.b * metallic;\n #endif\n perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);\n metallic = clamp(metallic, 0.0, 1.0);\n // Roughness is authored as perceptual roughness; as is convention,\n // convert to material roughness by squaring the perceptual roughness [2].\n let alphaRoughness = perceptualRoughness * perceptualRoughness;\n\n let f0 = vec3<f32>(0.04);\n var diffuseColor = baseColor.rgb * (vec3<f32>(1.0) - f0);\n diffuseColor *= 1.0 - metallic;\n let specularColor = mix(f0, baseColor.rgb, metallic);\n\n // Compute reflectance.\n let reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);\n\n // For typical incident reflectance range (between 4% to 100%) set the grazing\n // reflectance to 100% for typical fresnel effect.\n // For very low reflectance range on highly diffuse objects (below 4%),\n // incrementally reduce grazing reflectance to 0%.\n let reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);\n let specularEnvironmentR0 = specularColor;\n let specularEnvironmentR90 = vec3<f32>(1.0, 1.0, 1.0) * reflectance90;\n\n let n = getNormal(); // normal at surface point\n let v = normalize(pbrProjection.camera - fragmentInputs.pbr_vPosition); // Vector from surface point to camera\n\n let NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);\n let reflection = -normalize(reflect(v, n));\n\n var pbrInfo = PBRInfo(\n 0.0, // NdotL\n NdotV,\n 0.0, // NdotH\n 0.0, // LdotH\n 0.0, // VdotH\n perceptualRoughness,\n metallic,\n specularEnvironmentR0,\n specularEnvironmentR90,\n alphaRoughness,\n diffuseColor,\n specularColor,\n n,\n v\n );\n\n #ifdef USE_LIGHTS\n // Apply ambient light\n PBRInfo_setAmbientLight(&pbrInfo);\n color += calculateFinalColor(pbrInfo, lighting.ambientColor);\n\n // Apply directional light\n for (var i = 0; i < lighting.directionalLightCount; i++) {\n if (i < lighting.directionalLightCount) {\n PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);\n color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);\n }\n }\n\n // Apply point light\n for (var i = 0; i < lighting.pointLightCount; i++) {\n if (i < lighting.pointLightCount) {\n PBRInfo_setPointLight(&pbrInfo, lighting_getPointLight(i));\n let attenuation = getPointLightAttenuation(\n lighting_getPointLight(i),\n distance(lighting_getPointLight(i).position, fragmentInputs.pbr_vPosition)\n );\n color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);\n }\n }\n #endif\n\n // Calculate lighting contribution from image based lighting source (IBL)\n #ifdef USE_IBL\n if (pbrMaterial.IBLenabled != 0) {\n color += getIBLContribution(pbrInfo, n, reflection);\n }\n #endif\n\n // Apply optional PBR terms for additional (optional) shading\n #ifdef HAS_OCCLUSIONMAP\n if (pbrMaterial.occlusionMapEnabled != 0) {\n let ao =\n textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, fragmentInputs.pbr_vUV).r;\n color = mix(color, color * ao, pbrMaterial.occlusionStrength);\n }\n #endif\n\n #ifdef HAS_EMISSIVEMAP\n if (pbrMaterial.emissiveMapEnabled != 0u) {\n let emissive = SRGBtoLINEAR(\n textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, fragmentInputs.pbr_vUV)\n ).rgb * pbrMaterial.emissiveFactor;\n color += emissive;\n }\n #endif\n\n // This section uses mix to override final color for reference app visualization\n // of various parameters in the lighting equation.\n #ifdef PBR_DEBUG\n // TODO: Figure out how to debug multiple lights\n\n // color = mix(color, F, pbr_scaleFGDSpec.x);\n // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);\n // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);\n // color = mix(color, specContrib, pbr_scaleFGDSpec.w);\n\n // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);\n color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);\n color = mix(color, vec3<f32>(metallic), pbrMaterial.scaleDiffBaseMR.z);\n color = mix(color, vec3<f32>(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);\n #endif\n }\n\n return vec4<f32>(pow(color, vec3<f32>(1.0 / 2.2)), baseColor.a);\n}\n";
|
|
3
3
|
//# sourceMappingURL=pbr-material-wgsl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-material-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material-wgsl.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,mBAAmB,gsFAuH/B,CAAC;AAEF,eAAO,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"pbr-material-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material-wgsl.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,mBAAmB,gsFAuH/B,CAAC;AAEF,eAAO,MAAM,MAAM,wuhBA4blB,CAAC"}
|
|
@@ -130,51 +130,55 @@ export const source = /* wgsl */ `\
|
|
|
130
130
|
struct PBRFragmentInputs {
|
|
131
131
|
pbr_vPosition: vec3f,
|
|
132
132
|
pbr_vUV: vec2f,
|
|
133
|
-
pbr_vTBN:
|
|
133
|
+
pbr_vTBN: mat3x3f,
|
|
134
134
|
pbr_vNormal: vec3f
|
|
135
135
|
};
|
|
136
136
|
|
|
137
|
-
var fragmentInputs: PBRFragmentInputs;
|
|
137
|
+
var<private> fragmentInputs: PBRFragmentInputs;
|
|
138
138
|
|
|
139
139
|
fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, uv: vec2f)
|
|
140
140
|
{
|
|
141
141
|
var pos: vec4f = pbrProjection.modelMatrix * position;
|
|
142
|
-
fragmentInputs.pbr_vPosition =
|
|
142
|
+
fragmentInputs.pbr_vPosition = pos.xyz / pos.w;
|
|
143
|
+
fragmentInputs.pbr_vNormal = vec3f(0.0, 0.0, 1.0);
|
|
144
|
+
fragmentInputs.pbr_vTBN = mat3x3f(
|
|
145
|
+
vec3f(1.0, 0.0, 0.0),
|
|
146
|
+
vec3f(0.0, 1.0, 0.0),
|
|
147
|
+
vec3f(0.0, 0.0, 1.0)
|
|
148
|
+
);
|
|
149
|
+
fragmentInputs.pbr_vUV = vec2f(0.0, 0.0);
|
|
143
150
|
|
|
144
151
|
#ifdef HAS_NORMALS
|
|
152
|
+
let normalW: vec3f = normalize((pbrProjection.normalMatrix * vec4f(normal.xyz, 0.0)).xyz);
|
|
153
|
+
fragmentInputs.pbr_vNormal = normalW;
|
|
145
154
|
#ifdef HAS_TANGENTS
|
|
146
|
-
let
|
|
147
|
-
let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
|
|
155
|
+
let tangentW: vec3f = normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz);
|
|
148
156
|
let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;
|
|
149
|
-
fragmentInputs.pbr_vTBN =
|
|
150
|
-
#else // HAS_TANGENTS != 1
|
|
151
|
-
fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
|
|
157
|
+
fragmentInputs.pbr_vTBN = mat3x3f(tangentW, bitangentW, normalW);
|
|
152
158
|
#endif
|
|
153
159
|
#endif
|
|
154
160
|
|
|
155
161
|
#ifdef HAS_UV
|
|
156
162
|
fragmentInputs.pbr_vUV = uv;
|
|
157
|
-
#else
|
|
158
|
-
fragmentInputs.pbr_vUV = vec2(0.,0.);
|
|
159
163
|
#endif
|
|
160
164
|
}
|
|
161
165
|
|
|
162
166
|
struct pbrMaterialUniforms {
|
|
163
167
|
// Material is unlit
|
|
164
|
-
unlit:
|
|
168
|
+
unlit: u32,
|
|
165
169
|
|
|
166
170
|
// Base color map
|
|
167
|
-
baseColorMapEnabled:
|
|
171
|
+
baseColorMapEnabled: u32,
|
|
168
172
|
baseColorFactor: vec4f,
|
|
169
173
|
|
|
170
|
-
normalMapEnabled :
|
|
174
|
+
normalMapEnabled : u32,
|
|
171
175
|
normalScale: f32, // #ifdef HAS_NORMALMAP
|
|
172
176
|
|
|
173
|
-
emissiveMapEnabled:
|
|
177
|
+
emissiveMapEnabled: u32,
|
|
174
178
|
emissiveFactor: vec3f, // #ifdef HAS_EMISSIVEMAP
|
|
175
179
|
|
|
176
180
|
metallicRoughnessValues: vec2f,
|
|
177
|
-
metallicRoughnessMapEnabled:
|
|
181
|
+
metallicRoughnessMapEnabled: u32,
|
|
178
182
|
|
|
179
183
|
occlusionMapEnabled: i32,
|
|
180
184
|
occlusionStrength: f32, // #ifdef HAS_OCCLUSIONMAP
|
|
@@ -189,7 +193,7 @@ struct pbrMaterialUniforms {
|
|
|
189
193
|
// debugging flags used for shader output of intermediate PBR variables
|
|
190
194
|
// #ifdef PBR_DEBUG
|
|
191
195
|
scaleDiffBaseMR: vec4f,
|
|
192
|
-
scaleFGDSpec: vec4f
|
|
196
|
+
scaleFGDSpec: vec4f,
|
|
193
197
|
// #endif
|
|
194
198
|
}
|
|
195
199
|
|
|
@@ -197,24 +201,32 @@ struct pbrMaterialUniforms {
|
|
|
197
201
|
|
|
198
202
|
// Samplers
|
|
199
203
|
#ifdef HAS_BASECOLORMAP
|
|
200
|
-
|
|
204
|
+
@binding(3) @group(0) var pbr_baseColorSampler: texture_2d<f32>;
|
|
205
|
+
@binding(4) @group(0) var pbr_baseColorSamplerSampler: sampler;
|
|
201
206
|
#endif
|
|
202
207
|
#ifdef HAS_NORMALMAP
|
|
203
|
-
|
|
208
|
+
@binding(5) @group(0) var pbr_normalSampler: texture_2d<f32>;
|
|
209
|
+
@binding(6) @group(0) var pbr_normalSamplerSampler: sampler;
|
|
204
210
|
#endif
|
|
205
211
|
#ifdef HAS_EMISSIVEMAP
|
|
206
|
-
|
|
212
|
+
@binding(7) @group(0) var pbr_emissiveSampler: texture_2d<f32>;
|
|
213
|
+
@binding(8) @group(0) var pbr_emissiveSamplerSampler: sampler;
|
|
207
214
|
#endif
|
|
208
215
|
#ifdef HAS_METALROUGHNESSMAP
|
|
209
|
-
|
|
216
|
+
@binding(9) @group(0) var pbr_metallicRoughnessSampler: texture_2d<f32>;
|
|
217
|
+
@binding(10) @group(0) var pbr_metallicRoughnessSamplerSampler: sampler;
|
|
210
218
|
#endif
|
|
211
219
|
#ifdef HAS_OCCLUSIONMAP
|
|
212
|
-
|
|
220
|
+
@binding(11) @group(0) var pbr_occlusionSampler: texture_2d<f32>;
|
|
221
|
+
@binding(12) @group(0) var pbr_occlusionSamplerSampler: sampler;
|
|
213
222
|
#endif
|
|
214
223
|
#ifdef USE_IBL
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
224
|
+
@binding(13) @group(0) var pbr_diffuseEnvSampler: texture_cube<f32>;
|
|
225
|
+
@binding(14) @group(0) var pbr_diffuseEnvSamplerSampler: sampler;
|
|
226
|
+
@binding(15) @group(0) var pbr_specularEnvSampler: texture_cube<f32>;
|
|
227
|
+
@binding(16) @group(0) var pbr_specularEnvSamplerSampler: sampler;
|
|
228
|
+
@binding(17) @group(0) var pbr_BrdfLUT: texture_2d<f32>;
|
|
229
|
+
@binding(18) @group(0) var pbr_BrdfLUTSampler: sampler;
|
|
218
230
|
#endif
|
|
219
231
|
|
|
220
232
|
// Encapsulate the various inputs used by the various functions in the shading equation
|
|
@@ -242,17 +254,19 @@ const c_MinRoughness = 0.04;
|
|
|
242
254
|
|
|
243
255
|
fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
|
|
244
256
|
{
|
|
257
|
+
var linOut: vec3f = srgbIn.xyz;
|
|
245
258
|
#ifdef MANUAL_SRGB
|
|
259
|
+
let bLess: vec3f = step(vec3f(0.04045), srgbIn.xyz);
|
|
260
|
+
linOut = mix(
|
|
261
|
+
srgbIn.xyz / vec3f(12.92),
|
|
262
|
+
pow((srgbIn.xyz + vec3f(0.055)) / vec3f(1.055), vec3f(2.4)),
|
|
263
|
+
bLess
|
|
264
|
+
);
|
|
246
265
|
#ifdef SRGB_FAST_APPROXIMATION
|
|
247
|
-
|
|
248
|
-
#
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
#endif //SRGB_FAST_APPROXIMATION
|
|
252
|
-
return vec4f(linOut,srgbIn.w);;
|
|
253
|
-
#else //MANUAL_SRGB
|
|
254
|
-
return srgbIn;
|
|
255
|
-
#endif //MANUAL_SRGB
|
|
266
|
+
linOut = pow(srgbIn.xyz, vec3f(2.2));
|
|
267
|
+
#endif
|
|
268
|
+
#endif
|
|
269
|
+
return vec4f(linOut, srgbIn.w);
|
|
256
270
|
}
|
|
257
271
|
|
|
258
272
|
// Find the normal for this fragment, pulling either from a predefined normal map
|
|
@@ -260,32 +274,28 @@ fn SRGBtoLINEAR(srgbIn: vec4f ) -> vec4f
|
|
|
260
274
|
fn getNormal() -> vec3f
|
|
261
275
|
{
|
|
262
276
|
// Retrieve the tangent space matrix
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
var
|
|
268
|
-
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);
|
|
277
|
+
let pos_dx: vec3f = dpdx(fragmentInputs.pbr_vPosition);
|
|
278
|
+
let pos_dy: vec3f = dpdy(fragmentInputs.pbr_vPosition);
|
|
279
|
+
let tex_dx: vec3f = dpdx(vec3f(fragmentInputs.pbr_vUV, 0.0));
|
|
280
|
+
let tex_dy: vec3f = dpdy(vec3f(fragmentInputs.pbr_vUV, 0.0));
|
|
281
|
+
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);
|
|
269
282
|
|
|
270
|
-
#ifdef HAS_NORMALS
|
|
271
|
-
var ng: vec3f = normalize(fragmentInputs.pbr_vNormal);
|
|
272
|
-
#else
|
|
273
283
|
var ng: vec3f = cross(pos_dx, pos_dy);
|
|
284
|
+
#ifdef HAS_NORMALS
|
|
285
|
+
ng = normalize(fragmentInputs.pbr_vNormal);
|
|
274
286
|
#endif
|
|
275
|
-
|
|
276
287
|
t = normalize(t - ng * dot(ng, t));
|
|
277
288
|
var b: vec3f = normalize(cross(ng, t));
|
|
278
|
-
var tbn:
|
|
279
|
-
#
|
|
280
|
-
|
|
289
|
+
var tbn: mat3x3f = mat3x3f(t, b, ng);
|
|
290
|
+
#ifdef HAS_TANGENTS
|
|
291
|
+
tbn = fragmentInputs.pbr_vTBN;
|
|
281
292
|
#endif
|
|
282
293
|
|
|
283
|
-
#ifdef HAS_NORMALMAP
|
|
284
|
-
vec3 n = texture(pbr_normalSampler, fragmentInputs.pbr_vUV).rgb;
|
|
285
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
286
|
-
#else
|
|
287
294
|
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
288
|
-
|
|
295
|
+
var n: vec3f = normalize(tbn[2].xyz);
|
|
296
|
+
#ifdef HAS_NORMALMAP
|
|
297
|
+
n = textureSample(pbr_normalSampler, pbr_normalSamplerSampler, fragmentInputs.pbr_vUV).rgb;
|
|
298
|
+
n = normalize(tbn * ((2.0 * n - 1.0) * vec3f(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
|
|
289
299
|
#endif
|
|
290
300
|
|
|
291
301
|
return n;
|
|
@@ -295,27 +305,37 @@ fn getNormal() -> vec3f
|
|
|
295
305
|
// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
|
|
296
306
|
// See our README.md on Environment Maps [3] for additional discussion.
|
|
297
307
|
#ifdef USE_IBL
|
|
298
|
-
fn getIBLContribution(PBRInfo
|
|
308
|
+
fn getIBLContribution(pbrInfo: PBRInfo, n: vec3f, reflection: vec3f) -> vec3f
|
|
299
309
|
{
|
|
300
|
-
|
|
301
|
-
|
|
310
|
+
let mipCount: f32 = 9.0; // resolution of 512x512
|
|
311
|
+
let lod: f32 = pbrInfo.perceptualRoughness * mipCount;
|
|
302
312
|
// retrieve a scale and bias to F0. See [1], Figure 3
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
313
|
+
let brdf = SRGBtoLINEAR(
|
|
314
|
+
textureSample(
|
|
315
|
+
pbr_BrdfLUT,
|
|
316
|
+
pbr_BrdfLUTSampler,
|
|
317
|
+
vec2f(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness)
|
|
318
|
+
)
|
|
319
|
+
).rgb;
|
|
320
|
+
let diffuseLight =
|
|
321
|
+
SRGBtoLINEAR(textureSample(pbr_diffuseEnvSampler, pbr_diffuseEnvSamplerSampler, n)).rgb;
|
|
322
|
+
let specularLightDefault =
|
|
323
|
+
SRGBtoLINEAR(textureSample(pbr_specularEnvSampler, pbr_specularEnvSamplerSampler, reflection)).rgb;
|
|
324
|
+
var specularLight = specularLightDefault;
|
|
307
325
|
#ifdef USE_TEX_LOD
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
326
|
+
specularLight = SRGBtoLINEAR(
|
|
327
|
+
textureSampleLevel(
|
|
328
|
+
pbr_specularEnvSampler,
|
|
329
|
+
pbr_specularEnvSamplerSampler,
|
|
330
|
+
reflection,
|
|
331
|
+
lod
|
|
332
|
+
)
|
|
333
|
+
).rgb;
|
|
311
334
|
#endif
|
|
312
335
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
// For presentation, this allows us to disable IBL terms
|
|
317
|
-
diffuse *= pbrMaterial.scaleIBLAmbient.x;
|
|
318
|
-
specular *= pbrMaterial.scaleIBLAmbient.y;
|
|
336
|
+
let diffuse = diffuseLight * pbrInfo.diffuseColor * pbrMaterial.scaleIBLAmbient.x;
|
|
337
|
+
let specular =
|
|
338
|
+
specularLight * (pbrInfo.specularColor * brdf.x + brdf.y) * pbrMaterial.scaleIBLAmbient.y;
|
|
319
339
|
|
|
320
340
|
return diffuse + specular;
|
|
321
341
|
}
|
|
@@ -359,7 +379,7 @@ fn geometricOcclusion(pbrInfo: PBRInfo) -> f32 {
|
|
|
359
379
|
fn microfacetDistribution(pbrInfo: PBRInfo) -> f32 {
|
|
360
380
|
let roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
|
|
361
381
|
let f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
|
|
362
|
-
return roughnessSq / (
|
|
382
|
+
return roughnessSq / (M_PI * f * f);
|
|
363
383
|
}
|
|
364
384
|
|
|
365
385
|
fn PBRInfo_setAmbientLight(pbrInfo: ptr<function, PBRInfo>) {
|
|
@@ -401,11 +421,11 @@ fn calculateFinalColor(pbrInfo: PBRInfo, lightColor: vec3<f32>) -> vec3<f32> {
|
|
|
401
421
|
|
|
402
422
|
fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
403
423
|
// The albedo may be defined from a base texture or a flat color
|
|
404
|
-
var baseColor: vec4<f32
|
|
424
|
+
var baseColor: vec4<f32> = pbrMaterial.baseColorFactor;
|
|
405
425
|
#ifdef HAS_BASECOLORMAP
|
|
406
|
-
baseColor = SRGBtoLINEAR(
|
|
407
|
-
|
|
408
|
-
|
|
426
|
+
baseColor = SRGBtoLINEAR(
|
|
427
|
+
textureSample(pbr_baseColorSampler, pbr_baseColorSamplerSampler, fragmentInputs.pbr_vUV)
|
|
428
|
+
) * pbrMaterial.baseColorFactor;
|
|
409
429
|
#endif
|
|
410
430
|
|
|
411
431
|
#ifdef ALPHA_CUTOFF
|
|
@@ -416,7 +436,7 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
416
436
|
|
|
417
437
|
var color = vec3<f32>(0.0, 0.0, 0.0);
|
|
418
438
|
|
|
419
|
-
if (pbrMaterial.unlit) {
|
|
439
|
+
if (pbrMaterial.unlit != 0u) {
|
|
420
440
|
color = baseColor.rgb;
|
|
421
441
|
} else {
|
|
422
442
|
// Metallic and Roughness material properties are packed together
|
|
@@ -427,7 +447,11 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
427
447
|
#ifdef HAS_METALROUGHNESSMAP
|
|
428
448
|
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
429
449
|
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
430
|
-
let mrSample = textureSample(
|
|
450
|
+
let mrSample = textureSample(
|
|
451
|
+
pbr_metallicRoughnessSampler,
|
|
452
|
+
pbr_metallicRoughnessSamplerSampler,
|
|
453
|
+
fragmentInputs.pbr_vUV
|
|
454
|
+
);
|
|
431
455
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
432
456
|
metallic = mrSample.b * metallic;
|
|
433
457
|
#endif
|
|
@@ -504,22 +528,25 @@ fn pbr_filterColor(colorUnused: vec4<f32>) -> vec4<f32> {
|
|
|
504
528
|
|
|
505
529
|
// Calculate lighting contribution from image based lighting source (IBL)
|
|
506
530
|
#ifdef USE_IBL
|
|
507
|
-
if (pbrMaterial.IBLenabled) {
|
|
531
|
+
if (pbrMaterial.IBLenabled != 0) {
|
|
508
532
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
509
533
|
}
|
|
510
534
|
#endif
|
|
511
535
|
|
|
512
536
|
// Apply optional PBR terms for additional (optional) shading
|
|
513
537
|
#ifdef HAS_OCCLUSIONMAP
|
|
514
|
-
if (pbrMaterial.occlusionMapEnabled) {
|
|
515
|
-
let ao =
|
|
538
|
+
if (pbrMaterial.occlusionMapEnabled != 0) {
|
|
539
|
+
let ao =
|
|
540
|
+
textureSample(pbr_occlusionSampler, pbr_occlusionSamplerSampler, fragmentInputs.pbr_vUV).r;
|
|
516
541
|
color = mix(color, color * ao, pbrMaterial.occlusionStrength);
|
|
517
542
|
}
|
|
518
543
|
#endif
|
|
519
544
|
|
|
520
545
|
#ifdef HAS_EMISSIVEMAP
|
|
521
|
-
if (pbrMaterial.emissiveMapEnabled) {
|
|
522
|
-
let emissive = SRGBtoLINEAR(
|
|
546
|
+
if (pbrMaterial.emissiveMapEnabled != 0u) {
|
|
547
|
+
let emissive = SRGBtoLINEAR(
|
|
548
|
+
textureSample(pbr_emissiveSampler, pbr_emissiveSamplerSampler, fragmentInputs.pbr_vUV)
|
|
549
|
+
).rgb * pbrMaterial.emissiveFactor;
|
|
523
550
|
color += emissive;
|
|
524
551
|
}
|
|
525
552
|
#endif
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-material-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,eAAe;AACf,yEAAyE;AACzE,0FAA0F;AAC1F,yDAAyD;AAEzD,gDAAgD;AAEhD,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuH7C,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"pbr-material-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,eAAe;AACf,yEAAyE;AACzE,0FAA0F;AAC1F,yDAAyD;AAEzD,gDAAgD;AAEhD,MAAM,CAAC,MAAM,mBAAmB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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