@react-three/drei 9.74.13 → 9.74.14

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 (189) hide show
  1. package/core/CatmullRomLine.js +0 -2
  2. package/core/Cloud.js +0 -3
  3. package/core/CubeCamera.js +0 -1
  4. package/core/CubicBezierLine.js +0 -2
  5. package/core/Environment.js +0 -1
  6. package/core/Example.js +0 -6
  7. package/core/FaceControls.cjs.js +1 -1
  8. package/core/FaceControls.js +0 -2
  9. package/core/FaceLandmarker.cjs.js +1 -1
  10. package/core/FaceLandmarker.js +2 -3
  11. package/core/Facemesh.js +0 -2
  12. package/core/GizmoHelper.js +0 -3
  13. package/core/GizmoViewcube.js +0 -4
  14. package/core/GizmoViewport.js +0 -4
  15. package/core/Gltf.js +0 -4
  16. package/core/MeshDiscardMaterial.js +0 -2
  17. package/core/MeshDistortMaterial.js +1 -2
  18. package/core/MeshReflectorMaterial.js +0 -1
  19. package/core/MeshRefractionMaterial.js +0 -2
  20. package/core/MeshTransmissionMaterial.js +0 -1
  21. package/core/OrthographicCamera.js +0 -1
  22. package/core/PerspectiveCamera.js +0 -1
  23. package/core/QuadraticBezierLine.js +0 -2
  24. package/core/Reflector.js +0 -1
  25. package/core/SpotLight.js +1 -2
  26. package/core/Stage.js +0 -7
  27. package/core/Text3D.js +0 -1
  28. package/core/Wireframe.js +0 -1
  29. package/core/index.cjs.js +1 -1
  30. package/core/index.js +1 -0
  31. package/core/useKTX2.js +0 -1
  32. package/core/useMatcapTexture.js +0 -2
  33. package/core/useNormalTexture.js +0 -1
  34. package/index.cjs.js +1 -1
  35. package/materials/DiscardMaterial.js +0 -1
  36. package/materials/MeshRefractionMaterial.js +1 -1
  37. package/native/index.cjs.js +1 -1
  38. package/native/index.js +1 -0
  39. package/package.json +2 -2
  40. package/web/Loader.js +0 -2
  41. package/web/index.cjs.js +1 -1
  42. package/web/index.js +1 -0
  43. package/web/pivotControls/AxisArrow.js +0 -3
  44. package/web/pivotControls/AxisRotator.js +0 -3
  45. package/web/pivotControls/PlaneSlider.js +0 -3
  46. package/web/pivotControls/index.js +0 -5
  47. package/src/core/AccumulativeShadows.js +0 -311
  48. package/src/core/AdaptiveDpr.js +0 -28
  49. package/src/core/AdaptiveEvents.js +0 -20
  50. package/src/core/ArcballControls.js +0 -67
  51. package/src/core/AsciiRenderer.js +0 -60
  52. package/src/core/BBAnchor.js +0 -37
  53. package/src/core/Backdrop.js +0 -36
  54. package/src/core/BakeShadows.js +0 -16
  55. package/src/core/Billboard.js +0 -41
  56. package/src/core/Bounds.js +0 -245
  57. package/src/core/CameraControls.js +0 -92
  58. package/src/core/CameraShake.js +0 -61
  59. package/src/core/CatmullRomLine.js +0 -44
  60. package/src/core/Caustics.js +0 -375
  61. package/src/core/Center.js +0 -66
  62. package/src/core/Clone.js +0 -102
  63. package/src/core/Cloud.js +0 -59
  64. package/src/core/ComputedAttribute.js +0 -34
  65. package/src/core/ContactShadows.js +0 -114
  66. package/src/core/CubeCamera.js +0 -43
  67. package/src/core/CubicBezierLine.js +0 -28
  68. package/src/core/CurveModifier.js +0 -34
  69. package/src/core/Decal.js +0 -92
  70. package/src/core/Detailed.js +0 -34
  71. package/src/core/DeviceOrientationControls.js +0 -51
  72. package/src/core/Edges.js +0 -36
  73. package/src/core/Effects.js +0 -93
  74. package/src/core/Environment.js +0 -132
  75. package/src/core/Example.js +0 -42
  76. package/src/core/FaceControls.js +0 -315
  77. package/src/core/FaceLandmarker.js +0 -43
  78. package/src/core/Facemesh.js +0 -4545
  79. package/src/core/FirstPersonControls.js +0 -38
  80. package/src/core/Float.js +0 -36
  81. package/src/core/FlyControls.js +0 -55
  82. package/src/core/GizmoHelper.js +0 -111
  83. package/src/core/GizmoViewcube.js +0 -152
  84. package/src/core/GizmoViewport.js +0 -152
  85. package/src/core/Gltf.js +0 -20
  86. package/src/core/GradientTexture.js +0 -33
  87. package/src/core/Grid.js +0 -112
  88. package/src/core/Hud.js +0 -58
  89. package/src/core/Image.js +0 -119
  90. package/src/core/Instances.js +0 -215
  91. package/src/core/Lightformer.js +0 -51
  92. package/src/core/Line.js +0 -68
  93. package/src/core/MapControls.js +0 -64
  94. package/src/core/MarchingCubes.js +0 -76
  95. package/src/core/Mask.js +0 -42
  96. package/src/core/MeshDiscardMaterial.js +0 -15
  97. package/src/core/MeshDistortMaterial.js +0 -79
  98. package/src/core/MeshPortalMaterial.js +0 -381
  99. package/src/core/MeshReflectorMaterial.js +0 -182
  100. package/src/core/MeshRefractionMaterial.js +0 -79
  101. package/src/core/MeshTransmissionMaterial.js +0 -395
  102. package/src/core/MeshWobbleMaterial.js +0 -65
  103. package/src/core/OrbitControls.js +0 -82
  104. package/src/core/OrthographicCamera.js +0 -77
  105. package/src/core/PerformanceMonitor.js +0 -121
  106. package/src/core/PerspectiveCamera.js +0 -73
  107. package/src/core/PointMaterial.js +0 -36
  108. package/src/core/PointerLockControls.js +0 -90
  109. package/src/core/Points.js +0 -227
  110. package/src/core/PositionalAudio.js +0 -51
  111. package/src/core/Preload.js +0 -45
  112. package/src/core/QuadraticBezierLine.js +0 -44
  113. package/src/core/Reflector.js +0 -182
  114. package/src/core/RenderTexture.js +0 -96
  115. package/src/core/Resize.js +0 -39
  116. package/src/core/RoundedBox.js +0 -52
  117. package/src/core/Sampler.js +0 -85
  118. package/src/core/ScreenQuad.js +0 -24
  119. package/src/core/ScreenSpace.js +0 -25
  120. package/src/core/Segments.js +0 -102
  121. package/src/core/Shadow.js +0 -42
  122. package/src/core/Sky.js +0 -39
  123. package/src/core/Sparkles.js +0 -139
  124. package/src/core/SpotLight.js +0 -231
  125. package/src/core/SpriteAnimator.js +0 -342
  126. package/src/core/Stage.js +0 -135
  127. package/src/core/Stars.js +0 -108
  128. package/src/core/Stats.js +0 -30
  129. package/src/core/Svg.js +0 -59
  130. package/src/core/Text.js +0 -58
  131. package/src/core/Text3D.js +0 -76
  132. package/src/core/TrackballControls.js +0 -72
  133. package/src/core/Trail.js +0 -161
  134. package/src/core/TransformControls.js +0 -106
  135. package/src/core/Wireframe.js +0 -185
  136. package/src/core/meshBounds.js +0 -38
  137. package/src/core/shaderMaterial.js +0 -39
  138. package/src/core/shapes.js +0 -68
  139. package/src/core/softShadows.js +0 -161
  140. package/src/core/useAnimations.js +0 -56
  141. package/src/core/useAspect.js +0 -10
  142. package/src/core/useBVH.js +0 -90
  143. package/src/core/useBoxProjectedEnv.js +0 -98
  144. package/src/core/useCamera.js +0 -27
  145. package/src/core/useContextBridge.js +0 -21
  146. package/src/core/useCubeCamera.js +0 -49
  147. package/src/core/useCubeTexture.js +0 -18
  148. package/src/core/useDepthBuffer.js +0 -38
  149. package/src/core/useDetectGPU.js +0 -6
  150. package/src/core/useEnvironment.js +0 -48
  151. package/src/core/useFBO.js +0 -53
  152. package/src/core/useFBX.js +0 -12
  153. package/src/core/useFont.js +0 -20
  154. package/src/core/useGLTF.js +0 -37
  155. package/src/core/useHelper.js +0 -31
  156. package/src/core/useIntersect.js +0 -39
  157. package/src/core/useKTX2.js +0 -38
  158. package/src/core/useMatcapTexture.js +0 -45
  159. package/src/core/useNormalTexture.js +0 -30
  160. package/src/core/useProgress.js +0 -50
  161. package/src/core/useTexture.js +0 -35
  162. package/src/core/useTrailTexture.js +0 -164
  163. package/src/core/useVideoTexture.js +0 -41
  164. package/src/helpers/environment-assets.js +0 -14
  165. package/src/helpers/useEffectfulState.js +0 -18
  166. package/src/materials/BlurPass.js +0 -75
  167. package/src/materials/ConvolutionMaterial.js +0 -99
  168. package/src/materials/DiscardMaterial.js +0 -5
  169. package/src/materials/MeshReflectorMaterial.js +0 -290
  170. package/src/materials/MeshRefractionMaterial.js +0 -171
  171. package/src/materials/SpotLightMaterial.js +0 -111
  172. package/src/materials/WireframeMaterial.js +0 -235
  173. package/src/web/CycleRaycast.js +0 -97
  174. package/src/web/Html.js +0 -417
  175. package/src/web/KeyboardControls.js +0 -101
  176. package/src/web/Loader.js +0 -98
  177. package/src/web/PresentationControls.js +0 -86
  178. package/src/web/ScrollControls.js +0 -246
  179. package/src/web/Select.js +0 -175
  180. package/src/web/View.js +0 -206
  181. package/src/web/pivotControls/AxisArrow.js +0 -202
  182. package/src/web/pivotControls/AxisRotator.js +0 -235
  183. package/src/web/pivotControls/PlaneSlider.js +0 -211
  184. package/src/web/pivotControls/context.js +0 -5
  185. package/src/web/pivotControls/index.js +0 -223
  186. package/src/web/useCursor.js +0 -12
  187. /package/{src/helpers → helpers}/glsl/DefaultSpotlightShadowShadows.glsl.js +0 -0
  188. /package/{src/helpers → helpers}/glsl/distort.vert.glsl.js +0 -0
  189. /package/{src/index.js → index.js} +0 -0
@@ -1,290 +0,0 @@
1
- import { MeshStandardMaterial } from 'three';
2
-
3
- class MeshReflectorMaterial extends MeshStandardMaterial {
4
- constructor(parameters = {}) {
5
- super(parameters);
6
- this._tDepth = {
7
- value: null
8
- };
9
- this._distortionMap = {
10
- value: null
11
- };
12
- this._tDiffuse = {
13
- value: null
14
- };
15
- this._tDiffuseBlur = {
16
- value: null
17
- };
18
- this._textureMatrix = {
19
- value: null
20
- };
21
- this._hasBlur = {
22
- value: false
23
- };
24
- this._mirror = {
25
- value: 0.0
26
- };
27
- this._mixBlur = {
28
- value: 0.0
29
- };
30
- this._blurStrength = {
31
- value: 0.5
32
- };
33
- this._minDepthThreshold = {
34
- value: 0.9
35
- };
36
- this._maxDepthThreshold = {
37
- value: 1
38
- };
39
- this._depthScale = {
40
- value: 0
41
- };
42
- this._depthToBlurRatioBias = {
43
- value: 0.25
44
- };
45
- this._distortion = {
46
- value: 1
47
- };
48
- this._mixContrast = {
49
- value: 1.0
50
- };
51
- this.setValues(parameters);
52
- }
53
-
54
- onBeforeCompile(shader) {
55
- var _shader$defines;
56
-
57
- if (!((_shader$defines = shader.defines) != null && _shader$defines.USE_UV)) {
58
- shader.defines.USE_UV = '';
59
- }
60
-
61
- shader.uniforms.hasBlur = this._hasBlur;
62
- shader.uniforms.tDiffuse = this._tDiffuse;
63
- shader.uniforms.tDepth = this._tDepth;
64
- shader.uniforms.distortionMap = this._distortionMap;
65
- shader.uniforms.tDiffuseBlur = this._tDiffuseBlur;
66
- shader.uniforms.textureMatrix = this._textureMatrix;
67
- shader.uniforms.mirror = this._mirror;
68
- shader.uniforms.mixBlur = this._mixBlur;
69
- shader.uniforms.mixStrength = this._blurStrength;
70
- shader.uniforms.minDepthThreshold = this._minDepthThreshold;
71
- shader.uniforms.maxDepthThreshold = this._maxDepthThreshold;
72
- shader.uniforms.depthScale = this._depthScale;
73
- shader.uniforms.depthToBlurRatioBias = this._depthToBlurRatioBias;
74
- shader.uniforms.distortion = this._distortion;
75
- shader.uniforms.mixContrast = this._mixContrast;
76
- shader.vertexShader = `
77
- uniform mat4 textureMatrix;
78
- varying vec4 my_vUv;
79
- ${shader.vertexShader}`;
80
- shader.vertexShader = shader.vertexShader.replace('#include <project_vertex>', `#include <project_vertex>
81
- my_vUv = textureMatrix * vec4( position, 1.0 );
82
- gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );`);
83
- shader.fragmentShader = `
84
- uniform sampler2D tDiffuse;
85
- uniform sampler2D tDiffuseBlur;
86
- uniform sampler2D tDepth;
87
- uniform sampler2D distortionMap;
88
- uniform float distortion;
89
- uniform float cameraNear;
90
- uniform float cameraFar;
91
- uniform bool hasBlur;
92
- uniform float mixBlur;
93
- uniform float mirror;
94
- uniform float mixStrength;
95
- uniform float minDepthThreshold;
96
- uniform float maxDepthThreshold;
97
- uniform float mixContrast;
98
- uniform float depthScale;
99
- uniform float depthToBlurRatioBias;
100
- varying vec4 my_vUv;
101
- ${shader.fragmentShader}`;
102
- shader.fragmentShader = shader.fragmentShader.replace('#include <emissivemap_fragment>', `#include <emissivemap_fragment>
103
-
104
- float distortionFactor = 0.0;
105
- #ifdef USE_DISTORTION
106
- distortionFactor = texture2D(distortionMap, vUv).r * distortion;
107
- #endif
108
-
109
- vec4 new_vUv = my_vUv;
110
- new_vUv.x += distortionFactor;
111
- new_vUv.y += distortionFactor;
112
-
113
- vec4 base = texture2DProj(tDiffuse, new_vUv);
114
- vec4 blur = texture2DProj(tDiffuseBlur, new_vUv);
115
-
116
- vec4 merge = base;
117
-
118
- #ifdef USE_NORMALMAP
119
- vec2 normal_uv = vec2(0.0);
120
- vec4 normalColor = texture2D(normalMap, vUv * normalScale);
121
- vec3 my_normal = normalize( vec3( normalColor.r * 2.0 - 1.0, normalColor.b, normalColor.g * 2.0 - 1.0 ) );
122
- vec3 coord = new_vUv.xyz / new_vUv.w;
123
- normal_uv = coord.xy + coord.z * my_normal.xz * 0.05;
124
- vec4 base_normal = texture2D(tDiffuse, normal_uv);
125
- vec4 blur_normal = texture2D(tDiffuseBlur, normal_uv);
126
- merge = base_normal;
127
- blur = blur_normal;
128
- #endif
129
-
130
- float depthFactor = 0.0001;
131
- float blurFactor = 0.0;
132
-
133
- #ifdef USE_DEPTH
134
- vec4 depth = texture2DProj(tDepth, new_vUv);
135
- depthFactor = smoothstep(minDepthThreshold, maxDepthThreshold, 1.0-(depth.r * depth.a));
136
- depthFactor *= depthScale;
137
- depthFactor = max(0.0001, min(1.0, depthFactor));
138
-
139
- #ifdef USE_BLUR
140
- blur = blur * min(1.0, depthFactor + depthToBlurRatioBias);
141
- merge = merge * min(1.0, depthFactor + 0.5);
142
- #else
143
- merge = merge * depthFactor;
144
- #endif
145
-
146
- #endif
147
-
148
- float reflectorRoughnessFactor = roughness;
149
- #ifdef USE_ROUGHNESSMAP
150
- vec4 reflectorTexelRoughness = texture2D( roughnessMap, vUv );
151
- reflectorRoughnessFactor *= reflectorTexelRoughness.g;
152
- #endif
153
-
154
- #ifdef USE_BLUR
155
- blurFactor = min(1.0, mixBlur * reflectorRoughnessFactor);
156
- merge = mix(merge, blur, blurFactor);
157
- #endif
158
-
159
- vec4 newMerge = vec4(0.0, 0.0, 0.0, 1.0);
160
- newMerge.r = (merge.r - 0.5) * mixContrast + 0.5;
161
- newMerge.g = (merge.g - 0.5) * mixContrast + 0.5;
162
- newMerge.b = (merge.b - 0.5) * mixContrast + 0.5;
163
-
164
- diffuseColor.rgb = diffuseColor.rgb * ((1.0 - min(1.0, mirror)) + newMerge.rgb * mixStrength);
165
- `);
166
- }
167
-
168
- get tDiffuse() {
169
- return this._tDiffuse.value;
170
- }
171
-
172
- set tDiffuse(v) {
173
- this._tDiffuse.value = v;
174
- }
175
-
176
- get tDepth() {
177
- return this._tDepth.value;
178
- }
179
-
180
- set tDepth(v) {
181
- this._tDepth.value = v;
182
- }
183
-
184
- get distortionMap() {
185
- return this._distortionMap.value;
186
- }
187
-
188
- set distortionMap(v) {
189
- this._distortionMap.value = v;
190
- }
191
-
192
- get tDiffuseBlur() {
193
- return this._tDiffuseBlur.value;
194
- }
195
-
196
- set tDiffuseBlur(v) {
197
- this._tDiffuseBlur.value = v;
198
- }
199
-
200
- get textureMatrix() {
201
- return this._textureMatrix.value;
202
- }
203
-
204
- set textureMatrix(v) {
205
- this._textureMatrix.value = v;
206
- }
207
-
208
- get hasBlur() {
209
- return this._hasBlur.value;
210
- }
211
-
212
- set hasBlur(v) {
213
- this._hasBlur.value = v;
214
- }
215
-
216
- get mirror() {
217
- return this._mirror.value;
218
- }
219
-
220
- set mirror(v) {
221
- this._mirror.value = v;
222
- }
223
-
224
- get mixBlur() {
225
- return this._mixBlur.value;
226
- }
227
-
228
- set mixBlur(v) {
229
- this._mixBlur.value = v;
230
- }
231
-
232
- get mixStrength() {
233
- return this._blurStrength.value;
234
- }
235
-
236
- set mixStrength(v) {
237
- this._blurStrength.value = v;
238
- }
239
-
240
- get minDepthThreshold() {
241
- return this._minDepthThreshold.value;
242
- }
243
-
244
- set minDepthThreshold(v) {
245
- this._minDepthThreshold.value = v;
246
- }
247
-
248
- get maxDepthThreshold() {
249
- return this._maxDepthThreshold.value;
250
- }
251
-
252
- set maxDepthThreshold(v) {
253
- this._maxDepthThreshold.value = v;
254
- }
255
-
256
- get depthScale() {
257
- return this._depthScale.value;
258
- }
259
-
260
- set depthScale(v) {
261
- this._depthScale.value = v;
262
- }
263
-
264
- get depthToBlurRatioBias() {
265
- return this._depthToBlurRatioBias.value;
266
- }
267
-
268
- set depthToBlurRatioBias(v) {
269
- this._depthToBlurRatioBias.value = v;
270
- }
271
-
272
- get distortion() {
273
- return this._distortion.value;
274
- }
275
-
276
- set distortion(v) {
277
- this._distortion.value = v;
278
- }
279
-
280
- get mixContrast() {
281
- return this._mixContrast.value;
282
- }
283
-
284
- set mixContrast(v) {
285
- this._mixContrast.value = v;
286
- }
287
-
288
- }
289
-
290
- export { MeshReflectorMaterial };
@@ -1,171 +0,0 @@
1
- import * as THREE from 'three';
2
- import { shaderMaterial } from '../core/shaderMaterial.js';
3
- import { shaderStructs, shaderIntersectFunction, MeshBVHUniformStruct } from 'three-mesh-bvh';
4
-
5
- // Author: N8Programs
6
- const MeshRefractionMaterial = shaderMaterial({
7
- envMap: null,
8
- bounces: 3,
9
- ior: 2.4,
10
- correctMips: true,
11
- aberrationStrength: 0.01,
12
- fresnel: 0,
13
- bvh: new MeshBVHUniformStruct(),
14
- color: new THREE.Color('white'),
15
- resolution: new THREE.Vector2(),
16
- viewMatrixInverse: new THREE.Matrix4(),
17
- projectionMatrixInverse: new THREE.Matrix4()
18
- },
19
- /*glsl*/
20
- `
21
- uniform mat4 viewMatrixInverse;
22
-
23
- varying vec3 vWorldPosition;
24
- varying vec3 vNormal;
25
- varying mat4 vModelMatrixInverse;
26
-
27
- #ifdef USE_INSTANCING_COLOR
28
- varying vec3 vInstanceColor;
29
- #endif
30
-
31
- void main() {
32
- vec4 transformedNormal = vec4(normal, 0.0);
33
- vec4 transformedPosition = vec4(position, 1.0);
34
- #ifdef USE_INSTANCING
35
- transformedNormal = instanceMatrix * transformedNormal;
36
- transformedPosition = instanceMatrix * transformedPosition;
37
- #endif
38
-
39
- #ifdef USE_INSTANCING
40
- vModelMatrixInverse = inverse(modelMatrix * instanceMatrix);
41
- #else
42
- vModelMatrixInverse = inverse(modelMatrix);
43
- #endif
44
-
45
- #ifdef USE_INSTANCING_COLOR
46
- vInstanceColor = instanceColor.rgb;
47
- #endif
48
-
49
- vWorldPosition = (modelMatrix * transformedPosition).xyz;
50
- vNormal = normalize((viewMatrixInverse * vec4(normalMatrix * transformedNormal.xyz, 0.0)).xyz);
51
- gl_Position = projectionMatrix * viewMatrix * modelMatrix * transformedPosition;
52
- }`,
53
- /*glsl*/
54
- `
55
- #define ENVMAP_TYPE_CUBE_UV
56
- precision highp isampler2D;
57
- precision highp usampler2D;
58
- varying vec3 vWorldPosition;
59
- varying vec3 vNormal;
60
- varying mat4 vModelMatrixInverse;
61
-
62
- #ifdef USE_INSTANCING_COLOR
63
- varying vec3 vInstanceColor;
64
- #endif
65
-
66
- #ifdef ENVMAP_TYPE_CUBEM
67
- uniform samplerCube envMap;
68
- #else
69
- uniform sampler2D envMap;
70
- #endif
71
-
72
- uniform float bounces;
73
- ${shaderStructs}
74
- ${shaderIntersectFunction}
75
- uniform BVH bvh;
76
- uniform float ior;
77
- uniform bool correctMips;
78
- uniform vec2 resolution;
79
- uniform float fresnel;
80
- uniform mat4 modelMatrix;
81
- uniform mat4 projectionMatrixInverse;
82
- uniform mat4 viewMatrixInverse;
83
- uniform float aberrationStrength;
84
- uniform vec3 color;
85
-
86
- float fresnelFunc(vec3 viewDirection, vec3 worldNormal) {
87
- return pow( 1.0 + dot( viewDirection, worldNormal), 10.0 );
88
- }
89
-
90
- vec3 totalInternalReflection(vec3 ro, vec3 rd, vec3 normal, float ior, mat4 modelMatrixInverse) {
91
- vec3 rayOrigin = ro;
92
- vec3 rayDirection = rd;
93
- rayDirection = refract(rayDirection, normal, 1.0 / ior);
94
- rayOrigin = vWorldPosition + rayDirection * 0.001;
95
- rayOrigin = (modelMatrixInverse * vec4(rayOrigin, 1.0)).xyz;
96
- rayDirection = normalize((modelMatrixInverse * vec4(rayDirection, 0.0)).xyz);
97
- for(float i = 0.0; i < bounces; i++) {
98
- uvec4 faceIndices = uvec4( 0u );
99
- vec3 faceNormal = vec3( 0.0, 0.0, 1.0 );
100
- vec3 barycoord = vec3( 0.0 );
101
- float side = 1.0;
102
- float dist = 0.0;
103
- bvhIntersectFirstHit( bvh, rayOrigin, rayDirection, faceIndices, faceNormal, barycoord, side, dist );
104
- vec3 hitPos = rayOrigin + rayDirection * max(dist - 0.001, 0.0);
105
- vec3 tempDir = refract(rayDirection, faceNormal, ior);
106
- if (length(tempDir) != 0.0) {
107
- rayDirection = tempDir;
108
- break;
109
- }
110
- rayDirection = reflect(rayDirection, faceNormal);
111
- rayOrigin = hitPos + rayDirection * 0.01;
112
- }
113
- rayDirection = normalize((modelMatrix * vec4(rayDirection, 0.0)).xyz);
114
- return rayDirection;
115
- }
116
-
117
- #include <common>
118
- #include <cube_uv_reflection_fragment>
119
-
120
- #ifdef ENVMAP_TYPE_CUBEM
121
- vec4 textureGradient(samplerCube envMap, vec3 rayDirection, vec3 directionCamPerfect) {
122
- return textureGrad(envMap, rayDirection, dFdx(correctMips ? directionCamPerfect: rayDirection), dFdy(correctMips ? directionCamPerfect: rayDirection));
123
- }
124
- #else
125
- vec4 textureGradient(sampler2D envMap, vec3 rayDirection, vec3 directionCamPerfect) {
126
- vec2 uvv = equirectUv( rayDirection );
127
- vec2 smoothUv = equirectUv( directionCamPerfect );
128
- return textureGrad(envMap, uvv, dFdx(correctMips ? smoothUv : uvv), dFdy(correctMips ? smoothUv : uvv));
129
- }
130
- #endif
131
-
132
- void main() {
133
- vec2 uv = gl_FragCoord.xy / resolution;
134
- vec3 directionCamPerfect = (projectionMatrixInverse * vec4(uv * 2.0 - 1.0, 0.0, 1.0)).xyz;
135
- directionCamPerfect = (viewMatrixInverse * vec4(directionCamPerfect, 0.0)).xyz;
136
- directionCamPerfect = normalize(directionCamPerfect);
137
- vec3 normal = vNormal;
138
- vec3 rayOrigin = cameraPosition;
139
- vec3 rayDirection = normalize(vWorldPosition - cameraPosition);
140
- vec3 finalColor;
141
- #ifdef CHROMATIC_ABERRATIONS
142
- vec3 rayDirectionG = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
143
- #ifdef FAST_CHROMA
144
- vec3 rayDirectionR = normalize(rayDirectionG + 1.0 * vec3(aberrationStrength / 2.0));
145
- vec3 rayDirectionB = normalize(rayDirectionG - 1.0 * vec3(aberrationStrength / 2.0));
146
- #else
147
- vec3 rayDirectionR = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 - aberrationStrength), 1.0), vModelMatrixInverse);
148
- vec3 rayDirectionB = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior * (1.0 + aberrationStrength), 1.0), vModelMatrixInverse);
149
- #endif
150
- float finalColorR = textureGradient(envMap, rayDirectionR, directionCamPerfect).r;
151
- float finalColorG = textureGradient(envMap, rayDirectionG, directionCamPerfect).g;
152
- float finalColorB = textureGradient(envMap, rayDirectionB, directionCamPerfect).b;
153
- finalColor = vec3(finalColorR, finalColorG, finalColorB);
154
- #else
155
- rayDirection = totalInternalReflection(rayOrigin, rayDirection, normal, max(ior, 1.0), vModelMatrixInverse);
156
- finalColor = textureGradient(envMap, rayDirection, directionCamPerfect).rgb;
157
- #endif
158
-
159
- finalColor *= color;
160
- #ifdef USE_INSTANCING_COLOR
161
- finalColor *= vInstanceColor;
162
- #endif
163
-
164
- vec3 viewDirection = normalize(vWorldPosition - cameraPosition);
165
- float nFresnel = fresnelFunc(viewDirection, normal) * fresnel;
166
- gl_FragColor = vec4(mix(finalColor, vec3(1.0), nFresnel), 1.0);
167
- #include <tonemapping_fragment>
168
- #include <encodings_fragment>
169
- }`);
170
-
171
- export { MeshRefractionMaterial };
@@ -1,111 +0,0 @@
1
- import { ShaderMaterial, Vector3, Color, Vector2 } from 'three';
2
-
3
- class SpotLightMaterial extends ShaderMaterial {
4
- constructor() {
5
- super({
6
- uniforms: {
7
- depth: {
8
- value: null
9
- },
10
- opacity: {
11
- value: 1
12
- },
13
- attenuation: {
14
- value: 2.5
15
- },
16
- anglePower: {
17
- value: 12
18
- },
19
- spotPosition: {
20
- value: new Vector3(0, 0, 0)
21
- },
22
- lightColor: {
23
- value: new Color('white')
24
- },
25
- cameraNear: {
26
- value: 0
27
- },
28
- cameraFar: {
29
- value: 1
30
- },
31
- resolution: {
32
- value: new Vector2(0, 0)
33
- }
34
- },
35
- transparent: true,
36
- depthWrite: false,
37
- vertexShader:
38
- /* glsl */
39
- `
40
- varying vec3 vNormal;
41
- varying vec3 vWorldPosition;
42
- varying float vViewZ;
43
- varying float vIntensity;
44
- uniform vec3 spotPosition;
45
- uniform float attenuation;
46
-
47
- void main() {
48
- // compute intensity
49
- vNormal = normalize( normalMatrix * normal );
50
- vec4 worldPosition = modelMatrix * vec4( position, 1.0 );
51
- vWorldPosition = worldPosition.xyz;
52
- vec4 viewPosition = viewMatrix * worldPosition;
53
- vViewZ = viewPosition.z;
54
- float intensity = distance(worldPosition.xyz, spotPosition) / attenuation;
55
- intensity = 1.0 - clamp(intensity, 0.0, 1.0);
56
- vIntensity = intensity;
57
- // set gl_Position
58
- gl_Position = projectionMatrix * viewPosition;
59
-
60
- }`,
61
- fragmentShader:
62
- /* glsl */
63
- `
64
- #include <packing>
65
-
66
- varying vec3 vNormal;
67
- varying vec3 vWorldPosition;
68
- uniform vec3 lightColor;
69
- uniform vec3 spotPosition;
70
- uniform float attenuation;
71
- uniform float anglePower;
72
- uniform sampler2D depth;
73
- uniform vec2 resolution;
74
- uniform float cameraNear;
75
- uniform float cameraFar;
76
- varying float vViewZ;
77
- varying float vIntensity;
78
- uniform float opacity;
79
-
80
- float readDepth( sampler2D depthSampler, vec2 coord ) {
81
- float fragCoordZ = texture2D( depthSampler, coord ).x;
82
- float viewZ = perspectiveDepthToViewZ(fragCoordZ, cameraNear, cameraFar);
83
- return viewZ;
84
- }
85
-
86
- void main() {
87
- float d = 1.0;
88
- bool isSoft = resolution[0] > 0.0 && resolution[1] > 0.0;
89
- if (isSoft) {
90
- vec2 sUv = gl_FragCoord.xy / resolution;
91
- d = readDepth(depth, sUv);
92
- }
93
- float intensity = vIntensity;
94
- vec3 normal = vec3(vNormal.x, vNormal.y, abs(vNormal.z));
95
- float angleIntensity = pow( dot(normal, vec3(0.0, 0.0, 1.0)), anglePower );
96
- intensity *= angleIntensity;
97
- // fades when z is close to sampled depth, meaning the cone is intersecting existing geometry
98
- if (isSoft) {
99
- intensity *= smoothstep(0., 1., vViewZ - d);
100
- }
101
- gl_FragColor = vec4(lightColor, intensity * opacity);
102
-
103
- #include <tonemapping_fragment>
104
- #include <encodings_fragment>
105
- }`
106
- });
107
- }
108
-
109
- }
110
-
111
- export { SpotLightMaterial };