three-base 2.0.87 → 2.0.89
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/package.json +2 -2
- package/threeLoader.d.ts +2 -2
- package/threeLoader.js +97 -16
- package/threeUtils.d.ts +1 -0
- package/threeUtils.js +17 -1
- package/ApngTexture.ts +0 -91
- package/ApngTextureManage.ts +0 -130
- package/EventMesh.ts +0 -79
- package/ExtrudeMesh.ts +0 -576
- package/FPScontrol.ts +0 -209
- package/Fire/Fire.ts +0 -99
- package/Fire/FireGromtry.ts +0 -54
- package/Fire/FireMaterial.ts +0 -92
- package/InstancedMeshBase.ts +0 -316
- package/KeyFrameAnimation.ts +0 -122
- package/MeshBase.ts +0 -236
- package/Mirror.ts +0 -254
- package/PlaneModal1/PlaneModal1.ts +0 -151
- package/PlaneModal1/index.ts +0 -1
- package/PlaneText.ts +0 -58
- package/PlaneWithHtml.ts +0 -85
- package/PointLight/PointLight.ts +0 -75
- package/PointLight/index.ts +0 -1
- package/Sky/Sky.ts +0 -36
- package/Sky/index.ts +0 -1
- package/SpriteModal1/SpriteModal1.ts +0 -160
- package/SpriteModal1/index.ts +0 -1
- package/SpriteText.ts +0 -190
- package/SpriteText2.ts +0 -237
- package/SpriteWithHtml.ts +0 -62
- package/Text3D/Text3D.ts +0 -93
- package/Text3D/fontController.ts +0 -284
- package/Text3D/index.ts +0 -1
- package/ThreeBase.ts +0 -758
- package/ThreeMouse.ts +0 -483
- package/Transition.ts +0 -288
- package/index.ts +0 -2
- package/keyContorls.ts +0 -127
- package/pass/FullScreenQuad.ts +0 -33
- package/pass/glow_pass.ts +0 -607
- package/pass/stroke_pass.ts +0 -561
- package/shaders/FXAAShaderMaterial.ts +0 -248
- package/shaders.ts +0 -264
- package/threeLoader.ts +0 -447
- package/threeUtils.ts +0 -351
package/pass/glow_pass.ts
DELETED
|
@@ -1,607 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* @Author: xiaosihan
|
|
3
|
-
* @Date: 2023-05-09 00:35:17
|
|
4
|
-
* @Last Modified by: xiaosihan
|
|
5
|
-
* @Last Modified time: 2023-05-09 02:33:28
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { Camera, LinearFilter, Object3D, RGBAFormat, Vector2, WebGLRenderTarget, WebGLRenderer, ShaderMaterial, NoBlending, Scene, RawShaderMaterial, Color, NormalBlending, ShaderChunk, DepthTexture, DepthFormat, UnsignedShortType } from "three";
|
|
9
|
-
import FullScreenQuad from "./FullScreenQuad";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// 选中对象的深度纹理
|
|
13
|
-
const selectDepthTexture = (() => {
|
|
14
|
-
const baseDepthTexture = new DepthTexture(4096, 4096);
|
|
15
|
-
baseDepthTexture.format = DepthFormat;
|
|
16
|
-
baseDepthTexture.type = UnsignedShortType;
|
|
17
|
-
baseDepthTexture.anisotropy = 16;
|
|
18
|
-
return baseDepthTexture;
|
|
19
|
-
})();
|
|
20
|
-
|
|
21
|
-
// 选中对象的纹理
|
|
22
|
-
const selectTextureTarget = new WebGLRenderTarget(512, 512, {
|
|
23
|
-
minFilter: LinearFilter,
|
|
24
|
-
magFilter: LinearFilter,
|
|
25
|
-
format: RGBAFormat,
|
|
26
|
-
depthTexture: selectDepthTexture,
|
|
27
|
-
anisotropy: 16,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// 深度测试后的选中纹理
|
|
31
|
-
const selectDethpTestTextureTarget = new WebGLRenderTarget(512, 512, {
|
|
32
|
-
minFilter: LinearFilter,
|
|
33
|
-
magFilter: LinearFilter,
|
|
34
|
-
format: RGBAFormat,
|
|
35
|
-
anisotropy: 16,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// 由于不能同时读写自己的纹理
|
|
39
|
-
const blur1TextureTarget = new WebGLRenderTarget(512, 512, { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat });
|
|
40
|
-
|
|
41
|
-
// 所以需要用2个模糊纹理相互读写
|
|
42
|
-
const blur2TextureTarget = new WebGLRenderTarget(512, 512, { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat });
|
|
43
|
-
|
|
44
|
-
const size = new Vector2();
|
|
45
|
-
|
|
46
|
-
// 创建一个渲染工具 用于处理纹理
|
|
47
|
-
const fsQuad = new FullScreenQuad(); // 渲染辅助器
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//深度比对纹理
|
|
51
|
-
const depthTestShader = new ShaderMaterial({
|
|
52
|
-
uniforms: {
|
|
53
|
-
map: { value: null }, // 贴图纹理
|
|
54
|
-
baseDepth: { value: null }, // 整个场景的深度纹理
|
|
55
|
-
selectDepth: { value: null }, // 选中的对象深度纹理
|
|
56
|
-
},
|
|
57
|
-
vertexShader: `
|
|
58
|
-
${ShaderChunk.common}
|
|
59
|
-
${ShaderChunk.logdepthbuf_pars_vertex}
|
|
60
|
-
varying vec2 vUv;
|
|
61
|
-
void main() {
|
|
62
|
-
vUv = uv;
|
|
63
|
-
// gl_Position = vec4(position, 1.0);
|
|
64
|
-
// gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position, 1.0);
|
|
65
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
66
|
-
${ShaderChunk.logdepthbuf_vertex}
|
|
67
|
-
}
|
|
68
|
-
`,
|
|
69
|
-
fragmentShader: `
|
|
70
|
-
${ShaderChunk.logdepthbuf_pars_fragment}
|
|
71
|
-
uniform sampler2D map;
|
|
72
|
-
uniform sampler2D baseDepth;
|
|
73
|
-
uniform sampler2D selectDepth;
|
|
74
|
-
varying vec2 vUv;
|
|
75
|
-
void main() {
|
|
76
|
-
if(texture2D(baseDepth, vUv).r < texture2D(selectDepth, vUv).r){
|
|
77
|
-
discard;
|
|
78
|
-
}
|
|
79
|
-
gl_FragColor = texture2D(map, vUv);
|
|
80
|
-
${ShaderChunk.logdepthbuf_fragment}
|
|
81
|
-
}
|
|
82
|
-
`,
|
|
83
|
-
blending: NoBlending, // 渲染时不与背景融合计算 直接替换
|
|
84
|
-
depthTest: true,
|
|
85
|
-
depthWrite: true,
|
|
86
|
-
transparent: true
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// 抗锯齿着色器
|
|
90
|
-
const FXAAShaderMaterial = new ShaderMaterial({
|
|
91
|
-
uniforms: {
|
|
92
|
-
tDiffuse: { value: null }, // 贴图纹理
|
|
93
|
-
resolution: { value: new Vector2(1 / 1024, 1 / 1024) }
|
|
94
|
-
},
|
|
95
|
-
vertexShader: `
|
|
96
|
-
${ShaderChunk.common}
|
|
97
|
-
${ShaderChunk.logdepthbuf_pars_vertex}
|
|
98
|
-
varying vec2 vUv;
|
|
99
|
-
void main() {
|
|
100
|
-
vUv = uv;
|
|
101
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
102
|
-
${ShaderChunk.logdepthbuf_vertex}
|
|
103
|
-
}
|
|
104
|
-
`,
|
|
105
|
-
fragmentShader: `
|
|
106
|
-
${ShaderChunk.logdepthbuf_pars_fragment}
|
|
107
|
-
precision highp float;
|
|
108
|
-
|
|
109
|
-
uniform sampler2D tDiffuse;
|
|
110
|
-
|
|
111
|
-
uniform vec2 resolution;
|
|
112
|
-
|
|
113
|
-
varying vec2 vUv;
|
|
114
|
-
|
|
115
|
-
#ifndef FXAA_DISCARD
|
|
116
|
-
//
|
|
117
|
-
// Only valid for PC OpenGL currently.
|
|
118
|
-
// Probably will not work when FXAA_GREEN_AS_LUMA = 1.
|
|
119
|
-
//
|
|
120
|
-
// 1 = Use discard on pixels which don't need AA.
|
|
121
|
-
// For APIs which enable concurrent TEX+ROP from same surface.
|
|
122
|
-
// 0 = Return unchanged color on pixels which don't need AA.
|
|
123
|
-
//
|
|
124
|
-
#define FXAA_DISCARD 0
|
|
125
|
-
#endif
|
|
126
|
-
|
|
127
|
-
/*--------------------------------------------------------------------------*/
|
|
128
|
-
#define FxaaTexTop(t, p) texture2D(t, p, -100.0)
|
|
129
|
-
#define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r), -100.0)
|
|
130
|
-
/*--------------------------------------------------------------------------*/
|
|
131
|
-
|
|
132
|
-
#define NUM_SAMPLES 5
|
|
133
|
-
|
|
134
|
-
// assumes colors have premultipliedAlpha, so that the calculated color contrast is scaled by alpha
|
|
135
|
-
float contrast( vec4 a, vec4 b ) {
|
|
136
|
-
vec4 diff = abs( a - b );
|
|
137
|
-
return max( max( max( diff.r, diff.g ), diff.b ), diff.a );
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/*============================================================================
|
|
141
|
-
|
|
142
|
-
FXAA3 QUALITY - PC
|
|
143
|
-
|
|
144
|
-
============================================================================*/
|
|
145
|
-
|
|
146
|
-
/*--------------------------------------------------------------------------*/
|
|
147
|
-
vec4 FxaaPixelShader(
|
|
148
|
-
vec2 posM,
|
|
149
|
-
sampler2D tex,
|
|
150
|
-
vec2 fxaaQualityRcpFrame,
|
|
151
|
-
float fxaaQualityEdgeThreshold,
|
|
152
|
-
float fxaaQualityinvEdgeThreshold
|
|
153
|
-
) {
|
|
154
|
-
vec4 rgbaM = FxaaTexTop(tex, posM);
|
|
155
|
-
vec4 rgbaS = FxaaTexOff(tex, posM, vec2( 0.0, 1.0), fxaaQualityRcpFrame.xy);
|
|
156
|
-
vec4 rgbaE = FxaaTexOff(tex, posM, vec2( 1.0, 0.0), fxaaQualityRcpFrame.xy);
|
|
157
|
-
vec4 rgbaN = FxaaTexOff(tex, posM, vec2( 0.0,-1.0), fxaaQualityRcpFrame.xy);
|
|
158
|
-
vec4 rgbaW = FxaaTexOff(tex, posM, vec2(-1.0, 0.0), fxaaQualityRcpFrame.xy);
|
|
159
|
-
// . S .
|
|
160
|
-
// W M E
|
|
161
|
-
// . N .
|
|
162
|
-
|
|
163
|
-
bool earlyExit = max( max( max(
|
|
164
|
-
contrast( rgbaM, rgbaN ),
|
|
165
|
-
contrast( rgbaM, rgbaS ) ),
|
|
166
|
-
contrast( rgbaM, rgbaE ) ),
|
|
167
|
-
contrast( rgbaM, rgbaW ) )
|
|
168
|
-
< fxaaQualityEdgeThreshold;
|
|
169
|
-
// . 0 .
|
|
170
|
-
// 0 0 0
|
|
171
|
-
// . 0 .
|
|
172
|
-
|
|
173
|
-
#if (FXAA_DISCARD == 1)
|
|
174
|
-
if(earlyExit) FxaaDiscard;
|
|
175
|
-
#else
|
|
176
|
-
if(earlyExit) return rgbaM;
|
|
177
|
-
#endif
|
|
178
|
-
|
|
179
|
-
float contrastN = contrast( rgbaM, rgbaN );
|
|
180
|
-
float contrastS = contrast( rgbaM, rgbaS );
|
|
181
|
-
float contrastE = contrast( rgbaM, rgbaE );
|
|
182
|
-
float contrastW = contrast( rgbaM, rgbaW );
|
|
183
|
-
|
|
184
|
-
float relativeVContrast = ( contrastN + contrastS ) - ( contrastE + contrastW );
|
|
185
|
-
relativeVContrast *= fxaaQualityinvEdgeThreshold;
|
|
186
|
-
|
|
187
|
-
bool horzSpan = relativeVContrast > 0.;
|
|
188
|
-
// . 1 .
|
|
189
|
-
// 0 0 0
|
|
190
|
-
// . 1 .
|
|
191
|
-
|
|
192
|
-
// 45 deg edge detection and corners of objects, aka V/H contrast is too similar
|
|
193
|
-
if( abs( relativeVContrast ) < .3 ) {
|
|
194
|
-
// locate the edge
|
|
195
|
-
vec2 dirToEdge;
|
|
196
|
-
dirToEdge.x = contrastE > contrastW ? 1. : -1.;
|
|
197
|
-
dirToEdge.y = contrastS > contrastN ? 1. : -1.;
|
|
198
|
-
// . 2 . . 1 .
|
|
199
|
-
// 1 0 2 ~= 0 0 1
|
|
200
|
-
// . 1 . . 0 .
|
|
201
|
-
|
|
202
|
-
// tap 2 pixels and see which ones are "outside" the edge, to
|
|
203
|
-
// determine if the edge is vertical or horizontal
|
|
204
|
-
|
|
205
|
-
vec4 rgbaAlongH = FxaaTexOff(tex, posM, vec2( dirToEdge.x, -dirToEdge.y ), fxaaQualityRcpFrame.xy);
|
|
206
|
-
float matchAlongH = contrast( rgbaM, rgbaAlongH );
|
|
207
|
-
// . 1 .
|
|
208
|
-
// 0 0 1
|
|
209
|
-
// . 0 H
|
|
210
|
-
|
|
211
|
-
vec4 rgbaAlongV = FxaaTexOff(tex, posM, vec2( -dirToEdge.x, dirToEdge.y ), fxaaQualityRcpFrame.xy);
|
|
212
|
-
float matchAlongV = contrast( rgbaM, rgbaAlongV );
|
|
213
|
-
// V 1 .
|
|
214
|
-
// 0 0 1
|
|
215
|
-
// . 0 .
|
|
216
|
-
|
|
217
|
-
relativeVContrast = matchAlongV - matchAlongH;
|
|
218
|
-
relativeVContrast *= fxaaQualityinvEdgeThreshold;
|
|
219
|
-
|
|
220
|
-
if( abs( relativeVContrast ) < .3 ) { // 45 deg edge
|
|
221
|
-
// 1 1 .
|
|
222
|
-
// 0 0 1
|
|
223
|
-
// . 0 1
|
|
224
|
-
|
|
225
|
-
// do a simple blur
|
|
226
|
-
return mix(
|
|
227
|
-
rgbaM,
|
|
228
|
-
(rgbaN + rgbaS + rgbaE + rgbaW) * .25,
|
|
229
|
-
.4
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
horzSpan = relativeVContrast > 0.;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if(!horzSpan) rgbaN = rgbaW;
|
|
237
|
-
if(!horzSpan) rgbaS = rgbaE;
|
|
238
|
-
// . 0 . 1
|
|
239
|
-
// 1 0 1 -> 0
|
|
240
|
-
// . 0 . 1
|
|
241
|
-
|
|
242
|
-
bool pairN = contrast( rgbaM, rgbaN ) > contrast( rgbaM, rgbaS );
|
|
243
|
-
if(!pairN) rgbaN = rgbaS;
|
|
244
|
-
|
|
245
|
-
vec2 offNP;
|
|
246
|
-
offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;
|
|
247
|
-
offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;
|
|
248
|
-
|
|
249
|
-
bool doneN = false;
|
|
250
|
-
bool doneP = false;
|
|
251
|
-
|
|
252
|
-
float nDist = 0.;
|
|
253
|
-
float pDist = 0.;
|
|
254
|
-
|
|
255
|
-
vec2 posN = posM;
|
|
256
|
-
vec2 posP = posM;
|
|
257
|
-
|
|
258
|
-
int iterationsUsed = 0;
|
|
259
|
-
int iterationsUsedN = 0;
|
|
260
|
-
int iterationsUsedP = 0;
|
|
261
|
-
for( int i = 0; i < NUM_SAMPLES; i++ ) {
|
|
262
|
-
iterationsUsed = i;
|
|
263
|
-
|
|
264
|
-
float increment = float(i + 1);
|
|
265
|
-
|
|
266
|
-
if(!doneN) {
|
|
267
|
-
nDist += increment;
|
|
268
|
-
posN = posM + offNP * nDist;
|
|
269
|
-
vec4 rgbaEndN = FxaaTexTop(tex, posN.xy);
|
|
270
|
-
doneN = contrast( rgbaEndN, rgbaM ) > contrast( rgbaEndN, rgbaN );
|
|
271
|
-
iterationsUsedN = i;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
if(!doneP) {
|
|
275
|
-
pDist += increment;
|
|
276
|
-
posP = posM - offNP * pDist;
|
|
277
|
-
vec4 rgbaEndP = FxaaTexTop(tex, posP.xy);
|
|
278
|
-
doneP = contrast( rgbaEndP, rgbaM ) > contrast( rgbaEndP, rgbaN );
|
|
279
|
-
iterationsUsedP = i;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if(doneN || doneP) break;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
if ( !doneP && !doneN ) return rgbaM; // failed to find end of edge
|
|
287
|
-
|
|
288
|
-
float dist = min(
|
|
289
|
-
doneN ? float( iterationsUsedN ) / float( NUM_SAMPLES - 1 ) : 1.,
|
|
290
|
-
doneP ? float( iterationsUsedP ) / float( NUM_SAMPLES - 1 ) : 1.
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
// hacky way of reduces blurriness of mostly diagonal edges
|
|
294
|
-
// but reduces AA quality
|
|
295
|
-
dist = pow(dist, .5);
|
|
296
|
-
|
|
297
|
-
dist = 1. - dist;
|
|
298
|
-
|
|
299
|
-
return mix(
|
|
300
|
-
rgbaM,
|
|
301
|
-
rgbaN,
|
|
302
|
-
dist * .5
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
void main() {
|
|
307
|
-
const float edgeDetectionQuality = .2;
|
|
308
|
-
const float invEdgeDetectionQuality = 1. / edgeDetectionQuality;
|
|
309
|
-
|
|
310
|
-
gl_FragColor = FxaaPixelShader(
|
|
311
|
-
vUv,
|
|
312
|
-
tDiffuse,
|
|
313
|
-
resolution,
|
|
314
|
-
edgeDetectionQuality, // [0,1] contrast needed, otherwise early discard
|
|
315
|
-
invEdgeDetectionQuality
|
|
316
|
-
);
|
|
317
|
-
${ShaderChunk.logdepthbuf_fragment}
|
|
318
|
-
}
|
|
319
|
-
`,
|
|
320
|
-
blending: NoBlending, // 渲染时不与背景融合计算 直接替换
|
|
321
|
-
depthTest: false,
|
|
322
|
-
depthWrite: false,
|
|
323
|
-
transparent: true
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
// 描边着色器
|
|
327
|
-
const blurShader = new RawShaderMaterial({
|
|
328
|
-
uniforms: {
|
|
329
|
-
tDiffuse: { value: null },
|
|
330
|
-
color: { value: new Color("#0f0") }, // 没有被挡住的地方的颜色绿色
|
|
331
|
-
width: { value: 1.0 },
|
|
332
|
-
opacity: { value: 1.0 },
|
|
333
|
-
resolution: { value: new Vector2(1 / 512, 1 / 512) }, // 渲染器的分辨率
|
|
334
|
-
offset: {
|
|
335
|
-
value: [
|
|
336
|
-
new Vector2(0.000, 1.000),
|
|
337
|
-
new Vector2(0.259, 0.966),
|
|
338
|
-
new Vector2(0.500, 0.866),
|
|
339
|
-
new Vector2(0.707, 0.707),
|
|
340
|
-
new Vector2(0.866, 0.500),
|
|
341
|
-
new Vector2(0.966, 0.259),
|
|
342
|
-
new Vector2(1.000, 0.000),
|
|
343
|
-
new Vector2(0.966, -0.259),
|
|
344
|
-
new Vector2(0.866, -0.500),
|
|
345
|
-
new Vector2(0.707, -0.707),
|
|
346
|
-
new Vector2(0.500, -0.866),
|
|
347
|
-
new Vector2(0.259, -0.966),
|
|
348
|
-
new Vector2(0.000, -1.000),
|
|
349
|
-
new Vector2(-0.259, -0.966),
|
|
350
|
-
new Vector2(-0.500, -0.866),
|
|
351
|
-
new Vector2(-0.707, -0.707),
|
|
352
|
-
new Vector2(-0.866, -0.500),
|
|
353
|
-
new Vector2(-0.966, -0.259),
|
|
354
|
-
new Vector2(-1.000, -0.000),
|
|
355
|
-
new Vector2(-0.966, 0.259),
|
|
356
|
-
new Vector2(-0.866, 0.500),
|
|
357
|
-
new Vector2(-0.707, 0.707),
|
|
358
|
-
new Vector2(-0.500, 0.866),
|
|
359
|
-
new Vector2(-0.259, 0.966)
|
|
360
|
-
]
|
|
361
|
-
}
|
|
362
|
-
},
|
|
363
|
-
vertexShader: `
|
|
364
|
-
attribute vec3 position;
|
|
365
|
-
attribute vec2 uv;
|
|
366
|
-
varying vec2 vUv;
|
|
367
|
-
void main() {
|
|
368
|
-
vUv = uv;
|
|
369
|
-
gl_Position = vec4(position, 1.0);
|
|
370
|
-
}`,
|
|
371
|
-
fragmentShader: `
|
|
372
|
-
#ifdef GL_ES
|
|
373
|
-
precision highp float;
|
|
374
|
-
#endif
|
|
375
|
-
uniform sampler2D tDiffuse;
|
|
376
|
-
uniform vec3 color;
|
|
377
|
-
uniform float width;
|
|
378
|
-
uniform float opacity;
|
|
379
|
-
uniform vec2 resolution;
|
|
380
|
-
uniform vec2 offset[24];
|
|
381
|
-
varying vec2 vUv;
|
|
382
|
-
vec2 piexl = resolution * width; // 描边厚度
|
|
383
|
-
|
|
384
|
-
vec4 stroke(){
|
|
385
|
-
vec4 blurColor = vec4(0.0);
|
|
386
|
-
vec4 Color = vec4(0.0);
|
|
387
|
-
int vSum = 0; // 周围像素点中和 visibleColor 相似的数量
|
|
388
|
-
for (int i = 0; i < 24; i++ ) {
|
|
389
|
-
Color = texture2D(tDiffuse, vUv + (offset[i] * piexl));
|
|
390
|
-
if (Color.a > 0.0) {
|
|
391
|
-
blurColor += Color;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
if (blurColor.a < 0.001) {
|
|
395
|
-
return vec4(0.0);
|
|
396
|
-
} else {
|
|
397
|
-
return vec4(color, opacity);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
void main() {
|
|
401
|
-
vec4 Color = texture2D(tDiffuse, vUv);
|
|
402
|
-
if (Color.a > 0.0 || width == 0.0) {
|
|
403
|
-
gl_FragColor = Color;
|
|
404
|
-
} else {
|
|
405
|
-
gl_FragColor = stroke();
|
|
406
|
-
}
|
|
407
|
-
}`,
|
|
408
|
-
blending: NoBlending, // 渲染时不与背景融合计算 直接替换
|
|
409
|
-
depthTest: false,
|
|
410
|
-
depthWrite: false,
|
|
411
|
-
transparent: true
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
// 过滤着色器
|
|
415
|
-
const filterSelectShader = new RawShaderMaterial({
|
|
416
|
-
uniforms: {
|
|
417
|
-
selectTexture: { value: null },
|
|
418
|
-
blurTexture: { value: null },
|
|
419
|
-
opacity: { value: 1 },
|
|
420
|
-
},
|
|
421
|
-
vertexShader: `
|
|
422
|
-
attribute vec3 position;
|
|
423
|
-
attribute vec2 uv;
|
|
424
|
-
varying vec2 vUv;
|
|
425
|
-
void main() {
|
|
426
|
-
vUv = uv;
|
|
427
|
-
gl_Position = vec4(position, 1.0);
|
|
428
|
-
}
|
|
429
|
-
`,
|
|
430
|
-
fragmentShader: `
|
|
431
|
-
#ifdef GL_ES
|
|
432
|
-
precision highp float;
|
|
433
|
-
#endif
|
|
434
|
-
uniform sampler2D selectTexture;
|
|
435
|
-
uniform sampler2D blurTexture;
|
|
436
|
-
uniform float opacity;
|
|
437
|
-
varying vec2 vUv;
|
|
438
|
-
|
|
439
|
-
void main() {
|
|
440
|
-
gl_FragColor = texture2D(blurTexture, vUv);
|
|
441
|
-
gl_FragColor.a -= (texture2D(selectTexture, vUv).a);
|
|
442
|
-
gl_FragColor.a *= opacity;
|
|
443
|
-
}
|
|
444
|
-
`,
|
|
445
|
-
blending: NoBlending, // 渲染时不与背景融合计算 直接替换
|
|
446
|
-
depthTest: false,
|
|
447
|
-
depthWrite: false,
|
|
448
|
-
transparent: true
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
const copyShader = new ShaderMaterial({
|
|
452
|
-
uniforms: {
|
|
453
|
-
map: { value: null }, // 贴图纹理
|
|
454
|
-
},
|
|
455
|
-
vertexShader: `
|
|
456
|
-
${ShaderChunk.common}
|
|
457
|
-
${ShaderChunk.logdepthbuf_pars_vertex}
|
|
458
|
-
varying vec2 vUv;
|
|
459
|
-
void main() {
|
|
460
|
-
vUv = uv;
|
|
461
|
-
// gl_Position = vec4(position, 1.0);
|
|
462
|
-
// gl_Position = projectionMatrix * modelViewMatrix * instanceMatrix * vec4(position, 1.0);
|
|
463
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
|
|
464
|
-
${ShaderChunk.logdepthbuf_vertex}
|
|
465
|
-
}
|
|
466
|
-
`,
|
|
467
|
-
fragmentShader: `
|
|
468
|
-
${ShaderChunk.logdepthbuf_pars_fragment}
|
|
469
|
-
uniform sampler2D map;
|
|
470
|
-
varying vec2 vUv;
|
|
471
|
-
void main() {
|
|
472
|
-
gl_FragColor = texture2D(map, vUv);
|
|
473
|
-
${ShaderChunk.logdepthbuf_fragment}
|
|
474
|
-
}
|
|
475
|
-
`,
|
|
476
|
-
depthTest: true,
|
|
477
|
-
depthWrite: true,
|
|
478
|
-
transparent: true
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
// 场景对象
|
|
482
|
-
const scene = new Scene();
|
|
483
|
-
|
|
484
|
-
// 对象发光
|
|
485
|
-
export default function glow_pass(renderer: WebGLRenderer, camera: Camera, object3d: Object3D, baseDepthTexture: DepthTexture) {
|
|
486
|
-
|
|
487
|
-
const { glow_enable = false, glow_color = "#04fa12", glow_width = 1, glow_opacity = 1 } = object3d.userData;
|
|
488
|
-
|
|
489
|
-
if (!glow_enable || glow_width === 0) {
|
|
490
|
-
return;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// 保存原帧缓冲区
|
|
494
|
-
const originRenderTarget = renderer.getRenderTarget();
|
|
495
|
-
|
|
496
|
-
// 设置选中目标的帧缓冲区
|
|
497
|
-
renderer.getSize(size);
|
|
498
|
-
size.multiplyScalar(window.devicePixelRatio);
|
|
499
|
-
selectTextureTarget.setSize(size.x, size.y);
|
|
500
|
-
selectDethpTestTextureTarget.setSize(size.x, size.y);
|
|
501
|
-
blur1TextureTarget.setSize(size.x, size.y);
|
|
502
|
-
blur2TextureTarget.setSize(size.x, size.y);
|
|
503
|
-
|
|
504
|
-
renderer.setRenderTarget(selectTextureTarget);
|
|
505
|
-
scene.children = [object3d];
|
|
506
|
-
renderer.clear();
|
|
507
|
-
renderer.render(scene, camera);
|
|
508
|
-
|
|
509
|
-
// 设置描边着色器的分辨率
|
|
510
|
-
blurShader.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
511
|
-
// 设置抗锯齿着色器的分辨率
|
|
512
|
-
FXAAShaderMaterial.uniforms.resolution.value.set(1 / size.x, 1 / size.y);
|
|
513
|
-
//描边颜色
|
|
514
|
-
blurShader.uniforms.color.value.set(glow_color);
|
|
515
|
-
blurShader.uniforms.width.value = glow_width / 10;
|
|
516
|
-
|
|
517
|
-
//深度测试
|
|
518
|
-
renderer.setRenderTarget(selectDethpTestTextureTarget);
|
|
519
|
-
renderer.clear();
|
|
520
|
-
depthTestShader.uniforms.map.value = selectTextureTarget.texture;
|
|
521
|
-
depthTestShader.uniforms.baseDepth.value = baseDepthTexture;
|
|
522
|
-
depthTestShader.uniforms.selectDepth.value = selectDepthTexture;
|
|
523
|
-
fsQuad.render(renderer, depthTestShader);
|
|
524
|
-
|
|
525
|
-
//一次描边
|
|
526
|
-
renderer.setRenderTarget(blur1TextureTarget);
|
|
527
|
-
blurShader.uniforms.tDiffuse.value = selectDethpTestTextureTarget.texture;
|
|
528
|
-
blurShader.uniforms.opacity.value = 1.0;
|
|
529
|
-
fsQuad.render(renderer, blurShader);
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
//二次描边
|
|
534
|
-
renderer.setRenderTarget(blur2TextureTarget);
|
|
535
|
-
blurShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
536
|
-
blurShader.uniforms.opacity.value = 0.9;
|
|
537
|
-
fsQuad.render(renderer, blurShader);
|
|
538
|
-
|
|
539
|
-
//三次描边
|
|
540
|
-
renderer.setRenderTarget(blur1TextureTarget);
|
|
541
|
-
blurShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
542
|
-
blurShader.uniforms.opacity.value = 0.8;
|
|
543
|
-
fsQuad.render(renderer, blurShader);
|
|
544
|
-
|
|
545
|
-
//四次描边
|
|
546
|
-
renderer.setRenderTarget(blur2TextureTarget);
|
|
547
|
-
blurShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
548
|
-
blurShader.uniforms.opacity.value = 0.7;
|
|
549
|
-
fsQuad.render(renderer, blurShader);
|
|
550
|
-
|
|
551
|
-
//五次描边
|
|
552
|
-
renderer.setRenderTarget(blur1TextureTarget);
|
|
553
|
-
blurShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
554
|
-
blurShader.uniforms.opacity.value = 0.6;
|
|
555
|
-
fsQuad.render(renderer, blurShader);
|
|
556
|
-
|
|
557
|
-
//六次描边
|
|
558
|
-
renderer.setRenderTarget(blur2TextureTarget);
|
|
559
|
-
blurShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
560
|
-
blurShader.uniforms.opacity.value = 0.5;
|
|
561
|
-
fsQuad.render(renderer, blurShader);
|
|
562
|
-
|
|
563
|
-
//七次描边
|
|
564
|
-
renderer.setRenderTarget(blur1TextureTarget);
|
|
565
|
-
blurShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
566
|
-
blurShader.uniforms.opacity.value = 0.4;
|
|
567
|
-
fsQuad.render(renderer, blurShader);
|
|
568
|
-
|
|
569
|
-
//八次描边
|
|
570
|
-
renderer.setRenderTarget(blur2TextureTarget);
|
|
571
|
-
blurShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
572
|
-
blurShader.uniforms.opacity.value = 0.3;
|
|
573
|
-
fsQuad.render(renderer, blurShader);
|
|
574
|
-
|
|
575
|
-
//九次描边
|
|
576
|
-
renderer.setRenderTarget(blur1TextureTarget);
|
|
577
|
-
blurShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
578
|
-
blurShader.uniforms.opacity.value = 0.2;
|
|
579
|
-
fsQuad.render(renderer, blurShader);
|
|
580
|
-
|
|
581
|
-
//十次描边
|
|
582
|
-
renderer.setRenderTarget(blur2TextureTarget);
|
|
583
|
-
blurShader.uniforms.tDiffuse.value = blur1TextureTarget.texture;
|
|
584
|
-
blurShader.uniforms.opacity.value = 0.1;
|
|
585
|
-
fsQuad.render(renderer, blurShader);
|
|
586
|
-
|
|
587
|
-
//最后抗锯齿
|
|
588
|
-
renderer.setRenderTarget(blur1TextureTarget);
|
|
589
|
-
FXAAShaderMaterial.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
590
|
-
fsQuad.render(renderer, FXAAShaderMaterial);
|
|
591
|
-
|
|
592
|
-
// 还原帧缓冲区 减去原始纹理保留描边
|
|
593
|
-
renderer.setRenderTarget(originRenderTarget);
|
|
594
|
-
filterSelectShader.uniforms.selectTexture.value = selectDethpTestTextureTarget.texture;
|
|
595
|
-
filterSelectShader.uniforms.blurTexture.value = blur1TextureTarget.texture;
|
|
596
|
-
filterSelectShader.uniforms.opacity.value = glow_opacity;
|
|
597
|
-
filterSelectShader.blending = NormalBlending; // 与有的纹理融合计算 保留前面通道传递下来的纹理
|
|
598
|
-
fsQuad.render(renderer, filterSelectShader);
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
// 调试代码
|
|
602
|
-
// renderer.setRenderTarget(null);
|
|
603
|
-
// renderer.clearDepth();
|
|
604
|
-
// copyShader.uniforms.tDiffuse.value = blur2TextureTarget.texture;
|
|
605
|
-
// fsQuad.render(renderer, copyShader);
|
|
606
|
-
// return;
|
|
607
|
-
}
|