@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,35 +0,0 @@
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 };
@@ -1,164 +0,0 @@
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 };
@@ -1,41 +0,0 @@
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 };
@@ -1,14 +0,0 @@
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 };
@@ -1,18 +0,0 @@
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 };
@@ -1,75 +0,0 @@
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 };
@@ -1,99 +0,0 @@
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 };
@@ -1,5 +0,0 @@
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 };