@react-three/drei 7.25.1 → 7.25.5

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/index.js CHANGED
@@ -81,4 +81,5 @@ export { BakeShadows } from './core/BakeShadows.js';
81
81
  export { meshBounds } from './core/meshBounds.js';
82
82
  export { AdaptiveDpr } from './core/AdaptiveDpr.js';
83
83
  export { AdaptiveEvents } from './core/AdaptiveEvents.js';
84
+ export { BlurPass } from './materials/BlurPass.js';
84
85
  export { MeshReflectorMaterial } from './materials/MeshReflectorMaterial.js';
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),t=require("./ConvolutionMaterial.cjs.js");exports.BlurPass=class{constructor({gl:r,resolution:n,width:i=500,height:o=500,minDepthThreshold:s=0,maxDepthThreshold:a=1,depthScale:l=0,depthToBlurRatioBias:u=.25}){this.renderToScreen=!1,this.renderTargetA=new e.WebGLRenderTarget(n,n,{minFilter:e.LinearFilter,magFilter:e.LinearFilter,stencilBuffer:!1,depthBuffer:!1,encoding:r.outputEncoding}),this.renderTargetB=this.renderTargetA.clone(),this.convolutionMaterial=new t.ConvolutionMaterial,this.convolutionMaterial.setTexelSize(1/i,1/o),this.convolutionMaterial.setResolution(new e.Vector2(i,o)),this.scene=new e.Scene,this.camera=new e.Camera,this.convolutionMaterial.uniforms.minDepthThreshold.value=s,this.convolutionMaterial.uniforms.maxDepthThreshold.value=a,this.convolutionMaterial.uniforms.depthScale.value=l,this.convolutionMaterial.uniforms.depthToBlurRatioBias.value=u,this.convolutionMaterial.defines.USE_DEPTH=l>0;const h=new Float32Array([-1,-1,0,3,-1,0,-1,3,0]),c=new Float32Array([0,0,2,0,0,2]),d=new e.BufferGeometry;d.setAttribute("position",new e.BufferAttribute(h,3)),d.setAttribute("uv",new e.BufferAttribute(c,2)),this.screen=new e.Mesh(d,this.convolutionMaterial),this.screen.frustumCulled=!1,this.scene.add(this.screen)}render(e,t,r){const n=this.scene,i=this.camera,o=this.renderTargetA,s=this.renderTargetB;let a=this.convolutionMaterial,l=a.uniforms;l.depthBuffer.value=t.depthTexture;const u=a.kernel;let h,c,d,f=t;for(c=0,d=u.length-1;c<d;++c)h=0==(1&c)?o:s,l.kernel.value=u[c],l.inputBuffer.value=f.texture,e.setRenderTarget(h),e.render(n,i),f=h;l.kernel.value=u[c],l.inputBuffer.value=f.texture,e.setRenderTarget(this.renderToScreen?null:r),e.render(n,i)}};
@@ -0,0 +1,23 @@
1
+ import { Mesh, Scene, WebGLRenderTarget, WebGLRenderer, Camera } from 'three';
2
+ import { ConvolutionMaterial } from './ConvolutionMaterial';
3
+ export interface BlurPassProps {
4
+ gl: WebGLRenderer;
5
+ resolution: number;
6
+ width?: number;
7
+ height?: number;
8
+ minDepthThreshold?: number;
9
+ maxDepthThreshold?: number;
10
+ depthScale?: number;
11
+ depthToBlurRatioBias?: number;
12
+ }
13
+ export declare class BlurPass {
14
+ readonly renderTargetA: WebGLRenderTarget;
15
+ readonly renderTargetB: WebGLRenderTarget;
16
+ readonly convolutionMaterial: ConvolutionMaterial;
17
+ readonly scene: Scene;
18
+ readonly camera: Camera;
19
+ readonly screen: Mesh;
20
+ renderToScreen: boolean;
21
+ constructor({ gl, resolution, width, height, minDepthThreshold, maxDepthThreshold, depthScale, depthToBlurRatioBias, }: BlurPassProps);
22
+ render(renderer: any, inputBuffer: any, outputBuffer: any): void;
23
+ }
@@ -0,0 +1,75 @@
1
+ import { WebGLRenderTarget, LinearFilter, Vector2, Scene, Camera, BufferGeometry, BufferAttribute, Mesh } from 'three';
2
+ import { ConvolutionMaterial } from './ConvolutionMaterial.js';
3
+
4
+ class BlurPass {
5
+ constructor({
6
+ gl,
7
+ resolution,
8
+ width = 500,
9
+ height = 500,
10
+ minDepthThreshold = 0,
11
+ maxDepthThreshold = 1,
12
+ depthScale = 0,
13
+ depthToBlurRatioBias = 0.25
14
+ }) {
15
+ this.renderToScreen = false;
16
+ this.renderTargetA = new WebGLRenderTarget(resolution, resolution, {
17
+ minFilter: LinearFilter,
18
+ magFilter: LinearFilter,
19
+ stencilBuffer: false,
20
+ depthBuffer: false,
21
+ encoding: gl.outputEncoding
22
+ });
23
+ this.renderTargetB = this.renderTargetA.clone();
24
+ this.convolutionMaterial = new ConvolutionMaterial();
25
+ this.convolutionMaterial.setTexelSize(1.0 / width, 1.0 / height);
26
+ this.convolutionMaterial.setResolution(new Vector2(width, height));
27
+ this.scene = new Scene();
28
+ this.camera = new Camera();
29
+ this.convolutionMaterial.uniforms.minDepthThreshold.value = minDepthThreshold;
30
+ this.convolutionMaterial.uniforms.maxDepthThreshold.value = maxDepthThreshold;
31
+ this.convolutionMaterial.uniforms.depthScale.value = depthScale;
32
+ this.convolutionMaterial.uniforms.depthToBlurRatioBias.value = depthToBlurRatioBias;
33
+ this.convolutionMaterial.defines.USE_DEPTH = depthScale > 0;
34
+ const vertices = new Float32Array([-1, -1, 0, 3, -1, 0, -1, 3, 0]);
35
+ const uvs = new Float32Array([0, 0, 2, 0, 0, 2]);
36
+ const geometry = new BufferGeometry();
37
+ geometry.setAttribute('position', new BufferAttribute(vertices, 3));
38
+ geometry.setAttribute('uv', new BufferAttribute(uvs, 2));
39
+ this.screen = new Mesh(geometry, this.convolutionMaterial);
40
+ this.screen.frustumCulled = false;
41
+ this.scene.add(this.screen);
42
+ }
43
+
44
+ render(renderer, inputBuffer, outputBuffer) {
45
+ const scene = this.scene;
46
+ const camera = this.camera;
47
+ const renderTargetA = this.renderTargetA;
48
+ const renderTargetB = this.renderTargetB;
49
+ let material = this.convolutionMaterial;
50
+ let uniforms = material.uniforms;
51
+ uniforms.depthBuffer.value = inputBuffer.depthTexture;
52
+ const kernel = material.kernel;
53
+ let lastRT = inputBuffer;
54
+ let destRT;
55
+ let i, l; // Apply the multi-pass blur.
56
+
57
+ for (i = 0, l = kernel.length - 1; i < l; ++i) {
58
+ // Alternate between targets.
59
+ destRT = (i & 1) === 0 ? renderTargetA : renderTargetB;
60
+ uniforms.kernel.value = kernel[i];
61
+ uniforms.inputBuffer.value = lastRT.texture;
62
+ renderer.setRenderTarget(destRT);
63
+ renderer.render(scene, camera);
64
+ lastRT = destRT;
65
+ }
66
+
67
+ uniforms.kernel.value = kernel[i];
68
+ uniforms.inputBuffer.value = lastRT.texture;
69
+ renderer.setRenderTarget(this.renderToScreen ? null : outputBuffer);
70
+ renderer.render(scene, camera);
71
+ }
72
+
73
+ }
74
+
75
+ export { BlurPass };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class n extends e.ShaderMaterial{constructor(n=new e.Vector2){super({uniforms:{inputBuffer:new e.Uniform(null),depthBuffer:new e.Uniform(null),resolution:new e.Uniform(new e.Vector2),texelSize:new e.Uniform(new e.Vector2),halfTexelSize:new e.Uniform(new e.Vector2),kernel:new e.Uniform(0),scale:new e.Uniform(1),cameraNear:new e.Uniform(0),cameraFar:new e.Uniform(1),minDepthThreshold:new e.Uniform(0),maxDepthThreshold:new e.Uniform(1),depthScale:new e.Uniform(0),depthToBlurRatioBias:new e.Uniform(.25)},fragmentShader:"#include <common>\n #include <dithering_pars_fragment> \n uniform sampler2D inputBuffer;\n uniform sampler2D depthBuffer;\n uniform float cameraNear;\n uniform float cameraFar;\n uniform float minDepthThreshold;\n uniform float maxDepthThreshold;\n uniform float depthScale;\n uniform float depthToBlurRatioBias;\n varying vec2 vUv;\n varying vec2 vUv0;\n varying vec2 vUv1;\n varying vec2 vUv2;\n varying vec2 vUv3;\n\n void main() {\n float depthFactor = 0.0;\n \n #ifdef USE_DEPTH\n vec4 depth = texture2D(depthBuffer, vUv);\n depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n depthFactor *= depthScale;\n depthFactor = max(0.0, min(1.0, depthFactor + 0.25));\n #endif\n \n vec4 sum = texture2D(inputBuffer, mix(vUv0, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv1, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv2, vUv, depthFactor));\n sum += texture2D(inputBuffer, mix(vUv3, vUv, depthFactor));\n gl_FragColor = sum * 0.25 ;\n\n #include <dithering_fragment>\n }",vertexShader:"uniform vec2 texelSize;\n uniform vec2 halfTexelSize;\n uniform float kernel;\n uniform float scale;\n varying vec2 vUv;\n varying vec2 vUv0;\n varying vec2 vUv1;\n varying vec2 vUv2;\n varying vec2 vUv3;\n\n void main() {\n vec2 uv = position.xy * 0.5 + 0.5;\n vUv = uv;\n\n vec2 dUv = (texelSize * vec2(kernel) + halfTexelSize) * scale;\n vUv0 = vec2(uv.x - dUv.x, uv.y + dUv.y);\n vUv1 = vec2(uv.x + dUv.x, uv.y + dUv.y);\n vUv2 = vec2(uv.x + dUv.x, uv.y - dUv.y);\n vUv3 = vec2(uv.x - dUv.x, uv.y - dUv.y);\n\n gl_Position = vec4(position.xy, 1.0, 1.0);\n }",blending:e.NoBlending,depthWrite:!1,depthTest:!1}),this.toneMapped=!1,this.setTexelSize(n.x,n.y),this.kernel=new Float32Array([0,1,2,2,3])}setTexelSize(e,n){this.uniforms.texelSize.value.set(e,n),this.uniforms.halfTexelSize.value.set(e,n).multiplyScalar(.5)}setResolution(e){this.uniforms.resolution.value.copy(e)}}exports.ConvolutionMaterial=n;
@@ -0,0 +1,7 @@
1
+ import { ShaderMaterial, Vector2 } from 'three';
2
+ export declare class ConvolutionMaterial extends ShaderMaterial {
3
+ readonly kernel: Float32Array;
4
+ constructor(texelSize?: Vector2);
5
+ setTexelSize(x: number, y: number): void;
6
+ setResolution(resolution: Vector2): void;
7
+ }
@@ -0,0 +1,97 @@
1
+ import { ShaderMaterial, Vector2, Uniform, NoBlending } from 'three';
2
+
3
+ class ConvolutionMaterial extends ShaderMaterial {
4
+ constructor(texelSize = new Vector2()) {
5
+ super({
6
+ uniforms: {
7
+ inputBuffer: new Uniform(null),
8
+ depthBuffer: new Uniform(null),
9
+ resolution: new Uniform(new Vector2()),
10
+ texelSize: new Uniform(new Vector2()),
11
+ halfTexelSize: new Uniform(new Vector2()),
12
+ kernel: new Uniform(0.0),
13
+ scale: new Uniform(1.0),
14
+ cameraNear: new Uniform(0.0),
15
+ cameraFar: new Uniform(1.0),
16
+ minDepthThreshold: new Uniform(0.0),
17
+ maxDepthThreshold: new Uniform(1.0),
18
+ depthScale: new Uniform(0.0),
19
+ depthToBlurRatioBias: new Uniform(0.25)
20
+ },
21
+ fragmentShader: `#include <common>
22
+ #include <dithering_pars_fragment>
23
+ uniform sampler2D inputBuffer;
24
+ uniform sampler2D depthBuffer;
25
+ uniform float cameraNear;
26
+ uniform float cameraFar;
27
+ uniform float minDepthThreshold;
28
+ uniform float maxDepthThreshold;
29
+ uniform float depthScale;
30
+ uniform float depthToBlurRatioBias;
31
+ varying vec2 vUv;
32
+ varying vec2 vUv0;
33
+ varying vec2 vUv1;
34
+ varying vec2 vUv2;
35
+ varying vec2 vUv3;
36
+
37
+ void main() {
38
+ float depthFactor = 0.0;
39
+
40
+ #ifdef USE_DEPTH
41
+ vec4 depth = texture2D(depthBuffer, vUv);
42
+ depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));
43
+ depthFactor *= depthScale;
44
+ depthFactor = max(0.0, min(1.0, depthFactor + 0.25));
45
+ #endif
46
+
47
+ vec4 sum = texture2D(inputBuffer, mix(vUv0, vUv, depthFactor));
48
+ sum += texture2D(inputBuffer, mix(vUv1, vUv, depthFactor));
49
+ sum += texture2D(inputBuffer, mix(vUv2, vUv, depthFactor));
50
+ sum += texture2D(inputBuffer, mix(vUv3, vUv, depthFactor));
51
+ gl_FragColor = sum * 0.25 ;
52
+
53
+ #include <dithering_fragment>
54
+ }`,
55
+ vertexShader: `uniform vec2 texelSize;
56
+ uniform vec2 halfTexelSize;
57
+ uniform float kernel;
58
+ uniform float scale;
59
+ varying vec2 vUv;
60
+ varying vec2 vUv0;
61
+ varying vec2 vUv1;
62
+ varying vec2 vUv2;
63
+ varying vec2 vUv3;
64
+
65
+ void main() {
66
+ vec2 uv = position.xy * 0.5 + 0.5;
67
+ vUv = uv;
68
+
69
+ vec2 dUv = (texelSize * vec2(kernel) + halfTexelSize) * scale;
70
+ vUv0 = vec2(uv.x - dUv.x, uv.y + dUv.y);
71
+ vUv1 = vec2(uv.x + dUv.x, uv.y + dUv.y);
72
+ vUv2 = vec2(uv.x + dUv.x, uv.y - dUv.y);
73
+ vUv3 = vec2(uv.x - dUv.x, uv.y - dUv.y);
74
+
75
+ gl_Position = vec4(position.xy, 1.0, 1.0);
76
+ }`,
77
+ blending: NoBlending,
78
+ depthWrite: false,
79
+ depthTest: false
80
+ });
81
+ this.toneMapped = false;
82
+ this.setTexelSize(texelSize.x, texelSize.y);
83
+ this.kernel = new Float32Array([0.0, 1.0, 2.0, 2.0, 3.0]);
84
+ }
85
+
86
+ setTexelSize(x, y) {
87
+ this.uniforms.texelSize.value.set(x, y);
88
+ this.uniforms.halfTexelSize.value.set(x, y).multiplyScalar(0.5);
89
+ }
90
+
91
+ setResolution(resolution) {
92
+ this.uniforms.resolution.value.copy(resolution);
93
+ }
94
+
95
+ }
96
+
97
+ export { ConvolutionMaterial };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class i extends e.MeshStandardMaterial{constructor(e={}){super(e),this._debug={value:0},this._tDepth={value:null},this._distortionMap={value:null},this._tDiffuse={value:null},this._u_mipmap_0={value:null},this._u_mipmap_1={value:null},this._u_mipmap_2={value:null},this._u_mipmap_3={value:null},this._u_mipmap_4={value:null},this._u_mipmap_5={value:null},this._u_mipmap_6={value:null},this._u_mipmap_7={value:null},this._u_mipmap_res_0={value:null},this._u_mipmap_res_1={value:null},this._u_mipmap_res_2={value:null},this._u_mipmap_res_3={value:null},this._u_mipmap_res_4={value:null},this._u_mipmap_res_5={value:null},this._u_mipmap_res_6={value:null},this._u_mipmap_res_7={value:null},this._textureMatrix={value:null},this._mirror={value:0},this._mixBlur={value:0},this._blurStrength={value:.5},this._minDepthThreshold={value:.9},this._maxDepthThreshold={value:1},this._depthScale={value:0},this._depthToBlurRatioBias={value:.25},this._distortion={value:1},this.setValues(e)}onBeforeCompile(e){var i;null!=(i=e.defines)&&i.USE_UV||(e.defines.USE_UV=""),e.uniforms.debug=this._debug,e.uniforms.tDiffuse=this._tDiffuse,e.uniforms.tDepth=this._tDepth,e.uniforms.distortionMap=this._distortionMap,e.uniforms.u_mipmap_0=this._u_mipmap_0,e.uniforms.u_mipmap_1=this._u_mipmap_1,e.uniforms.u_mipmap_2=this._u_mipmap_2,e.uniforms.u_mipmap_3=this._u_mipmap_3,e.uniforms.u_mipmap_4=this._u_mipmap_4,e.uniforms.u_mipmap_5=this._u_mipmap_5,e.uniforms.u_mipmap_6=this._u_mipmap_6,e.uniforms.u_mipmap_7=this._u_mipmap_7,e.uniforms.u_mipmap_res_0=this._u_mipmap_res_0,e.uniforms.u_mipmap_res_1=this._u_mipmap_res_1,e.uniforms.u_mipmap_res_2=this._u_mipmap_res_2,e.uniforms.u_mipmap_res_3=this._u_mipmap_res_3,e.uniforms.u_mipmap_res_4=this._u_mipmap_res_4,e.uniforms.u_mipmap_res_5=this._u_mipmap_res_5,e.uniforms.u_mipmap_res_6=this._u_mipmap_res_6,e.uniforms.u_mipmap_res_7=this._u_mipmap_res_7,e.uniforms.textureMatrix=this._textureMatrix,e.uniforms.mirror=this._mirror,e.uniforms.mixBlur=this._mixBlur,e.uniforms.mixStrength=this._blurStrength,e.uniforms.minDepthThreshold=this._minDepthThreshold,e.uniforms.maxDepthThreshold=this._maxDepthThreshold,e.uniforms.depthScale=this._depthScale,e.uniforms.depthToBlurRatioBias=this._depthToBlurRatioBias,e.uniforms.distortion=this._distortion,e.vertexShader=`\n uniform mat4 textureMatrix;\n varying vec4 my_vUv; \n ${e.vertexShader}`,e.vertexShader=e.vertexShader.replace("#include <project_vertex>","#include <project_vertex>\n my_vUv = textureMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );"),e.fragmentShader=`\n uniform int debug;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDepth;\n uniform sampler2D distortionMap;\n uniform sampler2D u_mipmap_0;\n uniform sampler2D u_mipmap_1;\n uniform sampler2D u_mipmap_2;\n uniform sampler2D u_mipmap_3;\n uniform sampler2D u_mipmap_4;\n uniform sampler2D u_mipmap_5;\n uniform sampler2D u_mipmap_6;\n uniform sampler2D u_mipmap_7;\n uniform vec2 u_mipmap_res_0;\n uniform vec2 u_mipmap_res_1;\n uniform vec2 u_mipmap_res_2;\n uniform vec2 u_mipmap_res_3;\n uniform vec2 u_mipmap_res_4;\n uniform vec2 u_mipmap_res_5;\n uniform vec2 u_mipmap_res_6;\n uniform vec2 u_mipmap_res_7;\n uniform float distortion;\n uniform float cameraNear;\n\t\t\t uniform float cameraFar;\n uniform float mixBlur;\n uniform float mirror;\n uniform float mixStrength;\n uniform float minDepthThreshold;\n uniform float maxDepthThreshold;\n uniform float depthScale;\n uniform float depthToBlurRatioBias;\n varying vec4 my_vUv; \n \n // from http://www.java-gaming.org/index.php?topic=35123.0\n vec4 cubic( float v ) {\n vec4 n = vec4( 1.0, 2.0, 3.0, 4.0 ) - v;\n vec4 s = n * n * n;\n float x = s.x;\n float y = s.y - 4.0 * s.x;\n float z = s.z - 4.0 * s.y + 6.0 * s.x;\n float w = 6.0 - x - y - z;\n return vec4( x, y, z, w ) * ( 1.0 / 6.0 );\n }\n \n vec4 textureBicubic( sampler2D sampler, vec2 texCoords, vec2 texSize ) {\n vec2 invTexSize = 1.0 / texSize;\n texCoords = texCoords * texSize - 0.5;\n vec2 fxy = fract( texCoords );\n texCoords -= fxy;\n\n vec4 xcubic = cubic( fxy.x );\n vec4 ycubic = cubic( fxy.y );\n vec4 c = texCoords.xxyy + vec2 ( - 0.5, + 1.5 ).xyxy;\n vec4 s = vec4( xcubic.xz + xcubic.yw, ycubic.xz + ycubic.yw );\n\n vec4 offset = c + vec4( xcubic.yw, ycubic.yw ) / s;\n offset *= invTexSize.xxyy;\n \n vec4 sample0 = texture2D( sampler, offset.xz);\n vec4 sample1 = texture2D( sampler, offset.yz);\n vec4 sample2 = texture2D( sampler, offset.xw);\n vec4 sample3 = texture2D( sampler, offset.yw);\n \n float sx = s.x / ( s.x + s.y );\n float sy = s.z / ( s.z + s.w );\n\n return mix(\n mix(\n sample3,\n sample2,\n sx\n ),\n mix(\n sample1,\n sample0,\n sx\n ),\n sy\n );\n }\n\n\n ${e.fragmentShader}`,e.fragmentShader=e.fragmentShader.replace("#include <emissivemap_fragment>","#include <emissivemap_fragment>\n \n float depthFactor = 1.0;\n float distortionFactor = 0.0;\n vec3 my_normal = vec3(0.0);\n float reflectorRoughnessFactor = roughness;\n vec3 coord = my_vUv.xyz / my_vUv.w;\n\n #ifdef USE_DISTORTION\n distortionFactor = texture2D(distortionMap, vUv).r * distortion;\n #endif\n\n #ifdef USE_NORMALMAP\n vec4 normalColor = texture2D(normalMap, vUv * normalScale);\n my_normal = normalize( vec3( normalColor.r * 2.0 - 1.0, normalColor.b , normalColor.g * 2.0 - 1.0 ) );\n #endif\n\n #ifdef USE_ROUGHNESSMAP\n vec4 reflectorTexelRoughness = texture2D( roughnessMap, vUv );\n reflectorRoughnessFactor *= reflectorTexelRoughness.g;\n #endif\n\n vec2 proj_vUv = coord.xy + coord.z * my_normal.xz * 0.01;\n proj_vUv.x += distortionFactor;\n proj_vUv.y += distortionFactor;\n \n float lod = 1.0 - min(1.0, mixBlur * reflectorRoughnessFactor);\n\n #ifdef USE_DEPTH\n vec4 depth = texture2D(tDepth, proj_vUv);\n depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n depthFactor *= depthScale;\n depthFactor = max(0.0001, min(1.0, depthFactor + depthToBlurRatioBias));\n #endif\n\n vec4 baseColor = texture2D(tDiffuse, proj_vUv);\n vec4 mixedColor;\n\n float _lod = (1.0 - pow(1.0 - lod, 4.0)) * 8.0;\n if (_lod < 1.) {\n vec4 one = textureBicubic(u_mipmap_7, proj_vUv, u_mipmap_res_7);\n vec4 two = textureBicubic(u_mipmap_6, proj_vUv, u_mipmap_res_6);\n mixedColor = mix(one, two, _lod);\n } else if (_lod < 2.) {\n vec4 one = textureBicubic(u_mipmap_6, proj_vUv, u_mipmap_res_6);\n vec4 two = textureBicubic(u_mipmap_5, proj_vUv, u_mipmap_res_5);\n mixedColor = mix(one, two, _lod - 1.0);\n } else if (_lod < 3.) {\n vec4 one = textureBicubic(u_mipmap_5, proj_vUv, u_mipmap_res_5);\n vec4 two = textureBicubic(u_mipmap_4, proj_vUv, u_mipmap_res_4);\n mixedColor = mix(one, two, _lod - 2.0);\n } else if (_lod < 4.) {\n vec4 one = textureBicubic(u_mipmap_4, proj_vUv, u_mipmap_res_4);\n vec4 two = textureBicubic(u_mipmap_3, proj_vUv, u_mipmap_res_3);\n mixedColor = mix(one, two, _lod - 3.0);\n } else if (_lod < 5.) {\n vec4 one = textureBicubic(u_mipmap_3, proj_vUv, u_mipmap_res_3);\n vec4 two = textureBicubic(u_mipmap_2, proj_vUv, u_mipmap_res_2);\n mixedColor = mix(one, two, _lod - 4.0);\n } else if (_lod < 6.) {\n vec4 one = textureBicubic(u_mipmap_2, proj_vUv, u_mipmap_res_2);\n vec4 two = textureBicubic(u_mipmap_1, proj_vUv, u_mipmap_res_1);\n mixedColor = mix(one, two, _lod - 5.0);\n } else if (_lod < 7.) {\n vec4 one = textureBicubic(u_mipmap_1, proj_vUv, u_mipmap_res_1);\n vec4 two = textureBicubic(u_mipmap_0, proj_vUv, u_mipmap_res_0);\n mixedColor = mix(one, two, _lod - 6.0);\n } else {\n vec4 one = textureBicubic(u_mipmap_0, proj_vUv, u_mipmap_res_0);\n mixedColor = mix(one, baseColor, _lod - 7.0);\n }\n\n mixedColor.rgb *= depthFactor;\n diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + mixedColor.rgb * mixStrength); \n diffuseColor = sRGBToLinear(diffuseColor);\n\n if (debug == 1) {\n diffuseColor = sRGBToLinear(vec4(vec3(depthFactor), 1.0));\n }\n if (debug == 2) {\n diffuseColor = sRGBToLinear(texture2D(tDiffuse, proj_vUv));\n }\n if (debug == 3) {\n diffuseColor = sRGBToLinear(texture2D(distortionMap, vUv));\n }\n if (debug == 4) {\n diffuseColor = sRGBToLinear(vec4(vec3(lod), 1.0));\n }\n ")}get tDiffuse(){return this._tDiffuse.value}set tDiffuse(e){this._tDiffuse.value=e}get tDepth(){return this._tDepth.value}set tDepth(e){this._tDepth.value=e}get distortionMap(){return this._distortionMap.value}set distortionMap(e){this._distortionMap.value=e}get u_mipmap_0(){return this._u_mipmap_0.value}set u_mipmap_0(e){this._u_mipmap_0.value=e}get u_mipmap_1(){return this._u_mipmap_1.value}set u_mipmap_1(e){this._u_mipmap_1.value=e}get u_mipmap_2(){return this._u_mipmap_2.value}set u_mipmap_2(e){this._u_mipmap_2.value=e}get u_mipmap_3(){return this._u_mipmap_3.value}set u_mipmap_3(e){this._u_mipmap_3.value=e}get u_mipmap_4(){return this._u_mipmap_4.value}set u_mipmap_4(e){this._u_mipmap_4.value=e}get u_mipmap_5(){return this._u_mipmap_5.value}set u_mipmap_5(e){this._u_mipmap_5.value=e}get u_mipmap_6(){return this._u_mipmap_6.value}set u_mipmap_6(e){this._u_mipmap_6.value=e}get u_mipmap_7(){return this._u_mipmap_7.value}set u_mipmap_7(e){this._u_mipmap_7.value=e}get u_mipmap_res_0(){return this._u_mipmap_res_0.value}set u_mipmap_res_0(e){this._u_mipmap_res_0.value=e}get u_mipmap_res_1(){return this._u_mipmap_res_1.value}set u_mipmap_res_1(e){this._u_mipmap_res_1.value=e}get u_mipmap_res_2(){return this._u_mipmap_res_2.value}set u_mipmap_res_2(e){this._u_mipmap_res_2.value=e}get u_mipmap_res_3(){return this._u_mipmap_res_3.value}set u_mipmap_res_3(e){this._u_mipmap_res_3.value=e}get u_mipmap_res_4(){return this._u_mipmap_res_4.value}set u_mipmap_res_4(e){this._u_mipmap_res_4.value=e}get u_mipmap_res_5(){return this._u_mipmap_res_5.value}set u_mipmap_res_5(e){this._u_mipmap_res_5.value=e}get u_mipmap_res_6(){return this._u_mipmap_res_6.value}set u_mipmap_res_6(e){this._u_mipmap_res_6.value=e}get u_mipmap_res_7(){return this._u_mipmap_res_7.value}set u_mipmap_res_7(e){this._u_mipmap_res_7.value=e}get textureMatrix(){return this._textureMatrix.value}set textureMatrix(e){this._textureMatrix.value=e}get mirror(){return this._mirror.value}set mirror(e){this._mirror.value=e}get mixBlur(){return this._mixBlur.value}set mixBlur(e){this._mixBlur.value=e}get mixStrength(){return this._blurStrength.value}set mixStrength(e){this._blurStrength.value=e}get minDepthThreshold(){return this._minDepthThreshold.value}set minDepthThreshold(e){this._minDepthThreshold.value=e}get maxDepthThreshold(){return this._maxDepthThreshold.value}set maxDepthThreshold(e){this._maxDepthThreshold.value=e}get depthScale(){return this._depthScale.value}set depthScale(e){this._depthScale.value=e}get debug(){return this._debug.value}set debug(e){this._debug.value=e}get depthToBlurRatioBias(){return this._depthToBlurRatioBias.value}set depthToBlurRatioBias(e){this._depthToBlurRatioBias.value=e}get distortion(){return this._distortion.value}set distortion(e){this._distortion.value=e}}exports.MeshReflectorMaterial=i;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three");class t extends e.MeshStandardMaterial{constructor(e={}){super(e),this._debug={value:0},this._tDepth={value:null},this._distortionMap={value:null},this._tDiffuse={value:null},this._tDiffuseBlur={value:null},this._textureMatrix={value:null},this._hasBlur={value:!1},this._mirror={value:0},this._mixBlur={value:0},this._blurStrength={value:.5},this._minDepthThreshold={value:.9},this._maxDepthThreshold={value:1},this._depthScale={value:0},this._depthToBlurRatioBias={value:.25},this._distortion={value:1},this.setValues(e)}onBeforeCompile(e){var t;null!=(t=e.defines)&&t.USE_UV||(e.defines.USE_UV=""),e.uniforms.debug=this._debug,e.uniforms.hasBlur=this._hasBlur,e.uniforms.tDiffuse=this._tDiffuse,e.uniforms.tDepth=this._tDepth,e.uniforms.distortionMap=this._distortionMap,e.uniforms.tDiffuseBlur=this._tDiffuseBlur,e.uniforms.textureMatrix=this._textureMatrix,e.uniforms.mirror=this._mirror,e.uniforms.mixBlur=this._mixBlur,e.uniforms.mixStrength=this._blurStrength,e.uniforms.minDepthThreshold=this._minDepthThreshold,e.uniforms.maxDepthThreshold=this._maxDepthThreshold,e.uniforms.depthScale=this._depthScale,e.uniforms.depthToBlurRatioBias=this._depthToBlurRatioBias,e.uniforms.distortion=this._distortion,e.vertexShader=`\n uniform mat4 textureMatrix;\n varying vec4 my_vUv; \n ${e.vertexShader}`,e.vertexShader=e.vertexShader.replace("#include <project_vertex>","#include <project_vertex>\n my_vUv = textureMatrix * vec4( position, 1.0 );\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );"),e.fragmentShader=`\n uniform int debug;\n uniform sampler2D tDiffuse;\n uniform sampler2D tDiffuseBlur;\n uniform sampler2D tDepth;\n uniform sampler2D distortionMap;\n uniform float distortion;\n uniform float cameraNear;\n\t\t\t uniform float cameraFar;\n uniform bool hasBlur;\n uniform float mixBlur;\n uniform float mirror;\n uniform float mixStrength;\n uniform float minDepthThreshold;\n uniform float maxDepthThreshold;\n uniform float depthScale;\n uniform float depthToBlurRatioBias;\n varying vec4 my_vUv; \n ${e.fragmentShader}`,e.fragmentShader=e.fragmentShader.replace("#include <emissivemap_fragment>","#include <emissivemap_fragment>\n \n float distortionFactor = 0.0;\n #ifdef USE_DISTORTION\n distortionFactor = texture2D(distortionMap, vUv).r * distortion;\n #endif\n\n vec4 new_vUv = my_vUv;\n new_vUv.x += distortionFactor;\n new_vUv.y += distortionFactor;\n\n vec4 base = texture2DProj(tDiffuse, new_vUv);\n vec4 blur = texture2DProj(tDiffuseBlur, new_vUv);\n \n vec4 merge = base;\n \n #ifdef USE_NORMALMAP\n vec2 normal_uv = vec2(0.0);\n vec4 normalColor = texture2D(normalMap, vUv * normalScale);\n vec3 my_normal = normalize( vec3( normalColor.r * 2.0 - 1.0, normalColor.b, normalColor.g * 2.0 - 1.0 ) );\n vec3 coord = new_vUv.xyz / new_vUv.w;\n normal_uv = coord.xy + coord.z * my_normal.xz * 0.05;\n vec4 base_normal = texture2D(tDiffuse, normal_uv);\n vec4 blur_normal = texture2D(tDiffuseBlur, normal_uv);\n merge = base_normal;\n blur = blur_normal;\n #endif\n\n float depthFactor = 0.0001;\n float blurFactor = 0.0;\n\n #ifdef USE_DEPTH\n vec4 depth = texture2DProj(tDepth, new_vUv);\n depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));\n depthFactor *= depthScale;\n depthFactor = max(0.0001, min(1.0, depthFactor));\n\n #ifdef USE_BLUR\n blur = blur * min(1.0, depthFactor + depthToBlurRatioBias);\n merge = merge * min(1.0, depthFactor + 0.5);;\n #else\n merge = merge * depthFactor;\n #endif\n \n #endif\n\n float reflectorRoughnessFactor = roughness;\n #ifdef USE_ROUGHNESSMAP\n vec4 reflectorTexelRoughness = texture2D( roughnessMap, vUv );\n reflectorRoughnessFactor *= reflectorTexelRoughness.g;\n #endif\n \n #ifdef USE_BLUR\n blurFactor = min(1.0, mixBlur * reflectorRoughnessFactor);\n merge = mix(merge, blur, blurFactor);\n #endif\n\n diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + merge.rgb * mixStrength); \n diffuseColor = sRGBToLinear(diffuseColor);\n \n if (debug == 1) {\n diffuseColor = sRGBToLinear(vec4(vec3(depthFactor), 1.0));\n }\n if (debug == 2) {\n diffuseColor = sRGBToLinear(vec4(vec3(blurFactor), 1.0));\n }\n if (debug == 3) {\n diffuseColor = sRGBToLinear(texture2DProj(tDiffuse, new_vUv));\n }\n if (debug == 4) {\n diffuseColor = sRGBToLinear(texture2DProj(tDiffuseBlur, new_vUv));\n }\n ")}get tDiffuse(){return this._tDiffuse.value}set tDiffuse(e){this._tDiffuse.value=e}get tDepth(){return this._tDepth.value}set tDepth(e){this._tDepth.value=e}get distortionMap(){return this._distortionMap.value}set distortionMap(e){this._distortionMap.value=e}get tDiffuseBlur(){return this._tDiffuseBlur.value}set tDiffuseBlur(e){this._tDiffuseBlur.value=e}get textureMatrix(){return this._textureMatrix.value}set textureMatrix(e){this._textureMatrix.value=e}get hasBlur(){return this._hasBlur.value}set hasBlur(e){this._hasBlur.value=e}get mirror(){return this._mirror.value}set mirror(e){this._mirror.value=e}get mixBlur(){return this._mixBlur.value}set mixBlur(e){this._mixBlur.value=e}get mixStrength(){return this._blurStrength.value}set mixStrength(e){this._blurStrength.value=e}get minDepthThreshold(){return this._minDepthThreshold.value}set minDepthThreshold(e){this._minDepthThreshold.value=e}get maxDepthThreshold(){return this._maxDepthThreshold.value}set maxDepthThreshold(e){this._maxDepthThreshold.value=e}get depthScale(){return this._depthScale.value}set depthScale(e){this._depthScale.value=e}get debug(){return this._debug.value}set debug(e){this._debug.value=e}get depthToBlurRatioBias(){return this._depthToBlurRatioBias.value}set depthToBlurRatioBias(e){this._depthToBlurRatioBias.value=e}get distortion(){return this._distortion.value}set distortion(e){this._distortion.value=e}}exports.MeshReflectorMaterial=t;
@@ -1,26 +1,12 @@
1
- import { Matrix4, MeshStandardMaterial, Texture, Vector2 } from 'three';
1
+ import { Matrix4, MeshStandardMaterial, Texture } from 'three';
2
2
  export declare class MeshReflectorMaterial extends MeshStandardMaterial {
3
3
  private _debug;
4
4
  private _tDepth;
5
5
  private _distortionMap;
6
6
  private _tDiffuse;
7
- private _u_mipmap_0;
8
- private _u_mipmap_1;
9
- private _u_mipmap_2;
10
- private _u_mipmap_3;
11
- private _u_mipmap_4;
12
- private _u_mipmap_5;
13
- private _u_mipmap_6;
14
- private _u_mipmap_7;
15
- private _u_mipmap_res_0;
16
- private _u_mipmap_res_1;
17
- private _u_mipmap_res_2;
18
- private _u_mipmap_res_3;
19
- private _u_mipmap_res_4;
20
- private _u_mipmap_res_5;
21
- private _u_mipmap_res_6;
22
- private _u_mipmap_res_7;
7
+ private _tDiffuseBlur;
23
8
  private _textureMatrix;
9
+ private _hasBlur;
24
10
  private _mirror;
25
11
  private _mixBlur;
26
12
  private _blurStrength;
@@ -37,40 +23,12 @@ export declare class MeshReflectorMaterial extends MeshStandardMaterial {
37
23
  set tDepth(v: Texture | null);
38
24
  get distortionMap(): Texture | null;
39
25
  set distortionMap(v: Texture | null);
40
- get u_mipmap_0(): Texture | null;
41
- set u_mipmap_0(v: Texture | null);
42
- get u_mipmap_1(): Texture | null;
43
- set u_mipmap_1(v: Texture | null);
44
- get u_mipmap_2(): Texture | null;
45
- set u_mipmap_2(v: Texture | null);
46
- get u_mipmap_3(): Texture | null;
47
- set u_mipmap_3(v: Texture | null);
48
- get u_mipmap_4(): Texture | null;
49
- set u_mipmap_4(v: Texture | null);
50
- get u_mipmap_5(): Texture | null;
51
- set u_mipmap_5(v: Texture | null);
52
- get u_mipmap_6(): Texture | null;
53
- set u_mipmap_6(v: Texture | null);
54
- get u_mipmap_7(): Texture | null;
55
- set u_mipmap_7(v: Texture | null);
56
- get u_mipmap_res_0(): Vector2 | null;
57
- set u_mipmap_res_0(v: Vector2 | null);
58
- get u_mipmap_res_1(): Vector2 | null;
59
- set u_mipmap_res_1(v: Vector2 | null);
60
- get u_mipmap_res_2(): Vector2 | null;
61
- set u_mipmap_res_2(v: Vector2 | null);
62
- get u_mipmap_res_3(): Vector2 | null;
63
- set u_mipmap_res_3(v: Vector2 | null);
64
- get u_mipmap_res_4(): Vector2 | null;
65
- set u_mipmap_res_4(v: Vector2 | null);
66
- get u_mipmap_res_5(): Vector2 | null;
67
- set u_mipmap_res_5(v: Vector2 | null);
68
- get u_mipmap_res_6(): Vector2 | null;
69
- set u_mipmap_res_6(v: Vector2 | null);
70
- get u_mipmap_res_7(): Vector2 | null;
71
- set u_mipmap_res_7(v: Vector2 | null);
26
+ get tDiffuseBlur(): Texture | null;
27
+ set tDiffuseBlur(v: Texture | null);
72
28
  get textureMatrix(): Matrix4 | null;
73
29
  set textureMatrix(v: Matrix4 | null);
30
+ get hasBlur(): boolean;
31
+ set hasBlur(v: boolean);
74
32
  get mirror(): number;
75
33
  set mirror(v: number);
76
34
  get mixBlur(): number;
@@ -97,22 +55,8 @@ export declare type MeshReflectorMaterialImpl = {
97
55
  textureMatrix: Matrix4;
98
56
  tDiffuse: Texture;
99
57
  distortionMap?: Texture;
100
- u_mipmap_0?: Texture;
101
- u_mipmap_1?: Texture;
102
- u_mipmap_2?: Texture;
103
- u_mipmap_3?: Texture;
104
- u_mipmap_4?: Texture;
105
- u_mipmap_5?: Texture;
106
- u_mipmap_6?: Texture;
107
- u_mipmap_7?: Texture;
108
- u_mipmap_res_0?: Vector2;
109
- u_mipmap_res_1?: Vector2;
110
- u_mipmap_res_2?: Vector2;
111
- u_mipmap_res_3?: Vector2;
112
- u_mipmap_res_4?: Vector2;
113
- u_mipmap_res_5?: Vector2;
114
- u_mipmap_res_6?: Vector2;
115
- u_mipmap_res_7?: Vector2;
58
+ tDiffuseBlur: Texture;
59
+ hasBlur: boolean;
116
60
  minDepthThreshold: number;
117
61
  maxDepthThreshold: number;
118
62
  depthScale: number;