Skip to content

Commit 3fdaa14

Browse files
committed
fix: normalize particle speed and length across different refresh rates
- Add frameRateAdjustment uniform to normalize particle movement - Adjust trail length calculation based on frame rate - Ensure consistent particle behavior regardless of display refresh rate
1 parent 6d42f4b commit 3fdaa14

File tree

8 files changed

+29
-9
lines changed

8 files changed

+29
-9
lines changed

example/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# example
22

3+
## 0.4.7
4+
5+
### Patch Changes
6+
7+
- Updated dependencies
8+
- cesium-wind-layer@0.7.6
9+
310
## 0.4.6
411

512
### Patch Changes

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "example",
33
"private": true,
4-
"version": "0.4.6",
4+
"version": "0.4.7",
55
"type": "module",
66
"scripts": {
77
"dev": "vite",

packages/cesium-wind-layer/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# cesium-wind-layer
22

3+
## 0.7.6
4+
5+
### Patch Changes
6+
7+
- fix: normalize particle speed and length across different refresh rates
8+
9+
- Add frameRateAdjustment uniform to normalize particle movement
10+
- Adjust trail length calculation based on frame rate
11+
- Ensure consistent particle behavior regardless of display refresh rate
12+
313
## 0.7.5
414

515
### Patch Changes

packages/cesium-wind-layer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cesium-wind-layer",
3-
"version": "0.7.5",
3+
"version": "0.7.6",
44
"publishConfig": {
55
"access": "public"
66
},

packages/cesium-wind-layer/src/shaders/calculateSpeed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ uniform vec2 minimum; // minimum of each dimension
1313
uniform vec2 maximum; // maximum of each dimension
1414
1515
uniform float speedScaleFactor;
16+
uniform float frameRateAdjustment;
1617
1718
in vec2 v_textureCoordinates;
1819
@@ -142,10 +143,9 @@ void main() {
142143
// texture coordinate must be normalized
143144
vec2 lonLat = texture(currentParticlesPosition, v_textureCoordinates).rg;
144145
vec2 speedOrigin = bilinearInterpolation(lonLat);
145-
vec2 speed = calculateSpeedByRungeKutta2(lonLat);
146+
vec2 speed = calculateSpeedByRungeKutta2(lonLat) * frameRateAdjustment;
146147
vec2 speedInLonLat = convertSpeedUnitToLonLat(lonLat, speed);
147148
148-
vec4 particleSpeed = vec4(speedInLonLat, calculateWindNorm(speed / speedScaleFactor));
149149
fragColor = vec4(speedInLonLat, calculateWindNorm(speedOrigin));
150150
}
151151
`;

packages/cesium-wind-layer/src/shaders/segmentDraw.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ uniform sampler2D currentParticlesPosition;
99
uniform sampler2D postProcessingPosition;
1010
uniform sampler2D particlesSpeed;
1111
12+
uniform float frameRateAdjustment;
1213
uniform float particleHeight;
1314
uniform float aspect;
1415
uniform float pixelSize;
@@ -117,11 +118,11 @@ void main() {
117118
// 计算速度相关的宽度和长度因子
118119
float speedFactor = max(0.3, speed.y);
119120
float widthFactor = pointToUse < 0 ? 1.0 : 0.5; // 头部更宽,尾部更窄
120-
121+
121122
// Modify length calculation with constraints
122123
float baseLengthFactor = 10.0;
123124
float speedBasedLength = baseLengthFactor * speedFactor;
124-
float lengthFactor = clamp(speedBasedLength, 10.0, 100.0);
125+
float lengthFactor = clamp(speedBasedLength, 10.0, 100.0) / frameRateAdjustment;
125126
126127
if (pointToUse == 1) {
127128
// 头部位置

packages/cesium-wind-layer/src/windParticlesComputing.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ export class WindParticlesComputing {
2626
};
2727
windData: Required<WindData>;
2828
private frameRateMonitor: FrameRateMonitor;
29-
private frameRate: number = 60;
30-
private frameRateAdjustment: number = 1;
29+
frameRate: number = 60;
30+
frameRateAdjustment: number = 1;
3131

3232
constructor(context: any, windData: Required<WindData>, options: WindLayerOptions, viewerParameters: any, scene: any) {
3333
this.context = context;
@@ -150,8 +150,9 @@ export class WindParticlesComputing {
150150
speedRange: () => new Cartesian2(this.windData.speed.min, this.windData.speed.max),
151151
currentParticlesPosition: () => this.particlesTextures.currentParticlesPosition,
152152
speedScaleFactor: () => {
153-
return (this.viewerParameters.pixelSize + 50) * this.options.speedFactor * this.frameRateAdjustment;
153+
return (this.viewerParameters.pixelSize + 50) * this.options.speedFactor;
154154
},
155+
frameRateAdjustment: () => this.frameRateAdjustment,
155156
dimension: () => new Cartesian2(this.windData.width, this.windData.height),
156157
minimum: () => new Cartesian2(this.windData.bounds.west, this.windData.bounds.south),
157158
maximum: () => new Cartesian2(this.windData.bounds.east, this.windData.bounds.north),

packages/cesium-wind-layer/src/windParticlesRendering.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export class WindParticlesRendering {
189189
currentParticlesPosition: () => this.computing.particlesTextures.currentParticlesPosition,
190190
postProcessingPosition: () => this.computing.particlesTextures.postProcessingPosition,
191191
particlesSpeed: () => this.computing.particlesTextures.particlesSpeed,
192+
frameRateAdjustment: () => this.computing.frameRateAdjustment,
192193
colorTable: () => this.colorTable,
193194
domain: () => {
194195
const domain = new Cartesian2(this.options.domain?.min ?? this.computing.windData.speed.min, this.options.domain?.max ?? this.computing.windData.speed.max);

0 commit comments

Comments
 (0)