@xviewer.js/core 1.0.0-alpha.60 → 1.0.0-alpha.61

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/module.js CHANGED
@@ -3071,7 +3071,7 @@ class Plane extends Mesh {
3071
3071
  }
3072
3072
 
3073
3073
  class Reflector extends Component {
3074
- constructor({ textureWidth = 512, textureHeight = 512, clipBias = 0, multisample = 4, layer = 0, normal = new Vector3(0, 0, 1), mipmap = false } = {}){
3074
+ constructor({ textureWidth = 512, textureHeight = 512, clipBias = 0, multisample = 4, layer = 0, normal = new Vector3(0, 1, 0), mipmap = false } = {}){
3075
3075
  super();
3076
3076
  const reflectorPlane = new Plane$1();
3077
3077
  const reflectorNormal = new Vector3();
@@ -3345,10 +3345,11 @@ function getShaderMaterial(uniforms, vertexShader, fragmentShader, onInit) {
3345
3345
  return material;
3346
3346
  }
3347
3347
 
3348
- const vert_Reflector = `
3348
+ const vert_Reflector = /*glsl*/ `
3349
3349
  uniform mat4 textureMatrix;
3350
3350
  varying vec4 vUv4;
3351
3351
  varying vec2 vUv;
3352
+ varying vec3 vPositionWS;
3352
3353
 
3353
3354
  #ifdef USE_UV1
3354
3355
  varying vec2 vUv1;
@@ -3378,9 +3379,6 @@ void main() {
3378
3379
  transformed = instanceMatrix * transformed;
3379
3380
  #endif
3380
3381
 
3381
- vec4 positionWS = modelMatrix * transformed;
3382
- vec4 mvPosition = viewMatrix * positionWS;
3383
-
3384
3382
  vUv = uv;
3385
3383
 
3386
3384
  #ifdef USE_UV1
@@ -3395,8 +3393,11 @@ void main() {
3395
3393
  vUv3 = uv2;
3396
3394
  #endif
3397
3395
 
3398
- vUv4 = textureMatrix * transformed;
3396
+ vec4 positionWS = modelMatrix * transformed;
3397
+ vec4 mvPosition = viewMatrix * positionWS;
3399
3398
 
3399
+ vUv4 = textureMatrix * positionWS;
3400
+ vPositionWS = positionWS.xyz;
3400
3401
  vViewPosition = -mvPosition.xyz;
3401
3402
  vNormal = normalize(transformedNormal);
3402
3403
 
@@ -3405,7 +3406,7 @@ void main() {
3405
3406
  #include <logdepthbuf_vertex>
3406
3407
  }
3407
3408
  `;
3408
- const frag_Reflector = `
3409
+ const frag_Reflector = /*glsl*/ `
3409
3410
  uniform vec3 color;
3410
3411
  uniform float alpha;
3411
3412
  uniform float roughness;
@@ -3417,7 +3418,9 @@ uniform sampler2D aoMap;
3417
3418
  uniform float aoMapIntensity;
3418
3419
  uniform sampler2D lightMap;
3419
3420
  uniform float lightMapIntensity;
3420
- uniform sampler2D tReflect;
3421
+ uniform sampler2D reflectMap;
3422
+ uniform float reflectIntensity;
3423
+ varying vec3 vPositionWS;
3421
3424
 
3422
3425
  varying vec2 vUv;
3423
3426
 
@@ -3444,10 +3447,14 @@ varying vec3 vNormal;
3444
3447
  void main() {
3445
3448
  #include <logdepthbuf_fragment>
3446
3449
 
3450
+ vec3 coord = vUv4.xyz / vUv4.w;
3451
+ vec2 reflectUv = coord.xy;
3452
+
3453
+ #ifdef USE_NORMALMAP
3447
3454
  vec4 texelNormal = texture2D(normalMap, UV_NORMAL);
3448
3455
  vec3 normal = normalize(vec3(texelNormal.r * 2.0 - 1.0, texelNormal.b, texelNormal.g * 2.0 - 1.0));
3449
- vec3 coord = vUv4.xyz / vUv4.w;
3450
- vec2 reflectUv = coord.xy + coord.z * normal.xz * 0.05;
3456
+ reflectUv += coord.z * normal.xz * 0.05;
3457
+ #endif
3451
3458
 
3452
3459
  vec3 geometryNormal = normalize(vNormal);
3453
3460
  vec3 geometryViewDir = normalize(vViewPosition);
@@ -3468,7 +3475,11 @@ void main() {
3468
3475
  vec3 specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
3469
3476
  float specularF90 = 1.0;
3470
3477
 
3471
- float roughnessFactor = texture2D(roughnessMap, UV_ROUGHNESS).g * roughness;
3478
+ float roughnessFactor = roughness;
3479
+
3480
+ #ifdef USE_ROUGHNESSMAP
3481
+ roughnessFactor *= texture2D(roughnessMap, UV_ROUGHNESS).g * roughness;
3482
+ #endif
3472
3483
 
3473
3484
  computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
3474
3485
 
@@ -3476,10 +3487,13 @@ void main() {
3476
3487
  vec3 diffuse = diffuseColor.rgb * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
3477
3488
 
3478
3489
  vec3 irradiance = vec3(0.);
3490
+
3491
+ #ifdef USE_LIGHTMAP
3479
3492
  irradiance += texture2D(lightMap, UV_LIGHTMAP).rgb * lightMapIntensity;
3493
+ #endif
3480
3494
 
3481
3495
  float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
3482
- vec4 reflectColor = textureLod(tReflect, reflectUv, lod);
3496
+ vec4 reflectColor = textureLod(reflectMap, reflectUv, lod) * reflectIntensity;
3483
3497
 
3484
3498
  vec3 f_specular = vec3(0.);
3485
3499
  vec3 f_diffuse = vec3(0.);
@@ -3487,9 +3501,13 @@ void main() {
3487
3501
  f_specular += reflectColor.rgb * (1.0 - roughnessFactor * roughnessFactor) + multiScattering * irradiance;
3488
3502
  f_diffuse += diffuse * irradiance;
3489
3503
 
3504
+ #ifdef USE_AOMAP
3490
3505
  float ambientOcclusion = mix(1., texture2D(aoMap, UV_AO).r, aoMapIntensity);
3506
+
3491
3507
  float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
3492
3508
  f_specular *= computeSpecularOcclusion(dotNV, ambientOcclusion, roughnessFactor);
3509
+ f_diffuse *= ambientOcclusion;
3510
+ #endif
3493
3511
 
3494
3512
  gl_FragColor = vec4(f_specular + f_diffuse, diffuseColor.a);
3495
3513
 
@@ -3528,6 +3546,12 @@ class ReflectorMaterial extends ShaderMaterial {
3528
3546
  shader.defines[key] = "vUv" + channel;
3529
3547
  });
3530
3548
  }
3549
+ get color() {
3550
+ return this.uniforms.color.value;
3551
+ }
3552
+ set color(v) {
3553
+ this.uniforms.color.value = v;
3554
+ }
3531
3555
  get alpha() {
3532
3556
  return this.uniforms.alpha.value;
3533
3557
  }
@@ -3576,6 +3600,18 @@ class ReflectorMaterial extends ShaderMaterial {
3576
3600
  set lightMap(v) {
3577
3601
  this.uniforms.lightMap.value = v;
3578
3602
  }
3603
+ get lightMapIntensity() {
3604
+ return this.uniforms.lightMapIntensity.value;
3605
+ }
3606
+ set lightMapIntensity(v) {
3607
+ this.uniforms.lightMapIntensity.value = v;
3608
+ }
3609
+ get reflectIntensity() {
3610
+ return this.uniforms.reflectIntensity.value;
3611
+ }
3612
+ set reflectIntensity(v) {
3613
+ this.uniforms.reflectIntensity.value = v;
3614
+ }
3579
3615
  constructor(...args){
3580
3616
  super(...args);
3581
3617
  this.vertexShader = vert_Reflector;
@@ -3588,7 +3624,7 @@ class ReflectorMaterial extends ShaderMaterial {
3588
3624
  };
3589
3625
  this.uniforms = {
3590
3626
  color: {
3591
- value: new Color(0xffffff)
3627
+ value: new Color()
3592
3628
  },
3593
3629
  alpha: {
3594
3630
  value: 1
@@ -3596,9 +3632,12 @@ class ReflectorMaterial extends ShaderMaterial {
3596
3632
  map: {
3597
3633
  value: null
3598
3634
  },
3599
- tReflect: {
3635
+ reflectMap: {
3600
3636
  value: null
3601
3637
  },
3638
+ reflectIntensity: {
3639
+ value: 1
3640
+ },
3602
3641
  textureMatrix: {
3603
3642
  value: new Matrix4()
3604
3643
  },
@@ -3629,6 +3668,9 @@ class ReflectorMaterial extends ShaderMaterial {
3629
3668
  };
3630
3669
  }
3631
3670
  }
3671
+ __decorate([
3672
+ property
3673
+ ], ReflectorMaterial.prototype, "color", null);
3632
3674
  __decorate([
3633
3675
  property({
3634
3676
  min: 0,