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