@xviewer.js/core 1.0.0-alpha.25 → 1.0.0-alpha.26
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/main.js +86 -11
- package/dist/main.js.map +1 -1
- package/dist/module.js +86 -11
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/materials/ReflectorMaterial.d.ts +5 -1
package/dist/module.js
CHANGED
|
@@ -3180,7 +3180,19 @@ const vert_Reflector = `
|
|
|
3180
3180
|
uniform mat4 textureMatrix;
|
|
3181
3181
|
varying vec4 vUv4;
|
|
3182
3182
|
varying vec2 vUv;
|
|
3183
|
-
|
|
3183
|
+
|
|
3184
|
+
#ifdef USE_UV1
|
|
3185
|
+
varying vec2 vUv1;
|
|
3186
|
+
#endif
|
|
3187
|
+
|
|
3188
|
+
#ifdef USE_UV2
|
|
3189
|
+
varying vec2 vUv2;
|
|
3190
|
+
#endif
|
|
3191
|
+
|
|
3192
|
+
#ifdef USE_UV3
|
|
3193
|
+
varying vec2 vUv3;
|
|
3194
|
+
#endif
|
|
3195
|
+
|
|
3184
3196
|
varying vec3 vViewPosition;
|
|
3185
3197
|
|
|
3186
3198
|
#include <common>
|
|
@@ -3195,7 +3207,19 @@ void main() {
|
|
|
3195
3207
|
vec4 mvPosition = viewMatrix * positionWS;
|
|
3196
3208
|
|
|
3197
3209
|
vUv = uv;
|
|
3210
|
+
|
|
3211
|
+
#ifdef USE_UV1
|
|
3198
3212
|
vUv1 = uv1;
|
|
3213
|
+
#endif
|
|
3214
|
+
|
|
3215
|
+
#ifdef USE_UV2
|
|
3216
|
+
vUv2 = uv2;
|
|
3217
|
+
#endif
|
|
3218
|
+
|
|
3219
|
+
#ifdef USE_UV3
|
|
3220
|
+
vUv3 = uv2;
|
|
3221
|
+
#endif
|
|
3222
|
+
|
|
3199
3223
|
vUv4 = textureMatrix * vec4(position, 1.0);
|
|
3200
3224
|
|
|
3201
3225
|
vViewPosition = -mvPosition.xyz;
|
|
@@ -3213,13 +3237,25 @@ uniform sampler2D tDiffuse;
|
|
|
3213
3237
|
uniform sampler2D normalMap;
|
|
3214
3238
|
uniform sampler2D roughnessMap;
|
|
3215
3239
|
uniform sampler2D aoMap;
|
|
3216
|
-
uniform float
|
|
3240
|
+
uniform float aoMapIntensity;
|
|
3217
3241
|
uniform sampler2D lightMap;
|
|
3218
|
-
uniform float
|
|
3242
|
+
uniform float lightMapIntensity;
|
|
3219
3243
|
|
|
3220
|
-
varying vec4 vUv4;
|
|
3221
3244
|
varying vec2 vUv;
|
|
3222
|
-
|
|
3245
|
+
|
|
3246
|
+
#ifdef USE_UV1
|
|
3247
|
+
varying vec2 vUv1;
|
|
3248
|
+
#endif
|
|
3249
|
+
|
|
3250
|
+
#ifdef USE_UV2
|
|
3251
|
+
varying vec2 vUv2;
|
|
3252
|
+
#endif
|
|
3253
|
+
|
|
3254
|
+
#ifdef USE_UV3
|
|
3255
|
+
varying vec2 vUv3;
|
|
3256
|
+
#endif
|
|
3257
|
+
|
|
3258
|
+
varying vec4 vUv4;
|
|
3223
3259
|
varying vec3 vViewPosition;
|
|
3224
3260
|
varying vec3 vNormal;
|
|
3225
3261
|
|
|
@@ -3230,10 +3266,9 @@ varying vec3 vNormal;
|
|
|
3230
3266
|
void main() {
|
|
3231
3267
|
#include <logdepthbuf_fragment>
|
|
3232
3268
|
|
|
3233
|
-
vec4
|
|
3234
|
-
vec4 texelNormal = texture2D(normalMap, vUv);
|
|
3269
|
+
vec4 texelNormal = texture2D(normalMap, UV_NORMAL);
|
|
3235
3270
|
vec3 normal = normalize(vec3(texelNormal.r * 2.0 - 1.0, texelNormal.b, texelNormal.g * 2.0 - 1.0));
|
|
3236
|
-
vec3 coord =
|
|
3271
|
+
vec3 coord = vUv4.xyz / vUv4.w;
|
|
3237
3272
|
vec2 reflectUv = coord.xy + coord.z * normal.xz * 0.05;
|
|
3238
3273
|
|
|
3239
3274
|
vec3 geometryNormal = normalize(vNormal);
|
|
@@ -3247,7 +3282,7 @@ void main() {
|
|
|
3247
3282
|
vec3 specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
|
|
3248
3283
|
float specularF90 = 1.0;
|
|
3249
3284
|
|
|
3250
|
-
float roughnessFactor = texture2D(roughnessMap,
|
|
3285
|
+
float roughnessFactor = texture2D(roughnessMap, UV_ROUGHNESS).g * roughness;
|
|
3251
3286
|
|
|
3252
3287
|
computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
|
|
3253
3288
|
|
|
@@ -3255,7 +3290,7 @@ void main() {
|
|
|
3255
3290
|
vec3 diffuse = diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
3256
3291
|
|
|
3257
3292
|
vec3 irradiance = vec3(0.);
|
|
3258
|
-
irradiance += texture2D(lightMap,
|
|
3293
|
+
irradiance += texture2D(lightMap, UV_LIGHTMAP).rgb * lightMapIntensity;
|
|
3259
3294
|
|
|
3260
3295
|
float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
|
|
3261
3296
|
vec4 reflectColor = textureLod(tDiffuse, reflectUv, lod);
|
|
@@ -3266,7 +3301,7 @@ void main() {
|
|
|
3266
3301
|
f_specular += reflectColor.rgb * (1.0 - roughnessFactor * roughnessFactor) + multiScattering * irradiance;
|
|
3267
3302
|
f_diffuse += diffuse * irradiance;
|
|
3268
3303
|
|
|
3269
|
-
float ambientOcclusion = mix(1., texture2D(aoMap,
|
|
3304
|
+
float ambientOcclusion = mix(1., texture2D(aoMap, UV_AO).r, aoMapIntensity);
|
|
3270
3305
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
3271
3306
|
f_specular *= computeSpecularOcclusion(dotNV, ambientOcclusion, roughnessFactor);
|
|
3272
3307
|
|
|
@@ -3277,6 +3312,36 @@ void main() {
|
|
|
3277
3312
|
}
|
|
3278
3313
|
`;
|
|
3279
3314
|
class ReflectorMaterial extends ShaderMaterial {
|
|
3315
|
+
onBeforeCompile(shader, renderer) {
|
|
3316
|
+
const channels = [];
|
|
3317
|
+
if (this.aoMap && this.aoMap.channel) {
|
|
3318
|
+
channels.push([
|
|
3319
|
+
"UV_AO",
|
|
3320
|
+
this.aoMap.channel
|
|
3321
|
+
]);
|
|
3322
|
+
}
|
|
3323
|
+
if (this.lightMap && this.lightMap.channel) {
|
|
3324
|
+
channels.push([
|
|
3325
|
+
"UV_LIGHTMAP",
|
|
3326
|
+
this.lightMap.channel
|
|
3327
|
+
]);
|
|
3328
|
+
}
|
|
3329
|
+
if (this.roughnessMap && this.roughnessMap.channel) {
|
|
3330
|
+
channels.push([
|
|
3331
|
+
"UV_ROUGHNESS",
|
|
3332
|
+
this.roughnessMap.channel
|
|
3333
|
+
]);
|
|
3334
|
+
}
|
|
3335
|
+
if (this.normalMap && this.normalMap.channel) {
|
|
3336
|
+
channels.push([
|
|
3337
|
+
"UV_NORMAL",
|
|
3338
|
+
this.normalMap.channel
|
|
3339
|
+
]);
|
|
3340
|
+
}
|
|
3341
|
+
channels.forEach(([key, channel])=>{
|
|
3342
|
+
this.defines[key] = "vUv" + channel;
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3280
3345
|
get metalness() {
|
|
3281
3346
|
return this.uniforms.metalness.value;
|
|
3282
3347
|
}
|
|
@@ -3294,29 +3359,39 @@ class ReflectorMaterial extends ShaderMaterial {
|
|
|
3294
3359
|
}
|
|
3295
3360
|
set roughnessMap(v) {
|
|
3296
3361
|
this.uniforms.roughnessMap.value = v;
|
|
3362
|
+
this.needsUpdate = true;
|
|
3297
3363
|
}
|
|
3298
3364
|
get normalMap() {
|
|
3299
3365
|
return this.uniforms.normalMap.value;
|
|
3300
3366
|
}
|
|
3301
3367
|
set normalMap(v) {
|
|
3302
3368
|
this.uniforms.normalMap.value = v;
|
|
3369
|
+
this.needsUpdate = true;
|
|
3303
3370
|
}
|
|
3304
3371
|
get aoMap() {
|
|
3305
3372
|
return this.uniforms.aoMap.value;
|
|
3306
3373
|
}
|
|
3307
3374
|
set aoMap(v) {
|
|
3308
3375
|
this.uniforms.aoMap.value = v;
|
|
3376
|
+
this.needsUpdate = true;
|
|
3309
3377
|
}
|
|
3310
3378
|
get lightMap() {
|
|
3311
3379
|
return this.uniforms.lightMap.value;
|
|
3312
3380
|
}
|
|
3313
3381
|
set lightMap(v) {
|
|
3314
3382
|
this.uniforms.lightMap.value = v;
|
|
3383
|
+
this.needsUpdate = true;
|
|
3315
3384
|
}
|
|
3316
3385
|
constructor(...args){
|
|
3317
3386
|
super(...args);
|
|
3318
3387
|
this.vertexShader = vert_Reflector;
|
|
3319
3388
|
this.fragmentShader = frag_Reflector;
|
|
3389
|
+
this.defines = {
|
|
3390
|
+
UV_AO: "vUv",
|
|
3391
|
+
UV_LIGHTMAP: "vUv",
|
|
3392
|
+
UV_ROUGHNESS: "vUv",
|
|
3393
|
+
UV_NORMAL: "vUv"
|
|
3394
|
+
};
|
|
3320
3395
|
this.uniforms = {
|
|
3321
3396
|
color: {
|
|
3322
3397
|
value: new Color(0xffffff)
|