fl-web-component 1.0.11 → 1.1.0
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/README.md +12 -1
- package/dist/fl-web-component.common.js +10677 -2954
- package/dist/fl-web-component.css +1 -1
- package/package.json +2 -1
- package/packages/components/com-flcanvas/index.vue +58 -9
- package/packages/components/com-graphics/index.vue +173 -69
- package/packages/components/com-graphics/pid.vue +31 -16
- package/src/main.js +5 -2
- package/src/utils/instance-parser.js +8 -2
- package/src/utils/threejs/measure-angle.js +40 -30
- package/src/utils/threejs/measure-area.js +52 -44
- package/src/utils/threejs/measure-distance.js +39 -29
- package/src/utils/threejs/rain-shader.js +58 -0
- package/src/utils/threejs/snow-shader.js +75 -0
package/src/main.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import FlModel from '../packages/components/com-graphics/index.vue';
|
|
2
2
|
import Fl2dcanvas from '../packages/components/com-flcanvas/index.vue';
|
|
3
3
|
import FLPerControl from '../packages/components/com-graphics/per-control.vue';
|
|
4
|
+
import FlSvg from '../packages/components/com-graphics/pid.vue';
|
|
4
5
|
import * as THREE from 'three';
|
|
5
6
|
|
|
6
7
|
const components = [
|
|
7
8
|
FlModel,
|
|
8
9
|
Fl2dcanvas,
|
|
9
|
-
FLPerControl
|
|
10
|
+
FLPerControl,
|
|
11
|
+
FlSvg
|
|
10
12
|
];
|
|
11
13
|
|
|
12
14
|
const install = (Vue) => {
|
|
13
|
-
Vue.prototype.THREE = THREE
|
|
15
|
+
Vue.prototype.THREE = THREE;
|
|
14
16
|
components.forEach(component => {
|
|
15
17
|
Vue.component(component.name, component);
|
|
16
18
|
});
|
|
@@ -24,6 +26,7 @@ if (typeof window !== 'undefined' && window.Vue) {
|
|
|
24
26
|
export default {
|
|
25
27
|
install,
|
|
26
28
|
FlModel,
|
|
29
|
+
FlSvg,
|
|
27
30
|
Fl2dcanvas,
|
|
28
31
|
FLPerControl
|
|
29
32
|
};
|
|
@@ -48,12 +48,18 @@ function handleInstancedMeshModel(instances, drawObjs, type, scene, customColor,
|
|
|
48
48
|
if (!targetGroup) {
|
|
49
49
|
const drawObj = drawObjMapInstance[instances[i].drawObject];
|
|
50
50
|
const group = new THREE.Group();
|
|
51
|
+
// let grouphName = ''
|
|
52
|
+
for (const key in meshNameConfig) {
|
|
53
|
+
group.userData[key] = meshNameConfig[key]
|
|
54
|
+
// grouphName += ':' + meshNameConfig[key]
|
|
55
|
+
}
|
|
56
|
+
// grouphName !== '' ? instances[i].drawObject + grouphName: instances[i].drawObject;
|
|
51
57
|
group.name = instances[i].drawObject;
|
|
52
58
|
group.userData.isInstancedMeshGroup = true;
|
|
53
|
-
|
|
59
|
+
group.userData.instanceId = instances[i].drawObject;
|
|
54
60
|
const instanceCount = drawObj.MapInstance.length;
|
|
55
61
|
drawObj.MapMesh?.forEach(mesh => {
|
|
56
|
-
const model = drawModel(mesh,
|
|
62
|
+
const model = drawModel(mesh, instances[i].drawObject, instanceCount, customColor);
|
|
57
63
|
if (!model) {
|
|
58
64
|
return;
|
|
59
65
|
}
|
|
@@ -20,6 +20,7 @@ var MeasureAngle = function(renderer, scene, camera, width, height) {
|
|
|
20
20
|
this.timer = null
|
|
21
21
|
this.width = width
|
|
22
22
|
this.height = height
|
|
23
|
+
this.firstTime = 0
|
|
23
24
|
// this.POINT_MATERIAL = new THREE.PointsMaterial({ color: 0xff5000, size: 1, opacity: 0.6, transparent: true, depthWrite: false, depthTest: false })
|
|
24
25
|
// this.LINE_MATERIAL = new THREE.LineBasicMaterial({ color: 0xff0000, linewidth: 3, opacity: 0.8, transparent: true, side: THREE.DoubleSide, depthWrite: false, depthTest: false })
|
|
25
26
|
}
|
|
@@ -28,7 +29,8 @@ MeasureAngle.prototype = {
|
|
|
28
29
|
start() {
|
|
29
30
|
_this = this
|
|
30
31
|
this.renderer.domElement.style.cursor = 'crosshair'
|
|
31
|
-
this.renderer.domElement.addEventListener('
|
|
32
|
+
this.renderer.domElement.addEventListener('mouseup', this.click, false)
|
|
33
|
+
this.renderer.domElement.addEventListener('mousedown', this.mousedown, false)
|
|
32
34
|
this.renderer.domElement.addEventListener('mousemove', this.mousemove, false)
|
|
33
35
|
this.renderer.domElement.addEventListener('contextmenu', this.rightClick, false)
|
|
34
36
|
},
|
|
@@ -132,34 +134,41 @@ MeasureAngle.prototype = {
|
|
|
132
134
|
tipsLabel.position.set(position.x + 0.1, position.y, position.z + 0.05)
|
|
133
135
|
return tipsLabel
|
|
134
136
|
},
|
|
137
|
+
mousedown() {
|
|
138
|
+
this.firstTime = new Date().getTime();
|
|
139
|
+
},
|
|
135
140
|
click(e) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
_this.timer = setTimeout(() => {
|
|
141
|
-
_this.isCompleted = false
|
|
142
|
-
const point = _this.getPosition(e)
|
|
143
|
-
if (point) {
|
|
144
|
-
if(_this.tipsLabel) {
|
|
145
|
-
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05)
|
|
146
|
-
} else {
|
|
147
|
-
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point)
|
|
148
|
-
_this.scene.add(_this.tipsLabel)
|
|
149
|
-
}
|
|
150
|
-
if (_this.tempPoints) {
|
|
151
|
-
_this.tempPoints.position.set(point.x, point.y, point.z)
|
|
152
|
-
_this.tempPoints = undefined
|
|
153
|
-
} else {
|
|
154
|
-
const geom =_this.createLabel('circle-tag', '', point)
|
|
155
|
-
_this.points.push(geom)
|
|
156
|
-
_this.scene.add(geom)
|
|
157
|
-
}
|
|
158
|
-
_this.tempLine = undefined
|
|
159
|
-
_this.tempLabel = undefined
|
|
160
|
-
_this.pointArray.push(point)
|
|
141
|
+
let lastTime = new Date().getTime();
|
|
142
|
+
if (lastTime = this.firstTime < 300) {
|
|
143
|
+
if (_this.isCompleted) {
|
|
144
|
+
_this.renderer.domElement.addEventListener('mousemove', _this.mousemove)
|
|
161
145
|
}
|
|
162
|
-
|
|
146
|
+
clearTimeout(_this.timer)
|
|
147
|
+
_this.timer = setTimeout(() => {
|
|
148
|
+
_this.isCompleted = false
|
|
149
|
+
const point = _this.getPosition(e)
|
|
150
|
+
if (point) {
|
|
151
|
+
if(_this.tipsLabel) {
|
|
152
|
+
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05)
|
|
153
|
+
} else {
|
|
154
|
+
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point)
|
|
155
|
+
_this.scene.add(_this.tipsLabel)
|
|
156
|
+
}
|
|
157
|
+
if (_this.tempPoints) {
|
|
158
|
+
_this.tempPoints.position.set(point.x, point.y, point.z)
|
|
159
|
+
_this.tempPoints = undefined
|
|
160
|
+
} else {
|
|
161
|
+
const geom =_this.createLabel('circle-tag', '', point)
|
|
162
|
+
_this.points.push(geom)
|
|
163
|
+
_this.scene.add(geom)
|
|
164
|
+
}
|
|
165
|
+
_this.tempLine = undefined
|
|
166
|
+
_this.tempLabel = undefined
|
|
167
|
+
_this.pointArray.push(point)
|
|
168
|
+
}
|
|
169
|
+
})
|
|
170
|
+
}
|
|
171
|
+
|
|
163
172
|
},
|
|
164
173
|
rightClick(e) {
|
|
165
174
|
if(_this.tipsLabel) {
|
|
@@ -178,9 +187,10 @@ MeasureAngle.prototype = {
|
|
|
178
187
|
}
|
|
179
188
|
},
|
|
180
189
|
close() {
|
|
181
|
-
this.renderer.domElement.removeEventListener('
|
|
182
|
-
this.renderer.domElement.removeEventListener('
|
|
183
|
-
this.renderer.domElement.removeEventListener('
|
|
190
|
+
this.renderer.domElement.removeEventListener('mouseup', this.click, false)
|
|
191
|
+
this.renderer.domElement.removeEventListener('mousedown', this.mousedown, false)
|
|
192
|
+
this.renderer.domElement.removeEventListener('mousemove', this.mousemove, false)
|
|
193
|
+
this.renderer.domElement.removeEventListener('contextmenu', this.rightClick, false)
|
|
184
194
|
this.remove(this.points)
|
|
185
195
|
this.remove(this.polyline)
|
|
186
196
|
this.remove(this.labels)
|
|
@@ -20,13 +20,15 @@ var MeasureArea = function(renderer, scene, camera, width, height) {
|
|
|
20
20
|
this.polygons = []
|
|
21
21
|
this.width = width
|
|
22
22
|
this.height = height
|
|
23
|
+
this.firstTime = 0
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
MeasureArea.prototype = {
|
|
26
27
|
start() {
|
|
27
28
|
_this = this
|
|
28
29
|
this.renderer.domElement.style.cursor = 'crosshair'
|
|
29
|
-
this.renderer.domElement.addEventListener('
|
|
30
|
+
this.renderer.domElement.addEventListener('mouseup', this.click, false)
|
|
31
|
+
this.renderer.domElement.addEventListener('mousedown', this.mousedown, false)
|
|
30
32
|
this.renderer.domElement.addEventListener('mousemove', this.mousemove, false)
|
|
31
33
|
this.renderer.domElement.addEventListener('contextmenu', this.rightClick, false)
|
|
32
34
|
},
|
|
@@ -114,34 +116,39 @@ MeasureArea.prototype = {
|
|
|
114
116
|
tipsLabel.position.set(position.x + 0.1, position.y, position.z + 0.05)
|
|
115
117
|
return tipsLabel
|
|
116
118
|
},
|
|
119
|
+
mousedown() {
|
|
120
|
+
this.firstTime = new Date().getTime();
|
|
121
|
+
},
|
|
117
122
|
click(e) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
_this.timer = setTimeout(() => {
|
|
123
|
-
_this.isCompleted = false
|
|
124
|
-
const point = _this.getPosition(e)
|
|
125
|
-
if (point) {
|
|
126
|
-
if(_this.tipsLabel) {
|
|
127
|
-
_this.tipsLabel.position.set(point.x + 0.01, point.y, point.z + 0.05)
|
|
128
|
-
} else {
|
|
129
|
-
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point)
|
|
130
|
-
_this.scene.add(_this.tipsLabel)
|
|
131
|
-
}
|
|
132
|
-
if (_this.tempPoints) {
|
|
133
|
-
_this.tempPoints.position.set(point.x, point.y, point.z)
|
|
134
|
-
_this.tempPoints = undefined
|
|
135
|
-
} else {
|
|
136
|
-
const geom = _this.createLabel('circle-tag', '', point)
|
|
137
|
-
_this.points.push(geom)
|
|
138
|
-
_this.scene.add(geom)
|
|
139
|
-
}
|
|
140
|
-
_this.tempLine = undefined
|
|
141
|
-
_this.pointArray.push(point)
|
|
123
|
+
let lastTime = new Date().getTime();
|
|
124
|
+
if (lastTime - this.firstTime < 300) {
|
|
125
|
+
if (_this.isCompleted) {
|
|
126
|
+
_this.renderer.domElement.addEventListener('mousemove', _this.mousemove)
|
|
142
127
|
}
|
|
143
|
-
|
|
144
|
-
|
|
128
|
+
clearTimeout(_this.timer)
|
|
129
|
+
_this.timer = setTimeout(() => {
|
|
130
|
+
_this.isCompleted = false
|
|
131
|
+
const point = _this.getPosition(e)
|
|
132
|
+
if (point) {
|
|
133
|
+
if(_this.tipsLabel) {
|
|
134
|
+
_this.tipsLabel.position.set(point.x + 0.01, point.y, point.z + 0.05)
|
|
135
|
+
} else {
|
|
136
|
+
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point)
|
|
137
|
+
_this.scene.add(_this.tipsLabel)
|
|
138
|
+
}
|
|
139
|
+
if (_this.tempPoints) {
|
|
140
|
+
_this.tempPoints.position.set(point.x, point.y, point.z)
|
|
141
|
+
_this.tempPoints = undefined
|
|
142
|
+
} else {
|
|
143
|
+
const geom = _this.createLabel('circle-tag', '', point)
|
|
144
|
+
_this.points.push(geom)
|
|
145
|
+
_this.scene.add(geom)
|
|
146
|
+
}
|
|
147
|
+
_this.tempLine = undefined
|
|
148
|
+
_this.pointArray.push(point)
|
|
149
|
+
}
|
|
150
|
+
}, 100)
|
|
151
|
+
}
|
|
145
152
|
},
|
|
146
153
|
rightClick (e) {
|
|
147
154
|
if(_this.tipsLabel) {
|
|
@@ -164,23 +171,24 @@ MeasureArea.prototype = {
|
|
|
164
171
|
}
|
|
165
172
|
},
|
|
166
173
|
close() {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
174
|
+
this.renderer.domElement.removeEventListener('mouseup', this.click)
|
|
175
|
+
this.renderer.domElement.removeEventListener('mousedown', this.mousedown)
|
|
176
|
+
this.renderer.domElement.removeEventListener('mousemove', this.mousemove)
|
|
177
|
+
this.renderer.domElement.removeEventListener('contextmenu', this.rightClick)
|
|
178
|
+
this.remove(this.points)
|
|
179
|
+
this.remove(this.polyline)
|
|
180
|
+
this.remove(this.labels)
|
|
181
|
+
this.remove(this.polygons)
|
|
182
|
+
this.pointArray.splice(0)
|
|
183
|
+
this.points.splice(0)
|
|
184
|
+
this.polyline.splice(0)
|
|
185
|
+
this.labels.splice(0)
|
|
186
|
+
this.tempPoints = undefined
|
|
187
|
+
this.tempLabel = undefined
|
|
188
|
+
this.tempLine = undefined
|
|
189
|
+
this.scene.remove(this.tipsLabel)
|
|
190
|
+
this.tipsLabel = undefined
|
|
191
|
+
this.renderer.domElement.style.cursor = 'pointer'
|
|
184
192
|
},
|
|
185
193
|
remove(array) {
|
|
186
194
|
for (let index = 0; index < array.length; index++) {
|
|
@@ -18,13 +18,15 @@ var MeasureDistance = function(renderer, scene, camera, width, height) {
|
|
|
18
18
|
this.timer = null
|
|
19
19
|
this.width = width
|
|
20
20
|
this.height = height
|
|
21
|
+
this.firstTime = 0
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
MeasureDistance.prototype = {
|
|
24
25
|
start() {
|
|
25
26
|
_this = this
|
|
26
27
|
this.renderer.domElement.style.cursor = 'crosshair'
|
|
27
|
-
this.renderer.domElement.addEventListener('
|
|
28
|
+
this.renderer.domElement.addEventListener('mousedown', this.mousedown, false)
|
|
29
|
+
this.renderer.domElement.addEventListener('mouseup', this.click, false)
|
|
28
30
|
this.renderer.domElement.addEventListener('mousemove', this.mousemove, false)
|
|
29
31
|
this.renderer.domElement.addEventListener('contextmenu', this.rightClick, false)
|
|
30
32
|
},
|
|
@@ -105,34 +107,40 @@ MeasureDistance.prototype = {
|
|
|
105
107
|
tipsLabel.position.set(position.x + 0.1, position.y, position.z + 0.05)
|
|
106
108
|
return tipsLabel
|
|
107
109
|
},
|
|
110
|
+
mousedown() {
|
|
111
|
+
this.firstTime = new Date().getTime();
|
|
112
|
+
},
|
|
108
113
|
click(e) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
_this.timer = setTimeout(() => {
|
|
114
|
-
_this.isCompleted = false
|
|
115
|
-
const point = _this.getPosition(e)
|
|
116
|
-
if (point) {
|
|
117
|
-
if(_this.tipsLabel) {
|
|
118
|
-
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05)
|
|
119
|
-
} else {
|
|
120
|
-
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point)
|
|
121
|
-
_this.scene.add(_this.tipsLabel)
|
|
122
|
-
}
|
|
123
|
-
if (_this.tempPoints) {
|
|
124
|
-
_this.tempPoints.position.set(point.x, point.y, point.z)
|
|
125
|
-
_this.tempPoints = undefined
|
|
126
|
-
} else {
|
|
127
|
-
const geom = _this.createLabel('circle-tag', '', point)
|
|
128
|
-
_this.points.push(geom)
|
|
129
|
-
_this.scene.add(geom)
|
|
130
|
-
}
|
|
131
|
-
_this.tempLine = undefined
|
|
132
|
-
_this.tempLabel = undefined
|
|
133
|
-
_this.pointArray.push(point)
|
|
114
|
+
let lastTime = new Date().getTime();
|
|
115
|
+
if (lastTime - this.firstTime < 300) {
|
|
116
|
+
if (_this.isCompleted) {
|
|
117
|
+
_this.renderer.domElement.addEventListener('mousemove', _this.mousemove)
|
|
134
118
|
}
|
|
135
|
-
|
|
119
|
+
clearTimeout(_this.timer)
|
|
120
|
+
_this.timer = setTimeout(() => {
|
|
121
|
+
_this.isCompleted = false
|
|
122
|
+
const point = _this.getPosition(e)
|
|
123
|
+
if (point) {
|
|
124
|
+
if(_this.tipsLabel) {
|
|
125
|
+
_this.tipsLabel.position.set(point.x + 0.1, point.y, point.z + 0.05)
|
|
126
|
+
} else {
|
|
127
|
+
_this.tipsLabel = _this.createTipsLabel('左击绘制右击结束', point)
|
|
128
|
+
_this.scene.add(_this.tipsLabel)
|
|
129
|
+
}
|
|
130
|
+
if (_this.tempPoints) {
|
|
131
|
+
_this.tempPoints.position.set(point.x, point.y, point.z)
|
|
132
|
+
_this.tempPoints = undefined
|
|
133
|
+
} else {
|
|
134
|
+
const geom = _this.createLabel('circle-tag', '', point)
|
|
135
|
+
_this.points.push(geom)
|
|
136
|
+
_this.scene.add(geom)
|
|
137
|
+
}
|
|
138
|
+
_this.tempLine = undefined
|
|
139
|
+
_this.tempLabel = undefined
|
|
140
|
+
_this.pointArray.push(point)
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
}
|
|
136
144
|
},
|
|
137
145
|
rightClick(e) {
|
|
138
146
|
if(_this.tipsLabel) {
|
|
@@ -151,8 +159,9 @@ MeasureDistance.prototype = {
|
|
|
151
159
|
}
|
|
152
160
|
},
|
|
153
161
|
close() {
|
|
154
|
-
this.renderer.domElement.removeEventListener('
|
|
155
|
-
this.renderer.domElement.removeEventListener('
|
|
162
|
+
this.renderer.domElement.removeEventListener('mousedown', this.mousedown)
|
|
163
|
+
this.renderer.domElement.removeEventListener('mouseup', this.click)
|
|
164
|
+
this.renderer.domElement.removeEventListener('mousemove', this.mousemove)
|
|
156
165
|
this.renderer.domElement.removeEventListener('contextmenu', this.rightClick)
|
|
157
166
|
this.remove(this.points)
|
|
158
167
|
this.remove(this.polyline)
|
|
@@ -167,6 +176,7 @@ MeasureDistance.prototype = {
|
|
|
167
176
|
this.scene.remove(this.tipsLabel)
|
|
168
177
|
this.tipsLabel = undefined
|
|
169
178
|
this.renderer.domElement.style.cursor = 'pointer'
|
|
179
|
+
this.firstTime = 0
|
|
170
180
|
},
|
|
171
181
|
remove(array) {
|
|
172
182
|
for (let index = 0; index < array.length; index++) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import * as THREE from 'three'
|
|
2
|
+
const RainShader = {
|
|
3
|
+
uniforms: {
|
|
4
|
+
'tDiffuse': {value: null},
|
|
5
|
+
'iResolution': {value: null},
|
|
6
|
+
'iTime': {value: 0},
|
|
7
|
+
'radian': {value: 0 / 360 * Math.PI},
|
|
8
|
+
'rainSpeed': {value: 0.2},
|
|
9
|
+
'rainColor': {value: new THREE.Color(1, 1, 1)}
|
|
10
|
+
},
|
|
11
|
+
vertexShader: `
|
|
12
|
+
varying vec2 vUv;
|
|
13
|
+
void main() {
|
|
14
|
+
vUv = uv;
|
|
15
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
16
|
+
}
|
|
17
|
+
`,
|
|
18
|
+
fragmentShader: `
|
|
19
|
+
uniform sampler2D tDiffuse;
|
|
20
|
+
uniform vec2 iResolution;
|
|
21
|
+
uniform float iTime;
|
|
22
|
+
uniform float radian;
|
|
23
|
+
uniform float rainSpeed;
|
|
24
|
+
uniform vec3 rainColor;
|
|
25
|
+
varying vec2 vUv;
|
|
26
|
+
|
|
27
|
+
float hash(vec2 p){
|
|
28
|
+
p = 50.0 * fract(p * 0.3183099 + vec2(0.71, 0.113) );
|
|
29
|
+
return -1.0+2.0 * fract(p.x * p.y * (p.x + p.y));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
float noise(in vec2 p){
|
|
33
|
+
vec2 i = floor(p);
|
|
34
|
+
vec2 f = fract(p);
|
|
35
|
+
vec2 u = f * f * (3.0 - 2.0 * f);
|
|
36
|
+
return mix(mix( hash( i + vec2(0.0,0.0) ), hash( i + vec2(1.0,0.0) ), u.x), mix( hash( i + vec2(0.0,1.0) ), hash( i + vec2(1.0,1.0) ), u.x), u.y);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void main() {
|
|
40
|
+
vec3 col = texture(tDiffuse, vUv).rgb;
|
|
41
|
+
vec2 q = gl_FragCoord.xy / iResolution.xy;
|
|
42
|
+
vec2 p = -1.0 + 2.0 * q;
|
|
43
|
+
p.x *= iResolution.x / iResolution.y;
|
|
44
|
+
vec2 st = (p * vec2(.5, .01) + vec2 (iTime) * 0.05 * rainSpeed )-vec2(q.y*cos(radian), 0.0);
|
|
45
|
+
st *= 1000.;
|
|
46
|
+
float f = noise(st) * noise(st*.773)* 1.3;
|
|
47
|
+
f = clamp(pow(abs(f), 23.0) * 13.0, 0.0, q.y*.14) * 2.7;
|
|
48
|
+
col += clamp(f, 0.0, 1.0) * rainColor;
|
|
49
|
+
if(col.x > f){
|
|
50
|
+
gl_FragColor = vec4(col,1.0);
|
|
51
|
+
}else{
|
|
52
|
+
gl_FragColor = vec4(col,0.0);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
`
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { RainShader }
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const SnowShader = {
|
|
2
|
+
uniforms: {
|
|
3
|
+
'tDiffuse': {value: null},
|
|
4
|
+
'iResolution': {value: null},
|
|
5
|
+
'iTime': {value: 0.2},
|
|
6
|
+
'size': {value: 0.05},
|
|
7
|
+
'density': {value: 1.0},
|
|
8
|
+
'snowSpeed': {value: 0.6}
|
|
9
|
+
},
|
|
10
|
+
vertexShader: `
|
|
11
|
+
varying vec2 vUv;
|
|
12
|
+
void main() {
|
|
13
|
+
vUv = uv;
|
|
14
|
+
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
15
|
+
}
|
|
16
|
+
`,
|
|
17
|
+
fragmentShader: `
|
|
18
|
+
#define PI 3.14159265359
|
|
19
|
+
uniform sampler2D tDiffuse;
|
|
20
|
+
uniform vec2 iResolution;
|
|
21
|
+
uniform float iTime;
|
|
22
|
+
uniform float size;
|
|
23
|
+
uniform float density;
|
|
24
|
+
uniform float snowSpeed;
|
|
25
|
+
varying vec2 vUv;
|
|
26
|
+
|
|
27
|
+
float ball(vec2 p){
|
|
28
|
+
float d = distance(vec2(.5), p);
|
|
29
|
+
return smoothstep(size, size - 0.05, d);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
float N11(float n){
|
|
33
|
+
return fract(sin(n * 871.213) * 3134.422);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
float N21(vec2 uv){
|
|
37
|
+
return N11(N11(uv.x) + uv.y);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
float snow(vec2 uv,float t){
|
|
41
|
+
vec2 org_uv = vec2(uv.x, uv.y);
|
|
42
|
+
float z = 10.;
|
|
43
|
+
uv.y += t * 0.5;
|
|
44
|
+
vec2 gv = fract(uv * z);
|
|
45
|
+
vec2 id = floor(uv * z);
|
|
46
|
+
gv.x += (sin(N21(id) * 128. + t) * .4);
|
|
47
|
+
gv.y += (sin(N11(N21(id)) * 128. + t) * .4);
|
|
48
|
+
float dots = ball(gv);
|
|
49
|
+
return dots;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
void main(){
|
|
53
|
+
vec3 col = texture(tDiffuse, vUv).rgb;
|
|
54
|
+
vec2 uv = gl_FragCoord.xy / iResolution.xy;
|
|
55
|
+
uv.x *= iResolution.x / iResolution.y;
|
|
56
|
+
float t = iTime * 0.3 * snowSpeed;
|
|
57
|
+
vec2 gh_uv = uv;
|
|
58
|
+
vec3 colSnow = vec3(0.0);
|
|
59
|
+
float m = 0.0;
|
|
60
|
+
for(float i = 0.; i <= 1.; i += 1. / (10.* density)){
|
|
61
|
+
float z = mix(1., .5 , i);
|
|
62
|
+
vec2 offset = vec2(N11(i), N11(N11(i)));
|
|
63
|
+
m += snow((uv + offset) * z, t) * .1;
|
|
64
|
+
}
|
|
65
|
+
colSnow = vec3(m) * 1.2;
|
|
66
|
+
colSnow += col * 1.0 * mix(0.5, 1., uv.y);
|
|
67
|
+
if(colSnow.x > vec3(m).x * 1.2){
|
|
68
|
+
gl_FragColor = vec4(colSnow,1.0);
|
|
69
|
+
}else{
|
|
70
|
+
gl_FragColor = vec4(colSnow,0.0);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`
|
|
74
|
+
}
|
|
75
|
+
export { SnowShader }
|