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