@luma.gl/shadertools 9.0.23 → 9.0.24

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.
Files changed (29) hide show
  1. package/dist/dist.dev.js +100 -88
  2. package/dist/dist.min.js +127 -130
  3. package/dist/index.cjs +92 -77
  4. package/dist/index.cjs.map +3 -3
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +0 -1
  8. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
  9. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +49 -52
  10. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +10 -29
  11. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  12. package/dist/modules/lighting/pbr-material/pbr-material.js +14 -11
  13. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
  14. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
  15. package/dist/modules/lighting/pbr-material/pbr-projection.js +25 -0
  16. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
  17. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +8 -14
  18. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  19. package/package.json +2 -2
  20. package/src/index.ts +7 -1
  21. package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +56 -60
  22. package/src/modules/lighting/pbr-material/pbr-material.ts +25 -52
  23. package/src/modules/lighting/pbr-material/pbr-projection.ts +41 -0
  24. package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +8 -16
  25. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +0 -1
  26. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +0 -2
  27. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +0 -1
  28. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +0 -48
  29. package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +0 -69
package/dist/dist.dev.js CHANGED
@@ -5403,7 +5403,6 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
5403
5403
 
5404
5404
  return lightColor;
5405
5405
  }
5406
-
5407
5406
  `;
5408
5407
 
5409
5408
  // src/modules/lighting/gouraud-material/gouraud-material.ts
@@ -5470,38 +5469,30 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
5470
5469
 
5471
5470
  // src/modules/lighting/pbr-material/pbr-vertex-glsl.ts
5472
5471
  var vs2 = glsl`\
5473
- uniform projection {
5474
- mat4 u_MVPMatrix;
5475
- mat4 u_ModelMatrix;
5476
- mat4 u_NormalMatrix;
5477
- // Projection
5478
- vec3 u_Camera;
5479
- }
5480
-
5481
- varying vec3 pbr_vPosition;
5482
- varying vec2 pbr_vUV;
5472
+ out vec3 pbr_vPosition;
5473
+ out vec2 pbr_vUV;
5483
5474
 
5484
5475
  #ifdef HAS_NORMALS
5485
5476
  # ifdef HAS_TANGENTS
5486
- varying mat3 pbr_vTBN;
5477
+ out mat3 pbr_vTBN;
5487
5478
  # else
5488
- varying vec3 pbr_vNormal;
5479
+ out vec3 pbr_vNormal;
5489
5480
  # endif
5490
5481
  #endif
5491
5482
 
5492
5483
  void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
5493
5484
  {
5494
- vec4 pos = u_ModelMatrix * position;
5485
+ vec4 pos = pbrProjection.modelMatrix * position;
5495
5486
  pbr_vPosition = vec3(pos.xyz) / pos.w;
5496
5487
 
5497
5488
  #ifdef HAS_NORMALS
5498
5489
  #ifdef HAS_TANGENTS
5499
- vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
5500
- vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
5490
+ vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
5491
+ vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
5501
5492
  vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
5502
5493
  pbr_vTBN = mat3(tangentW, bitangentW, normalW);
5503
5494
  #else // HAS_TANGENTS != 1
5504
- pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
5495
+ pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
5505
5496
  #endif
5506
5497
  #endif
5507
5498
 
@@ -5517,12 +5508,7 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
5517
5508
  var fs3 = glsl`\
5518
5509
  precision highp float;
5519
5510
 
5520
- uniform Projection {
5521
- // Projection
5522
- uniform vec3 u_Camera;
5523
- };
5524
-
5525
- uniform pbrMaterial {
5511
+ uniform pbrMaterialUniforms {
5526
5512
  // Material is unlit
5527
5513
  bool unlit;
5528
5514
 
@@ -5554,40 +5540,40 @@ uniform pbrMaterial {
5554
5540
  vec4 scaleDiffBaseMR;
5555
5541
  vec4 scaleFGDSpec;
5556
5542
  // #endif
5557
- } u_pbrMaterial;
5543
+ } pbrMaterial;
5558
5544
 
5559
5545
  // Samplers
5560
5546
  #ifdef HAS_BASECOLORMAP
5561
- uniform sampler2D u_BaseColorSampler;
5547
+ uniform sampler2D pbr_baseColorSampler;
5562
5548
  #endif
5563
5549
  #ifdef HAS_NORMALMAP
5564
- uniform sampler2D u_NormalSampler;
5550
+ uniform sampler2D pbr_normalSampler;
5565
5551
  #endif
5566
5552
  #ifdef HAS_EMISSIVEMAP
5567
- uniform sampler2D u_EmissiveSampler;
5553
+ uniform sampler2D pbr_emissiveSampler;
5568
5554
  #endif
5569
5555
  #ifdef HAS_METALROUGHNESSMAP
5570
- uniform sampler2D u_MetallicRoughnessSampler;
5556
+ uniform sampler2D pbr_metallicRoughnessSampler;
5571
5557
  #endif
5572
5558
  #ifdef HAS_OCCLUSIONMAP
5573
- uniform sampler2D u_OcclusionSampler;
5559
+ uniform sampler2D pbr_occlusionSampler;
5574
5560
  #endif
5575
5561
  #ifdef USE_IBL
5576
- uniform samplerCube u_DiffuseEnvSampler;
5577
- uniform samplerCube u_SpecularEnvSampler;
5578
- uniform sampler2D u_brdfLUT;
5562
+ uniform samplerCube pbr_diffuseEnvSampler;
5563
+ uniform samplerCube pbr_specularEnvSampler;
5564
+ uniform sampler2D pbr_brdfLUT;
5579
5565
  #endif
5580
5566
 
5581
5567
  // Inputs from vertex shader
5582
5568
 
5583
- varying vec3 pbr_vPosition;
5584
- varying vec2 pbr_vUV;
5569
+ in vec3 pbr_vPosition;
5570
+ in vec2 pbr_vUV;
5585
5571
 
5586
5572
  #ifdef HAS_NORMALS
5587
5573
  #ifdef HAS_TANGENTS
5588
- varying mat3 pbr_vTBN;
5574
+ in mat3 pbr_vTBN;
5589
5575
  #else
5590
- varying vec3 pbr_vNormal;
5576
+ in vec3 pbr_vNormal;
5591
5577
  #endif
5592
5578
  #endif
5593
5579
 
@@ -5655,8 +5641,8 @@ vec3 getNormal()
5655
5641
  #endif
5656
5642
 
5657
5643
  #ifdef HAS_NORMALMAP
5658
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
5659
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));
5644
+ vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
5645
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
5660
5646
  #else
5661
5647
  // The tbn matrix is linearly interpolated, so we need to re-normalize
5662
5648
  vec3 n = normalize(tbn[2].xyz);
@@ -5674,22 +5660,22 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
5674
5660
  float mipCount = 9.0; // resolution of 512x512
5675
5661
  float lod = (pbrInfo.perceptualRoughness * mipCount);
5676
5662
  // retrieve a scale and bias to F0. See [1], Figure 3
5677
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
5663
+ vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
5678
5664
  vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
5679
- vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
5665
+ vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
5680
5666
 
5681
5667
  #ifdef USE_TEX_LOD
5682
- vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
5668
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
5683
5669
  #else
5684
- vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
5670
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
5685
5671
  #endif
5686
5672
 
5687
5673
  vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
5688
5674
  vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
5689
5675
 
5690
5676
  // For presentation, this allows us to disable IBL terms
5691
- diffuse *= u_pbrMaterial.scaleIBLAmbient.x;
5692
- specular *= u_pbrMaterial.scaleIBLAmbient.y;
5677
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
5678
+ specular *= pbrMaterial.scaleIBLAmbient.y;
5693
5679
 
5694
5680
  return diffuse + specular;
5695
5681
  }
@@ -5781,32 +5767,32 @@ vec4 pbr_filterColor(vec4 colorUnused)
5781
5767
  {
5782
5768
  // The albedo may be defined from a base texture or a flat color
5783
5769
  #ifdef HAS_BASECOLORMAP
5784
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;
5770
+ vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
5785
5771
  #else
5786
- vec4 baseColor = u_pbrMaterial.baseColorFactor;
5772
+ vec4 baseColor = pbrMaterial.baseColorFactor;
5787
5773
  #endif
5788
5774
 
5789
5775
  #ifdef ALPHA_CUTOFF
5790
- if (baseColor.a < u_pbrMaterial.alphaCutoff) {
5776
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
5791
5777
  discard;
5792
5778
  }
5793
5779
  #endif
5794
5780
 
5795
5781
  vec3 color = vec3(0, 0, 0);
5796
5782
 
5797
- if(u_pbrMaterial.unlit){
5783
+ if(pbrMaterial.unlit){
5798
5784
  color.rgb = baseColor.rgb;
5799
5785
  }
5800
5786
  else{
5801
5787
  // Metallic and Roughness material properties are packed together
5802
5788
  // In glTF, these factors can be specified by fixed scalar values
5803
5789
  // or from a metallic-roughness map
5804
- float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;
5805
- float metallic = u_pbrMaterial.metallicRoughnessValues.x;
5790
+ float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
5791
+ float metallic = pbrMaterial.metallicRoughnessValues.x;
5806
5792
  #ifdef HAS_METALROUGHNESSMAP
5807
5793
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
5808
5794
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
5809
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
5795
+ vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
5810
5796
  perceptualRoughness = mrSample.g * perceptualRoughness;
5811
5797
  metallic = mrSample.b * metallic;
5812
5798
  #endif
@@ -5833,7 +5819,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
5833
5819
  vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
5834
5820
 
5835
5821
  vec3 n = getNormal(); // normal at surface point
5836
- vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
5822
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
5837
5823
 
5838
5824
  float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
5839
5825
  vec3 reflection = -normalize(reflect(v, n));
@@ -5855,47 +5841,48 @@ vec4 pbr_filterColor(vec4 colorUnused)
5855
5841
  v
5856
5842
  );
5857
5843
 
5844
+
5858
5845
  #ifdef USE_LIGHTS
5859
5846
  // Apply ambient light
5860
5847
  PBRInfo_setAmbientLight(pbrInfo);
5861
- color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);
5848
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
5862
5849
 
5863
5850
  // Apply directional light
5864
- for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
5865
- if (i < lighting_uDirectionalLightCount) {
5866
- PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);
5867
- color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);
5851
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
5852
+ if (i < lighting.directionalLightCount) {
5853
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
5854
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
5868
5855
  }
5869
5856
  }
5870
5857
 
5871
5858
  // Apply point light
5872
- for(int i = 0; i < lighting_uPointLightCount; i++) {
5873
- if (i < lighting_uPointLightCount) {
5874
- PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);
5875
- float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
5876
- color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);
5859
+ for(int i = 0; i < lighting.pointLightCount; i++) {
5860
+ if (i < lighting.pointLightCount) {
5861
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
5862
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
5863
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
5877
5864
  }
5878
5865
  }
5879
5866
  #endif
5880
5867
 
5881
5868
  // Calculate lighting contribution from image based lighting source (IBL)
5882
5869
  #ifdef USE_IBL
5883
- if (u_pbrMateral.IBLEnabled) {
5870
+ if (pbrMaterial.IBLenabled) {
5884
5871
  color += getIBLContribution(pbrInfo, n, reflection);
5885
5872
  }
5886
5873
  #endif
5887
5874
 
5888
- // Apply optional PBR terms for additional (optional) shading
5875
+ // Apply optional PBR terms for additional (optional) shading
5889
5876
  #ifdef HAS_OCCLUSIONMAP
5890
- if (u_pbrMaterial.occlusionMapEnabled) {
5891
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
5892
- color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);
5877
+ if (pbrMaterial.occlusionMapEnabled) {
5878
+ float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
5879
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
5893
5880
  }
5894
5881
  #endif
5895
5882
 
5896
5883
  #ifdef HAS_EMISSIVEMAP
5897
- if (u_pbrMaterial.emmissiveMapEnabled) {
5898
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;
5884
+ if (pbrMaterial.emissiveMapEnabled) {
5885
+ vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
5899
5886
  color += emissive;
5900
5887
  }
5901
5888
  #endif
@@ -5905,15 +5892,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
5905
5892
  #ifdef PBR_DEBUG
5906
5893
  // TODO: Figure out how to debug multiple lights
5907
5894
 
5908
- // color = mix(color, F, u_ScaleFGDSpec.x);
5909
- // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
5910
- // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
5911
- // color = mix(color, specContrib, u_ScaleFGDSpec.w);
5895
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
5896
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
5897
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
5898
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
5912
5899
 
5913
- // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
5914
- color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);
5915
- color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);
5916
- color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);
5900
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
5901
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
5902
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
5903
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
5917
5904
  #endif
5918
5905
 
5919
5906
  }
@@ -5922,22 +5909,47 @@ vec4 pbr_filterColor(vec4 colorUnused)
5922
5909
  }
5923
5910
  `;
5924
5911
 
5912
+ // src/modules/lighting/pbr-material/pbr-projection.ts
5913
+ var uniformBlock = glsl`\
5914
+ uniform pbrProjectionUniforms {
5915
+ mat4 modelViewProjectionMatrix;
5916
+ mat4 modelMatrix;
5917
+ mat4 normalMatrix;
5918
+ vec3 camera;
5919
+ } pbrProjection;
5920
+ `;
5921
+ var pbrProjection = {
5922
+ name: "pbrProjection",
5923
+ vs: uniformBlock,
5924
+ fs: uniformBlock,
5925
+ // TODO why is this needed?
5926
+ getUniforms: (props) => props,
5927
+ uniformTypes: {
5928
+ modelViewProjectionMatrix: "mat4x4<f32>",
5929
+ modelMatrix: "mat4x4<f32>",
5930
+ normalMatrix: "mat4x4<f32>",
5931
+ camera: "vec3<i32>"
5932
+ }
5933
+ };
5934
+
5925
5935
  // src/modules/lighting/pbr-material/pbr-material.ts
5926
5936
  var pbrMaterial = {
5927
- name: "pbr",
5937
+ name: "pbrMaterial",
5928
5938
  vs: vs2,
5929
5939
  fs: fs3,
5930
5940
  defines: {
5931
- LIGHTING_FRAGMENT: 1,
5932
- HAS_NORMALMAP: 0,
5933
- HAS_EMISSIVEMAP: 0,
5934
- HAS_OCCLUSIONMAP: 0,
5935
- HAS_BASECOLORMAP: 0,
5936
- HAS_METALROUGHNESSMAP: 0,
5937
- ALPHA_CUTOFF: 0,
5938
- USE_IBL: 0,
5939
- PBR_DEBUG: 0
5941
+ LIGHTING_FRAGMENT: 1
5942
+ // TODO defining these as 0 breaks shader
5943
+ // HAS_NORMALMAP: 0
5944
+ // HAS_EMISSIVEMAP: 0,
5945
+ // HAS_OCCLUSIONMAP: 0,
5946
+ // HAS_BASECOLORMAP: 0,
5947
+ // HAS_METALROUGHNESSMAP: 0,
5948
+ // ALPHA_CUTOFF: 0
5949
+ // USE_IBL: 0
5950
+ // PBR_DEBUG: 0
5940
5951
  },
5952
+ getUniforms: (props) => props,
5941
5953
  uniformTypes: {
5942
5954
  // Material is unlit
5943
5955
  unlit: "i32",
@@ -5967,7 +5979,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
5967
5979
  scaleDiffBaseMR: "vec4<f32>",
5968
5980
  scaleFGDSpec: "vec4<f32>"
5969
5981
  },
5970
- dependencies: [lighting]
5982
+ dependencies: [lighting, pbrProjection]
5971
5983
  };
5972
5984
 
5973
5985
  // src/modules/postprocessing/image-adjust-filters/brightnesscontrast.ts