deeptwins-engine-3d 0.0.45 → 0.0.47

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.
@@ -1,32 +1,41 @@
1
1
  czm_material czm_getMaterial(czm_materialInput materialInput) {
2
2
  czm_material material = czm_getDefaultMaterial(materialInput);
3
3
  material.diffuse = 1.5 * color.rgb;
4
+
4
5
  vec2 st = materialInput.st;
5
6
  vec3 str = materialInput.str;
6
- float dis = distance(st, vec2(0.5, 0.5));
7
+ float dis = distance(st, vec2(0.5));
7
8
  float per = fract(time);
8
- if (abs(str.z) > 0.001) {
9
+ float perDis = 0.5 / count;
10
+
11
+ // discard if str.z != 0
12
+ float discardByStr = step(0.001, abs(str.z));
13
+ // discard if dis > 0.5
14
+ float discardByDis = step(0.5, dis);
15
+
16
+ if (discardByStr > 0.0 || discardByDis > 0.0) {
9
17
  discard;
10
18
  }
11
- if (dis > 0.5) {
12
- discard;
13
- } else {
14
- float perDis = 0.5 / count;
15
- float disNum;
16
- float bl = .0;
17
- for (int i = 0; i <= 9; i++) {
18
- if (float(i) <= count) {
19
- disNum = perDis * float(i) - dis + per / count;
20
- if (disNum > 0.0) {
21
- if (disNum < perDis) {
22
- bl = 1.0 - disNum / perDis;
23
- } else if (disNum - perDis < perDis) {
24
- bl = 1.0 - abs(1.0 - disNum / perDis);
25
- }
26
- material.alpha = pow(bl, gradient);
27
- }
28
- }
29
- }
19
+
20
+ float bl = 0.0;
21
+
22
+ for (int i = 0; i <= 9; i++) {
23
+ float idx = float(i);
24
+ float valid = step(idx, count); // 1.0 if i <= count, else 0.0
25
+
26
+ float disNum = perDis * idx - dis + per / count;
27
+ float inFirst = step(0.0, disNum) * (1.0 - step(perDis, disNum));
28
+ float inSecond = step(perDis, disNum) * (1.0 - step(2.0 * perDis, disNum));
29
+
30
+ float bl1 = 1.0 - disNum / perDis;
31
+ float bl2 = 1.0 - abs(1.0 - disNum / perDis);
32
+
33
+ float thisBl = mix(0.0, bl1, inFirst) + mix(0.0, bl2, inSecond);
34
+ thisBl *= valid; // only apply if i <= count
35
+
36
+ bl = max(bl, thisBl); // 保留最强的一层波纹
30
37
  }
38
+
39
+ material.alpha = pow(bl, gradient);
31
40
  return material;
32
41
  }
@@ -4,23 +4,26 @@ czm_material czm_getMaterial(czm_materialInput materialInput)
4
4
  vec2 st = materialInput.st;
5
5
  float vertical = 1.0;
6
6
  float directionAdd = 1.0;
7
- vec2 uv = vec2(0, 0);
8
- // 判断排列方向
9
- if (freely == vertical) {
10
- // 判断运动方向
11
- if (direction == directionAdd) {
12
- uv = vec2(fract(st.s), fract(count * st.t + time));
13
- } else {
14
- uv = vec2(fract(st.s), fract(count * st.t - time));
15
- }
16
- } else {
17
- // 判断运动方向
18
- if (direction == directionAdd) {
19
- uv = vec2(fract(count * st.s + time), fract(st.t));
20
- } else {
21
- uv = vec2(fract(count * st.s - time), fract(st.t));
22
- }
23
- }
7
+ // 使用 abs(a - b) < 0.0001(通过 step)判断浮点相等,避免精度误差
8
+ // 判断排列方向是否是纵向(freely == vertical)
9
+ float isVertical = 1.0 - step(0.0001, abs(freely - vertical));
10
+ // 判断运动方向是否是加(direction == directionAdd)
11
+ float isAdd = 1.0 - step(0.0001, abs(direction - directionAdd));
12
+
13
+ // 纵向排列:uv = (st.s, count * st.t ± time)
14
+ // 横向排列:uv = (count * st.s ± time, st.t)
15
+ vec2 uvVerticalAdd = vec2(fract(st.s), fract(count * st.t + time));
16
+ vec2 uvVerticalSub = vec2(fract(st.s), fract(count * st.t - time));
17
+ vec2 uvHorizontalAdd = vec2(fract(count * st.s + time), fract(st.t));
18
+ vec2 uvHorizontalSub = vec2(fract(count * st.s - time), fract(st.t));
19
+
20
+ // 按运动方向选择 mix(a, b, t) 作用类似于 t == 0 ? a : b
21
+ vec2 uvVertical = mix(uvVerticalSub, uvVerticalAdd, isAdd);
22
+ vec2 uvHorizontal = mix(uvHorizontalSub, uvHorizontalAdd, isAdd);
23
+
24
+ // 最终根据排列方向选择
25
+ vec2 uv = mix(uvHorizontal, uvVertical, isVertical);
26
+
24
27
  vec4 colorImage = texture(image, uv);
25
28
  vec3 mixedColor = mix(colorImage.rgb, color.rgb, mixRatio);
26
29
  vec4 fragColor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deeptwins-engine-3d",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "description": "map for 3d",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",