@react-three/drei 7.27.0 → 7.27.4
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/README.md +6 -5
- package/core/MeshReflectorMaterial.cjs.js +1 -1
- package/core/MeshReflectorMaterial.d.ts +2 -1
- package/core/MeshReflectorMaterial.js +9 -5
- package/core/OrthographicCamera.cjs.js +1 -1
- package/core/OrthographicCamera.js +1 -2
- package/core/PerspectiveCamera.cjs.js +1 -1
- package/core/PerspectiveCamera.js +1 -2
- package/core/Reflector.cjs.js +1 -1
- package/core/Reflector.d.ts +2 -1
- package/core/Reflector.js +5 -3
- package/index.cjs.js +1 -1
- package/materials/MeshReflectorMaterial.cjs.js +1 -1
- package/materials/MeshReflectorMaterial.d.ts +4 -0
- package/materials/MeshReflectorMaterial.js +20 -2
- package/package.json +1 -1
- package/web/PresentationControls.cjs.js +1 -1
- package/web/PresentationControls.js +1 -1
|
@@ -1 +1 @@
|
|
|
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)
|
|
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._mixContrast={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.uniforms.mixContrast=this._mixContrast,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 mixContrast;\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 vec4 newMerge = vec4(0.0, 0.0, 0.0, 1.0);\n newMerge.r = (merge.r - 0.5) * mixContrast + 0.5;\n newMerge.g = (merge.g - 0.5) * mixContrast + 0.5;\n newMerge.b = (merge.b - 0.5) * mixContrast + 0.5;\n\n diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + newMerge.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}get mixContrast(){return this._mixContrast.value}set mixContrast(e){this._mixContrast.value=e}}exports.MeshReflectorMaterial=t;
|
|
@@ -15,6 +15,7 @@ export declare class MeshReflectorMaterial extends MeshStandardMaterial {
|
|
|
15
15
|
private _depthScale;
|
|
16
16
|
private _depthToBlurRatioBias;
|
|
17
17
|
private _distortion;
|
|
18
|
+
private _mixContrast;
|
|
18
19
|
constructor(parameters?: {});
|
|
19
20
|
onBeforeCompile(shader: any): void;
|
|
20
21
|
get tDiffuse(): Texture | null;
|
|
@@ -47,6 +48,8 @@ export declare class MeshReflectorMaterial extends MeshStandardMaterial {
|
|
|
47
48
|
set depthToBlurRatioBias(v: number);
|
|
48
49
|
get distortion(): number;
|
|
49
50
|
set distortion(v: number);
|
|
51
|
+
get mixContrast(): number;
|
|
52
|
+
set mixContrast(v: number);
|
|
50
53
|
}
|
|
51
54
|
export declare type MeshReflectorMaterialProps = {
|
|
52
55
|
mixBlur: number;
|
|
@@ -62,4 +65,5 @@ export declare type MeshReflectorMaterialProps = {
|
|
|
62
65
|
depthScale: number;
|
|
63
66
|
depthToBlurRatioBias: number;
|
|
64
67
|
distortion: number;
|
|
68
|
+
mixContrast: number;
|
|
65
69
|
} & JSX.IntrinsicElements['meshStandardMaterial'];
|
|
@@ -48,6 +48,9 @@ class MeshReflectorMaterial extends MeshStandardMaterial {
|
|
|
48
48
|
this._distortion = {
|
|
49
49
|
value: 1
|
|
50
50
|
};
|
|
51
|
+
this._mixContrast = {
|
|
52
|
+
value: 1.0
|
|
53
|
+
};
|
|
51
54
|
this.setValues(parameters);
|
|
52
55
|
}
|
|
53
56
|
|
|
@@ -73,6 +76,7 @@ class MeshReflectorMaterial extends MeshStandardMaterial {
|
|
|
73
76
|
shader.uniforms.depthScale = this._depthScale;
|
|
74
77
|
shader.uniforms.depthToBlurRatioBias = this._depthToBlurRatioBias;
|
|
75
78
|
shader.uniforms.distortion = this._distortion;
|
|
79
|
+
shader.uniforms.mixContrast = this._mixContrast;
|
|
76
80
|
shader.vertexShader = `
|
|
77
81
|
uniform mat4 textureMatrix;
|
|
78
82
|
varying vec4 my_vUv;
|
|
@@ -95,6 +99,7 @@ class MeshReflectorMaterial extends MeshStandardMaterial {
|
|
|
95
99
|
uniform float mixStrength;
|
|
96
100
|
uniform float minDepthThreshold;
|
|
97
101
|
uniform float maxDepthThreshold;
|
|
102
|
+
uniform float mixContrast;
|
|
98
103
|
uniform float depthScale;
|
|
99
104
|
uniform float depthToBlurRatioBias;
|
|
100
105
|
varying vec4 my_vUv;
|
|
@@ -138,7 +143,7 @@ class MeshReflectorMaterial extends MeshStandardMaterial {
|
|
|
138
143
|
|
|
139
144
|
#ifdef USE_BLUR
|
|
140
145
|
blur = blur * min(1.0, depthFactor + depthToBlurRatioBias);
|
|
141
|
-
merge = merge * min(1.0, depthFactor + 0.5)
|
|
146
|
+
merge = merge * min(1.0, depthFactor + 0.5);
|
|
142
147
|
#else
|
|
143
148
|
merge = merge * depthFactor;
|
|
144
149
|
#endif
|
|
@@ -156,7 +161,12 @@ class MeshReflectorMaterial extends MeshStandardMaterial {
|
|
|
156
161
|
merge = mix(merge, blur, blurFactor);
|
|
157
162
|
#endif
|
|
158
163
|
|
|
159
|
-
|
|
164
|
+
vec4 newMerge = vec4(0.0, 0.0, 0.0, 1.0);
|
|
165
|
+
newMerge.r = (merge.r - 0.5) * mixContrast + 0.5;
|
|
166
|
+
newMerge.g = (merge.g - 0.5) * mixContrast + 0.5;
|
|
167
|
+
newMerge.b = (merge.b - 0.5) * mixContrast + 0.5;
|
|
168
|
+
|
|
169
|
+
diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + newMerge.rgb * mixStrength);
|
|
160
170
|
diffuseColor = sRGBToLinear(diffuseColor);
|
|
161
171
|
|
|
162
172
|
if (debug == 1) {
|
|
@@ -294,6 +304,14 @@ class MeshReflectorMaterial extends MeshStandardMaterial {
|
|
|
294
304
|
this._distortion.value = v;
|
|
295
305
|
}
|
|
296
306
|
|
|
307
|
+
get mixContrast() {
|
|
308
|
+
return this._mixContrast.value;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
set mixContrast(v) {
|
|
312
|
+
this._mixContrast.value = v;
|
|
313
|
+
}
|
|
314
|
+
|
|
297
315
|
}
|
|
298
316
|
|
|
299
317
|
export { MeshReflectorMaterial };
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),o=require("@react-three/fiber"),n=require("@react-spring/three"),a=require("@use-gesture/react");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var u=i(e),c=s(t);exports.PresentationControls=function({snap:e,global:t,children:i,speed:s=1,rotation:l=[0,0,0],zoom:f=1,polar:d=[0,Math.PI/2],azimuth:b=[-1/0,1/0],config:g={mass:1,tension:170,friction:26}}){const{size:m,gl:p}=o.useThree(),h=c.useMemo((()=>[l[0]+d[0],l[0]+d[1]]),[l[0],d[0],d[1]]),y=c.useMemo((()=>[l[1]+b[0],l[1]+b[1]]),[l[1],b[0],b[1]]),M=c.useMemo((()=>[r.MathUtils.clamp(l[0],...h),r.MathUtils.clamp(l[1],...y),l[2]]),[l[0],l[1],l[2],h,y]),[j
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@babel/runtime/helpers/extends"),t=require("react"),r=require("three"),o=require("@react-three/fiber"),n=require("@react-spring/three"),a=require("@use-gesture/react");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}function s(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var u=i(e),c=s(t);exports.PresentationControls=function({snap:e,global:t,children:i,speed:s=1,rotation:l=[0,0,0],zoom:f=1,polar:d=[0,Math.PI/2],azimuth:b=[-1/0,1/0],config:g={mass:1,tension:170,friction:26}}){const{size:m,gl:p}=o.useThree(),h=c.useMemo((()=>[l[0]+d[0],l[0]+d[1]]),[l[0],d[0],d[1]]),y=c.useMemo((()=>[l[1]+b[0],l[1]+b[1]]),[l[1],b[0],b[1]]),M=c.useMemo((()=>[r.MathUtils.clamp(l[0],...h),r.MathUtils.clamp(l[1],...y),l[2]]),[l[0],l[1],l[2],h,y]),[v,j]=n.useSpring((()=>({scale:1,rotation:M,config:g})));c.useEffect((()=>{j.start({scale:1,rotation:M,config:g})}),[M]),c.useEffect((()=>{t&&(document.body.style.cursor="grab")}),[t]);const O=a.useGesture({onHover:({last:e})=>{t||(document.body.style.cursor=e?"auto":"grab")},onDrag:({down:t,delta:[o,n],memo:[a,i]=v.rotation.animation.to||M})=>{document.body.style.cursor=t?"grabbing":"grab",o=r.MathUtils.clamp(i+o/m.width*Math.PI*s,...y),n=r.MathUtils.clamp(a+n/m.height*Math.PI*s,...h);const u=e&&!t&&"boolean"!=typeof e?e:g;return j.start({scale:t&&n>h[1]/2?f:1,rotation:e&&!t?M:[n,o,0],config:e=>"scale"===e?{...u,friction:3*u.friction}:u}),[n,o]}},{target:t?p.domElement:void 0});return c.createElement(n.a.group,u.default({},null==O?void 0:O(),v),i)};
|
|
@@ -65,7 +65,7 @@ function PresentationControls({
|
|
|
65
65
|
return [y, x];
|
|
66
66
|
}
|
|
67
67
|
}, {
|
|
68
|
-
target: global
|
|
68
|
+
target: global ? gl.domElement : undefined
|
|
69
69
|
});
|
|
70
70
|
return /*#__PURE__*/React.createElement(a.group, _extends({}, bind == null ? void 0 : bind(), spring), children);
|
|
71
71
|
}
|