@luma.gl/gltf 9.0.25 → 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 CHANGED
@@ -73,9 +73,9 @@ var __exports__ = (() => {
73
73
  bindings: {},
74
74
  uniforms: {
75
75
  // TODO: find better values?
76
- camera: [0, 0, 0],
76
+ u_Camera: [0, 0, 0],
77
77
  // Model should override
78
- metallicRoughnessValues: [1, 1]
78
+ u_MetallicRoughnessValues: [1, 1]
79
79
  // Default is 1 and 1
80
80
  },
81
81
  parameters: {},
@@ -85,15 +85,15 @@ var __exports__ = (() => {
85
85
  parsedMaterial.defines.USE_TEX_LOD = 1;
86
86
  const { imageBasedLightingEnvironment } = options;
87
87
  if (imageBasedLightingEnvironment) {
88
- parsedMaterial.bindings.pbr_diffuseEnvSampler = imageBasedLightingEnvironment.diffuseEnvSampler;
89
- parsedMaterial.bindings.pbr_specularEnvSampler = imageBasedLightingEnvironment.specularEnvSampler;
90
- parsedMaterial.bindings.pbr_BrdfLUT = imageBasedLightingEnvironment.brdfLutTexture;
91
- parsedMaterial.uniforms.scaleIBLAmbient = [1, 1];
88
+ parsedMaterial.bindings.u_DiffuseEnvSampler = imageBasedLightingEnvironment.diffuseEnvSampler;
89
+ parsedMaterial.bindings.u_SpecularEnvSampler = imageBasedLightingEnvironment.specularEnvSampler;
90
+ parsedMaterial.bindings.u_brdfLUT = imageBasedLightingEnvironment.brdfLutTexture;
91
+ parsedMaterial.uniforms.u_ScaleIBLAmbient = [1, 1];
92
92
  }
93
93
  if (options?.pbrDebug) {
94
94
  parsedMaterial.defines.PBR_DEBUG = 1;
95
- parsedMaterial.uniforms.scaleDiffBaseMR = [0, 0, 0, 0];
96
- parsedMaterial.uniforms.scaleFGDSpec = [0, 0, 0, 0];
95
+ parsedMaterial.uniforms.u_ScaleDiffBaseMR = [0, 0, 0, 0];
96
+ parsedMaterial.uniforms.u_ScaleFGDSpec = [0, 0, 0, 0];
97
97
  }
98
98
  if (attributes.NORMAL)
99
99
  parsedMaterial.defines.HAS_NORMALS = 1;
@@ -111,47 +111,41 @@ var __exports__ = (() => {
111
111
  return parsedMaterial;
112
112
  }
113
113
  function parseMaterial(device, material, parsedMaterial) {
114
- parsedMaterial.uniforms.unlit = Boolean(material.unlit);
114
+ parsedMaterial.uniforms.pbr_uUnlit = Boolean(material.unlit);
115
115
  if (material.pbrMetallicRoughness) {
116
116
  parsePbrMetallicRoughness(device, material.pbrMetallicRoughness, parsedMaterial);
117
117
  }
118
118
  if (material.normalTexture) {
119
- addTexture(
120
- device,
121
- material.normalTexture,
122
- "pbr_normalSampler",
123
- "HAS_NORMALMAP",
124
- parsedMaterial
125
- );
119
+ addTexture(device, material.normalTexture, "u_NormalSampler", "HAS_NORMALMAP", parsedMaterial);
126
120
  const { scale: scale4 = 1 } = material.normalTexture;
127
- parsedMaterial.uniforms.normalScale = scale4;
121
+ parsedMaterial.uniforms.u_NormalScale = scale4;
128
122
  }
129
123
  if (material.occlusionTexture) {
130
124
  addTexture(
131
125
  device,
132
126
  material.occlusionTexture,
133
- "pbr_occlusionSampler",
127
+ "u_OcclusionSampler",
134
128
  "HAS_OCCLUSIONMAP",
135
129
  parsedMaterial
136
130
  );
137
131
  const { strength = 1 } = material.occlusionTexture;
138
- parsedMaterial.uniforms.occlusionStrength = strength;
132
+ parsedMaterial.uniforms.u_OcclusionStrength = strength;
139
133
  }
140
134
  if (material.emissiveTexture) {
141
135
  addTexture(
142
136
  device,
143
137
  material.emissiveTexture,
144
- "pbr_emissiveSampler",
138
+ "u_EmissiveSampler",
145
139
  "HAS_EMISSIVEMAP",
146
140
  parsedMaterial
147
141
  );
148
- parsedMaterial.uniforms.emissiveFactor = material.emissiveFactor || [0, 0, 0];
142
+ parsedMaterial.uniforms.u_EmissiveFactor = material.emissiveFactor || [0, 0, 0];
149
143
  }
150
144
  switch (material.alphaMode) {
151
145
  case "MASK":
152
146
  const { alphaCutoff = 0.5 } = material;
153
147
  parsedMaterial.defines.ALPHA_CUTOFF = 1;
154
- parsedMaterial.uniforms.alphaCutoff = alphaCutoff;
148
+ parsedMaterial.uniforms.u_AlphaCutoff = alphaCutoff;
155
149
  break;
156
150
  case "BLEND":
157
151
  import_core.log.warn("glTF BLEND alphaMode might not work well because it requires mesh sorting")();
@@ -177,23 +171,23 @@ var __exports__ = (() => {
177
171
  addTexture(
178
172
  device,
179
173
  pbrMetallicRoughness.baseColorTexture,
180
- "pbr_baseColorSampler",
174
+ "u_BaseColorSampler",
181
175
  "HAS_BASECOLORMAP",
182
176
  parsedMaterial
183
177
  );
184
178
  }
185
- parsedMaterial.uniforms.baseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
179
+ parsedMaterial.uniforms.u_BaseColorFactor = pbrMetallicRoughness.baseColorFactor || [1, 1, 1, 1];
186
180
  if (pbrMetallicRoughness.metallicRoughnessTexture) {
187
181
  addTexture(
188
182
  device,
189
183
  pbrMetallicRoughness.metallicRoughnessTexture,
190
- "pbr_metallicRoughnessSampler",
184
+ "u_MetallicRoughnessSampler",
191
185
  "HAS_METALROUGHNESSMAP",
192
186
  parsedMaterial
193
187
  );
194
188
  }
195
189
  const { metallicFactor = 1, roughnessFactor = 1 } = pbrMetallicRoughness;
196
- parsedMaterial.uniforms.metallicRoughnessValues = [metallicFactor, roughnessFactor];
190
+ parsedMaterial.uniforms.u_MetallicRoughnessValues = [metallicFactor, roughnessFactor];
197
191
  }
198
192
  function addTexture(device, gltfTexture, uniformName, define = null, parsedMaterial) {
199
193
  const parameters = gltfTexture?.texture?.sampler?.parameters || {};
@@ -3576,24 +3570,25 @@ var __exports__ = (() => {
3576
3570
  }
3577
3571
 
3578
3572
  // src/gltf/create-gltf-model.ts
3579
- var import_core5 = __toESM(require_core(), 1);
3573
+ var import_core4 = __toESM(require_core(), 1);
3580
3574
 
3581
3575
  // ../shadertools/src/lib/glsl-utils/highlight.ts
3582
3576
  var glsl = (x) => `${x}`;
3583
3577
 
3584
- // ../shadertools/src/modules/lighting/lights/lighting-uniforms-glsl.ts
3585
- var lightingUniforms = glsl`\
3586
- precision highp int;
3578
+ // ../shadertools/src/modules-webgl1/lighting/lights/lights-glsl.ts
3579
+ var lightingShader = glsl`\
3580
+ #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
3587
3581
 
3588
- // #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
3589
3582
  struct AmbientLight {
3590
- vec3 color;
3583
+ vec3 color;
3591
3584
  };
3592
3585
 
3593
3586
  struct PointLight {
3594
- vec3 color;
3595
- vec3 position;
3596
- vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential
3587
+ vec3 color;
3588
+ vec3 position;
3589
+
3590
+ // Constant-Linear-Exponential
3591
+ vec3 attenuation;
3597
3592
  };
3598
3593
 
3599
3594
  struct DirectionalLight {
@@ -3601,54 +3596,13 @@ struct DirectionalLight {
3601
3596
  vec3 direction;
3602
3597
  };
3603
3598
 
3604
- uniform lightingUniforms {
3605
- int enabled;
3606
- int lightType;
3607
-
3608
- int directionalLightCount;
3609
- int pointLightCount;
3610
-
3611
- vec3 ambientColor;
3612
-
3613
- vec3 lightColor0;
3614
- vec3 lightPosition0;
3615
- vec3 lightDirection0;
3616
- vec3 lightAttenuation0;
3617
-
3618
- vec3 lightColor1;
3619
- vec3 lightPosition1;
3620
- vec3 lightDirection1;
3621
- vec3 lightAttenuation1;
3622
-
3623
- vec3 lightColor2;
3624
- vec3 lightPosition2;
3625
- vec3 lightDirection2;
3626
- vec3 lightAttenuation2;
3627
- } lighting;
3628
-
3629
- PointLight lighting_getPointLight(int index) {
3630
- switch (index) {
3631
- case 0:
3632
- return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
3633
- case 1:
3634
- return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
3635
- case 2:
3636
- default:
3637
- return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
3638
- }
3639
- }
3599
+ uniform AmbientLight lighting_uAmbientLight;
3600
+ uniform PointLight lighting_uPointLight[MAX_LIGHTS];
3601
+ uniform DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS];
3602
+ uniform int lighting_uPointLightCount;
3603
+ uniform int lighting_uDirectionalLightCount;
3640
3604
 
3641
- DirectionalLight lighting_getDirectionalLight(int index) {
3642
- switch (index) {
3643
- case 0:
3644
- return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
3645
- case 1:
3646
- return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
3647
- case 2:
3648
- default:
3649
- return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
3650
- }
3651
- }
3605
+ uniform bool lighting_uEnabled;
3652
3606
 
3653
3607
  float getPointLightAttenuation(PointLight pointLight, float distance) {
3654
3608
  return pointLight.attenuation.x
@@ -3656,87 +3610,16 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
3656
3610
  + pointLight.attenuation.z * distance * distance;
3657
3611
  }
3658
3612
 
3659
- // #endif
3613
+ #endif
3660
3614
  `;
3661
3615
 
3662
- // ../shadertools/src/modules/lighting/lights/lighting-uniforms.ts
3663
- var import_core4 = __toESM(require_core(), 1);
3664
- var MAX_LIGHTS = 3;
3665
- var COLOR_FACTOR = 255;
3666
- var lighting = {
3667
- name: "lighting",
3668
- vs: lightingUniforms,
3669
- fs: lightingUniforms,
3670
- getUniforms(props, prevUniforms) {
3671
- return getUniforms(props);
3672
- },
3673
- defines: {
3674
- MAX_LIGHTS
3675
- },
3676
- uniformTypes: {
3677
- enabled: "i32",
3678
- lightType: "i32",
3679
- directionalLightCount: "i32",
3680
- pointLightCount: "i32",
3681
- ambientLightColor: "vec3<f32>",
3682
- // TODO define as arrays once we have appropriate uniformTypes
3683
- lightColor0: "vec3<f32>",
3684
- lightPosition0: "vec3<f32>",
3685
- // TODO - could combine direction and attenuation
3686
- lightDirection0: "vec3<f32>",
3687
- lightAttenuation0: "vec3<f32>",
3688
- lightColor1: "vec3<f32>",
3689
- lightPosition1: "vec3<f32>",
3690
- lightDirection1: "vec3<f32>",
3691
- lightAttenuation1: "vec3<f32>",
3692
- lightColor2: "vec3<f32>",
3693
- lightPosition2: "vec3<f32>",
3694
- lightDirection2: "vec3<f32>",
3695
- lightAttenuation2: "vec3<f32>"
3696
- },
3697
- defaultUniforms: {
3698
- enabled: 1,
3699
- lightType: 0 /* POINT */,
3700
- directionalLightCount: 0,
3701
- pointLightCount: 0,
3702
- ambientLightColor: [0.1, 0.1, 0.1],
3703
- lightColor0: [1, 1, 1],
3704
- lightPosition0: [1, 1, 2],
3705
- // TODO - could combine direction and attenuation
3706
- lightDirection0: [1, 1, 1],
3707
- lightAttenuation0: [1, 0, 0],
3708
- lightColor1: [1, 1, 1],
3709
- lightPosition1: [1, 1, 2],
3710
- lightDirection1: [1, 1, 1],
3711
- lightAttenuation1: [1, 0, 0],
3712
- lightColor2: [1, 1, 1],
3713
- lightPosition2: [1, 1, 2],
3714
- lightDirection2: [1, 1, 1],
3715
- lightAttenuation2: [1, 0, 0]
3716
- }
3616
+ // ../shadertools/src/modules-webgl1/lighting/lights/lights.ts
3617
+ var INITIAL_MODULE_OPTIONS = {
3618
+ lightSources: {}
3717
3619
  };
3718
- function getUniforms(props, prevUniforms = {}) {
3719
- props = props ? { ...props } : props;
3720
- if (!props) {
3721
- return { ...lighting.defaultUniforms };
3722
- }
3723
- if (props.lights) {
3724
- props = { ...props, ...extractLightTypes(props.lights), lights: void 0 };
3725
- }
3726
- const { ambientLight, pointLights, directionalLights } = props || {};
3727
- const hasLights = ambientLight || pointLights && pointLights.length > 0 || directionalLights && directionalLights.length > 0;
3728
- if (!hasLights) {
3729
- return { ...lighting.defaultUniforms, enabled: 0 };
3730
- }
3731
- const uniforms = {
3732
- ...lighting.defaultUniforms,
3733
- ...prevUniforms,
3734
- ...getLightSourceUniforms({ ambientLight, pointLights, directionalLights })
3735
- };
3736
- if (props.enabled !== void 0) {
3737
- uniforms.enabled = props.enabled ? 1 : 0;
3738
- }
3739
- return uniforms;
3620
+ function convertColor(colorDef = {}) {
3621
+ const { color = [0, 0, 0], intensity = 1 } = colorDef;
3622
+ return color.map((component) => component * intensity / 255);
3740
3623
  }
3741
3624
  function getLightSourceUniforms({
3742
3625
  ambientLight,
@@ -3744,55 +3627,79 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
3744
3627
  directionalLights = []
3745
3628
  }) {
3746
3629
  const lightSourceUniforms = {};
3747
- lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
3748
- let currentLight = 0;
3749
- for (const pointLight of pointLights) {
3750
- lightSourceUniforms.lightType = 0 /* POINT */;
3751
- const i = currentLight;
3752
- lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
3753
- lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
3754
- lightSourceUniforms[`lightAttenuation${i}`] = pointLight.attenuation || [1, 0, 0];
3755
- currentLight++;
3756
- }
3757
- for (const directionalLight of directionalLights) {
3758
- lightSourceUniforms.lightType = 1 /* DIRECTIONAL */;
3759
- const i = currentLight;
3760
- lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
3761
- lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
3762
- currentLight++;
3763
- }
3764
- if (currentLight > MAX_LIGHTS) {
3765
- import_core4.log.warn("MAX_LIGHTS exceeded")();
3766
- }
3767
- lightSourceUniforms.directionalLightCount = directionalLights.length;
3768
- lightSourceUniforms.pointLightCount = pointLights.length;
3630
+ if (ambientLight) {
3631
+ lightSourceUniforms["lighting_uAmbientLight.color"] = convertColor(ambientLight);
3632
+ } else {
3633
+ lightSourceUniforms["lighting_uAmbientLight.color"] = [0, 0, 0];
3634
+ }
3635
+ pointLights.forEach((pointLight, index) => {
3636
+ lightSourceUniforms[`lighting_uPointLight[${index}].color`] = convertColor(pointLight);
3637
+ lightSourceUniforms[`lighting_uPointLight[${index}].position`] = pointLight.position;
3638
+ lightSourceUniforms[`lighting_uPointLight[${index}].attenuation`] = pointLight.attenuation || [
3639
+ 1,
3640
+ 0,
3641
+ 0
3642
+ ];
3643
+ });
3644
+ lightSourceUniforms.lighting_uPointLightCount = pointLights.length;
3645
+ directionalLights.forEach((directionalLight, index) => {
3646
+ lightSourceUniforms[`lighting_uDirectionalLight[${index}].color`] = convertColor(directionalLight);
3647
+ lightSourceUniforms[`lighting_uDirectionalLight[${index}].direction`] = directionalLight.direction;
3648
+ });
3649
+ lightSourceUniforms.lighting_uDirectionalLightCount = directionalLights.length;
3769
3650
  return lightSourceUniforms;
3770
3651
  }
3771
- function extractLightTypes(lights) {
3772
- const lightSources = { pointLights: [], directionalLights: [] };
3773
- for (const light of lights || []) {
3774
- switch (light.type) {
3775
- case "ambient":
3776
- lightSources.ambientLight = light;
3777
- break;
3778
- case "directional":
3779
- lightSources.directionalLights?.push(light);
3780
- break;
3781
- case "point":
3782
- lightSources.pointLights?.push(light);
3783
- break;
3784
- default:
3652
+ function getUniforms(opts = INITIAL_MODULE_OPTIONS) {
3653
+ if ("lightSources" in opts) {
3654
+ const { ambientLight, pointLights, directionalLights } = opts.lightSources || {};
3655
+ const hasLights = ambientLight || pointLights && pointLights.length > 0 || directionalLights && directionalLights.length > 0;
3656
+ if (!hasLights) {
3657
+ return { lighting_uEnabled: false };
3785
3658
  }
3659
+ return Object.assign(
3660
+ {},
3661
+ getLightSourceUniforms({ ambientLight, pointLights, directionalLights }),
3662
+ {
3663
+ lighting_uEnabled: true
3664
+ }
3665
+ );
3786
3666
  }
3787
- return lightSources;
3788
- }
3789
- function convertColor(colorDef = {}) {
3790
- const { color = [0, 0, 0], intensity = 1 } = colorDef;
3791
- return color.map((component) => component * intensity / COLOR_FACTOR);
3667
+ if ("lights" in opts) {
3668
+ const lightSources = { pointLights: [], directionalLights: [] };
3669
+ for (const light of opts.lights || []) {
3670
+ switch (light.type) {
3671
+ case "ambient":
3672
+ lightSources.ambientLight = light;
3673
+ break;
3674
+ case "directional":
3675
+ lightSources.directionalLights?.push(light);
3676
+ break;
3677
+ case "point":
3678
+ lightSources.pointLights?.push(light);
3679
+ break;
3680
+ default:
3681
+ }
3682
+ }
3683
+ return getUniforms({ lightSources });
3684
+ }
3685
+ return {};
3792
3686
  }
3687
+ var lights = {
3688
+ name: "lights",
3689
+ vs: lightingShader,
3690
+ fs: lightingShader,
3691
+ getUniforms,
3692
+ defines: {
3693
+ MAX_LIGHTS: 3
3694
+ }
3695
+ };
3793
3696
 
3794
- // ../shadertools/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts
3697
+ // ../shadertools/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts
3795
3698
  var vs = glsl`\
3699
+ uniform mat4 u_MVPMatrix;
3700
+ uniform mat4 u_ModelMatrix;
3701
+ uniform mat4 u_NormalMatrix;
3702
+
3796
3703
  out vec3 pbr_vPosition;
3797
3704
  out vec2 pbr_vUV;
3798
3705
 
@@ -3806,17 +3713,17 @@ out vec3 pbr_vNormal;
3806
3713
 
3807
3714
  void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
3808
3715
  {
3809
- vec4 pos = pbrProjection.modelMatrix * position;
3716
+ vec4 pos = u_ModelMatrix * position;
3810
3717
  pbr_vPosition = vec3(pos.xyz) / pos.w;
3811
3718
 
3812
3719
  #ifdef HAS_NORMALS
3813
3720
  #ifdef HAS_TANGENTS
3814
- vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
3815
- vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
3721
+ vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
3722
+ vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
3816
3723
  vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
3817
3724
  pbr_vTBN = mat3(tangentW, bitangentW, normalW);
3818
3725
  #else // HAS_TANGENTS != 1
3819
- pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
3726
+ pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
3820
3727
  #endif
3821
3728
  #endif
3822
3729
 
@@ -3828,69 +3735,55 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
3828
3735
  }
3829
3736
  `;
3830
3737
 
3831
- // ../shadertools/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts
3738
+ // ../shadertools/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts
3832
3739
  var fs = glsl`\
3833
3740
  precision highp float;
3834
3741
 
3835
- uniform pbrMaterialUniforms {
3836
- // Material is unlit
3837
- bool unlit;
3838
-
3839
- // Base color map
3840
- bool baseColorMapEnabled;
3841
- vec4 baseColorFactor;
3842
-
3843
- bool normalMapEnabled;
3844
- float normalScale; // #ifdef HAS_NORMALMAP
3845
-
3846
- bool emissiveMapEnabled;
3847
- vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP
3848
-
3849
- vec2 metallicRoughnessValues;
3850
- bool metallicRoughnessMapEnabled;
3851
-
3852
- bool occlusionMapEnabled;
3853
- float occlusionStrength; // #ifdef HAS_OCCLUSIONMAP
3854
-
3855
- bool alphaCutoffEnabled;
3856
- float alphaCutoff; // #ifdef ALPHA_CUTOFF
3857
-
3858
- // IBL
3859
- bool IBLenabled;
3860
- vec2 scaleIBLAmbient; // #ifdef USE_IBL
3861
-
3862
- // debugging flags used for shader output of intermediate PBR variables
3863
- // #ifdef PBR_DEBUG
3864
- vec4 scaleDiffBaseMR;
3865
- vec4 scaleFGDSpec;
3866
- // #endif
3867
- } pbrMaterial;
3868
-
3869
- // Samplers
3742
+ uniform bool pbr_uUnlit;
3743
+
3744
+ #ifdef USE_IBL
3745
+ uniform samplerCube u_DiffuseEnvSampler;
3746
+ uniform samplerCube u_SpecularEnvSampler;
3747
+ uniform sampler2D u_brdfLUT;
3748
+ uniform vec2 u_ScaleIBLAmbient;
3749
+ #endif
3750
+
3870
3751
  #ifdef HAS_BASECOLORMAP
3871
- uniform sampler2D pbr_baseColorSampler;
3752
+ uniform sampler2D u_BaseColorSampler;
3872
3753
  #endif
3873
3754
  #ifdef HAS_NORMALMAP
3874
- uniform sampler2D pbr_normalSampler;
3755
+ uniform sampler2D u_NormalSampler;
3756
+ uniform float u_NormalScale;
3875
3757
  #endif
3876
3758
  #ifdef HAS_EMISSIVEMAP
3877
- uniform sampler2D pbr_emissiveSampler;
3759
+ uniform sampler2D u_EmissiveSampler;
3760
+ uniform vec3 u_EmissiveFactor;
3878
3761
  #endif
3879
3762
  #ifdef HAS_METALROUGHNESSMAP
3880
- uniform sampler2D pbr_metallicRoughnessSampler;
3763
+ uniform sampler2D u_MetallicRoughnessSampler;
3881
3764
  #endif
3882
3765
  #ifdef HAS_OCCLUSIONMAP
3883
- uniform sampler2D pbr_occlusionSampler;
3766
+ uniform sampler2D u_OcclusionSampler;
3767
+ uniform float u_OcclusionStrength;
3884
3768
  #endif
3885
- #ifdef USE_IBL
3886
- uniform samplerCube pbr_diffuseEnvSampler;
3887
- uniform samplerCube pbr_specularEnvSampler;
3888
- uniform sampler2D pbr_brdfLUT;
3769
+
3770
+ #ifdef ALPHA_CUTOFF
3771
+ uniform float u_AlphaCutoff;
3889
3772
  #endif
3890
3773
 
3891
- // Inputs from vertex shader
3774
+ uniform vec2 u_MetallicRoughnessValues;
3775
+ uniform vec4 u_BaseColorFactor;
3776
+
3777
+ uniform vec3 u_Camera;
3778
+
3779
+ // debugging flags used for shader output of intermediate PBR variables
3780
+ #ifdef PBR_DEBUG
3781
+ uniform vec4 u_ScaleDiffBaseMR;
3782
+ uniform vec4 u_ScaleFGDSpec;
3783
+ #endif
3892
3784
 
3893
3785
  in vec3 pbr_vPosition;
3786
+
3894
3787
  in vec2 pbr_vUV;
3895
3788
 
3896
3789
  #ifdef HAS_NORMALS
@@ -3904,7 +3797,8 @@ in vec3 pbr_vNormal;
3904
3797
  // Encapsulate the various inputs used by the various functions in the shading equation
3905
3798
  // We store values in this struct to simplify the integration of alternative implementations
3906
3799
  // of the shading terms, outlined in the Readme.MD Appendix.
3907
- struct PBRInfo {
3800
+ struct PBRInfo
3801
+ {
3908
3802
  float NdotL; // cos angle between normal and light direction
3909
3803
  float NdotV; // cos angle between normal and view direction
3910
3804
  float NdotH; // cos angle between normal and half vector
@@ -3929,7 +3823,7 @@ vec4 SRGBtoLINEAR(vec4 srgbIn)
3929
3823
  #ifdef MANUAL_SRGB
3930
3824
  #ifdef SRGB_FAST_APPROXIMATION
3931
3825
  vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
3932
- #else // SRGB_FAST_APPROXIMATION
3826
+ #else //SRGB_FAST_APPROXIMATION
3933
3827
  vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
3934
3828
  vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
3935
3829
  #endif //SRGB_FAST_APPROXIMATION
@@ -3965,8 +3859,8 @@ vec3 getNormal()
3965
3859
  #endif
3966
3860
 
3967
3861
  #ifdef HAS_NORMALMAP
3968
- vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
3969
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
3862
+ vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
3863
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
3970
3864
  #else
3971
3865
  // The tbn matrix is linearly interpolated, so we need to re-normalize
3972
3866
  vec3 n = normalize(tbn[2].xyz);
@@ -3979,27 +3873,27 @@ vec3 getNormal()
3979
3873
  // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
3980
3874
  // See our README.md on Environment Maps [3] for additional discussion.
3981
3875
  #ifdef USE_IBL
3982
- vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
3876
+ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
3983
3877
  {
3984
3878
  float mipCount = 9.0; // resolution of 512x512
3985
- float lod = (pbrInfo.perceptualRoughness * mipCount);
3879
+ float lod = (pbrInputs.perceptualRoughness * mipCount);
3986
3880
  // retrieve a scale and bias to F0. See [1], Figure 3
3987
- vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
3988
- vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
3989
- vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
3881
+ vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
3882
+ vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
3883
+ vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
3990
3884
 
3991
3885
  #ifdef USE_TEX_LOD
3992
- vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
3886
+ vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
3993
3887
  #else
3994
- vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
3888
+ vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
3995
3889
  #endif
3996
3890
 
3997
- vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
3998
- vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
3891
+ vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;
3892
+ vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);
3999
3893
 
4000
3894
  // For presentation, this allows us to disable IBL terms
4001
- diffuse *= pbrMaterial.scaleIBLAmbient.x;
4002
- specular *= pbrMaterial.scaleIBLAmbient.y;
3895
+ diffuse *= u_ScaleIBLAmbient.x;
3896
+ specular *= u_ScaleIBLAmbient.y;
4003
3897
 
4004
3898
  return diffuse + specular;
4005
3899
  }
@@ -4008,29 +3902,29 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
4008
3902
  // Basic Lambertian diffuse
4009
3903
  // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
4010
3904
  // See also [1], Equation 1
4011
- vec3 diffuse(PBRInfo pbrInfo)
3905
+ vec3 diffuse(PBRInfo pbrInputs)
4012
3906
  {
4013
- return pbrInfo.diffuseColor / M_PI;
3907
+ return pbrInputs.diffuseColor / M_PI;
4014
3908
  }
4015
3909
 
4016
3910
  // The following equation models the Fresnel reflectance term of the spec equation (aka F())
4017
3911
  // Implementation of fresnel from [4], Equation 15
4018
- vec3 specularReflection(PBRInfo pbrInfo)
3912
+ vec3 specularReflection(PBRInfo pbrInputs)
4019
3913
  {
4020
- return pbrInfo.reflectance0 +
4021
- (pbrInfo.reflectance90 - pbrInfo.reflectance0) *
4022
- pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
3914
+ return pbrInputs.reflectance0 +
3915
+ (pbrInputs.reflectance90 - pbrInputs.reflectance0) *
3916
+ pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
4023
3917
  }
4024
3918
 
4025
3919
  // This calculates the specular geometric attenuation (aka G()),
4026
3920
  // where rougher material will reflect less light back to the viewer.
4027
3921
  // This implementation is based on [1] Equation 4, and we adopt their modifications to
4028
3922
  // alphaRoughness as input as originally proposed in [2].
4029
- float geometricOcclusion(PBRInfo pbrInfo)
3923
+ float geometricOcclusion(PBRInfo pbrInputs)
4030
3924
  {
4031
- float NdotL = pbrInfo.NdotL;
4032
- float NdotV = pbrInfo.NdotV;
4033
- float r = pbrInfo.alphaRoughness;
3925
+ float NdotL = pbrInputs.NdotL;
3926
+ float NdotV = pbrInputs.NdotV;
3927
+ float r = pbrInputs.alphaRoughness;
4034
3928
 
4035
3929
  float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
4036
3930
  float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
@@ -4043,80 +3937,80 @@ float geometricOcclusion(PBRInfo pbrInfo)
4043
3937
  // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
4044
3938
  // Follows the distribution function recommended in the SIGGRAPH 2013 course notes
4045
3939
  // from EPIC Games [1], Equation 3.
4046
- float microfacetDistribution(PBRInfo pbrInfo)
3940
+ float microfacetDistribution(PBRInfo pbrInputs)
4047
3941
  {
4048
- float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
4049
- float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
3942
+ float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
3943
+ float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
4050
3944
  return roughnessSq / (M_PI * f * f);
4051
3945
  }
4052
3946
 
4053
- void PBRInfo_setAmbientLight(inout PBRInfo pbrInfo) {
4054
- pbrInfo.NdotL = 1.0;
4055
- pbrInfo.NdotH = 0.0;
4056
- pbrInfo.LdotH = 0.0;
4057
- pbrInfo.VdotH = 1.0;
3947
+ void PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {
3948
+ pbrInputs.NdotL = 1.0;
3949
+ pbrInputs.NdotH = 0.0;
3950
+ pbrInputs.LdotH = 0.0;
3951
+ pbrInputs.VdotH = 1.0;
4058
3952
  }
4059
3953
 
4060
- void PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {
4061
- vec3 n = pbrInfo.n;
4062
- vec3 v = pbrInfo.v;
3954
+ void PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {
3955
+ vec3 n = pbrInputs.n;
3956
+ vec3 v = pbrInputs.v;
4063
3957
  vec3 l = normalize(lightDirection); // Vector from surface point to light
4064
3958
  vec3 h = normalize(l+v); // Half vector between both l and v
4065
3959
 
4066
- pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);
4067
- pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);
4068
- pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);
4069
- pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);
3960
+ pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);
3961
+ pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);
3962
+ pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);
3963
+ pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);
4070
3964
  }
4071
3965
 
4072
- void PBRInfo_setPointLight(inout PBRInfo pbrInfo, PointLight pointLight) {
3966
+ void PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {
4073
3967
  vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
4074
- PBRInfo_setDirectionalLight(pbrInfo, light_direction);
3968
+ PBRInfo_setDirectionalLight(pbrInputs, light_direction);
4075
3969
  }
4076
3970
 
4077
- vec3 calculateFinalColor(PBRInfo pbrInfo, vec3 lightColor) {
3971
+ vec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {
4078
3972
  // Calculate the shading terms for the microfacet specular shading model
4079
- vec3 F = specularReflection(pbrInfo);
4080
- float G = geometricOcclusion(pbrInfo);
4081
- float D = microfacetDistribution(pbrInfo);
3973
+ vec3 F = specularReflection(pbrInputs);
3974
+ float G = geometricOcclusion(pbrInputs);
3975
+ float D = microfacetDistribution(pbrInputs);
4082
3976
 
4083
3977
  // Calculation of analytical lighting contribution
4084
- vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInfo);
4085
- vec3 specContrib = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);
3978
+ vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
3979
+ vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);
4086
3980
  // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
4087
- return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
3981
+ return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);
4088
3982
  }
4089
3983
 
4090
3984
  vec4 pbr_filterColor(vec4 colorUnused)
4091
3985
  {
4092
3986
  // The albedo may be defined from a base texture or a flat color
4093
3987
  #ifdef HAS_BASECOLORMAP
4094
- vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
3988
+ vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
4095
3989
  #else
4096
- vec4 baseColor = pbrMaterial.baseColorFactor;
3990
+ vec4 baseColor = u_BaseColorFactor;
4097
3991
  #endif
4098
3992
 
4099
3993
  #ifdef ALPHA_CUTOFF
4100
- if (baseColor.a < pbrMaterial.alphaCutoff) {
3994
+ if (baseColor.a < u_AlphaCutoff) {
4101
3995
  discard;
4102
3996
  }
4103
3997
  #endif
4104
3998
 
4105
3999
  vec3 color = vec3(0, 0, 0);
4106
4000
 
4107
- if(pbrMaterial.unlit){
4001
+ if(pbr_uUnlit){
4108
4002
  color.rgb = baseColor.rgb;
4109
4003
  }
4110
4004
  else{
4111
4005
  // Metallic and Roughness material properties are packed together
4112
4006
  // In glTF, these factors can be specified by fixed scalar values
4113
4007
  // or from a metallic-roughness map
4114
- float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
4115
- float metallic = pbrMaterial.metallicRoughnessValues.x;
4008
+ float perceptualRoughness = u_MetallicRoughnessValues.y;
4009
+ float metallic = u_MetallicRoughnessValues.x;
4116
4010
  #ifdef HAS_METALROUGHNESSMAP
4117
4011
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
4118
4012
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
4119
- vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
4013
+ vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
4120
4014
  perceptualRoughness = mrSample.g * perceptualRoughness;
4121
4015
  metallic = mrSample.b * metallic;
4122
4016
  #endif
@@ -4143,12 +4037,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
4143
4037
  vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
4144
4038
 
4145
4039
  vec3 n = getNormal(); // normal at surface point
4146
- vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
4040
+ vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
4147
4041
 
4148
4042
  float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
4149
4043
  vec3 reflection = -normalize(reflect(v, n));
4150
4044
 
4151
- PBRInfo pbrInfo = PBRInfo(
4045
+ PBRInfo pbrInputs = PBRInfo(
4152
4046
  0.0, // NdotL
4153
4047
  NdotV,
4154
4048
  0.0, // NdotH
@@ -4165,50 +4059,43 @@ vec4 pbr_filterColor(vec4 colorUnused)
4165
4059
  v
4166
4060
  );
4167
4061
 
4168
-
4169
4062
  #ifdef USE_LIGHTS
4170
4063
  // Apply ambient light
4171
- PBRInfo_setAmbientLight(pbrInfo);
4172
- color += calculateFinalColor(pbrInfo, lighting.ambientColor);
4064
+ PBRInfo_setAmbientLight(pbrInputs);
4065
+ color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
4173
4066
 
4174
4067
  // Apply directional light
4175
- for(int i = 0; i < lighting.directionalLightCount; i++) {
4176
- if (i < lighting.directionalLightCount) {
4177
- PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
4178
- color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
4068
+ for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
4069
+ if (i < lighting_uDirectionalLightCount) {
4070
+ PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
4071
+ color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
4179
4072
  }
4180
4073
  }
4181
4074
 
4182
4075
  // Apply point light
4183
- for(int i = 0; i < lighting.pointLightCount; i++) {
4184
- if (i < lighting.pointLightCount) {
4185
- PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
4186
- float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
4187
- color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
4076
+ for(int i = 0; i < lighting_uPointLightCount; i++) {
4077
+ if (i < lighting_uPointLightCount) {
4078
+ PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
4079
+ float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
4080
+ color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
4188
4081
  }
4189
4082
  }
4190
4083
  #endif
4191
4084
 
4192
4085
  // Calculate lighting contribution from image based lighting source (IBL)
4193
4086
  #ifdef USE_IBL
4194
- if (pbrMaterial.IBLenabled) {
4195
- color += getIBLContribution(pbrInfo, n, reflection);
4196
- }
4087
+ color += getIBLContribution(pbrInputs, n, reflection);
4197
4088
  #endif
4198
4089
 
4199
- // Apply optional PBR terms for additional (optional) shading
4090
+ // Apply optional PBR terms for additional (optional) shading
4200
4091
  #ifdef HAS_OCCLUSIONMAP
4201
- if (pbrMaterial.occlusionMapEnabled) {
4202
- float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
4203
- color = mix(color, color * ao, pbrMaterial.occlusionStrength);
4204
- }
4092
+ float ao = texture(u_OcclusionSampler, pbr_vUV).r;
4093
+ color = mix(color, color * ao, u_OcclusionStrength);
4205
4094
  #endif
4206
4095
 
4207
4096
  #ifdef HAS_EMISSIVEMAP
4208
- if (pbrMaterial.emissiveMapEnabled) {
4209
- vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
4210
- color += emissive;
4211
- }
4097
+ vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
4098
+ color += emissive;
4212
4099
  #endif
4213
4100
 
4214
4101
  // This section uses mix to override final color for reference app visualization
@@ -4216,15 +4103,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
4216
4103
  #ifdef PBR_DEBUG
4217
4104
  // TODO: Figure out how to debug multiple lights
4218
4105
 
4219
- // color = mix(color, F, pbr_scaleFGDSpec.x);
4220
- // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
4221
- // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
4222
- // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
4106
+ // color = mix(color, F, u_ScaleFGDSpec.x);
4107
+ // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
4108
+ // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
4109
+ // color = mix(color, specContrib, u_ScaleFGDSpec.w);
4223
4110
 
4224
- // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
4225
- color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
4226
- color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
4227
- color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
4111
+ // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
4112
+ color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);
4113
+ color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);
4114
+ color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);
4228
4115
  #endif
4229
4116
 
4230
4117
  }
@@ -4233,77 +4120,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
4233
4120
  }
4234
4121
  `;
4235
4122
 
4236
- // ../shadertools/src/modules/lighting/pbr-material/pbr-projection.ts
4237
- var uniformBlock = glsl`\
4238
- uniform pbrProjectionUniforms {
4239
- mat4 modelViewProjectionMatrix;
4240
- mat4 modelMatrix;
4241
- mat4 normalMatrix;
4242
- vec3 camera;
4243
- } pbrProjection;
4244
- `;
4245
- var pbrProjection = {
4246
- name: "pbrProjection",
4247
- vs: uniformBlock,
4248
- fs: uniformBlock,
4249
- // TODO why is this needed?
4250
- getUniforms: (props) => props,
4251
- uniformTypes: {
4252
- modelViewProjectionMatrix: "mat4x4<f32>",
4253
- modelMatrix: "mat4x4<f32>",
4254
- normalMatrix: "mat4x4<f32>",
4255
- camera: "vec3<i32>"
4256
- }
4257
- };
4258
-
4259
- // ../shadertools/src/modules/lighting/pbr-material/pbr-material.ts
4260
- var pbrMaterial = {
4261
- name: "pbrMaterial",
4123
+ // ../shadertools/src/modules-webgl1/lighting/pbr/pbr.ts
4124
+ var pbr = {
4125
+ name: "pbr",
4262
4126
  vs,
4263
4127
  fs,
4264
4128
  defines: {
4265
4129
  LIGHTING_FRAGMENT: 1
4266
- // TODO defining these as 0 breaks shader
4267
- // HAS_NORMALMAP: 0
4268
- // HAS_EMISSIVEMAP: 0,
4269
- // HAS_OCCLUSIONMAP: 0,
4270
- // HAS_BASECOLORMAP: 0,
4271
- // HAS_METALROUGHNESSMAP: 0,
4272
- // ALPHA_CUTOFF: 0
4273
- // USE_IBL: 0
4274
- // PBR_DEBUG: 0
4275
4130
  },
4276
- getUniforms: (props) => props,
4277
- uniformTypes: {
4278
- // Material is unlit
4279
- unlit: "i32",
4280
- // Base color map
4281
- baseColorMapEnabled: "i32",
4282
- baseColorFactor: "vec4<f32>",
4283
- normalMapEnabled: "i32",
4284
- normalScale: "f32",
4285
- // #ifdef HAS_NORMALMAP
4286
- emissiveMapEnabled: "i32",
4287
- emissiveFactor: "vec3<f32>",
4288
- // #ifdef HAS_EMISSIVEMAP
4289
- metallicRoughnessValues: "vec2<f32>",
4290
- metallicRoughnessMapEnabled: "i32",
4291
- occlusionMapEnabled: "i32",
4292
- occlusionStrength: "f32",
4293
- // #ifdef HAS_OCCLUSIONMAP
4294
- alphaCutoffEnabled: "i32",
4295
- alphaCutoff: "f32",
4296
- // #ifdef ALPHA_CUTOFF
4297
- // IBL
4298
- IBLenabled: "i32",
4299
- scaleIBLAmbient: "vec2<f32>",
4300
- // #ifdef USE_IBL
4301
- // debugging flags used for shader output of intermediate PBR variables
4302
- // #ifdef PBR_DEBUG
4303
- scaleDiffBaseMR: "vec4<f32>",
4304
- scaleFGDSpec: "vec4<f32>"
4305
- },
4306
- dependencies: [lighting, pbrProjection]
4131
+ dependencies: [lights]
4307
4132
  };
4308
4133
 
4309
4134
  // src/gltf/create-gltf-model.ts
@@ -4351,7 +4176,7 @@ uniform pbrProjectionUniforms {
4351
4176
  #endif
4352
4177
 
4353
4178
  pbr_setPositionNormalTangentUV(positions, _NORMAL, _TANGENT, _TEXCOORD_0);
4354
- gl_Position = pbrProjection.modelViewProjectionMatrix * positions;
4179
+ gl_Position = u_MVPMatrix * positions;
4355
4180
  }
4356
4181
  `;
4357
4182
  var fs2 = `
@@ -4370,7 +4195,7 @@ uniform pbrProjectionUniforms {
4370
4195
  function createGLTFModel(device, options) {
4371
4196
  const { id, geometry, material, vertexCount, materialOptions, modelOptions } = options;
4372
4197
  const parsedMaterial = parsePBRMaterial(device, material, geometry.attributes, materialOptions);
4373
- import_core5.log.info(4, "createGLTFModel defines: ", parsedMaterial.defines)();
4198
+ import_core4.log.info(4, "createGLTFModel defines: ", parsedMaterial.defines)();
4374
4199
  const managedResources = [];
4375
4200
  const parameters = {
4376
4201
  depthWriteEnabled: true,
@@ -4383,22 +4208,16 @@ uniform pbrProjectionUniforms {
4383
4208
  geometry,
4384
4209
  topology: geometry.topology,
4385
4210
  vertexCount,
4386
- modules: [pbrMaterial],
4211
+ modules: [pbr],
4387
4212
  vs: addVersionToShader(device, vs2),
4388
4213
  fs: addVersionToShader(device, fs2),
4389
- // TODO can this be removed? Does deck need it?
4390
4214
  ...modelOptions,
4215
+ bindings: { ...parsedMaterial.bindings, ...modelOptions.bindings },
4391
4216
  defines: { ...parsedMaterial.defines, ...modelOptions.defines },
4392
- parameters: { ...parameters, ...parsedMaterial.parameters, ...modelOptions.parameters }
4217
+ parameters: { ...parameters, ...parsedMaterial.parameters, ...modelOptions.parameters },
4218
+ uniforms: { ...parsedMaterial.uniforms, ...modelOptions.uniforms }
4393
4219
  };
4394
4220
  const model = new import_engine.Model(device, modelProps);
4395
- const { camera, ...pbrMaterialProps } = {
4396
- ...parsedMaterial.uniforms,
4397
- ...modelOptions.uniforms,
4398
- ...parsedMaterial.bindings,
4399
- ...modelOptions.bindings
4400
- };
4401
- model.shaderInputs.setProps({ pbrMaterial: pbrMaterialProps, pbrProjection: { camera } });
4402
4221
  return new import_engine.ModelNode({ managedResources, model });
4403
4222
  }
4404
4223
  function addVersionToShader(device, source) {