three-stdlib 2.8.0 → 2.8.1

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.
Files changed (48) hide show
  1. package/cameras/CinematicCamera.cjs.js +1 -1
  2. package/cameras/CinematicCamera.js +3 -8
  3. package/exporters/GLTFExporter.cjs.js +1 -1
  4. package/exporters/GLTFExporter.js +9 -18
  5. package/index.cjs.js +1 -1
  6. package/loaders/EXRLoader.cjs.js +1 -1
  7. package/loaders/EXRLoader.js +21 -10
  8. package/loaders/GLTFLoader.cjs.js +1 -1
  9. package/loaders/GLTFLoader.js +4 -3
  10. package/loaders/HDRCubeTextureLoader.cjs.js +1 -1
  11. package/loaders/HDRCubeTextureLoader.js +1 -3
  12. package/loaders/LDrawLoader.cjs.js +1 -1
  13. package/loaders/LDrawLoader.js +1450 -1105
  14. package/loaders/LUT3dlLoader.cjs.js +1 -1
  15. package/loaders/LUT3dlLoader.js +18 -11
  16. package/loaders/LUTCubeLoader.cjs.js +1 -1
  17. package/loaders/LUTCubeLoader.js +4 -5
  18. package/loaders/PCDLoader.cjs.js +1 -1
  19. package/loaders/PCDLoader.js +2 -2
  20. package/loaders/RGBELoader.cjs.js +1 -1
  21. package/loaders/RGBELoader.js +6 -6
  22. package/loaders/VRMLLoader.cjs.js +1 -1
  23. package/loaders/VRMLLoader.js +10 -18
  24. package/modifiers/CurveModifier.cjs.js +1 -1
  25. package/modifiers/CurveModifier.js +9 -8
  26. package/objects/Lensflare.cjs.js +1 -1
  27. package/objects/Lensflare.js +3 -11
  28. package/objects/Reflector.cjs.js +1 -1
  29. package/objects/Reflector.js +16 -12
  30. package/objects/ReflectorForSSRPass.cjs.js +1 -1
  31. package/objects/ReflectorForSSRPass.js +1 -9
  32. package/objects/Refractor.cjs.js +1 -1
  33. package/objects/Refractor.js +7 -12
  34. package/objects/Water.cjs.js +1 -1
  35. package/objects/Water.js +5 -16
  36. package/package.json +1 -1
  37. package/postprocessing/GlitchPass.cjs.js +1 -1
  38. package/postprocessing/GlitchPass.js +36 -33
  39. package/postprocessing/SMAAPass.cjs.js +1 -1
  40. package/postprocessing/SMAAPass.js +93 -96
  41. package/postprocessing/SSAOPass.cjs.js +1 -1
  42. package/postprocessing/SSAOPass.js +151 -152
  43. package/postprocessing/SavePass.cjs.js +1 -1
  44. package/postprocessing/SavePass.js +27 -28
  45. package/renderers/webgpu/WebGPUTextures.cjs.js +1 -1
  46. package/renderers/webgpu/WebGPUTextures.js +1 -2
  47. package/utils/LDrawUtils.cjs.js +1 -0
  48. package/utils/LDrawUtils.js +144 -0
@@ -1,4 +1,4 @@
1
- import { Mesh, Color, Plane, Vector3, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, MathUtils, ShaderMaterial, UniformsUtils, LinearFilter, RGBFormat } from 'three';
1
+ import { Mesh, Color, Plane, Vector3, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, ShaderMaterial, UniformsUtils } from 'three';
2
2
 
3
3
  class Reflector extends Mesh {
4
4
  constructor(geometry, options = {}) {
@@ -23,17 +23,7 @@ class Reflector extends Mesh {
23
23
  const q = new Vector4();
24
24
  const textureMatrix = new Matrix4();
25
25
  const virtualCamera = new PerspectiveCamera();
26
- const parameters = {
27
- minFilter: LinearFilter,
28
- magFilter: LinearFilter,
29
- format: RGBFormat
30
- };
31
- const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, parameters);
32
-
33
- if (!MathUtils.isPowerOfTwo(textureWidth) || !MathUtils.isPowerOfTwo(textureHeight)) {
34
- renderTarget.texture.generateMipmaps = false;
35
- }
36
-
26
+ const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight);
37
27
  const material = new ShaderMaterial({
38
28
  uniforms: UniformsUtils.clone(shader.uniforms),
39
29
  fragmentShader: shader.fragmentShader,
@@ -124,6 +114,11 @@ class Reflector extends Mesh {
124
114
  this.getRenderTarget = function () {
125
115
  return renderTarget;
126
116
  };
117
+
118
+ this.dispose = function () {
119
+ renderTarget.dispose();
120
+ scope.material.dispose();
121
+ };
127
122
  }
128
123
 
129
124
  }
@@ -147,12 +142,17 @@ Reflector.ReflectorShader = {
147
142
  uniform mat4 textureMatrix;
148
143
  varying vec4 vUv;
149
144
 
145
+ #include <common>
146
+ #include <logdepthbuf_pars_vertex>
147
+
150
148
  void main() {
151
149
 
152
150
  vUv = textureMatrix * vec4( position, 1.0 );
153
151
 
154
152
  gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
155
153
 
154
+ #include <logdepthbuf_vertex>
155
+
156
156
  }`,
157
157
  fragmentShader:
158
158
  /* glsl */
@@ -161,6 +161,8 @@ Reflector.ReflectorShader = {
161
161
  uniform sampler2D tDiffuse;
162
162
  varying vec4 vUv;
163
163
 
164
+ #include <logdepthbuf_pars_fragment>
165
+
164
166
  float blendOverlay( float base, float blend ) {
165
167
 
166
168
  return( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );
@@ -175,6 +177,8 @@ Reflector.ReflectorShader = {
175
177
 
176
178
  void main() {
177
179
 
180
+ #include <logdepthbuf_fragment>
181
+
178
182
  vec4 base = texture2DProj( tDiffuse, vUv );
179
183
  gl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );
180
184
 
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(r,a={}){super(r),this.type="ReflectorForSSRPass";const n=this,i=void 0!==a.color?new t.Color(a.color):new t.Color(8355711),o=a.textureWidth||512,l=a.textureHeight||512,s=a.clipBias||0,u=a.shader||e.ReflectorShader,c=!0===a.useDepthTexture,d=new t.Vector3(0,1,0),v=new t.Vector3,f=new t.Vector3;n.needsUpdate=!1,n.maxDistance=e.ReflectorShader.uniforms.maxDistance.value,n.opacity=e.ReflectorShader.uniforms.opacity.value,n.color=i,n.resolution=a.resolution||new t.Vector2(window.innerWidth,window.innerHeight),n._distanceAttenuation=e.ReflectorShader.defines.DISTANCE_ATTENUATION,Object.defineProperty(n,"distanceAttenuation",{get:()=>n._distanceAttenuation,set(t){n._distanceAttenuation!==t&&(n._distanceAttenuation=t,n.material.defines.DISTANCE_ATTENUATION=t,n.material.needsUpdate=!0)}}),n._fresnel=e.ReflectorShader.defines.FRESNEL,Object.defineProperty(n,"fresnel",{get:()=>n._fresnel,set(t){n._fresnel!==t&&(n._fresnel=t,n.material.defines.FRESNEL=t,n.material.needsUpdate=!0)}});const p=new t.Vector3,m=new t.Vector3,x=new t.Vector3,h=new t.Matrix4,w=new t.Vector3(0,0,-1),M=new t.Vector3,g=new t.Vector3,b=new t.Matrix4,y=new t.PerspectiveCamera;let P;c&&(P=new t.DepthTexture,P.type=t.UnsignedShortType,P.minFilter=t.NearestFilter,P.magFilter=t.NearestFilter);const C={minFilter:t.LinearFilter,magFilter:t.LinearFilter,format:t.RGBFormat,depthTexture:c?P:null},D=new t.WebGLRenderTarget(o,l,C);t.MathUtils.isPowerOfTwo(o)&&t.MathUtils.isPowerOfTwo(l)||(D.texture.generateMipmaps=!1);const T=new t.ShaderMaterial({transparent:c,defines:Object.assign({},e.ReflectorShader.defines,{useDepthTexture:c}),uniforms:t.UniformsUtils.clone(u.uniforms),fragmentShader:u.fragmentShader,vertexShader:u.vertexShader});T.uniforms.tDiffuse.value=D.texture,T.uniforms.color.value=n.color,T.uniforms.textureMatrix.value=b,c&&(T.uniforms.tDepth.value=D.depthTexture),this.material=T;const S=[new t.Plane(new t.Vector3(0,1,0),s)];this.doRender=function(t,e,r){if(T.uniforms.maxDistance.value=n.maxDistance,T.uniforms.color.value=n.color,T.uniforms.opacity.value=n.opacity,v.copy(r.position).normalize(),f.copy(v).reflect(d),T.uniforms.fresnelCoe.value=(v.dot(f)+1)/2,m.setFromMatrixPosition(n.matrixWorld),x.setFromMatrixPosition(r.matrixWorld),h.extractRotation(n.matrixWorld),p.set(0,0,1),p.applyMatrix4(h),M.subVectors(m,x),M.dot(p)>0)return;M.reflect(p).negate(),M.add(m),h.extractRotation(r.matrixWorld),w.set(0,0,-1),w.applyMatrix4(h),w.add(x),g.subVectors(m,w),g.reflect(p).negate(),g.add(m),y.position.copy(M),y.up.set(0,1,0),y.up.applyMatrix4(h),y.up.reflect(p),y.lookAt(g),y.far=r.far,y.updateMatrixWorld(),y.projectionMatrix.copy(r.projectionMatrix),T.uniforms.virtualCameraNear.value=r.near,T.uniforms.virtualCameraFar.value=r.far,T.uniforms.virtualCameraMatrixWorld.value=y.matrixWorld,T.uniforms.virtualCameraProjectionMatrix.value=r.projectionMatrix,T.uniforms.virtualCameraProjectionMatrixInverse.value=r.projectionMatrixInverse,T.uniforms.resolution.value=n.resolution,b.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),b.multiply(y.projectionMatrix),b.multiply(y.matrixWorldInverse),b.multiply(n.matrixWorld),D.texture.encoding=t.outputEncoding;const a=t.getRenderTarget(),i=t.xr.enabled,o=t.shadowMap.autoUpdate,l=t.clippingPlanes;t.xr.enabled=!1,t.shadowMap.autoUpdate=!1,t.clippingPlanes=S,t.setRenderTarget(D),t.state.buffers.depth.setMask(!0),!1===t.autoClear&&t.clear(),t.render(e,y),t.xr.enabled=i,t.shadowMap.autoUpdate=o,t.clippingPlanes=l,t.setRenderTarget(a);const s=r.viewport;void 0!==s&&t.state.viewport(s)},this.getRenderTarget=function(){return D}}}e.prototype.isReflectorForSSRPass=!0,e.ReflectorShader={defines:{DISTANCE_ATTENUATION:!0,FRESNEL:!0},uniforms:{color:{value:null},tDiffuse:{value:null},tDepth:{value:null},textureMatrix:{value:new t.Matrix4},maxDistance:{value:180},opacity:{value:.5},fresnelCoe:{value:null},virtualCameraNear:{value:null},virtualCameraFar:{value:null},virtualCameraProjectionMatrix:{value:new t.Matrix4},virtualCameraMatrixWorld:{value:new t.Matrix4},virtualCameraProjectionMatrixInverse:{value:new t.Matrix4},resolution:{value:new t.Vector2}},vertexShader:"\n\t\tuniform mat4 textureMatrix;\n\t\tvarying vec4 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = textureMatrix * vec4( position, 1.0 );\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\t\tuniform vec3 color;\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform sampler2D tDepth;\n\t\tuniform float maxDistance;\n\t\tuniform float opacity;\n\t\tuniform float fresnelCoe;\n\t\tuniform float virtualCameraNear;\n\t\tuniform float virtualCameraFar;\n\t\tuniform mat4 virtualCameraProjectionMatrix;\n\t\tuniform mat4 virtualCameraProjectionMatrixInverse;\n\t\tuniform mat4 virtualCameraMatrixWorld;\n\t\tuniform vec2 resolution;\n\t\tvarying vec4 vUv;\n\t\t#include <packing>\n\t\tfloat blendOverlay( float base, float blend ) {\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\t\t}\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );\n\t\t}\n\t\tfloat getDepth( const in vec2 uv ) {\n\t\t\treturn texture2D( tDepth, uv ).x;\n\t\t}\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\treturn perspectiveDepthToViewZ( depth, virtualCameraNear, virtualCameraFar );\n\t\t}\n\t\tvec3 getViewPosition( const in vec2 uv, const in float depth/*clip space*/, const in float clipW ) {\n\t\t\tvec4 clipPosition = vec4( ( vec3( uv, depth ) - 0.5 ) * 2.0, 1.0 );//ndc\n\t\t\tclipPosition *= clipW; //clip\n\t\t\treturn ( virtualCameraProjectionMatrixInverse * clipPosition ).xyz;//view\n\t\t}\n\t\tvoid main() {\n\t\t\tvec4 base = texture2DProj( tDiffuse, vUv );\n\t\t\t#ifdef useDepthTexture\n\t\t\t\tvec2 uv=(gl_FragCoord.xy-.5)/resolution.xy;\n\t\t\t\tuv.x=1.-uv.x;\n\t\t\t\tfloat depth = texture2DProj( tDepth, vUv ).r;\n\t\t\t\tfloat viewZ = getViewZ( depth );\n\t\t\t\tfloat clipW = virtualCameraProjectionMatrix[2][3] * viewZ+virtualCameraProjectionMatrix[3][3];\n\t\t\t\tvec3 viewPosition=getViewPosition( uv, depth, clipW );\n\t\t\t\tvec3 worldPosition=(virtualCameraMatrixWorld*vec4(viewPosition,1)).xyz;\n\t\t\t\tif(worldPosition.y>maxDistance) discard;\n\t\t\t\tfloat op=opacity;\n\t\t\t\t#ifdef DISTANCE_ATTENUATION\n\t\t\t\t\tfloat ratio=1.-(worldPosition.y/maxDistance);\n\t\t\t\t\tfloat attenuation=ratio*ratio;\n\t\t\t\t\top=opacity*attenuation;\n\t\t\t\t#endif\n\t\t\t\t#ifdef FRESNEL\n\t\t\t\t\top*=fresnelCoe;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), op );\n\t\t\t#else\n\t\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\t\t\t#endif\n\t\t}\n\t"},exports.ReflectorForSSRPass=e;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(r,a={}){super(r),this.type="ReflectorForSSRPass";const n=this,i=void 0!==a.color?new t.Color(a.color):new t.Color(8355711),o=a.textureWidth||512,l=a.textureHeight||512,s=a.clipBias||0,u=a.shader||e.ReflectorShader,c=!0===a.useDepthTexture,d=new t.Vector3(0,1,0),v=new t.Vector3,f=new t.Vector3;n.needsUpdate=!1,n.maxDistance=e.ReflectorShader.uniforms.maxDistance.value,n.opacity=e.ReflectorShader.uniforms.opacity.value,n.color=i,n.resolution=a.resolution||new t.Vector2(window.innerWidth,window.innerHeight),n._distanceAttenuation=e.ReflectorShader.defines.DISTANCE_ATTENUATION,Object.defineProperty(n,"distanceAttenuation",{get:()=>n._distanceAttenuation,set(t){n._distanceAttenuation!==t&&(n._distanceAttenuation=t,n.material.defines.DISTANCE_ATTENUATION=t,n.material.needsUpdate=!0)}}),n._fresnel=e.ReflectorShader.defines.FRESNEL,Object.defineProperty(n,"fresnel",{get:()=>n._fresnel,set(t){n._fresnel!==t&&(n._fresnel=t,n.material.defines.FRESNEL=t,n.material.needsUpdate=!0)}});const p=new t.Vector3,m=new t.Vector3,x=new t.Vector3,h=new t.Matrix4,w=new t.Vector3(0,0,-1),g=new t.Vector3,M=new t.Vector3,b=new t.Matrix4,y=new t.PerspectiveCamera;let C;c&&(C=new t.DepthTexture,C.type=t.UnsignedShortType,C.minFilter=t.NearestFilter,C.magFilter=t.NearestFilter);const P={depthTexture:c?C:null},D=new t.WebGLRenderTarget(o,l,P),S=new t.ShaderMaterial({transparent:c,defines:Object.assign({},e.ReflectorShader.defines,{useDepthTexture:c}),uniforms:t.UniformsUtils.clone(u.uniforms),fragmentShader:u.fragmentShader,vertexShader:u.vertexShader});S.uniforms.tDiffuse.value=D.texture,S.uniforms.color.value=n.color,S.uniforms.textureMatrix.value=b,c&&(S.uniforms.tDepth.value=D.depthTexture),this.material=S;const T=[new t.Plane(new t.Vector3(0,1,0),s)];this.doRender=function(t,e,r){if(S.uniforms.maxDistance.value=n.maxDistance,S.uniforms.color.value=n.color,S.uniforms.opacity.value=n.opacity,v.copy(r.position).normalize(),f.copy(v).reflect(d),S.uniforms.fresnelCoe.value=(v.dot(f)+1)/2,m.setFromMatrixPosition(n.matrixWorld),x.setFromMatrixPosition(r.matrixWorld),h.extractRotation(n.matrixWorld),p.set(0,0,1),p.applyMatrix4(h),g.subVectors(m,x),g.dot(p)>0)return;g.reflect(p).negate(),g.add(m),h.extractRotation(r.matrixWorld),w.set(0,0,-1),w.applyMatrix4(h),w.add(x),M.subVectors(m,w),M.reflect(p).negate(),M.add(m),y.position.copy(g),y.up.set(0,1,0),y.up.applyMatrix4(h),y.up.reflect(p),y.lookAt(M),y.far=r.far,y.updateMatrixWorld(),y.projectionMatrix.copy(r.projectionMatrix),S.uniforms.virtualCameraNear.value=r.near,S.uniforms.virtualCameraFar.value=r.far,S.uniforms.virtualCameraMatrixWorld.value=y.matrixWorld,S.uniforms.virtualCameraProjectionMatrix.value=r.projectionMatrix,S.uniforms.virtualCameraProjectionMatrixInverse.value=r.projectionMatrixInverse,S.uniforms.resolution.value=n.resolution,b.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),b.multiply(y.projectionMatrix),b.multiply(y.matrixWorldInverse),b.multiply(n.matrixWorld),D.texture.encoding=t.outputEncoding;const a=t.getRenderTarget(),i=t.xr.enabled,o=t.shadowMap.autoUpdate,l=t.clippingPlanes;t.xr.enabled=!1,t.shadowMap.autoUpdate=!1,t.clippingPlanes=T,t.setRenderTarget(D),t.state.buffers.depth.setMask(!0),!1===t.autoClear&&t.clear(),t.render(e,y),t.xr.enabled=i,t.shadowMap.autoUpdate=o,t.clippingPlanes=l,t.setRenderTarget(a);const s=r.viewport;void 0!==s&&t.state.viewport(s)},this.getRenderTarget=function(){return D}}}e.prototype.isReflectorForSSRPass=!0,e.ReflectorShader={defines:{DISTANCE_ATTENUATION:!0,FRESNEL:!0},uniforms:{color:{value:null},tDiffuse:{value:null},tDepth:{value:null},textureMatrix:{value:new t.Matrix4},maxDistance:{value:180},opacity:{value:.5},fresnelCoe:{value:null},virtualCameraNear:{value:null},virtualCameraFar:{value:null},virtualCameraProjectionMatrix:{value:new t.Matrix4},virtualCameraMatrixWorld:{value:new t.Matrix4},virtualCameraProjectionMatrixInverse:{value:new t.Matrix4},resolution:{value:new t.Vector2}},vertexShader:"\n\t\tuniform mat4 textureMatrix;\n\t\tvarying vec4 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = textureMatrix * vec4( position, 1.0 );\n\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\t\tuniform vec3 color;\n\t\tuniform sampler2D tDiffuse;\n\t\tuniform sampler2D tDepth;\n\t\tuniform float maxDistance;\n\t\tuniform float opacity;\n\t\tuniform float fresnelCoe;\n\t\tuniform float virtualCameraNear;\n\t\tuniform float virtualCameraFar;\n\t\tuniform mat4 virtualCameraProjectionMatrix;\n\t\tuniform mat4 virtualCameraProjectionMatrixInverse;\n\t\tuniform mat4 virtualCameraMatrixWorld;\n\t\tuniform vec2 resolution;\n\t\tvarying vec4 vUv;\n\t\t#include <packing>\n\t\tfloat blendOverlay( float base, float blend ) {\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\t\t}\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );\n\t\t}\n\t\tfloat getDepth( const in vec2 uv ) {\n\t\t\treturn texture2D( tDepth, uv ).x;\n\t\t}\n\t\tfloat getViewZ( const in float depth ) {\n\t\t\treturn perspectiveDepthToViewZ( depth, virtualCameraNear, virtualCameraFar );\n\t\t}\n\t\tvec3 getViewPosition( const in vec2 uv, const in float depth/*clip space*/, const in float clipW ) {\n\t\t\tvec4 clipPosition = vec4( ( vec3( uv, depth ) - 0.5 ) * 2.0, 1.0 );//ndc\n\t\t\tclipPosition *= clipW; //clip\n\t\t\treturn ( virtualCameraProjectionMatrixInverse * clipPosition ).xyz;//view\n\t\t}\n\t\tvoid main() {\n\t\t\tvec4 base = texture2DProj( tDiffuse, vUv );\n\t\t\t#ifdef useDepthTexture\n\t\t\t\tvec2 uv=(gl_FragCoord.xy-.5)/resolution.xy;\n\t\t\t\tuv.x=1.-uv.x;\n\t\t\t\tfloat depth = texture2DProj( tDepth, vUv ).r;\n\t\t\t\tfloat viewZ = getViewZ( depth );\n\t\t\t\tfloat clipW = virtualCameraProjectionMatrix[2][3] * viewZ+virtualCameraProjectionMatrix[3][3];\n\t\t\t\tvec3 viewPosition=getViewPosition( uv, depth, clipW );\n\t\t\t\tvec3 worldPosition=(virtualCameraMatrixWorld*vec4(viewPosition,1)).xyz;\n\t\t\t\tif(worldPosition.y>maxDistance) discard;\n\t\t\t\tfloat op=opacity;\n\t\t\t\t#ifdef DISTANCE_ATTENUATION\n\t\t\t\t\tfloat ratio=1.-(worldPosition.y/maxDistance);\n\t\t\t\t\tfloat attenuation=ratio*ratio;\n\t\t\t\t\top=opacity*attenuation;\n\t\t\t\t#endif\n\t\t\t\t#ifdef FRESNEL\n\t\t\t\t\top*=fresnelCoe;\n\t\t\t\t#endif\n\t\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), op );\n\t\t\t#else\n\t\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\t\t\t#endif\n\t\t}\n\t"},exports.ReflectorForSSRPass=e;
@@ -1,4 +1,4 @@
1
- import { Mesh, Color, Vector3, Vector2, Matrix4, PerspectiveCamera, DepthTexture, UnsignedShortType, NearestFilter, WebGLRenderTarget, MathUtils, ShaderMaterial, UniformsUtils, Plane, LinearFilter, RGBFormat } from 'three';
1
+ import { Mesh, Color, Vector3, Vector2, Matrix4, PerspectiveCamera, DepthTexture, UnsignedShortType, NearestFilter, WebGLRenderTarget, ShaderMaterial, UniformsUtils, Plane } from 'three';
2
2
 
3
3
  class ReflectorForSSRPass extends Mesh {
4
4
  constructor(geometry, options = {}) {
@@ -67,17 +67,9 @@ class ReflectorForSSRPass extends Mesh {
67
67
  }
68
68
 
69
69
  const parameters = {
70
- minFilter: LinearFilter,
71
- magFilter: LinearFilter,
72
- format: RGBFormat,
73
70
  depthTexture: useDepthTexture ? depthTexture : null
74
71
  };
75
72
  const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, parameters);
76
-
77
- if (!MathUtils.isPowerOfTwo(textureWidth) || !MathUtils.isPowerOfTwo(textureHeight)) {
78
- renderTarget.texture.generateMipmaps = false;
79
- }
80
-
81
73
  const material = new ShaderMaterial({
82
74
  transparent: useDepthTexture,
83
75
  defines: Object.assign({}, ReflectorForSSRPass.ReflectorShader.defines, {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Mesh{constructor(r,n={}){super(r),this.type="Refractor";const a=this,o=void 0!==n.color?new e.Color(n.color):new e.Color(8355711),i=n.textureWidth||512,l=n.textureHeight||512,s=n.clipBias||0,c=n.shader||t.RefractorShader,u=new e.PerspectiveCamera;u.matrixAutoUpdate=!1,u.userData.refractor=!0;const d=new e.Plane,m=new e.Matrix4,x={minFilter:e.LinearFilter,magFilter:e.LinearFilter,format:e.RGBFormat},v=new e.WebGLRenderTarget(i,l,x);e.MathUtils.isPowerOfTwo(i)&&e.MathUtils.isPowerOfTwo(l)||(v.texture.generateMipmaps=!1),this.material=new e.ShaderMaterial({uniforms:e.UniformsUtils.clone(c.uniforms),vertexShader:c.vertexShader,fragmentShader:c.fragmentShader,transparent:!0}),this.material.uniforms.color.value=o,this.material.uniforms.tDiffuse.value=v.texture,this.material.uniforms.textureMatrix.value=m;const f=function(){const t=new e.Vector3,r=new e.Vector3,n=new e.Matrix4,o=new e.Vector3,i=new e.Vector3;return function(e){return t.setFromMatrixPosition(a.matrixWorld),r.setFromMatrixPosition(e.matrixWorld),o.subVectors(t,r),n.extractRotation(a.matrixWorld),i.set(0,0,1),i.applyMatrix4(n),o.dot(i)<0}}(),p=function(){const t=new e.Vector3,r=new e.Vector3,n=new e.Quaternion,o=new e.Vector3;return function(){a.matrixWorld.decompose(r,n,o),t.set(0,0,1).applyQuaternion(n).normalize(),t.negate(),d.setFromNormalAndCoplanarPoint(t,r)}}(),b=function(){const t=new e.Plane,r=new e.Vector4,n=new e.Vector4;return function(e){u.matrixWorld.copy(e.matrixWorld),u.matrixWorldInverse.copy(u.matrixWorld).invert(),u.projectionMatrix.copy(e.projectionMatrix),u.far=e.far,t.copy(d),t.applyMatrix4(u.matrixWorldInverse),r.set(t.normal.x,t.normal.y,t.normal.z,t.constant);const a=u.projectionMatrix;n.x=(Math.sign(r.x)+a.elements[8])/a.elements[0],n.y=(Math.sign(r.y)+a.elements[9])/a.elements[5],n.z=-1,n.w=(1+a.elements[10])/a.elements[14],r.multiplyScalar(2/r.dot(n)),a.elements[2]=r.x,a.elements[6]=r.y,a.elements[10]=r.z+1-s,a.elements[14]=r.w}}();this.onBeforeRender=function(e,t,r){v.texture.encoding=e.outputEncoding,!0!==r.userData.refractor&&!0!=!f(r)&&(p(),function(e){m.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),m.multiply(e.projectionMatrix),m.multiply(e.matrixWorldInverse),m.multiply(a.matrixWorld)}(r),b(r),function(e,t,r){a.visible=!1;const n=e.getRenderTarget(),o=e.xr.enabled,i=e.shadowMap.autoUpdate;e.xr.enabled=!1,e.shadowMap.autoUpdate=!1,e.setRenderTarget(v),!1===e.autoClear&&e.clear(),e.render(t,u),e.xr.enabled=o,e.shadowMap.autoUpdate=i,e.setRenderTarget(n);const l=r.viewport;void 0!==l&&e.state.viewport(l),a.visible=!0}(e,t,r))},this.getRenderTarget=function(){return v}}}t.prototype.isRefractor=!0,t.RefractorShader={uniforms:{color:{value:null},tDiffuse:{value:null},textureMatrix:{value:null}},vertexShader:"\n\n\t\tuniform mat4 textureMatrix;\n\n\t\tvarying vec4 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = textureMatrix * vec4( position, 1.0 );\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform vec3 color;\n\t\tuniform sampler2D tDiffuse;\n\n\t\tvarying vec4 vUv;\n\n\t\tfloat blendOverlay( float base, float blend ) {\n\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\n\t\t}\n\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvec4 base = texture2DProj( tDiffuse, vUv );\n\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\n\t\t}"},exports.Refractor=t;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.Mesh{constructor(r,n={}){super(r),this.type="Refractor";const o=this,a=void 0!==n.color?new e.Color(n.color):new e.Color(8355711),i=n.textureWidth||512,l=n.textureHeight||512,s=n.clipBias||0,c=n.shader||t.RefractorShader,u=new e.PerspectiveCamera;u.matrixAutoUpdate=!1,u.userData.refractor=!0;const d=new e.Plane,m=new e.Matrix4,v=new e.WebGLRenderTarget(i,l);this.material=new e.ShaderMaterial({uniforms:e.UniformsUtils.clone(c.uniforms),vertexShader:c.vertexShader,fragmentShader:c.fragmentShader,transparent:!0}),this.material.uniforms.color.value=a,this.material.uniforms.tDiffuse.value=v.texture,this.material.uniforms.textureMatrix.value=m;const x=function(){const t=new e.Vector3,r=new e.Vector3,n=new e.Matrix4,a=new e.Vector3,i=new e.Vector3;return function(e){return t.setFromMatrixPosition(o.matrixWorld),r.setFromMatrixPosition(e.matrixWorld),a.subVectors(t,r),n.extractRotation(o.matrixWorld),i.set(0,0,1),i.applyMatrix4(n),a.dot(i)<0}}(),p=function(){const t=new e.Vector3,r=new e.Vector3,n=new e.Quaternion,a=new e.Vector3;return function(){o.matrixWorld.decompose(r,n,a),t.set(0,0,1).applyQuaternion(n).normalize(),t.negate(),d.setFromNormalAndCoplanarPoint(t,r)}}(),f=function(){const t=new e.Plane,r=new e.Vector4,n=new e.Vector4;return function(e){u.matrixWorld.copy(e.matrixWorld),u.matrixWorldInverse.copy(u.matrixWorld).invert(),u.projectionMatrix.copy(e.projectionMatrix),u.far=e.far,t.copy(d),t.applyMatrix4(u.matrixWorldInverse),r.set(t.normal.x,t.normal.y,t.normal.z,t.constant);const o=u.projectionMatrix;n.x=(Math.sign(r.x)+o.elements[8])/o.elements[0],n.y=(Math.sign(r.y)+o.elements[9])/o.elements[5],n.z=-1,n.w=(1+o.elements[10])/o.elements[14],r.multiplyScalar(2/r.dot(n)),o.elements[2]=r.x,o.elements[6]=r.y,o.elements[10]=r.z+1-s,o.elements[14]=r.w}}();this.onBeforeRender=function(e,t,r){v.texture.encoding=e.outputEncoding,!0!==r.userData.refractor&&!0!=!x(r)&&(p(),function(e){m.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),m.multiply(e.projectionMatrix),m.multiply(e.matrixWorldInverse),m.multiply(o.matrixWorld)}(r),f(r),function(e,t,r){o.visible=!1;const n=e.getRenderTarget(),a=e.xr.enabled,i=e.shadowMap.autoUpdate;e.xr.enabled=!1,e.shadowMap.autoUpdate=!1,e.setRenderTarget(v),!1===e.autoClear&&e.clear(),e.render(t,u),e.xr.enabled=a,e.shadowMap.autoUpdate=i,e.setRenderTarget(n);const l=r.viewport;void 0!==l&&e.state.viewport(l),o.visible=!0}(e,t,r))},this.getRenderTarget=function(){return v},this.dispose=function(){v.dispose(),o.material.dispose()}}}t.prototype.isRefractor=!0,t.RefractorShader={uniforms:{color:{value:null},tDiffuse:{value:null},textureMatrix:{value:null}},vertexShader:"\n\n\t\tuniform mat4 textureMatrix;\n\n\t\tvarying vec4 vUv;\n\n\t\tvoid main() {\n\n\t\t\tvUv = textureMatrix * vec4( position, 1.0 );\n\t\t\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\n\t\t}",fragmentShader:"\n\n\t\tuniform vec3 color;\n\t\tuniform sampler2D tDiffuse;\n\n\t\tvarying vec4 vUv;\n\n\t\tfloat blendOverlay( float base, float blend ) {\n\n\t\t\treturn( base < 0.5 ? ( 2.0 * base * blend ) : ( 1.0 - 2.0 * ( 1.0 - base ) * ( 1.0 - blend ) ) );\n\n\t\t}\n\n\t\tvec3 blendOverlay( vec3 base, vec3 blend ) {\n\n\t\t\treturn vec3( blendOverlay( base.r, blend.r ), blendOverlay( base.g, blend.g ), blendOverlay( base.b, blend.b ) );\n\n\t\t}\n\n\t\tvoid main() {\n\n\t\t\tvec4 base = texture2DProj( tDiffuse, vUv );\n\t\t\tgl_FragColor = vec4( blendOverlay( base.rgb, color ), 1.0 );\n\n\t\t}"},exports.Refractor=t;
@@ -1,4 +1,4 @@
1
- import { Mesh, Color, PerspectiveCamera, Plane, Matrix4, WebGLRenderTarget, MathUtils, ShaderMaterial, UniformsUtils, Vector3, Quaternion, Vector4, LinearFilter, RGBFormat } from 'three';
1
+ import { Mesh, Color, PerspectiveCamera, Plane, Matrix4, WebGLRenderTarget, ShaderMaterial, UniformsUtils, Vector3, Quaternion, Vector4 } from 'three';
2
2
 
3
3
  class Refractor extends Mesh {
4
4
  constructor(geometry, options = {}) {
@@ -18,17 +18,7 @@ class Refractor extends Mesh {
18
18
  const refractorPlane = new Plane();
19
19
  const textureMatrix = new Matrix4(); // render target
20
20
 
21
- const parameters = {
22
- minFilter: LinearFilter,
23
- magFilter: LinearFilter,
24
- format: RGBFormat
25
- };
26
- const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, parameters);
27
-
28
- if (!MathUtils.isPowerOfTwo(textureWidth) || !MathUtils.isPowerOfTwo(textureHeight)) {
29
- renderTarget.texture.generateMipmaps = false;
30
- } // material
31
-
21
+ const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight); // material
32
22
 
33
23
  this.material = new ShaderMaterial({
34
24
  uniforms: UniformsUtils.clone(shader.uniforms),
@@ -162,6 +152,11 @@ class Refractor extends Mesh {
162
152
  this.getRenderTarget = function () {
163
153
  return renderTarget;
164
154
  };
155
+
156
+ this.dispose = function () {
157
+ renderTarget.dispose();
158
+ scope.material.dispose();
159
+ };
165
160
  }
166
161
 
167
162
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(e,r={}){super(e);const o=this,n=void 0!==r.textureWidth?r.textureWidth:512,i=void 0!==r.textureHeight?r.textureHeight:512,a=void 0!==r.clipBias?r.clipBias:0,l=void 0!==r.alpha?r.alpha:1,s=void 0!==r.time?r.time:0,u=void 0!==r.waterNormals?r.waterNormals:null,c=void 0!==r.sunDirection?r.sunDirection:new t.Vector3(.70707,.70707,0),m=new t.Color(void 0!==r.sunColor?r.sunColor:16777215),d=new t.Color(void 0!==r.waterColor?r.waterColor:8355711),v=void 0!==r.eye?r.eye:new t.Vector3(0,0,0),f=void 0!==r.distortionScale?r.distortionScale:20,p=void 0!==r.side?r.side:t.FrontSide,x=void 0!==r.fog&&r.fog,g=void 0!==r.format?r.format:t.RGBFormat,w=new t.Plane,h=new t.Vector3,y=new t.Vector3,M=new t.Vector3,C=new t.Matrix4,S=new t.Vector3(0,0,-1),_=new t.Vector4,b=new t.Vector3,D=new t.Vector3,P=new t.Vector4,L=new t.Matrix4,V=new t.PerspectiveCamera,z={minFilter:t.LinearFilter,magFilter:t.LinearFilter,format:g},N=new t.WebGLRenderTarget(n,i,z);t.MathUtils.isPowerOfTwo(n)&&t.MathUtils.isPowerOfTwo(i)||(N.texture.generateMipmaps=!1);const W={uniforms:t.UniformsUtils.merge([t.UniformsLib.fog,t.UniformsLib.lights,{normalSampler:{value:null},mirrorSampler:{value:null},alpha:{value:1},time:{value:0},size:{value:1},distortionScale:{value:20},textureMatrix:{value:new t.Matrix4},sunColor:{value:new t.Color(8355711)},sunDirection:{value:new t.Vector3(.70707,.70707,0)},eye:{value:new t.Vector3},waterColor:{value:new t.Color(5592405)}}]),vertexShader:"\n\t\t\t\tuniform mat4 textureMatrix;\n\t\t\t\tuniform float time;\n\n\t\t\t\tvarying vec4 mirrorCoord;\n\t\t\t\tvarying vec4 worldPosition;\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <shadowmap_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\n\t\t\t\tvoid main() {\n\t\t\t\t\tmirrorCoord = modelMatrix * vec4( position, 1.0 );\n\t\t\t\t\tworldPosition = mirrorCoord.xyzw;\n\t\t\t\t\tmirrorCoord = textureMatrix * mirrorCoord;\n\t\t\t\t\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\t\t\t\t\tgl_Position = projectionMatrix * mvPosition;\n\n\t\t\t\t#include <beginnormal_vertex>\n\t\t\t\t#include <defaultnormal_vertex>\n\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t#include <fog_vertex>\n\t\t\t\t#include <shadowmap_vertex>\n\t\t\t}",fragmentShader:"\n\t\t\t\tuniform sampler2D mirrorSampler;\n\t\t\t\tuniform float alpha;\n\t\t\t\tuniform float time;\n\t\t\t\tuniform float size;\n\t\t\t\tuniform float distortionScale;\n\t\t\t\tuniform sampler2D normalSampler;\n\t\t\t\tuniform vec3 sunColor;\n\t\t\t\tuniform vec3 sunDirection;\n\t\t\t\tuniform vec3 eye;\n\t\t\t\tuniform vec3 waterColor;\n\n\t\t\t\tvarying vec4 mirrorCoord;\n\t\t\t\tvarying vec4 worldPosition;\n\n\t\t\t\tvec4 getNoise( vec2 uv ) {\n\t\t\t\t\tvec2 uv0 = ( uv / 103.0 ) + vec2(time / 17.0, time / 29.0);\n\t\t\t\t\tvec2 uv1 = uv / 107.0-vec2( time / -19.0, time / 31.0 );\n\t\t\t\t\tvec2 uv2 = uv / vec2( 8907.0, 9803.0 ) + vec2( time / 101.0, time / 97.0 );\n\t\t\t\t\tvec2 uv3 = uv / vec2( 1091.0, 1027.0 ) - vec2( time / 109.0, time / -113.0 );\n\t\t\t\t\tvec4 noise = texture2D( normalSampler, uv0 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv1 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv2 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv3 );\n\t\t\t\t\treturn noise * 0.5 - 1.0;\n\t\t\t\t}\n\n\t\t\t\tvoid sunLight( const vec3 surfaceNormal, const vec3 eyeDirection, float shiny, float spec, float diffuse, inout vec3 diffuseColor, inout vec3 specularColor ) {\n\t\t\t\t\tvec3 reflection = normalize( reflect( -sunDirection, surfaceNormal ) );\n\t\t\t\t\tfloat direction = max( 0.0, dot( eyeDirection, reflection ) );\n\t\t\t\t\tspecularColor += pow( direction, shiny ) * sunColor * spec;\n\t\t\t\t\tdiffuseColor += max( dot( sunDirection, surfaceNormal ), 0.0 ) * sunColor * diffuse;\n\t\t\t\t}\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <packing>\n\t\t\t\t#include <bsdfs>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <lights_pars_begin>\n\t\t\t\t#include <shadowmap_pars_fragment>\n\t\t\t\t#include <shadowmask_pars_fragment>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\t\t\t\t\tvec4 noise = getNoise( worldPosition.xz * size );\n\t\t\t\t\tvec3 surfaceNormal = normalize( noise.xzy * vec3( 1.5, 1.0, 1.5 ) );\n\n\t\t\t\t\tvec3 diffuseLight = vec3(0.0);\n\t\t\t\t\tvec3 specularLight = vec3(0.0);\n\n\t\t\t\t\tvec3 worldToEye = eye-worldPosition.xyz;\n\t\t\t\t\tvec3 eyeDirection = normalize( worldToEye );\n\t\t\t\t\tsunLight( surfaceNormal, eyeDirection, 100.0, 2.0, 0.5, diffuseLight, specularLight );\n\n\t\t\t\t\tfloat distance = length(worldToEye);\n\n\t\t\t\t\tvec2 distortion = surfaceNormal.xz * ( 0.001 + 1.0 / distance ) * distortionScale;\n\t\t\t\t\tvec3 reflectionSample = vec3( texture2D( mirrorSampler, mirrorCoord.xy / mirrorCoord.w + distortion ) );\n\n\t\t\t\t\tfloat theta = max( dot( eyeDirection, surfaceNormal ), 0.0 );\n\t\t\t\t\tfloat rf0 = 0.3;\n\t\t\t\t\tfloat reflectance = rf0 + ( 1.0 - rf0 ) * pow( ( 1.0 - theta ), 5.0 );\n\t\t\t\t\tvec3 scatter = max( 0.0, dot( surfaceNormal, eyeDirection ) ) * waterColor;\n\t\t\t\t\tvec3 albedo = mix( ( sunColor * diffuseLight * 0.3 + scatter ) * getShadowMask(), ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance);\n\t\t\t\t\tvec3 outgoingLight = albedo;\n\t\t\t\t\tgl_FragColor = vec4( outgoingLight, alpha );\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t}"},F=new t.ShaderMaterial({fragmentShader:W.fragmentShader,vertexShader:W.vertexShader,uniforms:t.UniformsUtils.clone(W.uniforms),lights:!0,side:p,fog:x});F.uniforms.mirrorSampler.value=N.texture,F.uniforms.textureMatrix.value=L,F.uniforms.alpha.value=l,F.uniforms.time.value=s,F.uniforms.normalSampler.value=u,F.uniforms.sunColor.value=m,F.uniforms.waterColor.value=d,F.uniforms.sunDirection.value=c,F.uniforms.distortionScale.value=f,F.uniforms.eye.value=v,o.material=F,o.onBeforeRender=function(t,e,r){if(y.setFromMatrixPosition(o.matrixWorld),M.setFromMatrixPosition(r.matrixWorld),C.extractRotation(o.matrixWorld),h.set(0,0,1),h.applyMatrix4(C),b.subVectors(y,M),b.dot(h)>0)return;b.reflect(h).negate(),b.add(y),C.extractRotation(r.matrixWorld),S.set(0,0,-1),S.applyMatrix4(C),S.add(M),D.subVectors(y,S),D.reflect(h).negate(),D.add(y),V.position.copy(b),V.up.set(0,1,0),V.up.applyMatrix4(C),V.up.reflect(h),V.lookAt(D),V.far=r.far,V.updateMatrixWorld(),V.projectionMatrix.copy(r.projectionMatrix),L.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),L.multiply(V.projectionMatrix),L.multiply(V.matrixWorldInverse),w.setFromNormalAndCoplanarPoint(h,y),w.applyMatrix4(V.matrixWorldInverse),_.set(w.normal.x,w.normal.y,w.normal.z,w.constant);const n=V.projectionMatrix;P.x=(Math.sign(_.x)+n.elements[8])/n.elements[0],P.y=(Math.sign(_.y)+n.elements[9])/n.elements[5],P.z=-1,P.w=(1+n.elements[10])/n.elements[14],_.multiplyScalar(2/_.dot(P)),n.elements[2]=_.x,n.elements[6]=_.y,n.elements[10]=_.z+1-a,n.elements[14]=_.w,v.setFromMatrixPosition(r.matrixWorld);const i=t.getRenderTarget(),l=t.xr.enabled,s=t.shadowMap.autoUpdate;o.visible=!1,t.xr.enabled=!1,t.shadowMap.autoUpdate=!1,t.setRenderTarget(N),t.state.buffers.depth.setMask(!0),!1===t.autoClear&&t.clear(),t.render(e,V),o.visible=!0,t.xr.enabled=l,t.shadowMap.autoUpdate=s,t.setRenderTarget(i);const u=r.viewport;void 0!==u&&t.state.viewport(u)}}}e.prototype.isWater=!0,exports.Water=e;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three");class e extends t.Mesh{constructor(e,r={}){super(e);const o=this,n=void 0!==r.textureWidth?r.textureWidth:512,i=void 0!==r.textureHeight?r.textureHeight:512,a=void 0!==r.clipBias?r.clipBias:0,l=void 0!==r.alpha?r.alpha:1,s=void 0!==r.time?r.time:0,u=void 0!==r.waterNormals?r.waterNormals:null,c=void 0!==r.sunDirection?r.sunDirection:new t.Vector3(.70707,.70707,0),m=new t.Color(void 0!==r.sunColor?r.sunColor:16777215),d=new t.Color(void 0!==r.waterColor?r.waterColor:8355711),v=void 0!==r.eye?r.eye:new t.Vector3(0,0,0),f=void 0!==r.distortionScale?r.distortionScale:20,p=void 0!==r.side?r.side:t.FrontSide,x=void 0!==r.fog&&r.fog,g=new t.Plane,w=new t.Vector3,h=new t.Vector3,y=new t.Vector3,C=new t.Matrix4,M=new t.Vector3(0,0,-1),S=new t.Vector4,_=new t.Vector3,b=new t.Vector3,D=new t.Vector4,P=new t.Matrix4,V=new t.PerspectiveCamera,z=new t.WebGLRenderTarget(n,i),L={uniforms:t.UniformsUtils.merge([t.UniformsLib.fog,t.UniformsLib.lights,{normalSampler:{value:null},mirrorSampler:{value:null},alpha:{value:1},time:{value:0},size:{value:1},distortionScale:{value:20},textureMatrix:{value:new t.Matrix4},sunColor:{value:new t.Color(8355711)},sunDirection:{value:new t.Vector3(.70707,.70707,0)},eye:{value:new t.Vector3},waterColor:{value:new t.Color(5592405)}}]),vertexShader:"\n\t\t\t\tuniform mat4 textureMatrix;\n\t\t\t\tuniform float time;\n\n\t\t\t\tvarying vec4 mirrorCoord;\n\t\t\t\tvarying vec4 worldPosition;\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <shadowmap_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\n\t\t\t\tvoid main() {\n\t\t\t\t\tmirrorCoord = modelMatrix * vec4( position, 1.0 );\n\t\t\t\t\tworldPosition = mirrorCoord.xyzw;\n\t\t\t\t\tmirrorCoord = textureMatrix * mirrorCoord;\n\t\t\t\t\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\t\t\t\t\tgl_Position = projectionMatrix * mvPosition;\n\n\t\t\t\t#include <beginnormal_vertex>\n\t\t\t\t#include <defaultnormal_vertex>\n\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t#include <fog_vertex>\n\t\t\t\t#include <shadowmap_vertex>\n\t\t\t}",fragmentShader:"\n\t\t\t\tuniform sampler2D mirrorSampler;\n\t\t\t\tuniform float alpha;\n\t\t\t\tuniform float time;\n\t\t\t\tuniform float size;\n\t\t\t\tuniform float distortionScale;\n\t\t\t\tuniform sampler2D normalSampler;\n\t\t\t\tuniform vec3 sunColor;\n\t\t\t\tuniform vec3 sunDirection;\n\t\t\t\tuniform vec3 eye;\n\t\t\t\tuniform vec3 waterColor;\n\n\t\t\t\tvarying vec4 mirrorCoord;\n\t\t\t\tvarying vec4 worldPosition;\n\n\t\t\t\tvec4 getNoise( vec2 uv ) {\n\t\t\t\t\tvec2 uv0 = ( uv / 103.0 ) + vec2(time / 17.0, time / 29.0);\n\t\t\t\t\tvec2 uv1 = uv / 107.0-vec2( time / -19.0, time / 31.0 );\n\t\t\t\t\tvec2 uv2 = uv / vec2( 8907.0, 9803.0 ) + vec2( time / 101.0, time / 97.0 );\n\t\t\t\t\tvec2 uv3 = uv / vec2( 1091.0, 1027.0 ) - vec2( time / 109.0, time / -113.0 );\n\t\t\t\t\tvec4 noise = texture2D( normalSampler, uv0 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv1 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv2 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv3 );\n\t\t\t\t\treturn noise * 0.5 - 1.0;\n\t\t\t\t}\n\n\t\t\t\tvoid sunLight( const vec3 surfaceNormal, const vec3 eyeDirection, float shiny, float spec, float diffuse, inout vec3 diffuseColor, inout vec3 specularColor ) {\n\t\t\t\t\tvec3 reflection = normalize( reflect( -sunDirection, surfaceNormal ) );\n\t\t\t\t\tfloat direction = max( 0.0, dot( eyeDirection, reflection ) );\n\t\t\t\t\tspecularColor += pow( direction, shiny ) * sunColor * spec;\n\t\t\t\t\tdiffuseColor += max( dot( sunDirection, surfaceNormal ), 0.0 ) * sunColor * diffuse;\n\t\t\t\t}\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <packing>\n\t\t\t\t#include <bsdfs>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <lights_pars_begin>\n\t\t\t\t#include <shadowmap_pars_fragment>\n\t\t\t\t#include <shadowmask_pars_fragment>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\t\t\t\t\tvec4 noise = getNoise( worldPosition.xz * size );\n\t\t\t\t\tvec3 surfaceNormal = normalize( noise.xzy * vec3( 1.5, 1.0, 1.5 ) );\n\n\t\t\t\t\tvec3 diffuseLight = vec3(0.0);\n\t\t\t\t\tvec3 specularLight = vec3(0.0);\n\n\t\t\t\t\tvec3 worldToEye = eye-worldPosition.xyz;\n\t\t\t\t\tvec3 eyeDirection = normalize( worldToEye );\n\t\t\t\t\tsunLight( surfaceNormal, eyeDirection, 100.0, 2.0, 0.5, diffuseLight, specularLight );\n\n\t\t\t\t\tfloat distance = length(worldToEye);\n\n\t\t\t\t\tvec2 distortion = surfaceNormal.xz * ( 0.001 + 1.0 / distance ) * distortionScale;\n\t\t\t\t\tvec3 reflectionSample = vec3( texture2D( mirrorSampler, mirrorCoord.xy / mirrorCoord.w + distortion ) );\n\n\t\t\t\t\tfloat theta = max( dot( eyeDirection, surfaceNormal ), 0.0 );\n\t\t\t\t\tfloat rf0 = 0.3;\n\t\t\t\t\tfloat reflectance = rf0 + ( 1.0 - rf0 ) * pow( ( 1.0 - theta ), 5.0 );\n\t\t\t\t\tvec3 scatter = max( 0.0, dot( surfaceNormal, eyeDirection ) ) * waterColor;\n\t\t\t\t\tvec3 albedo = mix( ( sunColor * diffuseLight * 0.3 + scatter ) * getShadowMask(), ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance);\n\t\t\t\t\tvec3 outgoingLight = albedo;\n\t\t\t\t\tgl_FragColor = vec4( outgoingLight, alpha );\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t}"},N=new t.ShaderMaterial({fragmentShader:L.fragmentShader,vertexShader:L.vertexShader,uniforms:t.UniformsUtils.clone(L.uniforms),lights:!0,side:p,fog:x});N.uniforms.mirrorSampler.value=z.texture,N.uniforms.textureMatrix.value=P,N.uniforms.alpha.value=l,N.uniforms.time.value=s,N.uniforms.normalSampler.value=u,N.uniforms.sunColor.value=m,N.uniforms.waterColor.value=d,N.uniforms.sunDirection.value=c,N.uniforms.distortionScale.value=f,N.uniforms.eye.value=v,o.material=N,o.onBeforeRender=function(t,e,r){if(h.setFromMatrixPosition(o.matrixWorld),y.setFromMatrixPosition(r.matrixWorld),C.extractRotation(o.matrixWorld),w.set(0,0,1),w.applyMatrix4(C),_.subVectors(h,y),_.dot(w)>0)return;_.reflect(w).negate(),_.add(h),C.extractRotation(r.matrixWorld),M.set(0,0,-1),M.applyMatrix4(C),M.add(y),b.subVectors(h,M),b.reflect(w).negate(),b.add(h),V.position.copy(_),V.up.set(0,1,0),V.up.applyMatrix4(C),V.up.reflect(w),V.lookAt(b),V.far=r.far,V.updateMatrixWorld(),V.projectionMatrix.copy(r.projectionMatrix),P.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),P.multiply(V.projectionMatrix),P.multiply(V.matrixWorldInverse),g.setFromNormalAndCoplanarPoint(w,h),g.applyMatrix4(V.matrixWorldInverse),S.set(g.normal.x,g.normal.y,g.normal.z,g.constant);const n=V.projectionMatrix;D.x=(Math.sign(S.x)+n.elements[8])/n.elements[0],D.y=(Math.sign(S.y)+n.elements[9])/n.elements[5],D.z=-1,D.w=(1+n.elements[10])/n.elements[14],S.multiplyScalar(2/S.dot(D)),n.elements[2]=S.x,n.elements[6]=S.y,n.elements[10]=S.z+1-a,n.elements[14]=S.w,v.setFromMatrixPosition(r.matrixWorld);const i=t.getRenderTarget(),l=t.xr.enabled,s=t.shadowMap.autoUpdate;o.visible=!1,t.xr.enabled=!1,t.shadowMap.autoUpdate=!1,t.setRenderTarget(z),t.state.buffers.depth.setMask(!0),!1===t.autoClear&&t.clear(),t.render(e,V),o.visible=!0,t.xr.enabled=l,t.shadowMap.autoUpdate=s,t.setRenderTarget(i);const u=r.viewport;void 0!==u&&t.state.viewport(u)}}}e.prototype.isWater=!0,exports.Water=e;
package/objects/Water.js CHANGED
@@ -1,9 +1,9 @@
1
- import { Mesh, Vector3, Color, FrontSide, RGBFormat, Plane, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, MathUtils, UniformsUtils, UniformsLib, ShaderMaterial, LinearFilter } from 'three';
1
+ import { Mesh, Vector3, Color, FrontSide, Plane, Matrix4, Vector4, PerspectiveCamera, WebGLRenderTarget, UniformsUtils, UniformsLib, ShaderMaterial } from 'three';
2
2
 
3
3
  /**
4
4
  * Work based on :
5
- * http://slayvin.net : Flat mirror for three.js
6
- * http://www.adelphi.edu/~stemkoski : An implementation of water shader based on the flat mirror
5
+ * https://github.com/Slayvin: Flat mirror for three.js
6
+ * https://home.adelphi.edu/~stemkoski/ : An implementation of water shader based on the flat mirror
7
7
  * http://29a.ch/ && http://29a.ch/slides/2012/webglwater/ : Water shader explanations in WebGL
8
8
  */
9
9
 
@@ -23,8 +23,7 @@ class Water extends Mesh {
23
23
  const eye = options.eye !== undefined ? options.eye : new Vector3(0, 0, 0);
24
24
  const distortionScale = options.distortionScale !== undefined ? options.distortionScale : 20.0;
25
25
  const side = options.side !== undefined ? options.side : FrontSide;
26
- const fog = options.fog !== undefined ? options.fog : false;
27
- const format = options.format !== undefined ? options.format : RGBFormat; //
26
+ const fog = options.fog !== undefined ? options.fog : false; //
28
27
 
29
28
  const mirrorPlane = new Plane();
30
29
  const normal = new Vector3();
@@ -38,17 +37,7 @@ class Water extends Mesh {
38
37
  const q = new Vector4();
39
38
  const textureMatrix = new Matrix4();
40
39
  const mirrorCamera = new PerspectiveCamera();
41
- const parameters = {
42
- minFilter: LinearFilter,
43
- magFilter: LinearFilter,
44
- format
45
- };
46
- const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight, parameters);
47
-
48
- if (!MathUtils.isPowerOfTwo(textureWidth) || !MathUtils.isPowerOfTwo(textureHeight)) {
49
- renderTarget.texture.generateMipmaps = false;
50
- }
51
-
40
+ const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight);
52
41
  const mirrorShader = {
53
42
  uniforms: UniformsUtils.merge([UniformsLib['fog'], UniformsLib['lights'], {
54
43
  normalSampler: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "three-stdlib",
3
- "version": "2.8.0",
3
+ "version": "2.8.1",
4
4
  "private": false,
5
5
  "description": "stand-alone library of threejs examples",
6
6
  "main": "index.cjs.js",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three"),e=require("./Pass.cjs.js"),r=require("../shaders/DigitalGlitch.cjs.js");require("@babel/runtime/helpers/defineProperty");var i=function(i){void 0===r.DigitalGlitch&&console.error("THREE.GlitchPass relies on DigitalGlitch");var a=r.DigitalGlitch;this.uniforms=t.UniformsUtils.clone(a.uniforms),null==i&&(i=64),this.uniforms.tDisp.value=this.generateHeightmap(i),this.material=new t.ShaderMaterial({uniforms:this.uniforms,vertexShader:a.vertexShader,fragmentShader:a.fragmentShader}),this.fsQuad=new e.FullScreenQuad(this.material),this.goWild=!1,this.curF=0,this.generateTrigger()};i.prototype=Object.assign(Object.create(e.Pass.prototype),{constructor:i,render:function(e,r,i){this.uniforms.tDiffuse.value=i.texture,this.uniforms.seed.value=Math.random(),this.uniforms.byp.value=0,this.curF%this.randX==0||1==this.goWild?(this.uniforms.amount.value=Math.random()/30,this.uniforms.angle.value=t.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.seed_x.value=t.MathUtils.randFloat(-1,1),this.uniforms.seed_y.value=t.MathUtils.randFloat(-1,1),this.uniforms.distortion_x.value=t.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=t.MathUtils.randFloat(0,1),this.curF=0,this.generateTrigger()):this.curF%this.randX<this.randX/5?(this.uniforms.amount.value=Math.random()/90,this.uniforms.angle.value=t.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.distortion_x.value=t.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=t.MathUtils.randFloat(0,1),this.uniforms.seed_x.value=t.MathUtils.randFloat(-.3,.3),this.uniforms.seed_y.value=t.MathUtils.randFloat(-.3,.3)):0==this.goWild&&(this.uniforms.byp.value=1),this.curF++,this.renderToScreen?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(r),this.clear&&e.clear(),this.fsQuad.render(e))},generateTrigger:function(){this.randX=t.MathUtils.randInt(120,240)},generateHeightmap:function(e){var r=new Float32Array(e*e*3),i=e*e;for(let e=0;e<i;e++){var a=t.MathUtils.randFloat(0,1);r[3*e+0]=a,r[3*e+1]=a,r[3*e+2]=a}return new t.DataTexture(r,e,e,t.RGBFormat,t.FloatType)}}),exports.GlitchPass=i;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("three"),e=require("./Pass.cjs.js"),i=require("../shaders/DigitalGlitch.cjs.js");require("@babel/runtime/helpers/defineProperty");class s extends e.Pass{constructor(s=64){super(),void 0===i.DigitalGlitch&&console.error("THREE.GlitchPass relies on DigitalGlitch");const r=i.DigitalGlitch;this.uniforms=t.UniformsUtils.clone(r.uniforms),this.uniforms.tDisp.value=this.generateHeightmap(s),this.material=new t.ShaderMaterial({uniforms:this.uniforms,vertexShader:r.vertexShader,fragmentShader:r.fragmentShader}),this.fsQuad=new e.FullScreenQuad(this.material),this.goWild=!1,this.curF=0,this.generateTrigger()}render(e,i,s){!1===e.capabilities.isWebGL2&&(this.uniforms.tDisp.value.format=t.LuminanceFormat),this.uniforms.tDiffuse.value=s.texture,this.uniforms.seed.value=Math.random(),this.uniforms.byp.value=0,this.curF%this.randX==0||1==this.goWild?(this.uniforms.amount.value=Math.random()/30,this.uniforms.angle.value=t.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.seed_x.value=t.MathUtils.randFloat(-1,1),this.uniforms.seed_y.value=t.MathUtils.randFloat(-1,1),this.uniforms.distortion_x.value=t.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=t.MathUtils.randFloat(0,1),this.curF=0,this.generateTrigger()):this.curF%this.randX<this.randX/5?(this.uniforms.amount.value=Math.random()/90,this.uniforms.angle.value=t.MathUtils.randFloat(-Math.PI,Math.PI),this.uniforms.distortion_x.value=t.MathUtils.randFloat(0,1),this.uniforms.distortion_y.value=t.MathUtils.randFloat(0,1),this.uniforms.seed_x.value=t.MathUtils.randFloat(-.3,.3),this.uniforms.seed_y.value=t.MathUtils.randFloat(-.3,.3)):0==this.goWild&&(this.uniforms.byp.value=1),this.curF++,this.renderToScreen?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(i),this.clear&&e.clear(),this.fsQuad.render(e))}generateTrigger(){this.randX=t.MathUtils.randInt(120,240)}generateHeightmap(e){const i=new Float32Array(e*e),s=e*e;for(let e=0;e<s;e++){const s=t.MathUtils.randFloat(0,1);i[e]=s}const r=new t.DataTexture(i,e,e,t.RedFormat,t.FloatType);return r.needsUpdate=!0,r}}exports.GlitchPass=s;
@@ -1,29 +1,29 @@
1
- import { UniformsUtils, ShaderMaterial, MathUtils, DataTexture, RGBFormat, FloatType } from 'three';
2
- import { FullScreenQuad, Pass } from './Pass.js';
1
+ import { UniformsUtils, ShaderMaterial, LuminanceFormat, MathUtils, DataTexture, RedFormat, FloatType } from 'three';
2
+ import { Pass, FullScreenQuad } from './Pass.js';
3
3
  import { DigitalGlitch } from '../shaders/DigitalGlitch.js';
4
4
 
5
- var GlitchPass = function (dt_size) {
6
- if (DigitalGlitch === undefined) console.error('THREE.GlitchPass relies on DigitalGlitch');
7
- var shader = DigitalGlitch;
8
- this.uniforms = UniformsUtils.clone(shader.uniforms);
9
- if (dt_size == undefined) dt_size = 64;
10
- this.uniforms['tDisp'].value = this.generateHeightmap(dt_size);
11
- this.material = new ShaderMaterial({
12
- uniforms: this.uniforms,
13
- vertexShader: shader.vertexShader,
14
- fragmentShader: shader.fragmentShader
15
- });
16
- this.fsQuad = new FullScreenQuad(this.material);
17
- this.goWild = false;
18
- this.curF = 0;
19
- this.generateTrigger();
20
- };
5
+ class GlitchPass extends Pass {
6
+ constructor(dt_size = 64) {
7
+ super();
8
+ if (DigitalGlitch === undefined) console.error('THREE.GlitchPass relies on DigitalGlitch');
9
+ const shader = DigitalGlitch;
10
+ this.uniforms = UniformsUtils.clone(shader.uniforms);
11
+ this.uniforms['tDisp'].value = this.generateHeightmap(dt_size);
12
+ this.material = new ShaderMaterial({
13
+ uniforms: this.uniforms,
14
+ vertexShader: shader.vertexShader,
15
+ fragmentShader: shader.fragmentShader
16
+ });
17
+ this.fsQuad = new FullScreenQuad(this.material);
18
+ this.goWild = false;
19
+ this.curF = 0;
20
+ this.generateTrigger();
21
+ }
21
22
 
22
- GlitchPass.prototype = Object.assign(Object.create(Pass.prototype), {
23
- constructor: GlitchPass,
24
- render: function (renderer, writeBuffer, readBuffer
23
+ render(renderer, writeBuffer, readBuffer
25
24
  /*, deltaTime, maskActive */
26
25
  ) {
26
+ if (renderer.capabilities.isWebGL2 === false) this.uniforms['tDisp'].value.format = LuminanceFormat;
27
27
  this.uniforms['tDiffuse'].value = readBuffer.texture;
28
28
  this.uniforms['seed'].value = Math.random(); //default seeding
29
29
 
@@ -59,23 +59,26 @@ GlitchPass.prototype = Object.assign(Object.create(Pass.prototype), {
59
59
  if (this.clear) renderer.clear();
60
60
  this.fsQuad.render(renderer);
61
61
  }
62
- },
63
- generateTrigger: function () {
62
+ }
63
+
64
+ generateTrigger() {
64
65
  this.randX = MathUtils.randInt(120, 240);
65
- },
66
- generateHeightmap: function (dt_size) {
67
- var data_arr = new Float32Array(dt_size * dt_size * 3);
68
- var length = dt_size * dt_size;
66
+ }
67
+
68
+ generateHeightmap(dt_size) {
69
+ const data_arr = new Float32Array(dt_size * dt_size);
70
+ const length = dt_size * dt_size;
69
71
 
70
72
  for (let i = 0; i < length; i++) {
71
- var val = MathUtils.randFloat(0, 1);
72
- data_arr[i * 3 + 0] = val;
73
- data_arr[i * 3 + 1] = val;
74
- data_arr[i * 3 + 2] = val;
73
+ const val = MathUtils.randFloat(0, 1);
74
+ data_arr[i] = val;
75
75
  }
76
76
 
77
- return new DataTexture(data_arr, dt_size, dt_size, RGBFormat, FloatType);
77
+ const texture = new DataTexture(data_arr, dt_size, dt_size, RedFormat, FloatType);
78
+ texture.needsUpdate = true;
79
+ return texture;
78
80
  }
79
- });
81
+
82
+ }
80
83
 
81
84
  export { GlitchPass };