@rings-webgpu/core 1.0.9 → 1.0.11

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.
@@ -5804,202 +5804,219 @@ let IESProfiles_frag = `
5804
5804
  }
5805
5805
  `;
5806
5806
 
5807
- let ShadowMapping_frag = `
5808
- @group(1) @binding(auto) var shadowMapSampler: sampler;
5807
+ let ShadowMapping_frag = (
5808
+ /*wgsl*/
5809
+ `
5810
+ @group(1) @binding(auto) var shadowMapSampler: sampler_comparison;
5809
5811
  @group(1) @binding(auto) var shadowMap: texture_depth_2d_array;
5810
- @group(1) @binding(auto) var pointShadowMapSampler: sampler;
5812
+ @group(1) @binding(auto) var pointShadowMapSampler: sampler_comparison;
5811
5813
  @group(1) @binding(auto) var pointShadowMap: texture_depth_cube_array;
5812
5814
 
5813
5815
  var<private> directShadowVisibility: array<f32, 8>;
5814
5816
  var<private> pointShadows: array<f32, 8>;
5815
- var<private> shadowWeight: f32 = 1.0;
5817
+ var<private> shadowWeight: f32 = 1.0 ;
5816
5818
 
5817
5819
  fn useShadow(){
5818
- directShadowVisibility = array<f32, 8>(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0);
5820
+ directShadowVisibility = array<f32, 8>( 1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0) ;
5819
5821
  pointShadows = array<f32, 8>(1.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0) ;
5820
5822
  directShadowMaping(globalUniform.shadowBias);
5821
5823
  pointShadowMapCompare(globalUniform.pointShadowBias);
5822
5824
  }
5823
5825
 
5824
5826
  fn calcBasicBias(shadowWorldSize:f32, shadowDepthTexSize:f32, near:f32, far:f32) -> f32{
5825
- var bias = shadowWorldSize / shadowDepthTexSize;
5826
- bias = bias / (far - near);
5827
- return bias * 2.0;
5827
+ var bias = shadowWorldSize / shadowDepthTexSize;
5828
+ bias = bias / (far - near);
5829
+ return bias * 2.0;
5828
5830
  }
5829
5831
 
5830
- const dirCount:i32 = 8;
5831
- const pointCount:i32 = 8;
5832
- const csmCount:i32 = ${CSM.Cascades};
5832
+ const dirCount:i32 = 8 ;
5833
+ const pointCount:i32 = 8 ;
5834
+ const csmCount:i32 = ${CSM.Cascades} ;
5833
5835
  var<private> csmLevel:i32 = -1;
5836
+ fn directShadowMaping(shadowBias: f32) {
5834
5837
 
5835
- fn directShadowMaping(shadowBias: f32) {
5836
5838
  let enableCSM:bool = globalUniform.enableCSM > 0.5;
5837
- for(var i:i32 = 0; i < dirCount; i = i+1){
5838
- if(i >= globalUniform.nDirShadowStart && i < globalUniform.nDirShadowEnd){
5839
- let ldx = globalUniform.shadowLights[u32(i) / 4u][u32(i) % 4u];
5840
- let light = lightBuffer[u32(ldx)] ;
5841
- var shadowIndex = i32(light.castShadow);
5842
- var visibility = 1.0;
5843
- var shadowMatrix:mat4x4<f32>;
5844
- #if USE_CSM
5845
- if(enableCSM && shadowIndex == 0){
5846
- var totalWeight = 0.0;
5847
- visibility = 0.0;
5848
- var validCount = 0;
5849
- for(var csm:i32 = 0; csm < csmCount; csm ++){
5850
- var csmShadowBias = globalUniform.csmShadowBias[csm] * shadowBias;
5851
- shadowMatrix = globalUniform.csmMatrix[csm];
5852
- let csmShadowResult = directShadowMapingIndex(light, shadowMatrix, csm, csmShadowBias);
5853
- if(csmShadowResult.y < 0.5){
5854
- validCount ++;
5855
- var uv = 2.0 * csmShadowResult.zw - vec2<f32>(1.0);
5856
- uv = saturate(vec2<f32>(1.0) - abs(uv));
5857
- uv /= clamp(globalUniform.csmMargin, 0.01, 0.5);
5858
- var weight:f32 = min(uv.x, 1.0);
5859
- weight = min(weight, uv.y);
5860
-
5861
- if(validCount == 1 && csm == csmCount - 1){
5862
- visibility = 1.0 - weight + csmShadowResult.x * weight;
5863
- totalWeight = 1.0;
5864
- }else{
5865
- weight *= 1.0 - totalWeight;
5866
- visibility += csmShadowResult.x * weight;
5867
- totalWeight += weight;
5868
- };
5869
-
5870
- if(validCount >= 2 || totalWeight >= 0.99){
5871
- csmLevel = csm;
5872
- break;
5873
- };
5874
- }
5875
- }
5876
-
5877
- totalWeight += 0.0001;
5878
- if(validCount == 0){
5879
- visibility = 1.0;
5880
- }else{
5881
- visibility = visibility / totalWeight ;
5882
- };
5883
- } else {
5884
- shadowMatrix = globalUniform.shadowMatrix[shadowIndex];
5885
- if(enableCSM) {
5886
- shadowIndex += csmCount - 1;
5887
- }
5888
- visibility = directShadowMapingIndex(light, shadowMatrix, shadowIndex, shadowBias).x;
5839
+ for (var i: i32 = 0; i < dirCount ; i = i + 1) {
5840
+ if( i >= globalUniform.nDirShadowStart && i < globalUniform.nDirShadowEnd ){
5841
+ let ldx = globalUniform.shadowLights[u32(i) / 4u][u32(i) % 4u];
5842
+ let light = lightBuffer[u32(ldx)] ;
5843
+ var shadowIndex = i32(light.castShadow);
5844
+ var visibility = 1.0;
5845
+ var shadowMatrix:mat4x4<f32>;
5846
+ #if USE_CSM
5847
+ if(enableCSM && shadowIndex == 0){
5848
+ var totalWeight = 0.0;
5849
+ visibility = 0.0;
5850
+ var validCount = 0;
5851
+ for(var csm:i32 = 0; csm < csmCount; csm ++){
5852
+ var csmShadowBias = globalUniform.csmShadowBias[csm] * shadowBias;
5853
+ shadowMatrix = globalUniform.csmMatrix[csm];
5854
+ let csmShadowResult = directShadowMapingIndex(light, shadowMatrix, csm, csmShadowBias);
5855
+ if(csmShadowResult.y < 0.5){
5856
+ validCount ++;
5857
+
5858
+ var uv = 2.0 * csmShadowResult.zw - vec2<f32>(1.0);
5859
+ uv = saturate(vec2<f32>(1.0) - abs(uv));
5860
+ uv /= clamp(globalUniform.csmMargin, 0.01, 0.5);
5861
+ var weight:f32 = min(uv.x, 1.0);
5862
+ weight = min(weight, uv.y);
5863
+
5864
+ if(validCount == 1 && csm == csmCount - 1){
5865
+ visibility = 1.0 - weight + csmShadowResult.x * weight;
5866
+ totalWeight = 1.0;
5867
+ }else{
5868
+ weight *= 1.0 - totalWeight;
5869
+ visibility += csmShadowResult.x * weight;
5870
+ totalWeight += weight;
5889
5871
  }
5890
- #else
5891
- shadowMatrix = globalUniform.shadowMatrix[shadowIndex];
5892
- visibility = directShadowMapingIndex(light, shadowMatrix, shadowIndex, shadowBias).x;
5893
- #endif
5894
- directShadowVisibility[i] = visibility;
5895
- }
5872
+ // if(weight < 1.0){
5873
+ // visibility += 0.1;
5874
+ // }
5875
+ if(validCount >= 2 || totalWeight >= 0.99){
5876
+ csmLevel = csm;
5877
+ break;
5878
+ }
5879
+ }
5880
+ }
5881
+ totalWeight += 0.0001;
5882
+ if(validCount == 0){
5883
+ visibility = 1.0;
5884
+ }else{
5885
+ visibility = visibility / totalWeight ;
5886
+ }
5887
+ }else{
5888
+ shadowMatrix = globalUniform.shadowMatrix[shadowIndex];
5889
+ if(enableCSM) {
5890
+ shadowIndex += csmCount - 1;
5891
+ }
5892
+ visibility = directShadowMapingIndex(light, shadowMatrix, shadowIndex, shadowBias).x;
5893
+ }
5894
+ #else
5895
+ shadowMatrix = globalUniform.shadowMatrix[shadowIndex];
5896
+ visibility = directShadowMapingIndex(light, shadowMatrix, shadowIndex, shadowBias).x;
5897
+ #endif
5898
+ directShadowVisibility[i] = visibility;
5899
+ }
5896
5900
  }
5901
+
5897
5902
  }
5898
5903
 
5899
- fn directShadowMapingIndex(light:LightData, matrix:mat4x4<f32>, depthTexIndex:i32, shadowBias:f32) -> vec4<f32> {
5900
- var visibility = 1.0;
5901
- var isOutSideArea:f32 = 1.0;
5902
- var varying_shadowUV:vec2<f32> = vec2<f32>(0.0);
5903
- #if USE_SHADOWMAPING
5904
- var shadowPosTmp = matrix * vec4<f32>(ORI_VertexVarying.vWorldPos.xyz, 1.0);
5905
- var shadowPos = shadowPosTmp.xyz / shadowPosTmp.w;
5906
- varying_shadowUV = shadowPos.xy * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5, 0.5);
5907
- if (varying_shadowUV.x <= 1.0
5908
- && varying_shadowUV.x >= 0.0
5909
- && varying_shadowUV.y <= 1.0
5910
- && varying_shadowUV.y >= 0.0
5911
- && shadowPosTmp.z <= 1.0
5912
- && shadowPosTmp.z >= 0.0){
5913
- visibility = 0.0;
5914
- isOutSideArea = 0.0;
5915
- var uvOnePixel = 1.0 / vec2<f32>(globalUniform.shadowMapSize) ;
5916
- var totalWeight = 0.0;
5917
- var bias = -0.005 * max(dot(fragData.N, -light.direction) , 0.0 );
5918
- bias = clamp(bias, 0, 0.01) + -shadowBias;
5919
- let bound = 1;
5920
- for (var y = -bound; y <= bound; y++) {
5921
- for(var x = -bound; x <= bound; x++) {
5922
- var offset = vec2<f32>(f32(x), f32(y)) ;
5923
- var offsetUV = offset * uvOnePixel ;
5924
- var weight = min(length(offset),1.0) ;
5925
- var depth = textureSampleLevel(shadowMap, shadowMapSampler, varying_shadowUV + offsetUV , depthTexIndex, 0);
5926
- if ((shadowPos.z - bias ) < depth) {
5927
- visibility += weight ;
5928
- totalWeight += weight;
5929
- }else{
5930
- totalWeight += 1.0;
5931
- };
5932
- }
5904
+ fn directShadowMapingIndex(light:LightData, matrix:mat4x4<f32>, depthTexIndex:i32, shadowBias:f32) -> vec4<f32>
5905
+ {
5906
+ var visibility = 1.0;
5907
+ var isOutSideArea:f32 = 1.0;
5908
+ var varying_shadowUV:vec2<f32> = vec2<f32>(0.0);
5909
+ #if USE_SHADOWMAPING
5910
+ var shadowPosTmp = matrix * vec4<f32>(ORI_VertexVarying.vWorldPos.xyz, 1.0);
5911
+ var shadowPos = shadowPosTmp.xyz / shadowPosTmp.w;
5912
+ varying_shadowUV = shadowPos.xy * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5, 0.5);
5913
+ if (varying_shadowUV.x <= 1.0
5914
+ && varying_shadowUV.x >= 0.0
5915
+ && varying_shadowUV.y <= 1.0
5916
+ && varying_shadowUV.y >= 0.0
5917
+ && shadowPosTmp.z <= 1.0
5918
+ && shadowPosTmp.z >= 0.0)
5919
+ {
5920
+ visibility = 0.0;
5921
+ isOutSideArea = 0.0;
5922
+ var uvOnePixel = 1.0 / vec2<f32>(globalUniform.shadowMapSize) ;
5923
+ var totalWeight = 0.0;
5924
+ // var NoL = (dot(normalize(ORI_VertexVarying.vWorldNormal), normalize(-light.direction)));
5925
+ // let v = max(NoL, 0.0) ;
5926
+ // var bias = max(0.05 * (dot(normalize(fragData.N), normalize(-light.direction)) ), -shadowBias);
5927
+ var bias = -0.005 * max(dot(fragData.N, -light.direction) , 0.0 );
5928
+ bias = clamp(bias, 0, 0.01) + -shadowBias;
5929
+
5930
+ // var bias = shadowBias / v;
5931
+ let bound = 1 ;
5932
+ for (var y = -bound; y <= bound; y++) {
5933
+ for (var x = -bound; x <= bound; x++) {
5934
+ var offset = vec2<f32>(f32(x), f32(y)) ;
5935
+ var offsetUV = offset * uvOnePixel ;
5936
+ var weight = min(length(offset),1.0) ;
5937
+ var depth = textureSampleCompareLevel(shadowMap, shadowMapSampler, varying_shadowUV + offsetUV , depthTexIndex, shadowPos.z - bias);
5938
+ if (depth < 0.5) {
5939
+ totalWeight += 1.0;
5940
+ }else{
5941
+ visibility += weight;
5942
+ totalWeight += weight;
5933
5943
  }
5934
- visibility /= totalWeight;
5935
5944
  }
5936
- #endif
5937
- return vec4<f32>(visibility, isOutSideArea, varying_shadowUV);
5938
- }
5939
-
5940
- fn pointShadowMapCompare(shadowBias: f32) {
5941
- let worldPos = ORI_VertexVarying.vWorldPos.xyz;
5942
- let offset = 0.1;
5943
- for(var i: i32 = 0; i < pointCount ; i = i + 1){
5944
- if( i >= globalUniform.nPointShadowStart && i < globalUniform.nPointShadowEnd ){
5945
- let ldx = globalUniform.shadowLights[u32(i) / 4u][u32(i) % 4u];
5946
- let light = lightBuffer[u32(ldx)];
5947
-
5948
- #if USE_SHADOWMAPING
5949
- let lightPos = light.position.xyz;
5950
- var shadow = 0.0;
5951
- let frgToLight = worldPos - lightPos.xyz;
5952
- var dir: vec3<f32> = normalize(frgToLight);
5953
- var len = length(frgToLight);
5954
- var bias = max(shadowBias * globalUniform.far * (1.0 - dot(ORI_ShadingInput.Normal, dir)), 0.005);
5955
-
5956
- #if USE_PCF_SHADOW
5957
- let samples = 4.0;
5958
- let sampleOffset = offset / (samples * 0.5);
5959
- for (var x: f32 = -offset; x < offset; x += sampleOffset) {
5960
- for (var y: f32 = -offset; y < offset; y += sampleOffset) {
5961
- for (var z: f32 = -offset; z < offset; z += sampleOffset) {
5962
- let offsetDir = normalize(dir.xyz + vec3<f32>(x, y, z));
5963
- var depth = textureSampleLevel(pointShadowMap, pointShadowMapSampler, offsetDir, light.castShadow, 0);
5964
- depth *= globalUniform.far;
5965
- if ((len - bias) > depth) {
5966
- shadow += 1.0 * dot(offsetDir, dir.xyz);
5967
- }
5968
- }
5969
- }
5970
- }
5971
- shadow = min(max(shadow / (samples * samples * samples), 0.0), 1.0);
5972
- #endif
5945
+ }
5946
+ visibility /= totalWeight;
5947
+ }
5948
+ #endif
5949
+ return vec4<f32>(visibility, isOutSideArea, varying_shadowUV);
5950
+ }
5951
+
5952
+ fn pointShadowMapCompare(shadowBias: f32){
5953
+ let worldPos = ORI_VertexVarying.vWorldPos.xyz;
5954
+ let offset = 0.1;
5973
5955
 
5974
- #if USE_SOFT_SHADOW
5975
- let vDis = length(globalUniform.CameraPos.xyz - worldPos.xyz);
5976
- let sampleRadies = globalUniform.shadowSoft;
5977
- let samples = 20;
5978
- for (var j:i32 = 0; j < samples; j += 1) {
5979
- let offsetDir = normalize(dir.xyz + sampleOffsetDir[j] * sampleRadies);
5980
- var depth = textureSampleLevel(pointShadowMap, pointShadowMapSampler, offsetDir, light.castShadow, 0);
5981
- depth *= globalUniform.far;
5982
- if ((len - bias) > depth) {
5983
- shadow += 1.0 * dot(offsetDir, dir.xyz);
5956
+ for (var i: i32 = 0; i < pointCount ; i = i + 1) {
5957
+ if( i >= globalUniform.nPointShadowStart && i < globalUniform.nPointShadowEnd ){
5958
+ let ldx = globalUniform.shadowLights[u32(i) / 4u][u32(i) % 4u];
5959
+ let light = lightBuffer[u32(ldx)] ;
5960
+
5961
+ #if USE_SHADOWMAPING
5962
+ let lightPos = light.position.xyz;
5963
+ var shadow = 0.0;
5964
+ let frgToLight = worldPos - lightPos.xyz;
5965
+ var dir: vec3<f32> = normalize(frgToLight);
5966
+ var len = length(frgToLight);
5967
+ var bias = max(shadowBias * globalUniform.far * (1.0 - dot(ORI_ShadingInput.Normal, dir)), 0.005);
5968
+
5969
+ #if USE_PCF_SHADOW
5970
+ let samples = 4.0;
5971
+ let sampleOffset = offset / (samples * 0.5);
5972
+ for (var x: f32 = -offset; x < offset; x += sampleOffset) {
5973
+ for (var y: f32 = -offset; y < offset; y += sampleOffset) {
5974
+ for (var z: f32 = -offset; z < offset; z += sampleOffset) {
5975
+ let compareZ = (len - bias) / globalUniform.far;
5976
+ var depth = textureSampleCompareLevel(pointShadowMap, pointShadowMapSampler, dir.xyz, light.castShadow, compareZ);
5977
+ if (depth < 0.5) {
5978
+ shadow = 1.0;
5984
5979
  }
5980
+ for (var j = 0; j < pointCount ; j+=1 ){
5981
+ if(i32(light.castShadow) == j){
5982
+ pointShadows[j] = 1.0 - shadow;
5983
+ }
5984
+ }
5985
+ }
5985
5986
  }
5986
- shadow = min(max(shadow / f32(samples), 0.0), 1.0);
5987
+ }
5988
+ shadow = min(max(shadow / (samples * samples * samples), 0.0), 1.0);
5987
5989
  #endif
5988
-
5989
- #if USE_HARD_SHADOW
5990
- var depth = textureSampleLevel(pointShadowMap, pointShadowMapSampler, dir.xyz, light.castShadow, 0);
5990
+
5991
+ #if USE_SOFT_SHADOW
5992
+ let vDis = length(globalUniform.CameraPos.xyz - worldPos.xyz);
5993
+ let sampleRadies = globalUniform.shadowSoft;
5994
+ let samples = 20;
5995
+ for (var j: i32 = 0; j < samples; j += 1) {
5996
+ let offsetDir = normalize(dir.xyz + sampleOffsetDir[j] * sampleRadies);
5997
+ var depth = textureSampleCompareLevel(pointShadowMap, pointShadowMapSampler, offsetDir, light.castShadow, 0);
5991
5998
  depth *= globalUniform.far;
5992
5999
  if ((len - bias) > depth) {
5993
- shadow = 1.0;
6000
+ shadow += 1.0 * dot(offsetDir, dir.xyz);
5994
6001
  }
5995
- #endif
5996
- for (var j=0; j < pointCount; j+=1) {
5997
- if(i32(light.castShadow) == j){
5998
- pointShadows[j] = 1.0 - shadow;
5999
- }
6000
- }
6001
- #endif
6002
- }
6002
+ }
6003
+ shadow = min(max(shadow / f32(samples), 0.0), 1.0);
6004
+ #endif
6005
+
6006
+ #if USE_HARD_SHADOW
6007
+ var depth = textureSampleCompareLevel(pointShadowMap, pointShadowMapSampler, dir.xyz, light.castShadow, 0);
6008
+ depth *= globalUniform.far;
6009
+ if ((len - bias) > depth) {
6010
+ shadow = 1.0;
6011
+ }
6012
+ #endif
6013
+ for (var j = 0; j < pointCount ; j+=1 ) {
6014
+ if(i32(light.castShadow) == j){
6015
+ pointShadows[j] = 1.0 - shadow ;
6016
+ }
6017
+ }
6018
+ #endif
6019
+ }
6003
6020
  }
6004
6021
  }
6005
6022
 
@@ -6012,7 +6029,8 @@ let ShadowMapping_frag = `
6012
6029
  vec3<f32>(0.0, 1.0, 1.0), vec3<f32>(0.0, -1.0, 1.0), vec3<f32>(0.0, -1.0, -1.0), vec3<f32>(0.0, 1.0, -1.0),
6013
6030
  );
6014
6031
  #endif
6015
- `;
6032
+ `
6033
+ );
6016
6034
 
6017
6035
  let Irradiance_frag = `
6018
6036
  #include "IrradianceVolumeData_frag"
@@ -7167,19 +7185,10 @@ let PBRLItShader = (
7167
7185
  @group(1) @binding(auto)
7168
7186
  var normalMap: texture_2d<f32>;
7169
7187
 
7170
- // #if USE_ARMC
7171
- // @group(1) @binding(auto)
7172
- // var maskMapSampler: sampler;
7173
- // @group(1) @binding(auto)
7174
- // var maskMap: texture_2d<f32>;
7175
- // #endif
7176
-
7177
- // #if USE_MR
7178
7188
  @group(1) @binding(auto)
7179
7189
  var maskMapSampler: sampler;
7180
7190
  @group(1) @binding(auto)
7181
7191
  var maskMap: texture_2d<f32>;
7182
- // #endif
7183
7192
 
7184
7193
  #if USE_AOTEX
7185
7194
  @group(1) @binding(auto)
@@ -7207,7 +7216,6 @@ let PBRLItShader = (
7207
7216
 
7208
7217
  #if USE_SRGB_ALBEDO
7209
7218
  ORI_ShadingInput.BaseColor = textureSample(baseMap, baseMapSampler, uv ) ;
7210
- // ORI_ShadingInput.BaseColor = sRGBToLinear(ORI_ShadingInput.BaseColor.rgb) ;
7211
7219
  ORI_ShadingInput.BaseColor = vec4<f32>( ORI_ShadingInput.BaseColor * materialUniform.baseColor.rgb, ORI_ShadingInput.BaseColor.w * materialUniform.baseColor.a) ;
7212
7220
  #else
7213
7221
  ORI_ShadingInput.BaseColor = textureSample(baseMap, baseMapSampler, uv ) ;
@@ -7312,7 +7320,6 @@ let PBRLItShader = (
7312
7320
 
7313
7321
  BxDFShading();
7314
7322
 
7315
- // ORI_FragmentOutput.color = vec4<f32>(vec3<f32>(normal.rgb),1.0) ;
7316
7323
  }
7317
7324
  `
7318
7325
  );
@@ -39951,7 +39958,7 @@ class WayPoint3D extends Object3D {
39951
39958
  this.marker = new Object3D();
39952
39959
  const markerRenderer = this.marker.addComponent(MeshRenderer);
39953
39960
  markerRenderer.geometry = new SphereGeometry(0.1, 32, 16);
39954
- markerRenderer.material = new LitMaterial();
39961
+ markerRenderer.material = new UnLitMaterial();
39955
39962
  markerRenderer.material.baseColor = this.positionValid ? new Color(0, 1, 0, 1) : new Color(1, 0, 0, 1);
39956
39963
  this.addChild(this.marker);
39957
39964
  this.marker.name = "WayPoint3DMarker";
@@ -40538,7 +40545,7 @@ class PostProcessingComponent extends ComponentBase {
40538
40545
  }
40539
40546
  }
40540
40547
 
40541
- const version = "1.0.9";
40548
+ const version = "1.0.11";
40542
40549
 
40543
40550
  class Engine3D {
40544
40551
  /**