@zephyr3d/scene 0.9.23 → 0.9.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.
@@ -347,6 +347,28 @@ import { getDevice } from '../app/api.js';
347
347
  -0.4072
348
348
  ]
349
349
  ];
350
+ /** @internal */ function getProgressivePoissonDiscSample(scope, index) {
351
+ const pb = scope.$builder;
352
+ if (pb.getDevice().type === 'webgl') {
353
+ const funcName = 'lib_getProgressivePoissonDiscSampleWebGL1';
354
+ pb.func(funcName, [
355
+ pb.int('index')
356
+ ], function() {
357
+ for(let i = 0; i < PCF_POISSON_DISC.length; i++){
358
+ const sample = PCF_POISSON_DISC[i * 19 % PCF_POISSON_DISC.length];
359
+ this.$if(pb.equal(this.index, i), function() {
360
+ this.$return(pb.vec2(sample[0], sample[1]));
361
+ });
362
+ }
363
+ this.$return(pb.vec2(PCF_POISSON_DISC[0][0], PCF_POISSON_DISC[0][1]));
364
+ });
365
+ return pb.getGlobalScope()[funcName](index);
366
+ }
367
+ if (!pb.getGlobalScope().PCSSpdSamples) {
368
+ pb.getGlobalScope().PCSSpdSamples = PCF_POISSON_DISC.map((sample)=>pb.vec2(sample[0], sample[1]));
369
+ }
370
+ return pb.getGlobalScope().PCSSpdSamples.at(pb.mod(pb.mul(index, 19), PCF_POISSON_DISC.length));
371
+ }
350
372
  function getPCSSRotationMatrix(scope, sampleCoord, temporalJitter) {
351
373
  const funcName = `lib_getPCSSRotationMatrix_${temporalJitter ? 1 : 0}`;
352
374
  const pb = scope.$builder;
@@ -599,6 +621,7 @@ function samplePointShadowPCFPCSS(scope, shadowMapFormat, dir, compareDepth, tex
599
621
  function findBlockerPCSS(scope, shadowMapFormat, deviceEncoded, tapCount, texCoord, bounds, searchRadius, transitionWidth, matrix, cascade) {
600
622
  const funcName = `lib_findBlockerPCSS_${shadowMapFormat}_${cascade ? 1 : 0}${REVERSE_Z && deviceEncoded ? '_rev' : ''}`;
601
623
  const pb = scope.$builder;
624
+ const webgl1 = pb.getDevice().type === 'webgl';
602
625
  pb.func(funcName, [
603
626
  pb.vec4('texCoord'),
604
627
  pb.vec4('bounds'),
@@ -616,8 +639,13 @@ function findBlockerPCSS(scope, shadowMapFormat, deviceEncoded, tapCount, texCoo
616
639
  this.$l.sampleCoord = pb.vec2();
617
640
  this.$l.sampleDepth = pb.float();
618
641
  this.$l.blockerWeight = pb.float();
619
- this.$for(pb.float('i'), 0, this.tapCount, function() {
620
- this.duv = pb.mul(pb.mul(this.matrix, this.PCSSpdSamples.at(pb.mod(pb.mul(pb.int(this.i), 19), PCF_POISSON_DISC.length))), this.searchRadius);
642
+ this.$for(pb.float('i'), 0, webgl1 ? PCF_POISSON_DISC.length : this.tapCount, function() {
643
+ if (webgl1) {
644
+ this.$if(pb.greaterThanEqual(this.i, this.tapCount), function() {
645
+ this.$break();
646
+ });
647
+ }
648
+ this.duv = pb.mul(pb.mul(this.matrix, getProgressivePoissonDiscSample(this, pb.int(this.i))), this.searchRadius);
621
649
  this.sampleCoord = pb.add(this.texCoord.xy, this.duv);
622
650
  this.sampleDepth = sampleShadowDepthPCSS(this, shadowMapFormat, deviceEncoded, this.sampleCoord, this.bounds, this.cascade);
623
651
  // Blocker when the sample is closer to the light than the receiver;
@@ -635,6 +663,7 @@ function findBlockerPCSS(scope, shadowMapFormat, deviceEncoded, tapCount, texCoo
635
663
  function findPointBlockerPCSS(scope, shadowMapFormat, tapCount, dir, compareDepth, searchRadius, transitionWidth, matrix, tangent, bitangent) {
636
664
  const funcName = `lib_findPointBlockerPCSS_${shadowMapFormat}`;
637
665
  const pb = scope.$builder;
666
+ const webgl1 = pb.getDevice().type === 'webgl';
638
667
  pb.func(funcName, [
639
668
  pb.vec3('dir'),
640
669
  pb.float('compareDepth'),
@@ -651,8 +680,13 @@ function findPointBlockerPCSS(scope, shadowMapFormat, tapCount, dir, compareDept
651
680
  this.$l.sampleDir = pb.vec3();
652
681
  this.$l.sampleDepth = pb.float();
653
682
  this.$l.blockerWeight = pb.float();
654
- this.$for(pb.float('i'), 0, this.tapCount, function() {
655
- this.duv = pb.mul(pb.mul(this.matrix, this.PCSSpdSamples.at(pb.mod(pb.mul(pb.int(this.i), 19), PCF_POISSON_DISC.length))), this.searchRadius);
683
+ this.$for(pb.float('i'), 0, webgl1 ? PCF_POISSON_DISC.length : this.tapCount, function() {
684
+ if (webgl1) {
685
+ this.$if(pb.greaterThanEqual(this.i, this.tapCount), function() {
686
+ this.$break();
687
+ });
688
+ }
689
+ this.duv = pb.mul(pb.mul(this.matrix, getProgressivePoissonDiscSample(this, pb.int(this.i))), this.searchRadius);
656
690
  this.sampleDir = pb.normalize(pb.add(this.dir, pb.add(pb.mul(this.tangent, this.duv.x), pb.mul(this.bitangent, this.duv.y))));
657
691
  this.sampleDepth = samplePointShadowDepthPCSS(this, shadowMapFormat, this.sampleDir);
658
692
  this.blockerWeight = pb.sub(1, pb.smoothStep(pb.neg(this.transitionWidth), this.transitionWidth, pb.sub(this.sampleDepth, this.compareDepth)));
@@ -855,6 +889,7 @@ function chebyshevUpperBound(scope, distance, occluder, deviceEncoded) {
855
889
  /** @internal */ function filterShadowPCSS(scope, lightType, shadowMapFormat, texCoord, receiverPlaneDepthBias, cascade, temporalJitter = true, numCascades = 1) {
856
890
  const funcNameFilterShadowPCSS = `lib_filterShadowPCSS_${lightType}_${shadowMapFormat}_${receiverPlaneDepthBias ? 1 : 0}_${cascade ? 1 : 0}_${temporalJitter ? 1 : 0}_${numCascades}`;
857
891
  const pb = scope.$builder;
892
+ const webgl1 = pb.getDevice().type === 'webgl';
858
893
  pb.func(funcNameFilterShadowPCSS, [
859
894
  pb.vec4('texCoord'),
860
895
  ...receiverPlaneDepthBias ? [
@@ -869,9 +904,6 @@ function chebyshevUpperBound(scope, distance, occluder, deviceEncoded) {
869
904
  this.$l.PCSSlightRadius = ShaderHelper.getShadowImplParams(this).x;
870
905
  this.$l.PCSSmaxFilterRadius = ShaderHelper.getShadowImplParams(this).w;
871
906
  this.$l.PCSSsearchRadius = this.$choice(pb.greaterThan(this.PCSSlightRadius, 0), pb.max(this.PCSSlightRadius, this.PCSSmaxFilterRadius), 0);
872
- if (!pb.getGlobalScope().PCSSpdSamples) {
873
- pb.getGlobalScope().PCSSpdSamples = PCF_POISSON_DISC.map((s)=>pb.vec2(s[0], s[1]));
874
- }
875
907
  if (lightType === LIGHT_TYPE_POINT) {
876
908
  this.$l.lightDepth = this.texCoord.w;
877
909
  this.$l.sampleDir = pb.normalize(this.texCoord.xyz);
@@ -891,8 +923,13 @@ function chebyshevUpperBound(scope, distance, occluder, deviceEncoded) {
891
923
  this.$l.shadow = pb.float(0);
892
924
  this.$l.duv = pb.vec2();
893
925
  this.$l.samplePointDir = pb.vec3();
894
- this.$for(pb.float('i'), 0, this.PCSSfilterSampleCount, function() {
895
- this.duv = pb.mul(pb.mul(this.matrix, this.PCSSpdSamples.at(pb.mod(pb.mul(pb.int(this.i), 19), PCF_POISSON_DISC.length))), this.filterRadius);
926
+ this.$for(pb.float('i'), 0, webgl1 ? PCF_POISSON_DISC.length : this.PCSSfilterSampleCount, function() {
927
+ if (webgl1) {
928
+ this.$if(pb.greaterThanEqual(this.i, this.PCSSfilterSampleCount), function() {
929
+ this.$break();
930
+ });
931
+ }
932
+ this.duv = pb.mul(pb.mul(this.matrix, getProgressivePoissonDiscSample(this, pb.int(this.i))), this.filterRadius);
896
933
  this.samplePointDir = pb.normalize(pb.add(this.sampleDir, pb.add(pb.mul(this.tangent, this.duv.x), pb.mul(this.bitangent, this.duv.y))));
897
934
  this.shadow = pb.add(this.shadow, samplePointShadowPCFPCSS(this, shadowMapFormat, this.samplePointDir, this.lightDepth, this.shadowMapTexelSize, this.tangent, this.bitangent));
898
935
  });
@@ -932,8 +969,13 @@ function chebyshevUpperBound(scope, distance, occluder, deviceEncoded) {
932
969
  this.$l.duv = pb.vec2();
933
970
  this.$l.sampleCoord = pb.vec2();
934
971
  this.$l.compareDepth = pb.float();
935
- this.$for(pb.float('i'), 0, this.PCSSfilterSampleCount, function() {
936
- this.duv = pb.mul(pb.mul(this.matrix, this.PCSSpdSamples.at(pb.mod(pb.mul(pb.int(this.i), 19), PCF_POISSON_DISC.length))), this.filterRadius);
972
+ this.$for(pb.float('i'), 0, webgl1 ? PCF_POISSON_DISC.length : this.PCSSfilterSampleCount, function() {
973
+ if (webgl1) {
974
+ this.$if(pb.greaterThanEqual(this.i, this.PCSSfilterSampleCount), function() {
975
+ this.$break();
976
+ });
977
+ }
978
+ this.duv = pb.mul(pb.mul(this.matrix, getProgressivePoissonDiscSample(this, pb.int(this.i))), this.filterRadius);
937
979
  this.sampleCoord = pb.add(this.texCoord.xy, this.duv);
938
980
  this.compareDepth = receiverPlaneDepthBias ? pb.add(this.lightDepth, pb.dot(this.duv, this.receiverPlaneDepthBias.xy)) : this.lightDepth;
939
981
  this.shadow = pb.add(this.shadow, sampleShadowPCFPCSS(this, shadowMapFormat, deviceEncoded, this.sampleCoord, this.sampleBounds, this.compareDepth, this.shadowMapTexelSize, this.receiverPlaneDepthBias, this.cascade));
@@ -948,5 +990,5 @@ function chebyshevUpperBound(scope, distance, occluder, deviceEncoded) {
948
990
  ] : []);
949
991
  }
950
992
 
951
- export { applyShadowDepthBias, computeReceiverPlaneDepthBias, computeShadowMapDepth, filterShadowESM, filterShadowPCF, filterShadowPCSS, filterShadowVSM, isDeviceDepthShadow, ndcToShadowCoord, ndcToShadowCoord3, shadowCoordDepthInRange };
993
+ export { applyShadowDepthBias, computeReceiverPlaneDepthBias, computeShadowMapDepth, filterShadowESM, filterShadowPCF, filterShadowPCSS, filterShadowVSM, getProgressivePoissonDiscSample, isDeviceDepthShadow, ndcToShadowCoord, ndcToShadowCoord3, shadowCoordDepthInRange };
952
994
  //# sourceMappingURL=shadow.js.map