@react-three/drei 9.74.11 → 9.74.13

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 +2 -0
  2. package/core/Cloud.js +3 -0
  3. package/core/CubeCamera.js +1 -0
  4. package/core/CubicBezierLine.js +2 -0
  5. package/core/Environment.js +1 -0
  6. package/core/Example.js +6 -0
  7. package/core/FaceControls.cjs.js +1 -1
  8. package/core/FaceControls.js +2 -0
  9. package/core/FaceLandmarker.cjs.js +1 -1
  10. package/core/FaceLandmarker.js +3 -2
  11. package/core/Facemesh.js +2 -0
  12. package/core/GizmoHelper.js +3 -0
  13. package/core/GizmoViewcube.js +4 -0
  14. package/core/GizmoViewport.js +4 -0
  15. package/core/Gltf.js +4 -0
  16. package/core/MeshDiscardMaterial.js +2 -0
  17. package/core/MeshDistortMaterial.js +2 -1
  18. package/core/MeshReflectorMaterial.js +1 -0
  19. package/core/MeshRefractionMaterial.js +2 -0
  20. package/core/MeshTransmissionMaterial.js +1 -0
  21. package/core/OrthographicCamera.js +1 -0
  22. package/core/PerspectiveCamera.js +1 -0
  23. package/core/QuadraticBezierLine.js +2 -0
  24. package/core/Reflector.js +1 -0
  25. package/core/SpotLight.js +2 -1
  26. package/core/Stage.js +7 -0
  27. package/core/Text3D.js +1 -0
  28. package/core/Wireframe.js +1 -0
  29. package/core/index.cjs.js +1 -1
  30. package/core/index.js +0 -1
  31. package/core/useKTX2.js +1 -0
  32. package/core/useMatcapTexture.js +2 -0
  33. package/core/useNormalTexture.js +1 -0
  34. package/index.cjs.js +1 -1
  35. package/materials/DiscardMaterial.js +1 -0
  36. package/materials/MeshRefractionMaterial.js +1 -1
  37. package/native/index.cjs.js +1 -1
  38. package/native/index.js +0 -1
  39. package/package.json +9 -9
  40. package/src/core/AccumulativeShadows.js +311 -0
  41. package/src/core/AdaptiveDpr.js +28 -0
  42. package/src/core/AdaptiveEvents.js +20 -0
  43. package/src/core/ArcballControls.js +67 -0
  44. package/src/core/AsciiRenderer.js +60 -0
  45. package/src/core/BBAnchor.js +37 -0
  46. package/src/core/Backdrop.js +36 -0
  47. package/src/core/BakeShadows.js +16 -0
  48. package/src/core/Billboard.js +41 -0
  49. package/src/core/Bounds.js +245 -0
  50. package/src/core/CameraControls.js +92 -0
  51. package/src/core/CameraShake.js +61 -0
  52. package/src/core/CatmullRomLine.js +44 -0
  53. package/src/core/Caustics.js +375 -0
  54. package/src/core/Center.js +66 -0
  55. package/src/core/Clone.js +102 -0
  56. package/src/core/Cloud.js +59 -0
  57. package/src/core/ComputedAttribute.js +34 -0
  58. package/src/core/ContactShadows.js +114 -0
  59. package/src/core/CubeCamera.js +43 -0
  60. package/src/core/CubicBezierLine.js +28 -0
  61. package/src/core/CurveModifier.js +34 -0
  62. package/src/core/Decal.js +92 -0
  63. package/src/core/Detailed.js +34 -0
  64. package/src/core/DeviceOrientationControls.js +51 -0
  65. package/src/core/Edges.js +36 -0
  66. package/src/core/Effects.js +93 -0
  67. package/src/core/Environment.js +132 -0
  68. package/src/core/Example.js +42 -0
  69. package/src/core/FaceControls.js +315 -0
  70. package/src/core/FaceLandmarker.js +43 -0
  71. package/src/core/Facemesh.js +4545 -0
  72. package/src/core/FirstPersonControls.js +38 -0
  73. package/src/core/Float.js +36 -0
  74. package/src/core/FlyControls.js +55 -0
  75. package/src/core/GizmoHelper.js +111 -0
  76. package/src/core/GizmoViewcube.js +152 -0
  77. package/src/core/GizmoViewport.js +152 -0
  78. package/src/core/Gltf.js +20 -0
  79. package/src/core/GradientTexture.js +33 -0
  80. package/src/core/Grid.js +112 -0
  81. package/src/core/Hud.js +58 -0
  82. package/src/core/Image.js +119 -0
  83. package/src/core/Instances.js +215 -0
  84. package/src/core/Lightformer.js +51 -0
  85. package/src/core/Line.js +68 -0
  86. package/src/core/MapControls.js +64 -0
  87. package/src/core/MarchingCubes.js +76 -0
  88. package/src/core/Mask.js +42 -0
  89. package/src/core/MeshDiscardMaterial.js +15 -0
  90. package/src/core/MeshDistortMaterial.js +79 -0
  91. package/src/core/MeshPortalMaterial.js +381 -0
  92. package/src/core/MeshReflectorMaterial.js +182 -0
  93. package/src/core/MeshRefractionMaterial.js +79 -0
  94. package/src/core/MeshTransmissionMaterial.js +395 -0
  95. package/src/core/MeshWobbleMaterial.js +65 -0
  96. package/src/core/OrbitControls.js +82 -0
  97. package/src/core/OrthographicCamera.js +77 -0
  98. package/src/core/PerformanceMonitor.js +121 -0
  99. package/src/core/PerspectiveCamera.js +73 -0
  100. package/src/core/PointMaterial.js +36 -0
  101. package/src/core/PointerLockControls.js +90 -0
  102. package/src/core/Points.js +227 -0
  103. package/src/core/PositionalAudio.js +51 -0
  104. package/src/core/Preload.js +45 -0
  105. package/src/core/QuadraticBezierLine.js +44 -0
  106. package/src/core/Reflector.js +182 -0
  107. package/src/core/RenderTexture.js +96 -0
  108. package/src/core/Resize.js +39 -0
  109. package/src/core/RoundedBox.js +52 -0
  110. package/src/core/Sampler.js +85 -0
  111. package/src/core/ScreenQuad.js +24 -0
  112. package/src/core/ScreenSpace.js +25 -0
  113. package/src/core/Segments.js +102 -0
  114. package/src/core/Shadow.js +42 -0
  115. package/src/core/Sky.js +39 -0
  116. package/src/core/Sparkles.js +139 -0
  117. package/src/core/SpotLight.js +231 -0
  118. package/src/core/SpriteAnimator.js +342 -0
  119. package/src/core/Stage.js +135 -0
  120. package/src/core/Stars.js +108 -0
  121. package/src/core/Stats.js +30 -0
  122. package/src/core/Svg.js +59 -0
  123. package/src/core/Text.js +58 -0
  124. package/src/core/Text3D.js +76 -0
  125. package/src/core/TrackballControls.js +72 -0
  126. package/src/core/Trail.js +161 -0
  127. package/src/core/TransformControls.js +106 -0
  128. package/src/core/Wireframe.js +185 -0
  129. package/src/core/meshBounds.js +38 -0
  130. package/src/core/shaderMaterial.js +39 -0
  131. package/src/core/shapes.js +68 -0
  132. package/src/core/softShadows.js +161 -0
  133. package/src/core/useAnimations.js +56 -0
  134. package/src/core/useAspect.js +10 -0
  135. package/src/core/useBVH.js +90 -0
  136. package/src/core/useBoxProjectedEnv.js +98 -0
  137. package/src/core/useCamera.js +27 -0
  138. package/src/core/useContextBridge.js +21 -0
  139. package/src/core/useCubeCamera.js +49 -0
  140. package/src/core/useCubeTexture.js +18 -0
  141. package/src/core/useDepthBuffer.js +38 -0
  142. package/src/core/useDetectGPU.js +6 -0
  143. package/src/core/useEnvironment.js +48 -0
  144. package/src/core/useFBO.js +53 -0
  145. package/src/core/useFBX.js +12 -0
  146. package/src/core/useFont.js +20 -0
  147. package/src/core/useGLTF.js +37 -0
  148. package/src/core/useHelper.js +31 -0
  149. package/src/core/useIntersect.js +39 -0
  150. package/src/core/useKTX2.js +38 -0
  151. package/src/core/useMatcapTexture.js +45 -0
  152. package/src/core/useNormalTexture.js +30 -0
  153. package/src/core/useProgress.js +50 -0
  154. package/src/core/useTexture.js +35 -0
  155. package/src/core/useTrailTexture.js +164 -0
  156. package/src/core/useVideoTexture.js +41 -0
  157. package/src/helpers/environment-assets.js +14 -0
  158. package/src/helpers/useEffectfulState.js +18 -0
  159. package/src/materials/BlurPass.js +75 -0
  160. package/src/materials/ConvolutionMaterial.js +99 -0
  161. package/src/materials/DiscardMaterial.js +5 -0
  162. package/src/materials/MeshReflectorMaterial.js +290 -0
  163. package/src/materials/MeshRefractionMaterial.js +171 -0
  164. package/src/materials/SpotLightMaterial.js +111 -0
  165. package/src/materials/WireframeMaterial.js +235 -0
  166. package/src/web/CycleRaycast.js +97 -0
  167. package/src/web/Html.js +417 -0
  168. package/src/web/KeyboardControls.js +101 -0
  169. package/src/web/Loader.js +98 -0
  170. package/src/web/PresentationControls.js +86 -0
  171. package/src/web/ScrollControls.js +246 -0
  172. package/src/web/Select.js +175 -0
  173. package/src/web/View.js +206 -0
  174. package/src/web/pivotControls/AxisArrow.js +202 -0
  175. package/src/web/pivotControls/AxisRotator.js +235 -0
  176. package/src/web/pivotControls/PlaneSlider.js +211 -0
  177. package/src/web/pivotControls/context.js +5 -0
  178. package/src/web/pivotControls/index.js +223 -0
  179. package/src/web/useCursor.js +12 -0
  180. package/web/Loader.js +2 -0
  181. package/web/index.cjs.js +1 -1
  182. package/web/index.js +0 -1
  183. package/web/pivotControls/AxisArrow.js +3 -0
  184. package/web/pivotControls/AxisRotator.js +3 -0
  185. package/web/pivotControls/PlaneSlider.js +3 -0
  186. package/web/pivotControls/index.js +5 -0
  187. /package/{helpers → src/helpers}/glsl/DefaultSpotlightShadowShadows.glsl.js +0 -0
  188. /package/{helpers → src/helpers}/glsl/distort.vert.glsl.js +0 -0
  189. /package/{index.js → src/index.js} +0 -0
@@ -0,0 +1,35 @@
1
+ import { TextureLoader } from 'three';
2
+ import { useThree, useLoader } from '@react-three/fiber';
3
+ import { useLayoutEffect, useEffect } from 'react';
4
+
5
+ const IsObject = url => url === Object(url) && !Array.isArray(url) && typeof url !== 'function';
6
+ function useTexture(input, onLoad) {
7
+ const gl = useThree(state => state.gl);
8
+ const textures = useLoader(TextureLoader, IsObject(input) ? Object.values(input) : input);
9
+ useLayoutEffect(() => {
10
+ onLoad == null ? void 0 : onLoad(textures);
11
+ }, [onLoad]); // https://github.com/mrdoob/three.js/issues/22696
12
+ // Upload the texture to the GPU immediately instead of waiting for the first render
13
+
14
+ useEffect(() => {
15
+ const array = Array.isArray(textures) ? textures : [textures];
16
+ array.forEach(gl.initTexture);
17
+ }, [gl, textures]);
18
+
19
+ if (IsObject(input)) {
20
+ const keys = Object.keys(input);
21
+ const keyed = {};
22
+ keys.forEach(key => Object.assign(keyed, {
23
+ [key]: textures[keys.indexOf(key)]
24
+ }));
25
+ return keyed;
26
+ } else {
27
+ return textures;
28
+ }
29
+ }
30
+
31
+ useTexture.preload = url => useLoader.preload(TextureLoader, url);
32
+
33
+ useTexture.clear = input => useLoader.clear(TextureLoader, input);
34
+
35
+ export { IsObject, useTexture };
@@ -0,0 +1,164 @@
1
+ import { useMemo, useCallback } from 'react';
2
+ import { useFrame } from '@react-three/fiber';
3
+ import { Texture } from 'three';
4
+
5
+ /**
6
+ * Adapted from https://github.com/brunoimbrizi/interactive-particles/blob/master/src/scripts/webgl/particles/TrailTexture.js
7
+ * Changes:
8
+ * * accepts config as constructor params
9
+ * * frame-rate independent aging
10
+ * * added option to interpolate between slow mouse events
11
+ * * added option for smoothing between values to avoid large jumps in force
12
+ */
13
+
14
+ // smooth new sample (measurement) based on previous sample (current)
15
+ function smoothAverage(current, measurement, smoothing = 0.9) {
16
+ return measurement * smoothing + current * (1.0 - smoothing);
17
+ } // default ease
18
+
19
+
20
+ const easeCircleOut = x => Math.sqrt(1 - Math.pow(x - 1, 2));
21
+
22
+ class TrailTexture {
23
+ constructor({
24
+ size = 256,
25
+ maxAge = 750,
26
+ radius = 0.3,
27
+ intensity = 0.2,
28
+ interpolate = 0,
29
+ smoothing = 0,
30
+ minForce = 0.3,
31
+ blend = 'screen',
32
+ // source-over is canvas default. Others are slower
33
+ ease = easeCircleOut
34
+ } = {}) {
35
+ this.size = size;
36
+ this.maxAge = maxAge;
37
+ this.radius = radius;
38
+ this.intensity = intensity;
39
+ this.ease = ease;
40
+ this.interpolate = interpolate;
41
+ this.smoothing = smoothing;
42
+ this.minForce = minForce;
43
+ this.blend = blend;
44
+ this.trail = [];
45
+ this.force = 0;
46
+ this.initTexture();
47
+ }
48
+
49
+ initTexture() {
50
+ this.canvas = document.createElement('canvas');
51
+ this.canvas.width = this.canvas.height = this.size;
52
+ this.ctx = this.canvas.getContext('2d');
53
+ this.ctx.fillStyle = 'black';
54
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
55
+ this.texture = new Texture(this.canvas);
56
+ this.canvas.id = 'touchTexture';
57
+ this.canvas.style.width = this.canvas.style.height = `${this.canvas.width}px`;
58
+ }
59
+
60
+ update(delta) {
61
+ this.clear(); // age points
62
+
63
+ this.trail.forEach((point, i) => {
64
+ point.age += delta * 1000; // remove old
65
+
66
+ if (point.age > this.maxAge) {
67
+ this.trail.splice(i, 1);
68
+ }
69
+ }); // reset force when empty (when smoothing)
70
+
71
+ if (!this.trail.length) this.force = 0;
72
+ this.trail.forEach(point => {
73
+ this.drawTouch(point);
74
+ });
75
+ this.texture.needsUpdate = true;
76
+ }
77
+
78
+ clear() {
79
+ this.ctx.globalCompositeOperation = 'source-over';
80
+ this.ctx.fillStyle = 'black';
81
+ this.ctx.fillRect(0, 0, this.canvas.width, this.canvas.height);
82
+ }
83
+
84
+ addTouch(point) {
85
+ const last = this.trail[this.trail.length - 1];
86
+
87
+ if (last) {
88
+ const dx = last.x - point.x;
89
+ const dy = last.y - point.y;
90
+ const dd = dx * dx + dy * dy;
91
+ const force = Math.max(this.minForce, Math.min(dd * 10000, 1));
92
+ this.force = smoothAverage(force, this.force, this.smoothing);
93
+
94
+ if (!!this.interpolate) {
95
+ const lines = Math.ceil(dd / Math.pow(this.radius * 0.5 / this.interpolate, 2));
96
+
97
+ if (lines > 1) {
98
+ for (let i = 1; i < lines; i++) {
99
+ this.trail.push({
100
+ x: last.x - dx / lines * i,
101
+ y: last.y - dy / lines * i,
102
+ age: 0,
103
+ force
104
+ });
105
+ }
106
+ }
107
+ }
108
+ }
109
+
110
+ this.trail.push({
111
+ x: point.x,
112
+ y: point.y,
113
+ age: 0,
114
+ force: this.force
115
+ });
116
+ }
117
+
118
+ drawTouch(point) {
119
+ const pos = {
120
+ x: point.x * this.size,
121
+ y: (1 - point.y) * this.size
122
+ };
123
+ let intensity = 1;
124
+
125
+ if (point.age < this.maxAge * 0.3) {
126
+ intensity = this.ease(point.age / (this.maxAge * 0.3));
127
+ } else {
128
+ intensity = this.ease(1 - (point.age - this.maxAge * 0.3) / (this.maxAge * 0.7));
129
+ }
130
+
131
+ intensity *= point.force; // apply blending
132
+
133
+ this.ctx.globalCompositeOperation = this.blend;
134
+ const radius = this.size * this.radius * intensity;
135
+ const grd = this.ctx.createRadialGradient(pos.x, pos.y, Math.max(0, radius * 0.25), pos.x, pos.y, Math.max(0, radius));
136
+ grd.addColorStop(0, `rgba(255, 255, 255, ${this.intensity})`);
137
+ grd.addColorStop(1, `rgba(0, 0, 0, 0.0)`);
138
+ this.ctx.beginPath();
139
+ this.ctx.fillStyle = grd;
140
+ this.ctx.arc(pos.x, pos.y, Math.max(0, radius), 0, Math.PI * 2);
141
+ this.ctx.fill();
142
+ }
143
+
144
+ }
145
+
146
+ function useTrailTexture(config = {}) {
147
+ const {
148
+ size,
149
+ maxAge,
150
+ radius,
151
+ intensity,
152
+ interpolate,
153
+ smoothing,
154
+ minForce,
155
+ blend,
156
+ ease
157
+ } = config;
158
+ const trail = useMemo(() => new TrailTexture(config), [size, maxAge, radius, intensity, interpolate, smoothing, minForce, blend, ease]);
159
+ useFrame((_, delta) => void trail.update(delta));
160
+ const onMove = useCallback(e => trail.addTouch(e.uv), [trail]);
161
+ return [trail.texture, onMove];
162
+ }
163
+
164
+ export { useTrailTexture };
@@ -0,0 +1,41 @@
1
+ import * as THREE from 'three';
2
+ import { useEffect } from 'react';
3
+ import { useThree } from '@react-three/fiber';
4
+ import { suspend } from 'suspend-react';
5
+
6
+ function useVideoTexture(src, props) {
7
+ const {
8
+ unsuspend,
9
+ start,
10
+ crossOrigin,
11
+ muted,
12
+ loop,
13
+ ...rest
14
+ } = {
15
+ unsuspend: 'loadedmetadata',
16
+ crossOrigin: 'Anonymous',
17
+ muted: true,
18
+ loop: true,
19
+ start: true,
20
+ playsInline: true,
21
+ ...props
22
+ };
23
+ const gl = useThree(state => state.gl);
24
+ const texture = suspend(() => new Promise((res, rej) => {
25
+ const video = Object.assign(document.createElement('video'), {
26
+ src: typeof src === 'string' && src || undefined,
27
+ srcObject: src instanceof MediaStream && src || undefined,
28
+ crossOrigin,
29
+ loop,
30
+ muted,
31
+ ...rest
32
+ });
33
+ const texture = new THREE.VideoTexture(video);
34
+ if ('colorSpace' in texture) texture.colorSpace = gl.outputColorSpace;else texture.encoding = gl.outputEncoding;
35
+ video.addEventListener(unsuspend, () => res(texture));
36
+ }), [src]);
37
+ useEffect(() => void (start && texture.image.play()), [texture, start]);
38
+ return texture;
39
+ }
40
+
41
+ export { useVideoTexture };
@@ -0,0 +1,14 @@
1
+ const presetsObj = {
2
+ apartment: 'lebombo_1k.hdr',
3
+ city: 'potsdamer_platz_1k.hdr',
4
+ dawn: 'kiara_1_dawn_1k.hdr',
5
+ forest: 'forest_slope_1k.hdr',
6
+ lobby: 'st_fagans_interior_1k.hdr',
7
+ night: 'dikhololo_night_1k.hdr',
8
+ park: 'rooitou_park_1k.hdr',
9
+ studio: 'studio_small_03_1k.hdr',
10
+ sunset: 'venice_sunset_1k.hdr',
11
+ warehouse: 'empty_warehouse_01_1k.hdr'
12
+ };
13
+
14
+ export { presetsObj };
@@ -0,0 +1,18 @@
1
+ import * as React from 'react';
2
+
3
+ function call(ref, value) {
4
+ if (typeof ref === 'function') ref(value);else if (ref != null) ref.current = value;
5
+ }
6
+
7
+ function useEffectfulState(fn, deps = [], cb) {
8
+ const [state, set] = React.useState();
9
+ React.useLayoutEffect(() => {
10
+ const value = fn();
11
+ set(value);
12
+ call(cb, value);
13
+ return () => call(cb, null);
14
+ }, deps);
15
+ return state;
16
+ }
17
+
18
+ export { useEffectfulState };
@@ -0,0 +1,75 @@
1
+ import { WebGLRenderTarget, LinearFilter, HalfFloatType, 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
+ type: HalfFloatType
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,99 @@
1
+ import { ShaderMaterial, Uniform, Vector2, 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
+ #include <tonemapping_fragment>
55
+ #include <encodings_fragment>
56
+ }`,
57
+ vertexShader: `uniform vec2 texelSize;
58
+ uniform vec2 halfTexelSize;
59
+ uniform float kernel;
60
+ uniform float scale;
61
+ varying vec2 vUv;
62
+ varying vec2 vUv0;
63
+ varying vec2 vUv1;
64
+ varying vec2 vUv2;
65
+ varying vec2 vUv3;
66
+
67
+ void main() {
68
+ vec2 uv = position.xy * 0.5 + 0.5;
69
+ vUv = uv;
70
+
71
+ vec2 dUv = (texelSize * vec2(kernel) + halfTexelSize) * scale;
72
+ vUv0 = vec2(uv.x - dUv.x, uv.y + dUv.y);
73
+ vUv1 = vec2(uv.x + dUv.x, uv.y + dUv.y);
74
+ vUv2 = vec2(uv.x + dUv.x, uv.y - dUv.y);
75
+ vUv3 = vec2(uv.x - dUv.x, uv.y - dUv.y);
76
+
77
+ gl_Position = vec4(position.xy, 1.0, 1.0);
78
+ }`,
79
+ blending: NoBlending,
80
+ depthWrite: false,
81
+ depthTest: false
82
+ });
83
+ this.toneMapped = false;
84
+ this.setTexelSize(texelSize.x, texelSize.y);
85
+ this.kernel = new Float32Array([0.0, 1.0, 2.0, 2.0, 3.0]);
86
+ }
87
+
88
+ setTexelSize(x, y) {
89
+ this.uniforms.texelSize.value.set(x, y);
90
+ this.uniforms.halfTexelSize.value.set(x, y).multiplyScalar(0.5);
91
+ }
92
+
93
+ setResolution(resolution) {
94
+ this.uniforms.resolution.value.copy(resolution);
95
+ }
96
+
97
+ }
98
+
99
+ export { ConvolutionMaterial };
@@ -0,0 +1,5 @@
1
+ import { shaderMaterial } from '../core/shaderMaterial.js';
2
+
3
+ const DiscardMaterial = shaderMaterial({}, 'void main() { }', 'void main() { gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); discard; }');
4
+
5
+ export { DiscardMaterial };