@react-three/drei 9.108.2 → 9.108.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("../core/shaderMaterial.cjs.js"),n=require("three-mesh-bvh"),i=require("../helpers/constants.cjs.js");function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}})),r.default=e,Object.freeze(r)}var t=o(e);const a=r.shaderMaterial({envMap:null,bounces:3,ior:2.4,correctMips:!0,aberrationStrength:.01,fresnel:0,bvh:new n.MeshBVHUniformStruct,color:new t.Color("white"),resolution:new t.Vector2,viewMatrixInverse:new t.Matrix4,projectionMatrixInverse:new t.Matrix4},"\n uniform mat4 viewMatrixInverse;\n\n varying vec3 vWorldPosition
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("three"),r=require("../core/shaderMaterial.cjs.js"),n=require("three-mesh-bvh"),i=require("../helpers/constants.cjs.js");function o(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}})),r.default=e,Object.freeze(r)}var t=o(e);const a=r.shaderMaterial({envMap:null,bounces:3,ior:2.4,correctMips:!0,aberrationStrength:.01,fresnel:0,bvh:new n.MeshBVHUniformStruct,color:new t.Color("white"),opacity:1,resolution:new t.Vector2,viewMatrixInverse:new t.Matrix4,projectionMatrixInverse:new t.Matrix4},"\n uniform mat4 viewMatrixInverse;\n\n varying vec3 vWorldPosition;\n varying vec3 vNormal;\n varying mat4 vModelMatrixInverse;\n\n #include <color_pars_vertex>\n\n void main() {\n #include <color_vertex>\n\n vec4 transformedNormal = vec4(normal, 0.0);\n vec4 transformedPosition = vec4(position, 1.0);\n #ifdef USE_INSTANCING\n transformedNormal = instanceMatrix * transformedNormal;\n transformedPosition = instanceMatrix * transformedPosition;\n #endif\n\n #ifdef USE_INSTANCING\n vModelMatrixInverse = inverse(modelMatrix * instanceMatrix);\n #else\n vModelMatrixInverse = inverse(modelMatrix);\n #endif\n\n vWorldPosition = (modelMatrix * transformedPosition).xyz;\n vNormal = normalize((viewMatrixInverse * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);\n gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;\n }",`\n #define ENVMAP_TYPE_CUBE_UV\n precision highp isampler2D;\n precision highp usampler2D;\n varying vec3 vWorldPosition;\n varying vec3 vNormal;\n varying mat4 vModelMatrixInverse;\n\n #include <color_pars_fragment>\n\n #ifdef ENVMAP_TYPE_CUBEM\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n\n uniform float bounces;\n ${n.shaderStructs}\n ${n.shaderIntersectFunction}\n uniform BVH bvh;\n uniform float ior;\n uniform bool correctMips;\n uniform vec2 resolution;\n uniform float fresnel;\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrixInverse;\n uniform mat4 viewMatrixInverse;\n uniform float aberrationStrength;\n uniform vec3 color;\n uniform float opacity;\n\n float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {\n return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );\n }\n\n vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 normal, float ior, mat4 modelMatrixInverse) {\n vec3 rayOrigin = ro;\n vec3 rayDirection = rd;\n rayDirection = refract(rayDirection, normal, 1.0 / ior);\n rayOrigin = vWorldPosition + rayDirection * 0.001;\n rayOrigin = (modelMatrixInverse * vec4(rayOrigin, 1.0)).xyz;\n rayDirection = normalize((modelMatrixInverse * vec4(rayDirection, 0.0)).xyz);\n for(float i = 0.0; i < bounces; i++) {\n uvec4 faceIndices = uvec4( 0u );\n vec3 faceNormal = vec3( 0.0, 0.0, 1.0 );\n vec3 barycoord = vec3( 0.0 );\n float side = 1.0;\n float dist = 0.0;\n bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );\n vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0);\n vec3 tempDir = refract(rayDirection, faceNormal, ior);\n if (length(tempDir) != 0.0) {\n rayDirection = tempDir;\n break;\n }\n rayDirection = reflect(rayDirection, faceNormal);\n rayOrigin = hitPos + rayDirection * 0.01;\n }\n rayDirection = normalize((modelMatrix * vec4(rayDirection, 0.0)).xyz);\n return rayDirection;\n }\n\n #include <common>\n #include <cube_uv_reflection_fragment>\n\n #ifdef ENVMAP_TYPE_CUBEM\n vec4 textureGradient(samplerCube envMap, vec3 rayDirection, vec3 directionCamPerfect) {\n return textureGrad(envMap, rayDirection, dFdx(correctMips ? directionCamPerfect: rayDirection), dFdy(correctMips ? directionCamPerfect: rayDirection));\n }\n #else\n vec4 textureGradient(sampler2D envMap, vec3 rayDirection, vec3 directionCamPerfect) {\n vec2 uvv = equirectUv( rayDirection );\n vec2 smoothUv = equirectUv( directionCamPerfect );\n return textureGrad(envMap, uvv, dFdx(correctMips ? smoothUv : uvv), dFdy(correctMips ? smoothUv : uvv));\n }\n #endif\n\n void main() {\n vec2 uv = gl_FragCoord.xy / resolution;\n vec3 directionCamPerfect = (projectionMatrixInverse * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;\n directionCamPerfect = (viewMatrixInverse * vec4(directionCamPerfect, 0.0)).xyz;\n directionCamPerfect = normalize(directionCamPerfect);\n vec3 normal = vNormal;\n vec3 rayOrigin = cameraPosition;\n vec3 rayDirection = normalize(vWorldPosition - cameraPosition);\n\n vec4 diffuseColor = vec4(color, opacity);\n #include <color_fragment>\n\n #ifdef CHROMATIC_ABERRATIONS\n vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);\n #ifdef FAST_CHROMA\n vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));\n vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));\n #else\n vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0), vModelMatrixInverse);\n vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0), vModelMatrixInverse);\n #endif\n float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;\n float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;\n float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;\n diffuseColor.rgb *= vec3(finalColorR, finalColorG, finalColorB);\n #else\n rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);\n diffuseColor.rgb *= textureGradient(envMap, rayDirection, directionCamPerfect).rgb;\n #endif\n\n vec3 viewDirection = normalize(vWorldPosition - cameraPosition);\n float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;\n gl_FragColor = vec4(mix(diffuseColor.rgb, vec3(1.0), nFresnel), diffuseColor.a);\n\n #include <tonemapping_fragment>\n #include <${i.version>=154?"colorspace_fragment":"encodings_fragment"}>\n }`);exports.MeshRefractionMaterial=a;
|
|
@@ -13,21 +13,22 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
13
13
|
fresnel: 0,
|
|
14
14
|
bvh: /* @__PURE__ */new MeshBVHUniformStruct(),
|
|
15
15
|
color: /* @__PURE__ */new THREE.Color('white'),
|
|
16
|
+
opacity: 1,
|
|
16
17
|
resolution: /* @__PURE__ */new THREE.Vector2(),
|
|
17
18
|
viewMatrixInverse: /* @__PURE__ */new THREE.Matrix4(),
|
|
18
19
|
projectionMatrixInverse: /* @__PURE__ */new THREE.Matrix4()
|
|
19
20
|
}, /*glsl*/`
|
|
20
21
|
uniform mat4 viewMatrixInverse;
|
|
21
22
|
|
|
22
|
-
varying vec3 vWorldPosition;
|
|
23
|
+
varying vec3 vWorldPosition;
|
|
23
24
|
varying vec3 vNormal;
|
|
24
25
|
varying mat4 vModelMatrixInverse;
|
|
25
26
|
|
|
26
|
-
#
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
#include <color_pars_vertex>
|
|
28
|
+
|
|
29
|
+
void main() {
|
|
30
|
+
#include <color_vertex>
|
|
29
31
|
|
|
30
|
-
void main() {
|
|
31
32
|
vec4 transformedNormal = vec4(normal, 0.0);
|
|
32
33
|
vec4 transformedPosition = vec4(position, 1.0);
|
|
33
34
|
#ifdef USE_INSTANCING
|
|
@@ -41,10 +42,6 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
41
42
|
vModelMatrixInverse = inverse(modelMatrix);
|
|
42
43
|
#endif
|
|
43
44
|
|
|
44
|
-
#ifdef USE_INSTANCING_COLOR
|
|
45
|
-
vInstanceColor = instanceColor.rgb;
|
|
46
|
-
#endif
|
|
47
|
-
|
|
48
45
|
vWorldPosition = (modelMatrix * transformedPosition).xyz;
|
|
49
46
|
vNormal = normalize((viewMatrixInverse * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);
|
|
50
47
|
gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;
|
|
@@ -56,16 +53,14 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
56
53
|
varying vec3 vNormal;
|
|
57
54
|
varying mat4 vModelMatrixInverse;
|
|
58
55
|
|
|
59
|
-
#
|
|
60
|
-
|
|
61
|
-
#endif
|
|
62
|
-
|
|
56
|
+
#include <color_pars_fragment>
|
|
57
|
+
|
|
63
58
|
#ifdef ENVMAP_TYPE_CUBEM
|
|
64
59
|
uniform samplerCube envMap;
|
|
65
60
|
#else
|
|
66
61
|
uniform sampler2D envMap;
|
|
67
62
|
#endif
|
|
68
|
-
|
|
63
|
+
|
|
69
64
|
uniform float bounces;
|
|
70
65
|
${shaderStructs}
|
|
71
66
|
${shaderIntersectFunction}
|
|
@@ -79,11 +74,12 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
79
74
|
uniform mat4 viewMatrixInverse;
|
|
80
75
|
uniform float aberrationStrength;
|
|
81
76
|
uniform vec3 color;
|
|
82
|
-
|
|
77
|
+
uniform float opacity;
|
|
78
|
+
|
|
83
79
|
float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {
|
|
84
80
|
return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );
|
|
85
81
|
}
|
|
86
|
-
|
|
82
|
+
|
|
87
83
|
vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 normal, float ior, mat4 modelMatrixInverse) {
|
|
88
84
|
vec3 rayOrigin = ro;
|
|
89
85
|
vec3 rayDirection = rd;
|
|
@@ -98,7 +94,7 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
98
94
|
float side = 1.0;
|
|
99
95
|
float dist = 0.0;
|
|
100
96
|
bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );
|
|
101
|
-
vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0);
|
|
97
|
+
vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0);
|
|
102
98
|
vec3 tempDir = refract(rayDirection, faceNormal, ior);
|
|
103
99
|
if (length(tempDir) != 0.0) {
|
|
104
100
|
rayDirection = tempDir;
|
|
@@ -110,10 +106,10 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
110
106
|
rayDirection = normalize((modelMatrix * vec4(rayDirection, 0.0)).xyz);
|
|
111
107
|
return rayDirection;
|
|
112
108
|
}
|
|
113
|
-
|
|
109
|
+
|
|
114
110
|
#include <common>
|
|
115
111
|
#include <cube_uv_reflection_fragment>
|
|
116
|
-
|
|
112
|
+
|
|
117
113
|
#ifdef ENVMAP_TYPE_CUBEM
|
|
118
114
|
vec4 textureGradient(samplerCube envMap, vec3 rayDirection, vec3 directionCamPerfect) {
|
|
119
115
|
return textureGrad(envMap, rayDirection, dFdx(correctMips ? directionCamPerfect: rayDirection), dFdy(correctMips ? directionCamPerfect: rayDirection));
|
|
@@ -125,7 +121,7 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
125
121
|
return textureGrad(envMap, uvv, dFdx(correctMips ? smoothUv : uvv), dFdy(correctMips ? smoothUv : uvv));
|
|
126
122
|
}
|
|
127
123
|
#endif
|
|
128
|
-
|
|
124
|
+
|
|
129
125
|
void main() {
|
|
130
126
|
vec2 uv = gl_FragCoord.xy / resolution;
|
|
131
127
|
vec3 directionCamPerfect = (projectionMatrixInverse * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;
|
|
@@ -134,10 +130,13 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
134
130
|
vec3 normal = vNormal;
|
|
135
131
|
vec3 rayOrigin = cameraPosition;
|
|
136
132
|
vec3 rayDirection = normalize(vWorldPosition - cameraPosition);
|
|
137
|
-
|
|
133
|
+
|
|
134
|
+
vec4 diffuseColor = vec4(color, opacity);
|
|
135
|
+
#include <color_fragment>
|
|
136
|
+
|
|
138
137
|
#ifdef CHROMATIC_ABERRATIONS
|
|
139
138
|
vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
|
|
140
|
-
#ifdef FAST_CHROMA
|
|
139
|
+
#ifdef FAST_CHROMA
|
|
141
140
|
vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));
|
|
142
141
|
vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));
|
|
143
142
|
#else
|
|
@@ -147,20 +146,16 @@ const MeshRefractionMaterial = /* @__PURE__ */shaderMaterial({
|
|
|
147
146
|
float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;
|
|
148
147
|
float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;
|
|
149
148
|
float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;
|
|
150
|
-
|
|
149
|
+
diffuseColor.rgb *= vec3(finalColorR, finalColorG, finalColorB);
|
|
151
150
|
#else
|
|
152
151
|
rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
|
|
153
|
-
|
|
154
|
-
#endif
|
|
155
|
-
|
|
156
|
-
finalColor *= color;
|
|
157
|
-
#ifdef USE_INSTANCING_COLOR
|
|
158
|
-
finalColor *= vInstanceColor;
|
|
152
|
+
diffuseColor.rgb *= textureGradient(envMap, rayDirection, directionCamPerfect).rgb;
|
|
159
153
|
#endif
|
|
160
154
|
|
|
161
155
|
vec3 viewDirection = normalize(vWorldPosition - cameraPosition);
|
|
162
156
|
float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;
|
|
163
|
-
gl_FragColor = vec4(mix(
|
|
157
|
+
gl_FragColor = vec4(mix(diffuseColor.rgb, vec3(1.0), nFresnel), diffuseColor.a);
|
|
158
|
+
|
|
164
159
|
#include <tonemapping_fragment>
|
|
165
160
|
#include <${version >= 154 ? 'colorspace_fragment' : 'encodings_fragment'}>
|
|
166
161
|
}`);
|
package/package.json
CHANGED
|
Binary file
|