@xviewer.js/core 1.0.0-alpha.28 → 1.0.0-alpha.29
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 +190 -162
- package/dist/main.js.map +1 -1
- package/dist/module.js +191 -163
- package/dist/module.js.map +1 -1
- package/package.json +1 -1
- package/types/components/Reflector.d.ts +15 -0
- package/types/index.d.ts +1 -1
- package/types/materials/ReflectorMaterial.d.ts +6 -2
- package/types/passes/cubeuv/MergeBlurPass.d.ts +1 -3
- package/types/passes/cubeuv/MergeInfo.d.ts +4 -0
- package/types/passes/cubeuv/MergeReflectPass.d.ts +2 -2
- package/types/passes/cubeuv/utils.d.ts +7 -1
- package/types/plugins/EnvironmentPlugin.d.ts +7 -0
- package/types/loader/aEXRLoader.d.ts +0 -5
- package/types/loader/aFBXLoader.d.ts +0 -5
- package/types/loader/aGLTFLoader.d.ts +0 -5
- package/types/loader/aHDRLoader.d.ts +0 -5
- package/types/loader/aJSONLoader.d.ts +0 -5
- package/types/loader/aTextureLoader.d.ts +0 -5
- package/types/loader/index.d.ts +0 -6
- package/types/material/getShaderMaterial.d.ts +0 -4
- package/types/material/glsl/boxfilterblur.glsl.d.ts +0 -1
- package/types/material/glsl/copy.glsl.d.ts +0 -1
- package/types/material/glsl/fullscreen.glsl.d.ts +0 -1
- package/types/material/glsl/panorama.glsl.d.ts +0 -2
- package/types/material/index.d.ts +0 -1
- package/types/object/Reflector.d.ts +0 -18
- package/types/passes/MipBlurPass2.d.ts +0 -27
- package/types/plugin/Environment.d.ts +0 -5
- package/types/plugins/EnvironmentPlugin2.d.ts +0 -18
- package/types/plugins/EnvironmentPlugin3.d.ts +0 -19
- /package/types/{object → components}/index.d.ts +0 -0
package/dist/main.js
CHANGED
|
@@ -2899,68 +2899,11 @@ class Plane extends three.Mesh {
|
|
|
2899
2899
|
}
|
|
2900
2900
|
}
|
|
2901
2901
|
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
color: {
|
|
2906
|
-
value: null
|
|
2907
|
-
},
|
|
2908
|
-
tDiffuse: {
|
|
2909
|
-
value: null
|
|
2910
|
-
},
|
|
2911
|
-
textureMatrix: {
|
|
2912
|
-
value: null
|
|
2913
|
-
}
|
|
2914
|
-
},
|
|
2915
|
-
vertexShader: /* glsl */ `
|
|
2916
|
-
uniform mat4 textureMatrix;
|
|
2917
|
-
varying vec4 vUv;
|
|
2918
|
-
|
|
2919
|
-
#include <common>
|
|
2920
|
-
#include <logdepthbuf_pars_vertex>
|
|
2921
|
-
|
|
2922
|
-
void main() {
|
|
2923
|
-
vUv = textureMatrix * vec4( position, 1.0 );
|
|
2924
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
2925
|
-
#include <logdepthbuf_vertex>
|
|
2926
|
-
}`,
|
|
2927
|
-
fragmentShader: /* glsl */ `
|
|
2928
|
-
uniform vec3 color;
|
|
2929
|
-
uniform sampler2D tDiffuse;
|
|
2930
|
-
varying vec4 vUv;
|
|
2931
|
-
|
|
2932
|
-
#include <logdepthbuf_pars_fragment>
|
|
2933
|
-
|
|
2934
|
-
float blendOverlay( float base, float blend ) {
|
|
2935
|
-
return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
|
|
2936
|
-
}
|
|
2937
|
-
|
|
2938
|
-
vec3 blendOverlay( vec3 base, vec3 blend ) {
|
|
2939
|
-
return vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );
|
|
2940
|
-
}
|
|
2941
|
-
|
|
2942
|
-
void main() {
|
|
2943
|
-
#include <logdepthbuf_fragment>
|
|
2944
|
-
|
|
2945
|
-
vec4 base = texture2DProj( tDiffuse, vUv );
|
|
2946
|
-
gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
|
|
2947
|
-
|
|
2948
|
-
#include <tonemapping_fragment>
|
|
2949
|
-
#include <colorspace_fragment>
|
|
2950
|
-
}`
|
|
2951
|
-
};
|
|
2952
|
-
class Reflector extends three.Mesh {
|
|
2953
|
-
constructor(options = {}){
|
|
2954
|
-
super(options.geometry || new three.PlaneGeometry());
|
|
2955
|
-
this.isReflector = true;
|
|
2956
|
-
const color = options.color !== undefined ? new three.Color(options.color) : new three.Color(0x7F7F7F);
|
|
2957
|
-
const textureWidth = options.textureWidth || 512;
|
|
2958
|
-
const textureHeight = options.textureHeight || 512;
|
|
2959
|
-
const clipBias = options.clipBias || 0;
|
|
2960
|
-
const multisample = options.multisample !== undefined ? options.multisample : 4;
|
|
2961
|
-
const defaultNormal = options.normal || new three.Vector3(0, 0, 1);
|
|
2902
|
+
class Reflector extends Component {
|
|
2903
|
+
constructor({ textureWidth = 512, textureHeight = 512, clipBias = 0, multisample = 4, layer = 0, normal = new three.Vector3(0, 0, 1), mipmap = false } = {}){
|
|
2904
|
+
super();
|
|
2962
2905
|
const reflectorPlane = new three.Plane();
|
|
2963
|
-
const
|
|
2906
|
+
const reflectorNormal = new three.Vector3();
|
|
2964
2907
|
const reflectorWorldPosition = new three.Vector3();
|
|
2965
2908
|
const cameraWorldPosition = new three.Vector3();
|
|
2966
2909
|
const rotationMatrix = new three.Matrix4();
|
|
@@ -2971,51 +2914,37 @@ class Reflector extends three.Mesh {
|
|
|
2971
2914
|
const q = new three.Vector4();
|
|
2972
2915
|
const textureMatrix = new three.Matrix4();
|
|
2973
2916
|
const virtualCamera = new three.PerspectiveCamera();
|
|
2974
|
-
virtualCamera.layers.set(
|
|
2917
|
+
virtualCamera.layers.set(layer);
|
|
2975
2918
|
const renderTarget = new three.WebGLRenderTarget(textureWidth, textureHeight, {
|
|
2976
2919
|
samples: multisample,
|
|
2977
|
-
type: three.HalfFloatType
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
const material = options.material || new three.ShaderMaterial({
|
|
2981
|
-
name: shader.name ,
|
|
2982
|
-
uniforms: three.UniformsUtils.clone(shader.uniforms),
|
|
2983
|
-
fragmentShader: shader.fragmentShader,
|
|
2984
|
-
vertexShader: shader.vertexShader
|
|
2920
|
+
type: three.HalfFloatType,
|
|
2921
|
+
minFilter: mipmap ? three.LinearMipMapLinearFilter : three.LinearFilter,
|
|
2922
|
+
generateMipmaps: mipmap
|
|
2985
2923
|
});
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
material.uniforms.textureMatrix.value = textureMatrix;
|
|
2991
|
-
}
|
|
2992
|
-
if (material.uniforms.color) {
|
|
2993
|
-
material.uniforms.color.value = color;
|
|
2994
|
-
}
|
|
2995
|
-
this.material = material;
|
|
2996
|
-
const scope = this;
|
|
2997
|
-
this.onBeforeRender = function(renderer, scene, camera) {
|
|
2998
|
-
reflectorWorldPosition.setFromMatrixPosition(scope.matrixWorld);
|
|
2924
|
+
this.update = ()=>{
|
|
2925
|
+
const node = this.node;
|
|
2926
|
+
const { renderer, camera, scene } = this.viewer;
|
|
2927
|
+
reflectorWorldPosition.setFromMatrixPosition(node.matrixWorld);
|
|
2999
2928
|
cameraWorldPosition.setFromMatrixPosition(camera.matrixWorld);
|
|
3000
|
-
rotationMatrix.extractRotation(
|
|
3001
|
-
|
|
3002
|
-
|
|
2929
|
+
rotationMatrix.extractRotation(node.matrixWorld);
|
|
2930
|
+
reflectorNormal.copy(normal);
|
|
2931
|
+
reflectorNormal.applyMatrix4(rotationMatrix);
|
|
3003
2932
|
view.subVectors(reflectorWorldPosition, cameraWorldPosition);
|
|
3004
2933
|
// Avoid rendering when reflector is facing away
|
|
3005
|
-
if (view.dot(
|
|
3006
|
-
view.reflect(
|
|
2934
|
+
if (view.dot(reflectorNormal) > 0) return;
|
|
2935
|
+
view.reflect(reflectorNormal).negate();
|
|
3007
2936
|
view.add(reflectorWorldPosition);
|
|
3008
2937
|
rotationMatrix.extractRotation(camera.matrixWorld);
|
|
3009
2938
|
lookAtPosition.set(0, 0, -1);
|
|
3010
2939
|
lookAtPosition.applyMatrix4(rotationMatrix);
|
|
3011
2940
|
lookAtPosition.add(cameraWorldPosition);
|
|
3012
2941
|
target.subVectors(reflectorWorldPosition, lookAtPosition);
|
|
3013
|
-
target.reflect(
|
|
2942
|
+
target.reflect(reflectorNormal).negate();
|
|
3014
2943
|
target.add(reflectorWorldPosition);
|
|
3015
2944
|
virtualCamera.position.copy(view);
|
|
3016
2945
|
virtualCamera.up.set(0, 1, 0);
|
|
3017
2946
|
virtualCamera.up.applyMatrix4(rotationMatrix);
|
|
3018
|
-
virtualCamera.up.reflect(
|
|
2947
|
+
virtualCamera.up.reflect(reflectorNormal);
|
|
3019
2948
|
virtualCamera.lookAt(target);
|
|
3020
2949
|
virtualCamera.far = camera.far; // Used in WebGLBackground
|
|
3021
2950
|
virtualCamera.updateMatrixWorld();
|
|
@@ -3024,10 +2953,10 @@ class Reflector extends three.Mesh {
|
|
|
3024
2953
|
textureMatrix.set(0.5, 0.0, 0.0, 0.5, 0.0, 0.5, 0.0, 0.5, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 1.0);
|
|
3025
2954
|
textureMatrix.multiply(virtualCamera.projectionMatrix);
|
|
3026
2955
|
textureMatrix.multiply(virtualCamera.matrixWorldInverse);
|
|
3027
|
-
textureMatrix.multiply(
|
|
2956
|
+
textureMatrix.multiply(node.matrixWorld);
|
|
3028
2957
|
// Now update projection matrix with new clip plane, implementing code from: http://www.terathon.com/code/oblique.html
|
|
3029
2958
|
// Paper explaining this technique: http://www.terathon.com/lengyel/Lengyel-Oblique.pdf
|
|
3030
|
-
reflectorPlane.setFromNormalAndCoplanarPoint(
|
|
2959
|
+
reflectorPlane.setFromNormalAndCoplanarPoint(reflectorNormal, reflectorWorldPosition);
|
|
3031
2960
|
reflectorPlane.applyMatrix4(virtualCamera.matrixWorldInverse);
|
|
3032
2961
|
clipPlane.set(reflectorPlane.normal.x, reflectorPlane.normal.y, reflectorPlane.normal.z, reflectorPlane.constant);
|
|
3033
2962
|
const projectionMatrix = virtualCamera.projectionMatrix;
|
|
@@ -3043,7 +2972,7 @@ class Reflector extends three.Mesh {
|
|
|
3043
2972
|
projectionMatrix.elements[10] = clipPlane.z + 1.0 - clipBias;
|
|
3044
2973
|
projectionMatrix.elements[14] = clipPlane.w;
|
|
3045
2974
|
// Render
|
|
3046
|
-
|
|
2975
|
+
node.visible = false;
|
|
3047
2976
|
const currentRenderTarget = renderer.getRenderTarget();
|
|
3048
2977
|
const currentActiveCubeFace = renderer.getActiveCubeFace();
|
|
3049
2978
|
const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
@@ -3063,7 +2992,7 @@ class Reflector extends three.Mesh {
|
|
|
3063
2992
|
if (viewport !== undefined) {
|
|
3064
2993
|
renderer.state.viewport(viewport);
|
|
3065
2994
|
}
|
|
3066
|
-
|
|
2995
|
+
node.visible = true;
|
|
3067
2996
|
};
|
|
3068
2997
|
this.getRenderTarget = function() {
|
|
3069
2998
|
return renderTarget;
|
|
@@ -3071,9 +3000,8 @@ class Reflector extends three.Mesh {
|
|
|
3071
3000
|
this.getTextureMatrix = function() {
|
|
3072
3001
|
return textureMatrix;
|
|
3073
3002
|
};
|
|
3074
|
-
this.
|
|
3003
|
+
this.onDestroy = function() {
|
|
3075
3004
|
renderTarget.dispose();
|
|
3076
|
-
scope.material.dispose();
|
|
3077
3005
|
};
|
|
3078
3006
|
}
|
|
3079
3007
|
}
|
|
@@ -3206,7 +3134,13 @@ void main() {
|
|
|
3206
3134
|
#include <beginnormal_vertex>
|
|
3207
3135
|
#include <defaultnormal_vertex>
|
|
3208
3136
|
|
|
3209
|
-
vec4
|
|
3137
|
+
vec4 transformed = vec4(position, 1.);
|
|
3138
|
+
|
|
3139
|
+
#ifdef USE_INSTANCING
|
|
3140
|
+
transformed = instanceMatrix * transformed;
|
|
3141
|
+
#endif
|
|
3142
|
+
|
|
3143
|
+
vec4 positionWS = modelMatrix * transformed;
|
|
3210
3144
|
vec4 mvPosition = viewMatrix * positionWS;
|
|
3211
3145
|
|
|
3212
3146
|
vUv = uv;
|
|
@@ -3223,26 +3157,29 @@ void main() {
|
|
|
3223
3157
|
vUv3 = uv2;
|
|
3224
3158
|
#endif
|
|
3225
3159
|
|
|
3226
|
-
vUv4 = textureMatrix *
|
|
3160
|
+
vUv4 = textureMatrix * transformed;
|
|
3227
3161
|
|
|
3228
3162
|
vViewPosition = -mvPosition.xyz;
|
|
3229
3163
|
vNormal = normalize(transformedNormal);
|
|
3230
3164
|
|
|
3231
3165
|
gl_Position = projectionMatrix * mvPosition;
|
|
3166
|
+
|
|
3232
3167
|
#include <logdepthbuf_vertex>
|
|
3233
3168
|
}
|
|
3234
3169
|
`;
|
|
3235
3170
|
const frag_Reflector = `
|
|
3236
3171
|
uniform vec3 color;
|
|
3172
|
+
uniform float alpha;
|
|
3237
3173
|
uniform float roughness;
|
|
3238
3174
|
uniform float metalness;
|
|
3239
|
-
uniform sampler2D
|
|
3175
|
+
uniform sampler2D map;
|
|
3240
3176
|
uniform sampler2D normalMap;
|
|
3241
3177
|
uniform sampler2D roughnessMap;
|
|
3242
3178
|
uniform sampler2D aoMap;
|
|
3243
3179
|
uniform float aoMapIntensity;
|
|
3244
3180
|
uniform sampler2D lightMap;
|
|
3245
3181
|
uniform float lightMapIntensity;
|
|
3182
|
+
uniform sampler2D tReflect;
|
|
3246
3183
|
|
|
3247
3184
|
varying vec2 vUv;
|
|
3248
3185
|
|
|
@@ -3281,7 +3218,15 @@ void main() {
|
|
|
3281
3218
|
vec3 multiScattering = vec3( 0.0 );
|
|
3282
3219
|
|
|
3283
3220
|
float metalnessFactor = metalness;
|
|
3284
|
-
|
|
3221
|
+
|
|
3222
|
+
vec4 diffuseColor = vec4(color, alpha);
|
|
3223
|
+
|
|
3224
|
+
#ifdef USE_MAP
|
|
3225
|
+
diffuseColor *= texture2D(map, vUv);
|
|
3226
|
+
#endif
|
|
3227
|
+
|
|
3228
|
+
diffuseColor.rgb = diffuseColor.rgb * ( 1.0 - metalnessFactor );
|
|
3229
|
+
|
|
3285
3230
|
vec3 specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );
|
|
3286
3231
|
float specularF90 = 1.0;
|
|
3287
3232
|
|
|
@@ -3290,13 +3235,13 @@ void main() {
|
|
|
3290
3235
|
computeMultiscattering( geometryNormal, geometryViewDir, specularColor, specularF90, roughnessFactor, singleScattering, multiScattering );
|
|
3291
3236
|
|
|
3292
3237
|
vec3 totalScattering = singleScattering + multiScattering;
|
|
3293
|
-
vec3 diffuse = diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
3238
|
+
vec3 diffuse = diffuseColor.rgb * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );
|
|
3294
3239
|
|
|
3295
3240
|
vec3 irradiance = vec3(0.);
|
|
3296
3241
|
irradiance += texture2D(lightMap, UV_LIGHTMAP).rgb * lightMapIntensity;
|
|
3297
3242
|
|
|
3298
3243
|
float lod = roughnessFactor * (1.7 - 0.7 * roughnessFactor) * 6.;
|
|
3299
|
-
vec4 reflectColor = textureLod(
|
|
3244
|
+
vec4 reflectColor = textureLod(tReflect, reflectUv, lod);
|
|
3300
3245
|
|
|
3301
3246
|
vec3 f_specular = vec3(0.);
|
|
3302
3247
|
vec3 f_diffuse = vec3(0.);
|
|
@@ -3308,14 +3253,14 @@ void main() {
|
|
|
3308
3253
|
float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
|
|
3309
3254
|
f_specular *= computeSpecularOcclusion(dotNV, ambientOcclusion, roughnessFactor);
|
|
3310
3255
|
|
|
3311
|
-
gl_FragColor = vec4(f_specular + f_diffuse,
|
|
3256
|
+
gl_FragColor = vec4(f_specular + f_diffuse, diffuseColor.a);
|
|
3312
3257
|
|
|
3313
3258
|
#include <tonemapping_fragment>
|
|
3314
3259
|
#include <colorspace_fragment>
|
|
3315
3260
|
}
|
|
3316
3261
|
`;
|
|
3317
3262
|
class ReflectorMaterial extends three.ShaderMaterial {
|
|
3318
|
-
onBeforeCompile(shader
|
|
3263
|
+
onBeforeCompile(shader) {
|
|
3319
3264
|
const channels = [];
|
|
3320
3265
|
if (this.aoMap && this.aoMap.channel) {
|
|
3321
3266
|
channels.push([
|
|
@@ -3345,6 +3290,12 @@ class ReflectorMaterial extends three.ShaderMaterial {
|
|
|
3345
3290
|
shader.defines[key] = "vUv" + channel;
|
|
3346
3291
|
});
|
|
3347
3292
|
}
|
|
3293
|
+
get alpha() {
|
|
3294
|
+
return this.uniforms.alpha.value;
|
|
3295
|
+
}
|
|
3296
|
+
set alpha(v) {
|
|
3297
|
+
this.uniforms.alpha.value = v;
|
|
3298
|
+
}
|
|
3348
3299
|
get metalness() {
|
|
3349
3300
|
return this.uniforms.metalness.value;
|
|
3350
3301
|
}
|
|
@@ -3357,33 +3308,35 @@ class ReflectorMaterial extends three.ShaderMaterial {
|
|
|
3357
3308
|
set roughness(v) {
|
|
3358
3309
|
this.uniforms.roughness.value = v;
|
|
3359
3310
|
}
|
|
3311
|
+
get map() {
|
|
3312
|
+
return this.uniforms.map.value;
|
|
3313
|
+
}
|
|
3314
|
+
set map(v) {
|
|
3315
|
+
this.uniforms.map.value = v;
|
|
3316
|
+
}
|
|
3360
3317
|
get roughnessMap() {
|
|
3361
3318
|
return this.uniforms.roughnessMap.value;
|
|
3362
3319
|
}
|
|
3363
3320
|
set roughnessMap(v) {
|
|
3364
3321
|
this.uniforms.roughnessMap.value = v;
|
|
3365
|
-
this.needsUpdate = true;
|
|
3366
3322
|
}
|
|
3367
3323
|
get normalMap() {
|
|
3368
3324
|
return this.uniforms.normalMap.value;
|
|
3369
3325
|
}
|
|
3370
3326
|
set normalMap(v) {
|
|
3371
3327
|
this.uniforms.normalMap.value = v;
|
|
3372
|
-
this.needsUpdate = true;
|
|
3373
3328
|
}
|
|
3374
3329
|
get aoMap() {
|
|
3375
3330
|
return this.uniforms.aoMap.value;
|
|
3376
3331
|
}
|
|
3377
3332
|
set aoMap(v) {
|
|
3378
3333
|
this.uniforms.aoMap.value = v;
|
|
3379
|
-
this.needsUpdate = true;
|
|
3380
3334
|
}
|
|
3381
3335
|
get lightMap() {
|
|
3382
3336
|
return this.uniforms.lightMap.value;
|
|
3383
3337
|
}
|
|
3384
3338
|
set lightMap(v) {
|
|
3385
3339
|
this.uniforms.lightMap.value = v;
|
|
3386
|
-
this.needsUpdate = true;
|
|
3387
3340
|
}
|
|
3388
3341
|
constructor(...args){
|
|
3389
3342
|
super(...args);
|
|
@@ -3399,12 +3352,18 @@ class ReflectorMaterial extends three.ShaderMaterial {
|
|
|
3399
3352
|
color: {
|
|
3400
3353
|
value: new three.Color(0xffffff)
|
|
3401
3354
|
},
|
|
3402
|
-
|
|
3355
|
+
alpha: {
|
|
3356
|
+
value: 1
|
|
3357
|
+
},
|
|
3358
|
+
map: {
|
|
3403
3359
|
value: null
|
|
3404
3360
|
},
|
|
3405
|
-
|
|
3361
|
+
tReflect: {
|
|
3406
3362
|
value: null
|
|
3407
3363
|
},
|
|
3364
|
+
textureMatrix: {
|
|
3365
|
+
value: new three.Matrix4()
|
|
3366
|
+
},
|
|
3408
3367
|
metalness: {
|
|
3409
3368
|
value: 0
|
|
3410
3369
|
},
|
|
@@ -3432,6 +3391,13 @@ class ReflectorMaterial extends three.ShaderMaterial {
|
|
|
3432
3391
|
};
|
|
3433
3392
|
}
|
|
3434
3393
|
}
|
|
3394
|
+
__decorate([
|
|
3395
|
+
property({
|
|
3396
|
+
min: 0,
|
|
3397
|
+
max: 1,
|
|
3398
|
+
step: 0.01
|
|
3399
|
+
})
|
|
3400
|
+
], ReflectorMaterial.prototype, "alpha", null);
|
|
3435
3401
|
__decorate([
|
|
3436
3402
|
property({
|
|
3437
3403
|
min: 0,
|
|
@@ -3481,6 +3447,28 @@ class DebugPlugin extends Plugin {
|
|
|
3481
3447
|
|
|
3482
3448
|
const LOD_MIN = 4;
|
|
3483
3449
|
const _flatCamera = /*@__PURE__*/ new three.OrthographicCamera();
|
|
3450
|
+
// Golden Ratio
|
|
3451
|
+
const PHI = (1 + Math.sqrt(5)) / 2;
|
|
3452
|
+
const INV_PHI = 1 / PHI;
|
|
3453
|
+
// Vertices of a dodecahedron (except the opposites, which represent the
|
|
3454
|
+
// same axis), used as axis directions evenly spread on a sphere.
|
|
3455
|
+
const _axisDirections = [
|
|
3456
|
+
/*@__PURE__*/ new three.Vector3(1, 1, 1),
|
|
3457
|
+
/*@__PURE__*/ new three.Vector3(-1, 1, 1),
|
|
3458
|
+
/*@__PURE__*/ new three.Vector3(1, 1, -1),
|
|
3459
|
+
/*@__PURE__*/ new three.Vector3(-1, 1, -1),
|
|
3460
|
+
/*@__PURE__*/ new three.Vector3(0, PHI, INV_PHI),
|
|
3461
|
+
/*@__PURE__*/ new three.Vector3(0, PHI, -INV_PHI),
|
|
3462
|
+
/*@__PURE__*/ new three.Vector3(INV_PHI, 0, PHI),
|
|
3463
|
+
/*@__PURE__*/ new three.Vector3(-INV_PHI, 0, PHI),
|
|
3464
|
+
/*@__PURE__*/ new three.Vector3(PHI, INV_PHI, 0),
|
|
3465
|
+
/*@__PURE__*/ new three.Vector3(-PHI, INV_PHI, 0)
|
|
3466
|
+
];
|
|
3467
|
+
const _Performance = {
|
|
3468
|
+
HIGH: 0,
|
|
3469
|
+
MEDIUM: 1,
|
|
3470
|
+
LOW: 2
|
|
3471
|
+
};
|
|
3484
3472
|
function _setViewport(target, x, y, width, height) {
|
|
3485
3473
|
target.viewport.set(x, y, width, height);
|
|
3486
3474
|
target.scissor.set(x, y, width, height);
|
|
@@ -3562,6 +3550,9 @@ function _getCubeMapMaterial() {
|
|
|
3562
3550
|
},
|
|
3563
3551
|
lod: {
|
|
3564
3552
|
value: 0
|
|
3553
|
+
},
|
|
3554
|
+
exposure: {
|
|
3555
|
+
value: 1
|
|
3565
3556
|
}
|
|
3566
3557
|
},
|
|
3567
3558
|
vertexShader: _getCommonVertexShader(),
|
|
@@ -3572,9 +3563,11 @@ function _getCubeMapMaterial() {
|
|
|
3572
3563
|
varying vec3 vOutputDirection;
|
|
3573
3564
|
uniform samplerCube envMap;
|
|
3574
3565
|
uniform float lod;
|
|
3566
|
+
uniform float exposure;
|
|
3575
3567
|
|
|
3576
3568
|
void main() {
|
|
3577
3569
|
gl_FragColor = textureCubeLodEXT(envMap, vOutputDirection, lod);
|
|
3570
|
+
gl_FragColor.rgb *= exposure;
|
|
3578
3571
|
}
|
|
3579
3572
|
`,
|
|
3580
3573
|
blending: three.AdditiveBlending,
|
|
@@ -4851,12 +4844,13 @@ class MergeRefectPass {
|
|
|
4851
4844
|
return this._envMapTarget;
|
|
4852
4845
|
}
|
|
4853
4846
|
dispose() {
|
|
4847
|
+
this._sourceTarget.dispose();
|
|
4854
4848
|
this._envMapTarget.dispose();
|
|
4855
4849
|
this._pmremGenerator.dispose();
|
|
4856
4850
|
}
|
|
4857
4851
|
mergeReflect(info) {
|
|
4858
|
-
this._pmremGenerator.
|
|
4859
|
-
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap);
|
|
4852
|
+
this._pmremGenerator._copyTexture(this._envMapTarget, this._sourceTarget.texture, info.envMapIntensity);
|
|
4853
|
+
this._pmremGenerator._mergeReflect(this._envMapTarget, this._reflectMap, info.performance);
|
|
4860
4854
|
info.envMapTarget = this._envMapTarget;
|
|
4861
4855
|
info.lodMax = this._pmremGenerator._lodMeshes.length - 1;
|
|
4862
4856
|
}
|
|
@@ -4879,6 +4873,8 @@ class MergeRefectPass {
|
|
|
4879
4873
|
const uniforms = this._copyTexMaterial.uniforms;
|
|
4880
4874
|
uniforms.map.value = texture;
|
|
4881
4875
|
uniforms.intensity.value = intensity;
|
|
4876
|
+
targetOut.scissorTest = false;
|
|
4877
|
+
_setViewport(targetOut, 0, 0, targetOut.width, targetOut.height);
|
|
4882
4878
|
const renderer = this._renderer;
|
|
4883
4879
|
renderer.autoClear = true;
|
|
4884
4880
|
renderer.setRenderTarget(targetOut);
|
|
@@ -4886,31 +4882,45 @@ class MergeRefectPass {
|
|
|
4886
4882
|
renderer.setRenderTarget(null);
|
|
4887
4883
|
};
|
|
4888
4884
|
pmremGenerator._clearTexture = function(targetOut, intensity) {
|
|
4889
|
-
|
|
4890
|
-
if (this._sourceInit === false) {
|
|
4891
|
-
this._sourceInit = true;
|
|
4892
|
-
source.scissorTest = false;
|
|
4893
|
-
_setViewport(source, 0, 0, source.width, source.height);
|
|
4894
|
-
this._copyTexture(source, targetOut.texture);
|
|
4895
|
-
} else {
|
|
4896
|
-
this._copyTexture(targetOut, source.texture, intensity);
|
|
4897
|
-
}
|
|
4885
|
+
this._copyTexture(targetOut, this._sourceTarget.texture, intensity);
|
|
4898
4886
|
};
|
|
4899
|
-
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap,
|
|
4887
|
+
pmremGenerator._mergeReflect = function(sourceTarget, reflectMap, performance) {
|
|
4900
4888
|
const renderer = this._renderer;
|
|
4901
4889
|
const autoClear = renderer.autoClear;
|
|
4902
4890
|
const cubeMapMaterial = this._cubeMapMaterial;
|
|
4903
4891
|
const uniforms = this._cubeMapMaterial.uniforms;
|
|
4904
4892
|
uniforms.envMap.value = reflectMap;
|
|
4905
|
-
renderer.autoClear =
|
|
4906
|
-
|
|
4907
|
-
|
|
4908
|
-
|
|
4893
|
+
renderer.autoClear = false;
|
|
4894
|
+
if (performance === _Performance.HIGH) {
|
|
4895
|
+
for(let i = 0; i < this._lodMeshes.length - 1; i++){
|
|
4896
|
+
uniforms.lod.value = i < 5 ? 0 : i;
|
|
4897
|
+
this._blit(sourceTarget, i, cubeMapMaterial);
|
|
4898
|
+
}
|
|
4899
|
+
} else if (performance === _Performance.MEDIUM) {
|
|
4900
|
+
for(let i = 0; i < this._lodMeshes.length; i++){
|
|
4901
|
+
if (i < 4) {
|
|
4902
|
+
uniforms.lod.value = 0;
|
|
4903
|
+
this._blit(sourceTarget, i, cubeMapMaterial);
|
|
4904
|
+
} else {
|
|
4905
|
+
this._pmremblur(sourceTarget, i - 1, i);
|
|
4906
|
+
}
|
|
4907
|
+
}
|
|
4908
|
+
} else {
|
|
4909
|
+
uniforms.lod.value = 0;
|
|
4910
|
+
this._blit(sourceTarget, 0, cubeMapMaterial);
|
|
4911
|
+
for(let i = 1; i < this._lodMeshes.length; i++){
|
|
4912
|
+
this._pmremblur(sourceTarget, i - 1, i);
|
|
4913
|
+
}
|
|
4909
4914
|
}
|
|
4910
4915
|
sourceTarget.scissorTest = false;
|
|
4911
4916
|
_setViewport(sourceTarget, 0, 0, sourceTarget.width, sourceTarget.height);
|
|
4912
4917
|
renderer.autoClear = autoClear;
|
|
4913
4918
|
};
|
|
4919
|
+
pmremGenerator._pmremblur = function(targetOut, lodIn, lodOut) {
|
|
4920
|
+
const sigma = Math.sqrt(this._sigmas[lodOut] * this._sigmas[lodOut] - this._sigmas[lodIn] * this._sigmas[lodIn]);
|
|
4921
|
+
const poleAxis = _axisDirections[lodIn % _axisDirections.length];
|
|
4922
|
+
this._blur(targetOut, lodIn, lodOut, sigma, poleAxis);
|
|
4923
|
+
};
|
|
4914
4924
|
pmremGenerator._blit = function(targetOut, lodOut, material) {
|
|
4915
4925
|
const renderer = this._renderer;
|
|
4916
4926
|
const _lodMax = this._lodMax;
|
|
@@ -4927,10 +4937,11 @@ class MergeRefectPass {
|
|
|
4927
4937
|
return pmremGenerator;
|
|
4928
4938
|
}
|
|
4929
4939
|
constructor({ envMap, reflectMap, viewer }){
|
|
4930
|
-
this.envMapIntensity = 1;
|
|
4931
4940
|
this._reflectMap = reflectMap;
|
|
4932
4941
|
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
4933
4942
|
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap, envMap);
|
|
4943
|
+
this._sourceTarget = this._envMapTarget.clone();
|
|
4944
|
+
this._pmremGenerator._copyTexture(this._sourceTarget, this._envMapTarget.texture);
|
|
4934
4945
|
viewer.scene.environment = this._envMapTarget.texture;
|
|
4935
4946
|
}
|
|
4936
4947
|
}
|
|
@@ -4945,12 +4956,21 @@ function mipGaussianBlendWeight(sigma, lod) {
|
|
|
4945
4956
|
|
|
4946
4957
|
const MAX_LOD = 10;
|
|
4947
4958
|
class MergeMipBlurPass {
|
|
4948
|
-
get
|
|
4949
|
-
return this.
|
|
4959
|
+
get envMapTarget() {
|
|
4960
|
+
return this._envMapTarget;
|
|
4950
4961
|
}
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4962
|
+
dispose() {
|
|
4963
|
+
this._envMapTarget.dispose();
|
|
4964
|
+
this._pmremGenerator.dispose();
|
|
4965
|
+
}
|
|
4966
|
+
mergeMipBlur(info) {
|
|
4967
|
+
this._setBlurIntensity(info.blurIntensity);
|
|
4968
|
+
const targetIn = this._pmremGenerator._applyMipBlur(this._envMapTarget, this._reflectMap, this._blurMinLod, this._blurMaxLod, this._sigma, info.exposure);
|
|
4969
|
+
this._pmremGenerator._mipCopy(info.envMapTarget, targetIn, info.lodMax, this._blurMinLod);
|
|
4970
|
+
}
|
|
4971
|
+
_setBlurIntensity(blurIntensity) {
|
|
4972
|
+
if (this._blurIntensity !== blurIntensity) {
|
|
4973
|
+
this._blurIntensity = blurIntensity;
|
|
4954
4974
|
this._sigma = three.MathUtils.lerp(1, 40, this._blurIntensity / 10);
|
|
4955
4975
|
for(let lod = 0; lod <= MAX_LOD; lod++){
|
|
4956
4976
|
let w = mipGaussianBlendWeight(this._sigma, lod);
|
|
@@ -4964,17 +4984,6 @@ class MergeMipBlurPass {
|
|
|
4964
4984
|
}
|
|
4965
4985
|
}
|
|
4966
4986
|
}
|
|
4967
|
-
get envMapTarget() {
|
|
4968
|
-
return this._envMapTarget;
|
|
4969
|
-
}
|
|
4970
|
-
dispose() {
|
|
4971
|
-
this._envMapTarget.dispose();
|
|
4972
|
-
this._pmremGenerator.dispose();
|
|
4973
|
-
}
|
|
4974
|
-
mergeMipBlur(info) {
|
|
4975
|
-
const targetIn = this._pmremGenerator._applyMipBlur(this._envMapTarget, this._reflectMap, this._blurMinLod, this._blurMaxLod, this._sigma, this.exposure);
|
|
4976
|
-
this._pmremGenerator._mipCopy(info.envMapTarget, targetIn, info.lodMax, this._blurMinLod);
|
|
4977
|
-
}
|
|
4978
4987
|
_getPMREMExtension(renderer) {
|
|
4979
4988
|
const pmremGenerator = new three.PMREMGenerator(renderer);
|
|
4980
4989
|
pmremGenerator._fromTextureExtension = function(texture) {
|
|
@@ -4985,7 +4994,7 @@ class MergeMipBlurPass {
|
|
|
4985
4994
|
this._lodMeshes = this._lodPlanes.map((v)=>new three.Mesh(v, this._mipBlurMaterial));
|
|
4986
4995
|
return target;
|
|
4987
4996
|
};
|
|
4988
|
-
pmremGenerator._applyMipBlur = function(sourceTarget, texture, blurMinLod, blurMaxLod, sigma, exposure) {
|
|
4997
|
+
pmremGenerator._applyMipBlur = function(sourceTarget, texture, blurMinLod, blurMaxLod, sigma, exposure = 1) {
|
|
4989
4998
|
const pingPongRenderTarget = this._pingPongRenderTarget;
|
|
4990
4999
|
const uniforms = this._mipBlurMaterial.uniforms;
|
|
4991
5000
|
uniforms.envMap.value = texture;
|
|
@@ -5038,7 +5047,6 @@ class MergeMipBlurPass {
|
|
|
5038
5047
|
this._blurMinLod = 0;
|
|
5039
5048
|
this._blurMaxLod = MAX_LOD;
|
|
5040
5049
|
this._blurIntensity = -1;
|
|
5041
|
-
this.exposure = 1;
|
|
5042
5050
|
this._reflectMap = reflectMap;
|
|
5043
5051
|
this._pmremGenerator = this._getPMREMExtension(viewer.renderer);
|
|
5044
5052
|
this._envMapTarget = this._pmremGenerator._fromTextureExtension(reflectMap);
|
|
@@ -5066,13 +5074,15 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5066
5074
|
}),
|
|
5067
5075
|
position: new three.Vector3(1.1, 3, 0)
|
|
5068
5076
|
});
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5077
|
+
if (this._mipBlurPass) {
|
|
5078
|
+
viewer.addNode(Plane, {
|
|
5079
|
+
parent: this._debugNode,
|
|
5080
|
+
material: new three.MeshBasicMaterial({
|
|
5081
|
+
map: this._mipBlurPass.envMapTarget.texture
|
|
5082
|
+
}),
|
|
5083
|
+
position: new three.Vector3(0, 3, 0)
|
|
5084
|
+
});
|
|
5085
|
+
}
|
|
5076
5086
|
}
|
|
5077
5087
|
}
|
|
5078
5088
|
if (this._debugNode) {
|
|
@@ -5086,24 +5096,38 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5086
5096
|
const oldTarget = renderer.getRenderTarget();
|
|
5087
5097
|
const oldActiveCubeFace = renderer.getActiveCubeFace();
|
|
5088
5098
|
const oldActiveMipmapLevel = renderer.getActiveMipmapLevel();
|
|
5089
|
-
this._reflectPass.envMapIntensity = this.envMapIntensity;
|
|
5090
|
-
this._mipBlurPass.exposure = this.reflectExposure;
|
|
5091
|
-
this._mipBlurPass.blurIntensity = this.reflectBlurIntensity;
|
|
5092
5099
|
renderer.autoClear = true;
|
|
5093
5100
|
this._cubeCamera.update(renderer, this._scene);
|
|
5101
|
+
this._mergeInfo.performance = this.performance;
|
|
5102
|
+
this._mergeInfo.exposure = this.reflectExposure;
|
|
5103
|
+
this._mergeInfo.envMapIntensity = this.envMapIntensity;
|
|
5104
|
+
this._mergeInfo.blurIntensity = this.reflectBlurIntensity;
|
|
5094
5105
|
this._reflectPass.mergeReflect(this._mergeInfo);
|
|
5095
|
-
this.
|
|
5106
|
+
if (this.performance === _Performance.HIGH) {
|
|
5107
|
+
if (this._mipBlurPass === undefined) {
|
|
5108
|
+
this._mipBlurPass = new MergeMipBlurPass({
|
|
5109
|
+
viewer: this.viewer,
|
|
5110
|
+
reflectMap: this._cubeCamera.renderTarget.texture
|
|
5111
|
+
});
|
|
5112
|
+
}
|
|
5113
|
+
this._mipBlurPass.mergeMipBlur(this._mergeInfo);
|
|
5114
|
+
}
|
|
5096
5115
|
renderer.autoClear = autoClear;
|
|
5097
5116
|
renderer.setRenderTarget(oldTarget, oldActiveCubeFace, oldActiveMipmapLevel);
|
|
5098
5117
|
}
|
|
5099
5118
|
constructor({ envMap, scene, near, far, layer = 0, resolution = 256, floatType = three.HalfFloatType, position = new three.Vector3(0, 1, 0) } = {}){
|
|
5100
5119
|
super();
|
|
5101
5120
|
this._mergeInfo = {
|
|
5121
|
+
performance: _Performance.HIGH,
|
|
5102
5122
|
envMapTarget: null,
|
|
5103
|
-
|
|
5123
|
+
envMapIntensity: 1,
|
|
5124
|
+
blurIntensity: 1,
|
|
5125
|
+
lodMax: 0,
|
|
5126
|
+
exposure: 1
|
|
5104
5127
|
};
|
|
5105
5128
|
this._debug = false;
|
|
5106
5129
|
this._debugNode = null;
|
|
5130
|
+
this.performance = _Performance.LOW;
|
|
5107
5131
|
this.envMapIntensity = 1;
|
|
5108
5132
|
this.reflectExposure = 1;
|
|
5109
5133
|
this.reflectBlurIntensity = 5;
|
|
@@ -5120,20 +5144,24 @@ class EnvironmentPlugin extends Plugin {
|
|
|
5120
5144
|
reflectMap,
|
|
5121
5145
|
envMap
|
|
5122
5146
|
});
|
|
5123
|
-
this._mipBlurPass = new MergeMipBlurPass({
|
|
5124
|
-
viewer,
|
|
5125
|
-
reflectMap
|
|
5126
|
-
});
|
|
5127
5147
|
};
|
|
5128
5148
|
this.uninstall = ()=>{
|
|
5129
5149
|
this._reflectPass.dispose();
|
|
5130
|
-
this._mipBlurPass
|
|
5150
|
+
if (this._mipBlurPass) {
|
|
5151
|
+
this._mipBlurPass.dispose();
|
|
5152
|
+
}
|
|
5131
5153
|
};
|
|
5132
5154
|
}
|
|
5133
5155
|
}
|
|
5156
|
+
EnvironmentPlugin.Performance = _Performance;
|
|
5134
5157
|
__decorate([
|
|
5135
5158
|
property
|
|
5136
5159
|
], EnvironmentPlugin.prototype, "debug", null);
|
|
5160
|
+
__decorate([
|
|
5161
|
+
property({
|
|
5162
|
+
value: _Performance
|
|
5163
|
+
})
|
|
5164
|
+
], EnvironmentPlugin.prototype, "performance", void 0);
|
|
5137
5165
|
__decorate([
|
|
5138
5166
|
property({
|
|
5139
5167
|
min: 0,
|