three-base 2.0.130 → 2.0.134
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/ApngTexture.d.ts +13 -13
- package/ApngTexture.js +61 -61
- package/ApngTextureManage.d.ts +18 -18
- package/ApngTextureManage.js +87 -87
- package/DirectionalLight.d.ts +6 -0
- package/DirectionalLight.js +68 -0
- package/EventMesh.d.ts +18 -18
- package/EventMesh.js +59 -59
- package/ExtrudeMesh.d.ts +112 -112
- package/ExtrudeMesh.js +366 -366
- package/FPScontrol.d.ts +71 -50
- package/FPScontrol.js +505 -232
- package/Fire/Fire.d.ts +28 -28
- package/Fire/Fire.js +79 -79
- package/Fire/FireGromtry.d.ts +9 -9
- package/Fire/FireGromtry.js +40 -40
- package/Fire/FireMaterial.d.ts +28 -28
- package/Fire/FireMaterial.js +32 -32
- package/Fire/index.d.ts +1 -1
- package/Fire/index.js +1 -1
- package/Grass/Grass.d.ts +8 -8
- package/Grass/Grass.js +38 -38
- package/Grass/index.d.ts +1 -1
- package/Grass/index.js +1 -1
- package/Ground1/Ground1.d.ts +11 -11
- package/Ground1/Ground1.js +54 -54
- package/Ground1/index.d.ts +1 -1
- package/Ground1/index.js +1 -1
- package/InstancedMeshBase.d.ts +39 -39
- package/InstancedMeshBase.js +293 -293
- package/KeyFrameAnimation.d.ts +25 -25
- package/KeyFrameAnimation.js +78 -78
- package/MeshBase.d.ts +35 -35
- package/MeshBase.js +223 -223
- package/Mirror.d.ts +25 -25
- package/Mirror.js +139 -139
- package/PipeMesh/PathGeometry.d.ts +44 -44
- package/PipeMesh/PathGeometry.js +300 -300
- package/PipeMesh/PathPoint.d.ts +17 -17
- package/PipeMesh/PathPoint.js +31 -31
- package/PipeMesh/PathPointList.d.ts +31 -31
- package/PipeMesh/PathPointList.js +208 -208
- package/PipeMesh/PathTubeGeometry.d.ts +25 -25
- package/PipeMesh/PathTubeGeometry.js +130 -130
- package/PipeMesh/PipeMesh.d.ts +25 -25
- package/PipeMesh/PipeMesh.js +63 -63
- package/PipeMesh/index.d.ts +1 -1
- package/PipeMesh/index.js +1 -1
- package/PlaneModal1/PlaneModal1.d.ts +31 -31
- package/PlaneModal1/PlaneModal1.js +105 -105
- package/PlaneModal1/index.d.ts +1 -1
- package/PlaneModal1/index.js +1 -1
- package/PlaneText.d.ts +39 -39
- package/PlaneText.js +30 -30
- package/PlaneWithHtml.d.ts +11 -11
- package/PlaneWithHtml.js +63 -68
- package/PointLight/PointLight.d.ts +14 -13
- package/PointLight/PointLight.js +70 -64
- package/PointLight/index.d.ts +1 -1
- package/PointLight/index.js +1 -1
- package/Sky/Sky.d.ts +9 -9
- package/Sky/Sky.js +22 -22
- package/Sky/index.d.ts +1 -1
- package/Sky/index.js +1 -1
- package/SpotLight.d.ts +6 -0
- package/SpotLight.js +72 -0
- package/SpriteModal1/SpriteModal1.d.ts +30 -30
- package/SpriteModal1/SpriteModal1.js +110 -110
- package/SpriteModal1/index.d.ts +1 -1
- package/SpriteModal1/index.js +1 -1
- package/SpriteText.d.ts +45 -45
- package/SpriteText.js +163 -163
- package/SpriteText2.d.ts +47 -47
- package/SpriteText2.js +198 -198
- package/SpriteWithHtml.d.ts +7 -7
- package/SpriteWithHtml.js +44 -49
- package/Text3D/Text3D.d.ts +20 -20
- package/Text3D/Text3D.js +62 -62
- package/Text3D/fontController.d.ts +59 -59
- package/Text3D/fontController.js +199 -199
- package/Text3D/index.d.ts +1 -1
- package/Text3D/index.js +1 -1
- package/ThreeBase.d.ts +97 -81
- package/ThreeBase.js +613 -560
- package/ThreeMouse.d.ts +40 -40
- package/ThreeMouse.js +407 -407
- package/Transition.d.ts +40 -40
- package/Transition.js +210 -210
- package/Water/Water.d.ts +5 -0
- package/Water/Water.js +26 -0
- package/Water/waternormals.jpg +0 -0
- package/declare.d.ts +167 -0
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/keyContorls.d.ts +25 -25
- package/keyContorls.js +98 -98
- package/package.json +1 -1
- package/pass/bloom_pass.d.ts +2 -2
- package/pass/bloom_pass.js +99 -99
- package/pass/cover_pass.d.ts +2 -2
- package/pass/cover_pass.js +95 -95
- package/pass/frosted_glass_pass.d.ts +2 -0
- package/pass/frosted_glass_pass.js +275 -0
- package/pass/fsQuad.d.ts +9 -9
- package/pass/fsQuad.js +28 -28
- package/pass/glow_pass.d.ts +2 -2
- package/pass/glow_pass.js +310 -254
- package/pass/ssao_pass.d.ts +11 -0
- package/pass/ssao_pass.js +294 -0
- package/pass/stroke_pass.d.ts +2 -2
- package/pass/stroke_pass.js +199 -199
- package/shaders/FXAAShaderMaterial.d.ts +3 -3
- package/shaders/FXAAShaderMaterial.js +21 -21
- package/shaders/baseTextureToRenderShader.d.ts +2 -2
- package/shaders/baseTextureToRenderShader.js +14 -14
- package/shaders/copyShader.d.ts +3 -3
- package/shaders/copyShader.js +14 -14
- package/shaders.d.ts +5 -5
- package/shaders.js +42 -42
- package/threeLoader.d.ts +34 -34
- package/threeLoader.js +527 -527
- package/threeUtils.d.ts +52 -52
- package/threeUtils.js +330 -330
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { AddEquation, CustomBlending, LinearFilter, NoBlending, NormalBlending, OneFactor, RGBAFormat, RawShaderMaterial, SrcColorFactor, Vector2, WebGLRenderTarget, Matrix4, } from "three";
|
|
2
|
+
import fsQuad from "./fsQuad";
|
|
3
|
+
const ssaoTextureTarget = new WebGLRenderTarget(512, 512, {
|
|
4
|
+
minFilter: LinearFilter,
|
|
5
|
+
magFilter: LinearFilter,
|
|
6
|
+
format: RGBAFormat,
|
|
7
|
+
});
|
|
8
|
+
const blurTextureTarget = new WebGLRenderTarget(512, 512, {
|
|
9
|
+
minFilter: LinearFilter,
|
|
10
|
+
magFilter: LinearFilter,
|
|
11
|
+
format: RGBAFormat,
|
|
12
|
+
});
|
|
13
|
+
const size = new Vector2();
|
|
14
|
+
const projectionMatrix = new Matrix4();
|
|
15
|
+
const inverseProjectionMatrix = new Matrix4();
|
|
16
|
+
const ssaoShader = new RawShaderMaterial({
|
|
17
|
+
uniforms: {
|
|
18
|
+
depthTexture: { value: null },
|
|
19
|
+
resolution: { value: new Vector2(1 / 512, 1 / 512) },
|
|
20
|
+
projectionMatrix: { value: new Matrix4() },
|
|
21
|
+
inverseProjectionMatrix: { value: new Matrix4() },
|
|
22
|
+
ssaoRadius: { value: 0.5 },
|
|
23
|
+
ssaoBias: { value: 0.025 },
|
|
24
|
+
ssaoIntensity: { value: 1.5 },
|
|
25
|
+
sampleCount: { value: 16 },
|
|
26
|
+
// 对数深度缓冲区的 far 参数,用于反算线性视距
|
|
27
|
+
cameraFar: { value: 20000 },
|
|
28
|
+
},
|
|
29
|
+
vertexShader: `
|
|
30
|
+
attribute vec3 position;
|
|
31
|
+
attribute vec2 uv;
|
|
32
|
+
varying vec2 vUv;
|
|
33
|
+
void main() {
|
|
34
|
+
vUv = uv;
|
|
35
|
+
gl_Position = vec4(position, 1.0);
|
|
36
|
+
}`,
|
|
37
|
+
fragmentShader: `
|
|
38
|
+
#ifdef GL_ES
|
|
39
|
+
precision highp float;
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
uniform sampler2D depthTexture;
|
|
43
|
+
uniform vec2 resolution;
|
|
44
|
+
uniform mat4 projectionMatrix;
|
|
45
|
+
uniform mat4 inverseProjectionMatrix;
|
|
46
|
+
uniform float ssaoRadius;
|
|
47
|
+
uniform float ssaoBias;
|
|
48
|
+
uniform float ssaoIntensity;
|
|
49
|
+
uniform int sampleCount;
|
|
50
|
+
uniform float cameraFar;
|
|
51
|
+
|
|
52
|
+
varying vec2 vUv;
|
|
53
|
+
|
|
54
|
+
// 将对数深度值反算回线性视距(正数,单位与世界坐标一致)
|
|
55
|
+
// Three.js 对数深度编码: logDepth = log2(viewZ + 1.0) / log2(cameraFar + 1.0)
|
|
56
|
+
float linearizeLogDepth(float logDepth) {
|
|
57
|
+
return pow(cameraFar + 1.0, logDepth) - 1.0;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 从屏幕 UV 和视距重建视空间坐标
|
|
61
|
+
// viewDistance: 相机到该像素的视距(正数)
|
|
62
|
+
vec3 reconstructPosition(vec2 uv, float viewDistance) {
|
|
63
|
+
// 用 inverseProjectionMatrix 求出该像素的视空间射线方向
|
|
64
|
+
vec4 ndc = vec4(uv * 2.0 - 1.0, 0.0, 1.0);
|
|
65
|
+
vec4 viewDir4 = inverseProjectionMatrix * ndc;
|
|
66
|
+
vec3 viewDir = viewDir4.xyz / viewDir4.w;
|
|
67
|
+
// viewDir.z 为负数(相机看向 -Z),viewDistance 为正数
|
|
68
|
+
return viewDir * (viewDistance / (-viewDir.z));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
float random(vec2 seed) {
|
|
72
|
+
return fract(sin(dot(seed, vec2(12.9898, 78.233))) * 43758.5453);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void main() {
|
|
76
|
+
float logDepth = texture2D(depthTexture, vUv).r;
|
|
77
|
+
|
|
78
|
+
// 背景 / 无穷远 → 无遮挡
|
|
79
|
+
if (logDepth >= 1.0) {
|
|
80
|
+
gl_FragColor = vec4(1.0);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 对数深度 → 线性视距
|
|
85
|
+
float viewDistance = linearizeLogDepth(logDepth);
|
|
86
|
+
vec3 position = reconstructPosition(vUv, viewDistance);
|
|
87
|
+
|
|
88
|
+
float occlusion = 0.0;
|
|
89
|
+
float radius = ssaoRadius;
|
|
90
|
+
|
|
91
|
+
float angle = random(vUv) * 6.2831853;
|
|
92
|
+
float stepAngle = 6.2831853 / float(sampleCount);
|
|
93
|
+
|
|
94
|
+
for (int i = 0; i < 64; i++) {
|
|
95
|
+
if (i >= sampleCount) break;
|
|
96
|
+
|
|
97
|
+
float theta = angle + float(i) * stepAngle;
|
|
98
|
+
float r = sqrt(float(i + 1)) * (radius / sqrt(float(sampleCount)));
|
|
99
|
+
|
|
100
|
+
vec2 offset = vec2(cos(theta), sin(theta)) * r;
|
|
101
|
+
vec2 sampleUv = vUv + offset * resolution;
|
|
102
|
+
|
|
103
|
+
if (sampleUv.x < 0.0 || sampleUv.x > 1.0 || sampleUv.y < 0.0 || sampleUv.y > 1.0) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
float sampleLogDepth = texture2D(depthTexture, sampleUv).r;
|
|
108
|
+
float sampleDistance = linearizeLogDepth(sampleLogDepth);
|
|
109
|
+
vec3 samplePosition = reconstructPosition(sampleUv, sampleDistance);
|
|
110
|
+
|
|
111
|
+
vec3 diff = samplePosition - position;
|
|
112
|
+
float dist = length(diff);
|
|
113
|
+
|
|
114
|
+
if (dist < radius && diff.z > ssaoBias) {
|
|
115
|
+
float rangeCheck = smoothstep(0.0, radius, dist);
|
|
116
|
+
occlusion += (1.0 - rangeCheck) * (1.0 - diff.z / radius);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
occlusion = 1.0 - (occlusion * ssaoIntensity / float(sampleCount));
|
|
121
|
+
occlusion = clamp(occlusion, 0.0, 1.0);
|
|
122
|
+
|
|
123
|
+
gl_FragColor = vec4(vec3(occlusion), 1.0);
|
|
124
|
+
}`,
|
|
125
|
+
blending: NoBlending,
|
|
126
|
+
depthTest: false,
|
|
127
|
+
depthWrite: false,
|
|
128
|
+
transparent: true,
|
|
129
|
+
});
|
|
130
|
+
const blurHShader = new RawShaderMaterial({
|
|
131
|
+
uniforms: {
|
|
132
|
+
tDiffuse: { value: null },
|
|
133
|
+
resolution: { value: new Vector2(1 / 512, 1 / 512) },
|
|
134
|
+
blurRadius: { value: 2.0 },
|
|
135
|
+
},
|
|
136
|
+
vertexShader: `
|
|
137
|
+
attribute vec3 position;
|
|
138
|
+
attribute vec2 uv;
|
|
139
|
+
varying vec2 vUv;
|
|
140
|
+
void main() {
|
|
141
|
+
vUv = uv;
|
|
142
|
+
gl_Position = vec4(position, 1.0);
|
|
143
|
+
}`,
|
|
144
|
+
fragmentShader: `
|
|
145
|
+
#ifdef GL_ES
|
|
146
|
+
precision highp float;
|
|
147
|
+
#endif
|
|
148
|
+
|
|
149
|
+
uniform sampler2D tDiffuse;
|
|
150
|
+
uniform vec2 resolution;
|
|
151
|
+
uniform float blurRadius;
|
|
152
|
+
|
|
153
|
+
varying vec2 vUv;
|
|
154
|
+
|
|
155
|
+
void main() {
|
|
156
|
+
vec4 color = vec4(0.0);
|
|
157
|
+
float totalWeight = 0.0;
|
|
158
|
+
|
|
159
|
+
for (int i = -4; i <= 4; i++) {
|
|
160
|
+
float weight = exp(-float(i * i) / 8.0);
|
|
161
|
+
vec2 offset = vec2(float(i) * blurRadius * resolution.x, 0.0);
|
|
162
|
+
color += texture2D(tDiffuse, vUv + offset) * weight;
|
|
163
|
+
totalWeight += weight;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
gl_FragColor = color / totalWeight;
|
|
167
|
+
}`,
|
|
168
|
+
blending: NoBlending,
|
|
169
|
+
depthTest: false,
|
|
170
|
+
depthWrite: false,
|
|
171
|
+
transparent: true,
|
|
172
|
+
});
|
|
173
|
+
const blurVShader = new RawShaderMaterial({
|
|
174
|
+
uniforms: {
|
|
175
|
+
tDiffuse: { value: null },
|
|
176
|
+
resolution: { value: new Vector2(1 / 512, 1 / 512) },
|
|
177
|
+
blurRadius: { value: 2.0 },
|
|
178
|
+
},
|
|
179
|
+
vertexShader: `
|
|
180
|
+
attribute vec3 position;
|
|
181
|
+
attribute vec2 uv;
|
|
182
|
+
varying vec2 vUv;
|
|
183
|
+
void main() {
|
|
184
|
+
vUv = uv;
|
|
185
|
+
gl_Position = vec4(position, 1.0);
|
|
186
|
+
}`,
|
|
187
|
+
fragmentShader: `
|
|
188
|
+
#ifdef GL_ES
|
|
189
|
+
precision highp float;
|
|
190
|
+
#endif
|
|
191
|
+
|
|
192
|
+
uniform sampler2D tDiffuse;
|
|
193
|
+
uniform vec2 resolution;
|
|
194
|
+
uniform float blurRadius;
|
|
195
|
+
|
|
196
|
+
varying vec2 vUv;
|
|
197
|
+
|
|
198
|
+
void main() {
|
|
199
|
+
vec4 color = vec4(0.0);
|
|
200
|
+
float totalWeight = 0.0;
|
|
201
|
+
|
|
202
|
+
for (int i = -4; i <= 4; i++) {
|
|
203
|
+
float weight = exp(-float(i * i) / 8.0);
|
|
204
|
+
vec2 offset = vec2(0.0, float(i) * blurRadius * resolution.y);
|
|
205
|
+
color += texture2D(tDiffuse, vUv + offset) * weight;
|
|
206
|
+
totalWeight += weight;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
gl_FragColor = color / totalWeight;
|
|
210
|
+
}`,
|
|
211
|
+
blending: NoBlending,
|
|
212
|
+
depthTest: false,
|
|
213
|
+
depthWrite: false,
|
|
214
|
+
transparent: true,
|
|
215
|
+
});
|
|
216
|
+
const compositeShader = new RawShaderMaterial({
|
|
217
|
+
uniforms: {
|
|
218
|
+
ssaoTexture: { value: null },
|
|
219
|
+
ssaoStrength: { value: 1.0 },
|
|
220
|
+
},
|
|
221
|
+
vertexShader: `
|
|
222
|
+
attribute vec3 position;
|
|
223
|
+
attribute vec2 uv;
|
|
224
|
+
varying vec2 vUv;
|
|
225
|
+
void main() {
|
|
226
|
+
vUv = uv;
|
|
227
|
+
gl_Position = vec4(position, 1.0);
|
|
228
|
+
}`,
|
|
229
|
+
fragmentShader: `
|
|
230
|
+
#ifdef GL_ES
|
|
231
|
+
precision highp float;
|
|
232
|
+
#endif
|
|
233
|
+
|
|
234
|
+
uniform sampler2D ssaoTexture;
|
|
235
|
+
uniform float ssaoStrength;
|
|
236
|
+
|
|
237
|
+
varying vec2 vUv;
|
|
238
|
+
|
|
239
|
+
void main() {
|
|
240
|
+
float ssao = texture2D(ssaoTexture, vUv).r;
|
|
241
|
+
float finalOcclusion = mix(1.0, ssao, ssaoStrength);
|
|
242
|
+
|
|
243
|
+
gl_FragColor = vec4(finalOcclusion, finalOcclusion, finalOcclusion, 1.0);
|
|
244
|
+
}`,
|
|
245
|
+
blending: CustomBlending,
|
|
246
|
+
blendSrc: SrcColorFactor,
|
|
247
|
+
blendDst: OneFactor,
|
|
248
|
+
blendEquation: AddEquation,
|
|
249
|
+
depthTest: false,
|
|
250
|
+
depthWrite: false,
|
|
251
|
+
transparent: false,
|
|
252
|
+
});
|
|
253
|
+
export default function ssao_pass(renderer, camera, depthTexture, devicePixelRatio, options) {
|
|
254
|
+
if (!options.enable) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const originRenderTarget = renderer.getRenderTarget();
|
|
258
|
+
renderer.getSize(size);
|
|
259
|
+
size.multiplyScalar(devicePixelRatio);
|
|
260
|
+
ssaoTextureTarget.setSize(size.x, size.y);
|
|
261
|
+
blurTextureTarget.setSize(size.x, size.y);
|
|
262
|
+
projectionMatrix.copy(camera.projectionMatrix);
|
|
263
|
+
inverseProjectionMatrix.copy(projectionMatrix).invert();
|
|
264
|
+
ssaoShader.uniforms.depthTexture.value = depthTexture;
|
|
265
|
+
ssaoShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
266
|
+
ssaoShader.uniforms.projectionMatrix.value = projectionMatrix;
|
|
267
|
+
ssaoShader.uniforms.inverseProjectionMatrix.value = inverseProjectionMatrix;
|
|
268
|
+
ssaoShader.uniforms.ssaoRadius.value = options.radius || 0.5;
|
|
269
|
+
ssaoShader.uniforms.ssaoBias.value = options.bias || 0.025;
|
|
270
|
+
ssaoShader.uniforms.ssaoIntensity.value = options.intensity || 1.5;
|
|
271
|
+
ssaoShader.uniforms.sampleCount.value = options.sampleCount || 16;
|
|
272
|
+
ssaoShader.uniforms.cameraFar.value = options.cameraFar || camera.far || 20000;
|
|
273
|
+
renderer.setRenderTarget(ssaoTextureTarget);
|
|
274
|
+
renderer.clear();
|
|
275
|
+
fsQuad.render(renderer, ssaoShader);
|
|
276
|
+
blurHShader.uniforms.tDiffuse.value = ssaoTextureTarget.texture;
|
|
277
|
+
blurHShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
278
|
+
blurHShader.uniforms.blurRadius.value = options.blurRadius || 2.0;
|
|
279
|
+
renderer.setRenderTarget(blurTextureTarget);
|
|
280
|
+
renderer.clear();
|
|
281
|
+
fsQuad.render(renderer, blurHShader);
|
|
282
|
+
blurVShader.uniforms.tDiffuse.value = blurTextureTarget.texture;
|
|
283
|
+
blurVShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
284
|
+
blurVShader.uniforms.blurRadius.value = options.blurRadius || 2.0;
|
|
285
|
+
renderer.setRenderTarget(ssaoTextureTarget);
|
|
286
|
+
renderer.clear();
|
|
287
|
+
fsQuad.render(renderer, blurVShader);
|
|
288
|
+
compositeShader.uniforms.ssaoTexture.value = ssaoTextureTarget.texture;
|
|
289
|
+
compositeShader.uniforms.ssaoStrength.value = options.strength || 1.0;
|
|
290
|
+
renderer.setRenderTarget(originRenderTarget);
|
|
291
|
+
compositeShader.blending = NormalBlending;
|
|
292
|
+
compositeShader.transparent = false;
|
|
293
|
+
fsQuad.render(renderer, compositeShader);
|
|
294
|
+
}
|
package/pass/stroke_pass.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Camera, DepthTexture, Object3D, WebGLRenderer } from "three";
|
|
2
|
-
export default function stroke_pass(renderer: WebGLRenderer, camera: Camera, object3d: Object3D, baseDepthTexture: DepthTexture, devicePixelRatio: number): void;
|
|
1
|
+
import { Camera, DepthTexture, Object3D, WebGLRenderer } from "three";
|
|
2
|
+
export default function stroke_pass(renderer: WebGLRenderer, camera: Camera, object3d: Object3D, baseDepthTexture: DepthTexture, devicePixelRatio: number): void;
|