@luma.gl/shadertools 9.0.26 → 9.0.27
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 +88 -100
- package/dist/dist.min.js +130 -127
- package/dist/index.cjs +77 -92
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +52 -49
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +29 -10
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +11 -14
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +2 -0
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +48 -0
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +14 -8
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +1 -7
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +60 -56
- package/src/modules/lighting/pbr-material/pbr-material.ts +52 -25
- package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +69 -0
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +16 -8
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +1 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +0 -10
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +0 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js +0 -25
- package/src/modules/lighting/pbr-material/pbr-projection.ts +0 -41
package/dist/index.d.ts
CHANGED
|
@@ -33,8 +33,6 @@ export type { GouraudMaterialProps } from "./modules/lighting/gouraud-material/g
|
|
|
33
33
|
export { gouraudMaterial } from "./modules/lighting/gouraud-material/gouraud-material.js";
|
|
34
34
|
export type { PhongMaterialProps } from "./modules/lighting/phong-material/phong-material.js";
|
|
35
35
|
export { phongMaterial } from "./modules/lighting/phong-material/phong-material.js";
|
|
36
|
-
export type { PBRMaterialBindings, PBRMaterialProps, PBRMaterialUniforms } from "./modules/lighting/pbr-material/pbr-material.js";
|
|
37
|
-
export type { PBRProjectionProps } from "./modules/lighting/pbr-material/pbr-projection.js";
|
|
38
36
|
export { pbrMaterial } from "./modules/lighting/pbr-material/pbr-material.js";
|
|
39
37
|
export type { BrightnessContrastProps } from "./modules/postprocessing/image-adjust-filters/brightnesscontrast.js";
|
|
40
38
|
export { brightnessContrast } from "./modules/postprocessing/image-adjust-filters/brightnesscontrast.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,OAAO,EAAC,IAAI,EAAC,sCAAmC;AAEhD,YAAY,EAAC,YAAY,EAAC,+CAA4C;AAEtE,YAAY,EAAC,YAAY,EAAC,6CAA0C;AACpE,YAAY,EAAC,UAAU,EAAC,2CAAwC;AAChE,YAAY,EAAC,UAAU,EAAC,8CAA2C;AACnE,YAAY,EAAC,eAAe,EAAC,mDAAgD;AAC7E,OAAO,EAAC,oBAAoB,EAAC,sDAAmD;AAGhF,OAAO,EAAC,eAAe,EAAC,kCAA+B;AAEvD,OAAO,EAAC,qBAAqB,EAAC,uDAAoD;AAKlF,OAAO,EAAC,aAAa,EAAC,4CAAyC;AAC/D,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,aAAa,EACd,yCAAsC;AAGvC,YAAY,EAAC,uBAAuB,EAAC,kDAA+C;AACpF,OAAO,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O,EAAC,IAAI,EAAC,8CAA2C;AAGxD,YAAY,EAAC,SAAS,EAAC,4DAAyD;AAChF,OAAO,EAAC,IAAI,IAAI,KAAK,EAAC,4DAAyD;AAK/E,OAAO,EAAC,IAAI,EAAE,cAAc,EAAC,2CAAwC;AAGrE,OAAO,EAAC,QAAQ,IAAI,SAAS,EAAC,8CAA2C;AACzE,OAAO,EAAC,OAAO,IAAI,QAAQ,EAAC,4CAAyC;AAErE,OAAO,EAAC,MAAM,IAAI,OAAO,EAAC,mDAAgD;AAC1E,OAAO,EAAC,QAAQ,IAAI,SAAS,EAAC,uDAAoD;AAClF,OAAO,EACL,eAAe,EACf,aAAa,EACd,mEAAgE;AACjE,OAAO,EAAC,GAAG,EAAC,6CAA0C"}
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ export { lighting } from "./modules/lighting/lights/lighting-uniforms.js";
|
|
|
35
35
|
export { dirlight } from "./modules/lighting/no-material/dirlight.js";
|
|
36
36
|
export { gouraudMaterial } from "./modules/lighting/gouraud-material/gouraud-material.js";
|
|
37
37
|
export { phongMaterial } from "./modules/lighting/phong-material/phong-material.js";
|
|
38
|
+
// export type {PBRMaterialSettings, PBRMaterialUniforms} from './modules/lighting/pbr-material/pbr';
|
|
38
39
|
export { pbrMaterial } from "./modules/lighting/pbr-material/pbr-material.js";
|
|
39
40
|
export { brightnessContrast } from "./modules/postprocessing/image-adjust-filters/brightnesscontrast.js";
|
|
40
41
|
export { denoise } from "./modules/postprocessing/image-adjust-filters/denoise.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-fragment-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-fragment-glsl.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"pbr-fragment-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-fragment-glsl.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,EAAE,QAsZd,CAAC"}
|
|
@@ -9,7 +9,10 @@
|
|
|
9
9
|
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
10
10
|
export const fs = `\
|
|
11
11
|
precision highp float;
|
|
12
|
-
uniform
|
|
12
|
+
uniform Projection {
|
|
13
|
+
uniform vec3 u_Camera;
|
|
14
|
+
};
|
|
15
|
+
uniform pbrMaterial {
|
|
13
16
|
bool unlit;
|
|
14
17
|
bool baseColorMapEnabled;
|
|
15
18
|
vec4 baseColorFactor;
|
|
@@ -27,34 +30,34 @@ bool IBLenabled;
|
|
|
27
30
|
vec2 scaleIBLAmbient;
|
|
28
31
|
vec4 scaleDiffBaseMR;
|
|
29
32
|
vec4 scaleFGDSpec;
|
|
30
|
-
}
|
|
33
|
+
} u_pbrMaterial;
|
|
31
34
|
#ifdef HAS_BASECOLORMAP
|
|
32
|
-
uniform sampler2D
|
|
35
|
+
uniform sampler2D u_BaseColorSampler;
|
|
33
36
|
#endif
|
|
34
37
|
#ifdef HAS_NORMALMAP
|
|
35
|
-
uniform sampler2D
|
|
38
|
+
uniform sampler2D u_NormalSampler;
|
|
36
39
|
#endif
|
|
37
40
|
#ifdef HAS_EMISSIVEMAP
|
|
38
|
-
uniform sampler2D
|
|
41
|
+
uniform sampler2D u_EmissiveSampler;
|
|
39
42
|
#endif
|
|
40
43
|
#ifdef HAS_METALROUGHNESSMAP
|
|
41
|
-
uniform sampler2D
|
|
44
|
+
uniform sampler2D u_MetallicRoughnessSampler;
|
|
42
45
|
#endif
|
|
43
46
|
#ifdef HAS_OCCLUSIONMAP
|
|
44
|
-
uniform sampler2D
|
|
47
|
+
uniform sampler2D u_OcclusionSampler;
|
|
45
48
|
#endif
|
|
46
49
|
#ifdef USE_IBL
|
|
47
|
-
uniform samplerCube
|
|
48
|
-
uniform samplerCube
|
|
49
|
-
uniform sampler2D
|
|
50
|
+
uniform samplerCube u_DiffuseEnvSampler;
|
|
51
|
+
uniform samplerCube u_SpecularEnvSampler;
|
|
52
|
+
uniform sampler2D u_brdfLUT;
|
|
50
53
|
#endif
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
varying vec3 pbr_vPosition;
|
|
55
|
+
varying vec2 pbr_vUV;
|
|
53
56
|
#ifdef HAS_NORMALS
|
|
54
57
|
#ifdef HAS_TANGENTS
|
|
55
|
-
|
|
58
|
+
varying mat3 pbr_vTBN;
|
|
56
59
|
#else
|
|
57
|
-
|
|
60
|
+
varying vec3 pbr_vNormal;
|
|
58
61
|
#endif
|
|
59
62
|
#endif
|
|
60
63
|
struct PBRInfo {
|
|
@@ -109,8 +112,8 @@ mat3 tbn = mat3(t, b, ng);
|
|
|
109
112
|
mat3 tbn = pbr_vTBN;
|
|
110
113
|
#endif
|
|
111
114
|
#ifdef HAS_NORMALMAP
|
|
112
|
-
vec3 n =
|
|
113
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(
|
|
115
|
+
vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
|
|
116
|
+
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));
|
|
114
117
|
#else
|
|
115
118
|
vec3 n = normalize(tbn[2].xyz);
|
|
116
119
|
#endif
|
|
@@ -121,18 +124,18 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
|
|
|
121
124
|
{
|
|
122
125
|
float mipCount = 9.0;
|
|
123
126
|
float lod = (pbrInfo.perceptualRoughness * mipCount);
|
|
124
|
-
vec3 brdf = SRGBtoLINEAR(
|
|
127
|
+
vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
|
|
125
128
|
vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
|
|
126
|
-
vec3 diffuseLight = SRGBtoLINEAR(
|
|
129
|
+
vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
|
|
127
130
|
#ifdef USE_TEX_LOD
|
|
128
|
-
vec3 specularLight = SRGBtoLINEAR(
|
|
131
|
+
vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
|
|
129
132
|
#else
|
|
130
|
-
vec3 specularLight = SRGBtoLINEAR(
|
|
133
|
+
vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
|
|
131
134
|
#endif
|
|
132
135
|
vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
|
|
133
136
|
vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
|
|
134
|
-
diffuse *=
|
|
135
|
-
specular *=
|
|
137
|
+
diffuse *= u_pbrMaterial.scaleIBLAmbient.x;
|
|
138
|
+
specular *= u_pbrMaterial.scaleIBLAmbient.y;
|
|
136
139
|
return diffuse + specular;
|
|
137
140
|
}
|
|
138
141
|
#endif
|
|
@@ -192,24 +195,24 @@ return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
|
|
|
192
195
|
vec4 pbr_filterColor(vec4 colorUnused)
|
|
193
196
|
{
|
|
194
197
|
#ifdef HAS_BASECOLORMAP
|
|
195
|
-
vec4 baseColor = SRGBtoLINEAR(
|
|
198
|
+
vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;
|
|
196
199
|
#else
|
|
197
|
-
vec4 baseColor =
|
|
200
|
+
vec4 baseColor = u_pbrMaterial.baseColorFactor;
|
|
198
201
|
#endif
|
|
199
202
|
#ifdef ALPHA_CUTOFF
|
|
200
|
-
if (baseColor.a <
|
|
203
|
+
if (baseColor.a < u_pbrMaterial.alphaCutoff) {
|
|
201
204
|
discard;
|
|
202
205
|
}
|
|
203
206
|
#endif
|
|
204
207
|
vec3 color = vec3(0, 0, 0);
|
|
205
|
-
if(
|
|
208
|
+
if(u_pbrMaterial.unlit){
|
|
206
209
|
color.rgb = baseColor.rgb;
|
|
207
210
|
}
|
|
208
211
|
else{
|
|
209
|
-
float perceptualRoughness =
|
|
210
|
-
float metallic =
|
|
212
|
+
float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;
|
|
213
|
+
float metallic = u_pbrMaterial.metallicRoughnessValues.x;
|
|
211
214
|
#ifdef HAS_METALROUGHNESSMAP
|
|
212
|
-
vec4 mrSample =
|
|
215
|
+
vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
|
|
213
216
|
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
214
217
|
metallic = mrSample.b * metallic;
|
|
215
218
|
#endif
|
|
@@ -225,7 +228,7 @@ float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
|
225
228
|
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
226
229
|
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
227
230
|
vec3 n = getNormal();
|
|
228
|
-
vec3 v = normalize(
|
|
231
|
+
vec3 v = normalize(u_Camera - pbr_vPosition);
|
|
229
232
|
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
230
233
|
vec3 reflection = -normalize(reflect(v, n));
|
|
231
234
|
PBRInfo pbrInfo = PBRInfo(
|
|
@@ -246,42 +249,42 @@ v
|
|
|
246
249
|
);
|
|
247
250
|
#ifdef USE_LIGHTS
|
|
248
251
|
PBRInfo_setAmbientLight(pbrInfo);
|
|
249
|
-
color += calculateFinalColor(pbrInfo,
|
|
250
|
-
for(int i = 0; i <
|
|
251
|
-
if (i <
|
|
252
|
-
PBRInfo_setDirectionalLight(pbrInfo,
|
|
253
|
-
color += calculateFinalColor(pbrInfo,
|
|
252
|
+
color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);
|
|
253
|
+
for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
|
|
254
|
+
if (i < lighting_uDirectionalLightCount) {
|
|
255
|
+
PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);
|
|
256
|
+
color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);
|
|
254
257
|
}
|
|
255
258
|
}
|
|
256
|
-
for(int i = 0; i <
|
|
257
|
-
if (i <
|
|
258
|
-
PBRInfo_setPointLight(pbrInfo,
|
|
259
|
-
float attenuation = getPointLightAttenuation(
|
|
260
|
-
color += calculateFinalColor(pbrInfo,
|
|
259
|
+
for(int i = 0; i < lighting_uPointLightCount; i++) {
|
|
260
|
+
if (i < lighting_uPointLightCount) {
|
|
261
|
+
PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);
|
|
262
|
+
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
|
|
263
|
+
color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);
|
|
261
264
|
}
|
|
262
265
|
}
|
|
263
266
|
#endif
|
|
264
267
|
#ifdef USE_IBL
|
|
265
|
-
if (
|
|
268
|
+
if (u_pbrMateral.IBLEnabled) {
|
|
266
269
|
color += getIBLContribution(pbrInfo, n, reflection);
|
|
267
270
|
}
|
|
268
271
|
#endif
|
|
269
272
|
#ifdef HAS_OCCLUSIONMAP
|
|
270
|
-
if (
|
|
271
|
-
float ao =
|
|
272
|
-
color = mix(color, color * ao,
|
|
273
|
+
if (u_pbrMaterial.occlusionMapEnabled) {
|
|
274
|
+
float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
|
|
275
|
+
color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);
|
|
273
276
|
}
|
|
274
277
|
#endif
|
|
275
278
|
#ifdef HAS_EMISSIVEMAP
|
|
276
|
-
if (
|
|
277
|
-
vec3 emissive = SRGBtoLINEAR(
|
|
279
|
+
if (u_pbrMaterial.emmissiveMapEnabled) {
|
|
280
|
+
vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;
|
|
278
281
|
color += emissive;
|
|
279
282
|
}
|
|
280
283
|
#endif
|
|
281
284
|
#ifdef PBR_DEBUG
|
|
282
|
-
color = mix(color, baseColor.rgb,
|
|
283
|
-
color = mix(color, vec3(metallic),
|
|
284
|
-
color = mix(color, vec3(perceptualRoughness),
|
|
285
|
+
color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);
|
|
286
|
+
color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);
|
|
287
|
+
color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);
|
|
285
288
|
#endif
|
|
286
289
|
}
|
|
287
290
|
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
@@ -2,16 +2,35 @@ import type { Texture } from '@luma.gl/core';
|
|
|
2
2
|
import type { Vector2, Vector3, Vector4 } from '@math.gl/core';
|
|
3
3
|
import type { NumberArray2, NumberArray3, NumberArray4 } from "../../../lib/utils/uniform-types.js";
|
|
4
4
|
import { ShaderModule } from "../../../lib/shader-module/shader-module.js";
|
|
5
|
+
export type PBRMaterialProps = PBRMaterialBindings & {
|
|
6
|
+
unlit: boolean;
|
|
7
|
+
baseColorMapEnabled: boolean;
|
|
8
|
+
baseColorFactor: Readonly<Vector4 | NumberArray4>;
|
|
9
|
+
normalMapEnabled: boolean;
|
|
10
|
+
normalScale: number;
|
|
11
|
+
emissiveMapEnabled: boolean;
|
|
12
|
+
emissiveFactor: Readonly<Vector3 | NumberArray3>;
|
|
13
|
+
metallicRoughnessValues: Readonly<Vector2 | NumberArray2>;
|
|
14
|
+
metallicRoughnessMapEnabled: boolean;
|
|
15
|
+
occlusionMapEnabled: boolean;
|
|
16
|
+
occlusionStrength: number;
|
|
17
|
+
alphaCutoffEnabled: boolean;
|
|
18
|
+
alphaCutoff: number;
|
|
19
|
+
IBLenabled: boolean;
|
|
20
|
+
scaleIBLAmbient: Readonly<Vector2 | NumberArray2>;
|
|
21
|
+
scaleDiffBaseMR: Readonly<Vector4 | NumberArray4>;
|
|
22
|
+
scaleFGDSpec: Readonly<Vector4 | NumberArray4>;
|
|
23
|
+
};
|
|
5
24
|
/** Non-uniform block bindings for pbr module */
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
25
|
+
type PBRMaterialBindings = {
|
|
26
|
+
baseColorSampler?: Texture | null;
|
|
27
|
+
normalSampler?: Texture | null;
|
|
28
|
+
emissiveSampler?: Texture | null;
|
|
29
|
+
metallicRoughnessSampler?: Texture | null;
|
|
30
|
+
occlusionSampler?: Texture | null;
|
|
31
|
+
diffuseEnvSampler: Texture | null;
|
|
32
|
+
specularEnvSampler: Texture | null;
|
|
33
|
+
brdfLUT?: Texture | null;
|
|
15
34
|
};
|
|
16
35
|
export type PBRMaterialUniforms = {
|
|
17
36
|
unlit: boolean;
|
|
@@ -32,10 +51,10 @@ export type PBRMaterialUniforms = {
|
|
|
32
51
|
scaleDiffBaseMR: Readonly<Vector4 | NumberArray4>;
|
|
33
52
|
scaleFGDSpec: Readonly<Vector4 | NumberArray4>;
|
|
34
53
|
};
|
|
35
|
-
export type PBRMaterialProps = PBRMaterialBindings & PBRMaterialUniforms;
|
|
36
54
|
/**
|
|
37
55
|
* An implementation of PBR (Physically-Based Rendering).
|
|
38
56
|
* Physically Based Shading of a microfacet surface defined by a glTF material.
|
|
39
57
|
*/
|
|
40
58
|
export declare const pbrMaterial: ShaderModule<PBRMaterialProps, PBRMaterialUniforms>;
|
|
59
|
+
export {};
|
|
41
60
|
//# sourceMappingURL=pbr-material.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-material.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAC,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C,CAAC;CAChD,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,EAAE,YAAY,CAAC,gBAAgB,EAAE,mBAAmB,CAgD3E,CAAC"}
|
|
@@ -4,28 +4,25 @@
|
|
|
4
4
|
import { lighting } from "../lights/lighting-uniforms.js";
|
|
5
5
|
import { vs } from "./pbr-vertex-glsl.js";
|
|
6
6
|
import { fs } from "./pbr-fragment-glsl.js";
|
|
7
|
-
import { pbrProjection } from "./pbr-projection.js";
|
|
8
7
|
/**
|
|
9
8
|
* An implementation of PBR (Physically-Based Rendering).
|
|
10
9
|
* Physically Based Shading of a microfacet surface defined by a glTF material.
|
|
11
10
|
*/
|
|
12
11
|
export const pbrMaterial = {
|
|
13
|
-
name: '
|
|
12
|
+
name: 'pbr',
|
|
14
13
|
vs,
|
|
15
14
|
fs,
|
|
16
15
|
defines: {
|
|
17
|
-
LIGHTING_FRAGMENT: 1
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// PBR_DEBUG: 0
|
|
16
|
+
LIGHTING_FRAGMENT: 1,
|
|
17
|
+
HAS_NORMALMAP: 0,
|
|
18
|
+
HAS_EMISSIVEMAP: 0,
|
|
19
|
+
HAS_OCCLUSIONMAP: 0,
|
|
20
|
+
HAS_BASECOLORMAP: 0,
|
|
21
|
+
HAS_METALROUGHNESSMAP: 0,
|
|
22
|
+
ALPHA_CUTOFF: 0,
|
|
23
|
+
USE_IBL: 0,
|
|
24
|
+
PBR_DEBUG: 0
|
|
27
25
|
},
|
|
28
|
-
getUniforms: props => props,
|
|
29
26
|
uniformTypes: {
|
|
30
27
|
// Material is unlit
|
|
31
28
|
unlit: 'i32',
|
|
@@ -50,5 +47,5 @@ export const pbrMaterial = {
|
|
|
50
47
|
scaleDiffBaseMR: 'vec4<f32>',
|
|
51
48
|
scaleFGDSpec: 'vec4<f32>'
|
|
52
49
|
},
|
|
53
|
-
dependencies: [lighting
|
|
50
|
+
dependencies: [lighting]
|
|
54
51
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pbr-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,mBAAmB,QA8D/B,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
5
|
+
export const pbrMaterialUniforms = `\
|
|
6
|
+
uniform Projection {
|
|
7
|
+
vec3 u_Camera;
|
|
8
|
+
};
|
|
9
|
+
uniform pbrMaterialUniforms {
|
|
10
|
+
bool unlit;
|
|
11
|
+
bool baseColorMapEnabled;
|
|
12
|
+
vec4 baseColorFactor;
|
|
13
|
+
bool normalMapEnabled;
|
|
14
|
+
float normalScale;
|
|
15
|
+
bool emissiveMapEnabled;
|
|
16
|
+
vec3 emissiveFactor;
|
|
17
|
+
vec2 metallicRoughnessValues;
|
|
18
|
+
bool metallicRoughnessMapEnabled;
|
|
19
|
+
bool occlusionMapEnabled;
|
|
20
|
+
float occlusionStrength;
|
|
21
|
+
bool alphaCutoffEnabled;
|
|
22
|
+
float alphaCutoff;
|
|
23
|
+
bool IBLenabled;
|
|
24
|
+
vec2 scaleIBLAmbient;
|
|
25
|
+
vec4 scaleDiffBaseMR;
|
|
26
|
+
vec4 scaleFGDSpec;
|
|
27
|
+
};
|
|
28
|
+
#ifdef HAS_BASECOLORMAP
|
|
29
|
+
uniform sampler2D u_BaseColorSampler;
|
|
30
|
+
#endif
|
|
31
|
+
#ifdef HAS_NORMALMAP
|
|
32
|
+
uniform sampler2D u_NormalSampler;
|
|
33
|
+
#endif
|
|
34
|
+
#ifdef HAS_EMISSIVEMAP
|
|
35
|
+
uniform sampler2D u_EmissiveSampler;
|
|
36
|
+
#endif
|
|
37
|
+
#ifdef HAS_METALROUGHNESSMAP
|
|
38
|
+
uniform sampler2D u_MetallicRoughnessSampler;
|
|
39
|
+
#endif
|
|
40
|
+
#ifdef HAS_OCCLUSIONMAP
|
|
41
|
+
uniform sampler2D u_OcclusionSampler;
|
|
42
|
+
#endif
|
|
43
|
+
#ifdef USE_IBL
|
|
44
|
+
uniform samplerCube u_DiffuseEnvSampler;
|
|
45
|
+
uniform samplerCube u_SpecularEnvSampler;
|
|
46
|
+
uniform sampler2D u_brdfLUT;
|
|
47
|
+
#endif
|
|
48
|
+
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-vertex-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-vertex-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"pbr-vertex-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-material/pbr-vertex-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,EAAE,QA0Cd,CAAC"}
|
|
@@ -3,27 +3,33 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
5
5
|
export const vs = `\
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
uniform projection {
|
|
7
|
+
mat4 u_MVPMatrix;
|
|
8
|
+
mat4 u_ModelMatrix;
|
|
9
|
+
mat4 u_NormalMatrix;
|
|
10
|
+
vec3 u_Camera;
|
|
11
|
+
}
|
|
12
|
+
varying vec3 pbr_vPosition;
|
|
13
|
+
varying vec2 pbr_vUV;
|
|
8
14
|
#ifdef HAS_NORMALS
|
|
9
15
|
# ifdef HAS_TANGENTS
|
|
10
|
-
|
|
16
|
+
varying mat3 pbr_vTBN;
|
|
11
17
|
# else
|
|
12
|
-
|
|
18
|
+
varying vec3 pbr_vNormal;
|
|
13
19
|
# endif
|
|
14
20
|
#endif
|
|
15
21
|
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
16
22
|
{
|
|
17
|
-
vec4 pos =
|
|
23
|
+
vec4 pos = u_ModelMatrix * position;
|
|
18
24
|
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
19
25
|
#ifdef HAS_NORMALS
|
|
20
26
|
#ifdef HAS_TANGENTS
|
|
21
|
-
vec3 normalW = normalize(vec3(
|
|
22
|
-
vec3 tangentW = normalize(vec3(
|
|
27
|
+
vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
|
|
28
|
+
vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
|
|
23
29
|
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
24
30
|
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
25
31
|
#else
|
|
26
|
-
pbr_vNormal = normalize(vec3(
|
|
32
|
+
pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
|
|
27
33
|
#endif
|
|
28
34
|
#endif
|
|
29
35
|
#ifdef HAS_UV
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phong-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,QAOpB,CAAC;AAEF,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"phong-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,QAOpB,CAAC;AAEF,eAAO,MAAM,QAAQ,QA+CpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.27",
|
|
4
4
|
"description": "Shader module system for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"@math.gl/types": "^4.0.0",
|
|
54
54
|
"wgsl_reflect": "^1.0.1"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "5c313ac8abddc896162c41e4eee8c1f27bb4f522"
|
|
57
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -75,13 +75,7 @@ export type {GouraudMaterialProps} from './modules/lighting/gouraud-material/gou
|
|
|
75
75
|
export {gouraudMaterial} from './modules/lighting/gouraud-material/gouraud-material';
|
|
76
76
|
export type {PhongMaterialProps} from './modules/lighting/phong-material/phong-material';
|
|
77
77
|
export {phongMaterial} from './modules/lighting/phong-material/phong-material';
|
|
78
|
-
export type {
|
|
79
|
-
PBRMaterialBindings,
|
|
80
|
-
PBRMaterialProps,
|
|
81
|
-
PBRMaterialUniforms
|
|
82
|
-
} from './modules/lighting/pbr-material/pbr-material';
|
|
83
|
-
export type {PBRProjectionProps} from './modules/lighting/pbr-material/pbr-projection';
|
|
84
|
-
|
|
78
|
+
// export type {PBRMaterialSettings, PBRMaterialUniforms} from './modules/lighting/pbr-material/pbr';
|
|
85
79
|
export {pbrMaterial} from './modules/lighting/pbr-material/pbr-material';
|
|
86
80
|
|
|
87
81
|
// POST PROCESSING / SHADER PASS MODULES
|