@luma.gl/shadertools 9.0.26 → 9.0.28

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