three-base 1.0.82 → 1.0.83

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.
@@ -4,173 +4,101 @@
4
4
  * @Last Modified by: xiaosihan
5
5
  * @Last Modified time: 2023-03-09 19:15:35
6
6
  */
7
- var __extends = (this && this.__extends) || (function () {
8
- var extendStatics = function (d, b) {
9
- extendStatics = Object.setPrototypeOf ||
10
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
11
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
12
- return extendStatics(d, b);
13
- };
14
- return function (d, b) {
15
- if (typeof b !== "function" && b !== null)
16
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
17
- extendStatics(d, b);
18
- function __() { this.constructor = d; }
19
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
20
- };
21
- })();
22
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
24
- return new (P || (P = Promise))(function (resolve, reject) {
25
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
26
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
27
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
28
- step((generator = generator.apply(thisArg, _arguments || [])).next());
29
- });
30
- };
31
- var __generator = (this && this.__generator) || function (thisArg, body) {
32
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
33
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
34
- function verb(n) { return function (v) { return step([n, v]); }; }
35
- function step(op) {
36
- if (f) throw new TypeError("Generator is already executing.");
37
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
38
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
39
- if (y = 0, t) op = [op[0] & 2, t.value];
40
- switch (op[0]) {
41
- case 0: case 1: t = op; break;
42
- case 4: _.label++; return { value: op[1], done: false };
43
- case 5: _.label++; y = op[1]; op = [0]; continue;
44
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
45
- default:
46
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
47
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
48
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
49
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
50
- if (t[2]) _.ops.pop();
51
- _.trys.pop(); continue;
52
- }
53
- op = body.call(thisArg, _);
54
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
55
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
56
- }
57
- };
58
7
  import { MeshBasicMaterial, Mesh, DoubleSide, CanvasTexture, Vector2, PlaneGeometry } from "three";
59
8
  import planeModalPNG from "./planeModal.png";
60
9
  // 平面模型弹窗
61
- var PlaneModal1 = /** @class */ (function (_super) {
62
- __extends(PlaneModal1, _super);
63
- function PlaneModal1(config) {
64
- if (config === void 0) { config = {}; }
65
- var _this = _super.call(this) || this;
66
- _this.geometry = new PlaneGeometry(1 * 0.65, 0.728 * 0.65, 1, 1);
67
- _this.material = new MeshBasicMaterial({
68
- side: DoubleSide,
69
- transparent: true,
70
- alphaTest: 0.01
71
- });
72
- _this.canvas = (function () {
73
- var canvas = document.createElement("canvas");
74
- canvas.width = 660;
75
- canvas.height = 481;
76
- return canvas;
77
- })();
78
- _this.context = _this.canvas.getContext("2d");
79
- _this.texture = new CanvasTexture(_this.canvas);
80
- // 配置
81
- _this._config = {
82
- size: 10,
83
- title: "PlaneModal1",
84
- titleColor: "#ffffff",
85
- texts: []
86
- // [
87
- // {
88
- // text: "1",
89
- // color: "#ffff00",
90
- // size: 40
91
- // },
92
- // {
93
- // text: "2",
94
- // color: "#ff00ff",
95
- // size: 40
96
- // },
97
- // ]
98
- };
99
- _this.updata(config);
100
- _this.material.map = _this.texture;
101
- _this.scale.set(10, 10, 10);
102
- return _this;
10
+ export default class PlaneModal1 extends Mesh {
11
+ constructor(config = {}) {
12
+ super();
13
+ this.updata(config);
14
+ this.material.map = this.texture;
15
+ this.scale.set(10, 10, 10);
103
16
  }
104
- PlaneModal1.prototype.updata = function (config) {
105
- return __awaiter(this, void 0, void 0, function () {
106
- var textPos, maxWidth;
107
- var _this = this;
108
- return __generator(this, function (_a) {
109
- switch (_a.label) {
110
- case 0:
111
- Object.assign(this._config, config);
112
- //绘制背景
113
- this.context.clearRect(0, 0, 660, 481);
114
- _a.label = 1;
115
- case 1:
116
- if (!!PlaneModal1.img.complete) return [3 /*break*/, 3];
117
- return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 100); })];
118
- case 2:
119
- _a.sent();
120
- return [3 /*break*/, 1];
121
- case 3:
122
- // 设置大小
123
- this.scale.set(this._config.size, this._config.size, this._config.size);
124
- // this.context.fillStyle = "#00000088";
125
- // this.context.fillRect(0, 0, 660, 481);
126
- //绘制背景
127
- this.context.drawImage(PlaneModal1.img, 0, 0);
128
- // 绘制标题
129
- this.context.fillStyle = this._config.titleColor;
130
- this.context.font = '40px serif'; // 设置字体大小
131
- this.context.textAlign = "left";
132
- this.context.textBaseline = "top";
133
- this.context.fillText(this._config.title, 60, 72);
134
- textPos = new Vector2(60, 150);
135
- maxWidth = 530;
136
- // 绘制内容
137
- this._config.texts.map(function (_a) {
138
- var _b = _a.text, text = _b === void 0 ? "text" : _b, _c = _a.color, color = _c === void 0 ? "#ffffff" : _c, _d = _a.size, size = _d === void 0 ? 40 : _d;
139
- _this.context.fillStyle = color;
140
- _this.context.font = "".concat(size, "px serif"); // 设置字体大小
141
- _this.context.textAlign = "left";
142
- _this.context.textBaseline = "top";
143
- // 字符分隔为数组
144
- var arrText = text.split('');
145
- var line = '';
146
- for (var n = 0; n < arrText.length; n++) {
147
- var metrics = _this.context.measureText(line + arrText[n]);
148
- var testWidth = metrics.width;
149
- if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
150
- _this.context.fillText(line, textPos.x, textPos.y);
151
- line = "";
152
- textPos.y += size;
153
- }
154
- else {
155
- line += arrText[n];
156
- }
157
- }
158
- _this.context.fillText(line, textPos.x, textPos.y);
159
- textPos.y += size;
160
- });
161
- this.texture.needsUpdate = true;
162
- this.dispatchEvent({ type: "loaded" });
163
- return [2 /*return*/];
164
- }
165
- });
166
- });
167
- };
17
+ geometry = new PlaneGeometry(1 * 0.65, 0.728 * 0.65, 1, 1);
18
+ material = new MeshBasicMaterial({
19
+ side: DoubleSide,
20
+ transparent: true,
21
+ alphaTest: 0.01
22
+ });
168
23
  // 背景图
169
- PlaneModal1.img = (function () {
170
- var img = new Image();
24
+ static img = (() => {
25
+ const img = new Image();
171
26
  img.src = planeModalPNG;
172
27
  return img;
173
28
  })();
174
- return PlaneModal1;
175
- }(Mesh));
176
- export default PlaneModal1;
29
+ canvas = (() => {
30
+ const canvas = document.createElement("canvas");
31
+ canvas.width = 660;
32
+ canvas.height = 481;
33
+ return canvas;
34
+ })();
35
+ context = this.canvas.getContext("2d");
36
+ texture = new CanvasTexture(this.canvas);
37
+ // 配置
38
+ _config = {
39
+ size: 10,
40
+ title: "PlaneModal1",
41
+ titleColor: "#ffffff",
42
+ texts: []
43
+ // [
44
+ // {
45
+ // text: "1",
46
+ // color: "#ffff00",
47
+ // size: 40
48
+ // },
49
+ // {
50
+ // text: "2",
51
+ // color: "#ff00ff",
52
+ // size: 40
53
+ // },
54
+ // ]
55
+ };
56
+ async updata(config) {
57
+ Object.assign(this._config, config);
58
+ //绘制背景
59
+ this.context.clearRect(0, 0, 660, 481);
60
+ while (!PlaneModal1.img.complete) {
61
+ await new Promise(resolve => setTimeout(resolve, 100));
62
+ }
63
+ // 设置大小
64
+ this.scale.set(this._config.size, this._config.size, this._config.size);
65
+ // this.context.fillStyle = "#00000088";
66
+ // this.context.fillRect(0, 0, 660, 481);
67
+ //绘制背景
68
+ this.context.drawImage(PlaneModal1.img, 0, 0);
69
+ // 绘制标题
70
+ this.context.fillStyle = this._config.titleColor;
71
+ this.context.font = '40px serif'; // 设置字体大小
72
+ this.context.textAlign = "left";
73
+ this.context.textBaseline = "top";
74
+ this.context.fillText(this._config.title, 60, 72);
75
+ let textPos = new Vector2(60, 150);
76
+ let maxWidth = 530;
77
+ // 绘制内容
78
+ this._config.texts.map(({ text = "text", color = "#ffffff", size = 40 }) => {
79
+ this.context.fillStyle = color;
80
+ this.context.font = `${size}px serif`; // 设置字体大小
81
+ this.context.textAlign = "left";
82
+ this.context.textBaseline = "top";
83
+ // 字符分隔为数组
84
+ var arrText = text.split('');
85
+ var line = '';
86
+ for (var n = 0; n < arrText.length; n++) {
87
+ var metrics = this.context.measureText(line + arrText[n]);
88
+ var testWidth = metrics.width;
89
+ if ((testWidth > maxWidth && n > 0) || arrText[n] === "\n") {
90
+ this.context.fillText(line, textPos.x, textPos.y);
91
+ line = "";
92
+ textPos.y += size;
93
+ }
94
+ else {
95
+ line += arrText[n];
96
+ }
97
+ }
98
+ this.context.fillText(line, textPos.x, textPos.y);
99
+ textPos.y += size;
100
+ });
101
+ this.texture.needsUpdate = true;
102
+ this.dispatchEvent({ type: "loaded" });
103
+ }
104
+ }
package/lib/shaders.js CHANGED
@@ -6,72 +6,115 @@
6
6
  */
7
7
  import { BufferGeometry, Color, Float32BufferAttribute, Mesh, NoBlending, OrthographicCamera, ShaderChunk, ShaderMaterial, Vector2 } from "three";
8
8
  // https://github.com/mrdoob/three.js/pull/21358
9
- var _geometry = new BufferGeometry();
9
+ const _geometry = new BufferGeometry();
10
10
  _geometry.setAttribute("position", new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3));
11
11
  _geometry.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2));
12
- var FullScreenQuad = /** @class */ (function () {
13
- function FullScreenQuad() {
12
+ class FullScreenQuad {
13
+ constructor() {
14
14
  this._mesh = new Mesh(_geometry);
15
15
  }
16
- FullScreenQuad.prototype.dispose = function () {
16
+ _mesh;
17
+ dispose() {
17
18
  this._mesh.geometry.dispose();
18
- };
19
- FullScreenQuad.prototype.render = function (renderer) {
19
+ }
20
+ render(renderer) {
20
21
  renderer.render(this._mesh, orthographicCamera);
21
- };
22
- Object.defineProperty(FullScreenQuad.prototype, "material", {
23
- get: function () {
24
- return this._mesh.material;
25
- },
26
- set: function (value) {
27
- this._mesh.material = value;
28
- },
29
- enumerable: false,
30
- configurable: true
31
- });
32
- return FullScreenQuad;
33
- }());
22
+ }
23
+ get material() {
24
+ return this._mesh.material;
25
+ }
26
+ set material(value) {
27
+ this._mesh.material = value;
28
+ }
29
+ }
34
30
  // 常用着色器及工具
35
31
  // 全屏渲染模型
36
- export var fullScreenMesh = new FullScreenQuad();
37
- export var orthographicCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
32
+ export const fullScreenMesh = new FullScreenQuad();
33
+ export const orthographicCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
38
34
  // 清理着色器
39
- export var clearShader = new ShaderMaterial({
40
- vertexShader: "\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = vec4(position, 1.0);\n }\n ",
41
- fragmentShader: "\n void main() {\n gl_FragColor = vec4(0.0);\n }\n ",
35
+ export const clearShader = new ShaderMaterial({
36
+ vertexShader: `
37
+ varying vec2 vUv;
38
+ void main() {
39
+ vUv = uv;
40
+ gl_Position = vec4(position, 1.0);
41
+ }
42
+ `,
43
+ fragmentShader: `
44
+ void main() {
45
+ gl_FragColor = vec4(0.0);
46
+ }
47
+ `,
42
48
  blending: NoBlending,
43
49
  depthTest: false,
44
50
  depthWrite: false,
45
51
  transparent: true
46
52
  });
47
53
  // 交集着色器提取相同的像素点
48
- export var intersectionShader = new ShaderMaterial({
54
+ export const intersectionShader = new ShaderMaterial({
49
55
  uniforms: {
50
56
  map1: { value: null },
51
57
  map2: { value: null }, // 贴图纹理2
52
58
  },
53
- vertexShader: "\n ".concat(ShaderChunk.common, "\n ").concat(ShaderChunk.logdepthbuf_pars_vertex, "\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = vec4(position, 1.0);\n ").concat(ShaderChunk.logdepthbuf_vertex, "\n }\n "),
54
- fragmentShader: "\n ".concat(ShaderChunk.logdepthbuf_pars_fragment, "\n uniform sampler2D map1;\n uniform sampler2D map2;\n varying vec2 vUv;\n void main() {\n if(texture2D(map1, vUv) == texture2D(map2, vUv)){\n gl_FragColor = texture2D(map1, vUv);\n }else{\n discard;\n }\n ").concat(ShaderChunk.logdepthbuf_fragment, "\n }\n "),
59
+ vertexShader: `
60
+ ${ShaderChunk.common}
61
+ ${ShaderChunk.logdepthbuf_pars_vertex}
62
+ varying vec2 vUv;
63
+ void main() {
64
+ vUv = uv;
65
+ gl_Position = vec4(position, 1.0);
66
+ ${ShaderChunk.logdepthbuf_vertex}
67
+ }
68
+ `,
69
+ fragmentShader: `
70
+ ${ShaderChunk.logdepthbuf_pars_fragment}
71
+ uniform sampler2D map1;
72
+ uniform sampler2D map2;
73
+ varying vec2 vUv;
74
+ void main() {
75
+ if(texture2D(map1, vUv) == texture2D(map2, vUv)){
76
+ gl_FragColor = texture2D(map1, vUv);
77
+ }else{
78
+ discard;
79
+ }
80
+ ${ShaderChunk.logdepthbuf_fragment}
81
+ }
82
+ `,
55
83
  blending: NoBlending,
56
84
  depthTest: true,
57
85
  depthWrite: true,
58
86
  transparent: true
59
87
  });
60
88
  // 拷贝着色器
61
- export var coptyShader = new ShaderMaterial({
89
+ export const coptyShader = new ShaderMaterial({
62
90
  uniforms: {
63
91
  map: { value: null },
64
92
  opacity: { value: 1.0 } // 透明度
65
93
  },
66
- vertexShader: "\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = vec4(position, 1.0);\n }\n ",
67
- fragmentShader: "\n uniform sampler2D map;\n uniform float opacity;\n varying vec2 vUv;\n void main() {\n\n gl_FragColor = texture2D(map, vUv) * opacity;\n\n }\n ",
94
+ vertexShader: `
95
+ varying vec2 vUv;
96
+ void main() {
97
+ vUv = uv;
98
+ gl_Position = vec4(position, 1.0);
99
+ }
100
+ `,
101
+ fragmentShader: `
102
+ uniform sampler2D map;
103
+ uniform float opacity;
104
+ varying vec2 vUv;
105
+ void main() {
106
+
107
+ gl_FragColor = texture2D(map, vUv) * opacity;
108
+
109
+ }
110
+ `,
68
111
  // blending: NoBlending, // 渲染时不与背景融合计算 直接替换
69
112
  depthTest: true,
70
113
  depthWrite: true,
71
114
  transparent: true,
72
115
  });
73
116
  // 描边着色器
74
- export var strokeShader = new ShaderMaterial({
117
+ export const strokeShader = new ShaderMaterial({
75
118
  uniforms: {
76
119
  map: { value: null },
77
120
  resolution: { value: new Vector2(512, 512) },
@@ -79,23 +122,122 @@ export var strokeShader = new ShaderMaterial({
79
122
  strokeColor: { value: new Color("#B2F2FF") },
80
123
  opacity: { value: 1.0 } // 透明度
81
124
  },
82
- vertexShader: "\n varying vec2 vUv;\n void main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n }\n ",
83
- fragmentShader: "\n uniform sampler2D map;\n uniform vec2 resolution;\n uniform vec3 strokeColor; // \u63CF\u8FB9\u989C\u8272\n uniform float strokeWidth; // \u63CF\u8FB9\u539A\u5EA6\n uniform float opacity; // \u900F\u660E\u5EA6\n \n varying vec2 vUv;\n\n // \u83B7\u53D6\u5F53\u524D\u53E0\u52A0vu\u5750\u6807\u504F\u79FB\u91CF\u7684\u989C\u8272\u503C\n vec4 offsetColor(vec2 vu){\n return texture2D(map, vUv + (vu * (strokeWidth / resolution) ) );\n }\n\n vec4 fragColor(){\n\n vec4 currentColor = offsetColor(vec2(0.0, 0.0));\n\n if(\n currentColor.a < min(0.2, opacity) && (\n offsetColor(vec2(0.0, 1.0)).a > 0.0 ||\n offsetColor(vec2(0.0, -1.0)).a > 0.0 ||\n offsetColor(vec2(1.0, 0.0)).a > 0.0 ||\n offsetColor(vec2(-1.0, 0.0)).a > 0.0 ||\n\n offsetColor(vec2(1.0) * 0.7).a > 0.0 ||\n offsetColor(vec2(-1.0) * 0.7).a > 0.0 ||\n offsetColor(vec2(-1.0, 1.0) * 0.7).a > 0.0 ||\n offsetColor(vec2(1.0, -1.0) * 0.7).a > 0.0\n )\n ){\n return vec4( strokeColor, opacity);\n }else{\n // discard;\n return offsetColor(vec2(0.0, 0.0));\n }\n\n }\n\n void main() {\n gl_FragColor = fragColor();\n }\n ",
125
+ vertexShader: `
126
+ varying vec2 vUv;
127
+ void main() {
128
+ vUv = uv;
129
+ gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
130
+ }
131
+ `,
132
+ fragmentShader: `
133
+ uniform sampler2D map;
134
+ uniform vec2 resolution;
135
+ uniform vec3 strokeColor; // 描边颜色
136
+ uniform float strokeWidth; // 描边厚度
137
+ uniform float opacity; // 透明度
138
+
139
+ varying vec2 vUv;
140
+
141
+ // 获取当前叠加vu坐标偏移量的颜色值
142
+ vec4 offsetColor(vec2 vu){
143
+ return texture2D(map, vUv + (vu * (strokeWidth / resolution) ) );
144
+ }
145
+
146
+ vec4 fragColor(){
147
+
148
+ vec4 currentColor = offsetColor(vec2(0.0, 0.0));
149
+
150
+ if(
151
+ currentColor.a < min(0.2, opacity) && (
152
+ offsetColor(vec2(0.0, 1.0)).a > 0.0 ||
153
+ offsetColor(vec2(0.0, -1.0)).a > 0.0 ||
154
+ offsetColor(vec2(1.0, 0.0)).a > 0.0 ||
155
+ offsetColor(vec2(-1.0, 0.0)).a > 0.0 ||
156
+
157
+ offsetColor(vec2(1.0) * 0.7).a > 0.0 ||
158
+ offsetColor(vec2(-1.0) * 0.7).a > 0.0 ||
159
+ offsetColor(vec2(-1.0, 1.0) * 0.7).a > 0.0 ||
160
+ offsetColor(vec2(1.0, -1.0) * 0.7).a > 0.0
161
+ )
162
+ ){
163
+ return vec4( strokeColor, opacity);
164
+ }else{
165
+ // discard;
166
+ return offsetColor(vec2(0.0, 0.0));
167
+ }
168
+
169
+ }
170
+
171
+ void main() {
172
+ gl_FragColor = fragColor();
173
+ }
174
+ `,
84
175
  blending: NoBlending,
85
176
  depthTest: true,
86
177
  depthWrite: true,
87
178
  transparent: true
88
179
  });
89
180
  // 高斯模糊着色器 让颜色过渡更自然
90
- export var gaussBlurShader = new ShaderMaterial({
181
+ export const gaussBlurShader = new ShaderMaterial({
91
182
  uniforms: {
92
183
  map: { value: null },
93
184
  opacity: { value: 1.0 },
94
185
  radius: { value: 3.0 },
95
186
  resolution: { value: new Vector2(512, 512) }, // 渲染器的分辨率
96
187
  },
97
- vertexShader: "\n\t\tvarying vec2 vUv;\n\t\tvoid main() {\n\t\t\tvUv = uv;\n\t\t\tgl_Position = vec4(position, 1.0);\n\t\t}\n\t",
98
- fragmentShader: "\n\t\tuniform sampler2D map;\n\t\tuniform float opacity;\n\t\tuniform vec2 resolution;\n\t\tuniform float radius;\n\t\tvarying vec2 vUv;\n\n vec4 offsetColor( vec2 uv){\n return texture2D(map, vUv + (uv / resolution * radius) );\n }\n\n vec4 blurColor(){\n\n vec4 leftColor = offsetColor( vec2(-1.0, 0.0) );\n\n vec4 rightColor = offsetColor( vec2(1.0, 0.0) );\n\n // \u5DE6\u53F3\u989C\u8272\u6DF7\u5408\n vec4 leftRightColor = vec4( \n mix( leftColor.rgb ,rightColor.rgb, rightColor.a / (leftColor.a + rightColor.a)),\n (leftColor.a + rightColor.a) / 2.0\n );\n\n vec4 downColor = offsetColor( vec2(0.0, -1.0));\n\n vec4 upColor = offsetColor( vec2(0.0, 1.0));\n\n // \u4E0A\u4E0B\u989C\u8272\u6DF7\u5408\n vec4 upDownColor = vec4(\n mix( downColor.rgb, upColor.rgb, upColor.a / (downColor.a + upColor.a) ),\n (downColor.a + upColor.a) / 2.0\n );\n \n vec4 color = vec4(\n mix( leftRightColor.rgb, upDownColor.rgb, upDownColor.a / (leftRightColor.a + upDownColor.a) ),\n (leftRightColor.a + upDownColor.a) / 2.0\n );\n \n return color;\n }\n\n\t\tvoid main() {\n\t\t\tgl_FragColor = blurColor();\n gl_FragColor.a *= opacity;\n\t\t}\n\t",
188
+ vertexShader: `
189
+ varying vec2 vUv;
190
+ void main() {
191
+ vUv = uv;
192
+ gl_Position = vec4(position, 1.0);
193
+ }
194
+ `,
195
+ fragmentShader: `
196
+ uniform sampler2D map;
197
+ uniform float opacity;
198
+ uniform vec2 resolution;
199
+ uniform float radius;
200
+ varying vec2 vUv;
201
+
202
+ vec4 offsetColor( vec2 uv){
203
+ return texture2D(map, vUv + (uv / resolution * radius) );
204
+ }
205
+
206
+ vec4 blurColor(){
207
+
208
+ vec4 leftColor = offsetColor( vec2(-1.0, 0.0) );
209
+
210
+ vec4 rightColor = offsetColor( vec2(1.0, 0.0) );
211
+
212
+ // 左右颜色混合
213
+ vec4 leftRightColor = vec4(
214
+ mix( leftColor.rgb ,rightColor.rgb, rightColor.a / (leftColor.a + rightColor.a)),
215
+ (leftColor.a + rightColor.a) / 2.0
216
+ );
217
+
218
+ vec4 downColor = offsetColor( vec2(0.0, -1.0));
219
+
220
+ vec4 upColor = offsetColor( vec2(0.0, 1.0));
221
+
222
+ // 上下颜色混合
223
+ vec4 upDownColor = vec4(
224
+ mix( downColor.rgb, upColor.rgb, upColor.a / (downColor.a + upColor.a) ),
225
+ (downColor.a + upColor.a) / 2.0
226
+ );
227
+
228
+ vec4 color = vec4(
229
+ mix( leftRightColor.rgb, upDownColor.rgb, upDownColor.a / (leftRightColor.a + upDownColor.a) ),
230
+ (leftRightColor.a + upDownColor.a) / 2.0
231
+ );
232
+
233
+ return color;
234
+ }
235
+
236
+ void main() {
237
+ gl_FragColor = blurColor();
238
+ gl_FragColor.a *= opacity;
239
+ }
240
+ `,
99
241
  blending: NoBlending,
100
242
  depthTest: false,
101
243
  depthWrite: false,