Skip to content

Commit 48faec7

Browse files
committed
fix twister & rain effects
Also apply a spin (self-rotation) so each splat rotates about its own center.
1 parent f8b41cc commit 48faec7

File tree

5 files changed

+21
-14
lines changed

5 files changed

+21
-14
lines changed

dist/spark.cjs.js

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

dist/spark.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/spark.module.js

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

dist/spark.module.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/splat-reveal-effects/index.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,12 @@
194194
}
195195
// Twister weather effect
196196
vec4 twister(vec3 pos, vec3 scale, float t) {
197-
float h = hash(pos).x + .1;
197+
vec3 h = hash(pos);
198198
float s = smoothstep(0., 8., t*t*.1 - length(pos.xz)*2.+2.);
199-
if (length(scale) < .05) pos.y = mix(-10., pos.y, pow(s, 2.*h));
200-
pos.xz = mix(pos.xz*.5, pos.xz, pow(s, 2.*h));
201-
pos.xz *= rot(t*.2 + pos.y*20.*(1.-s)*exp(-1.*length(pos.xz)));
199+
if (length(scale) < .05) pos.y = mix(-10., pos.y, pow(s, 2.*h.x));
200+
pos.xz = mix(pos.xz*.5, pos.xz, pow(s, 2.*h.x));
201+
float rotationTime = t * (1.0 - s) * 0.2;
202+
pos.xz *= rot(rotationTime + pos.y*20.*(1.-s)*exp(-1.*length(pos.xz)));
202203
return vec4(pos, s*s*s*s);
203204
}
204205
@@ -208,7 +209,6 @@
208209
float s = pow(smoothstep(0., 5., t*t*.1 - length(pos.xz)*2. + 1.), .5 + h.x);
209210
float y = pos.y;
210211
pos.y = min(-10. + s*15., pos.y);
211-
pos.x += pos.y*.2;
212212
pos.xz = mix(pos.xz*.3, pos.xz, s);
213213
pos.xz *= rot(t*.3);
214214
return vec4(pos, smoothstep(-10., y, pos.y));
@@ -253,14 +253,21 @@
253253
// Twister Effect: swirling weather reveal
254254
vec4 effectResult = twister(localPos, scales, t);
255255
${outputs.gsplat}.center = effectResult.xyz;
256-
${outputs.gsplat}.scales = mix(vec3(.005), scales, pow(effectResult.w, 30.));
257-
${outputs.gsplat}.rgba.a = pow(effectResult.w, .7) * smoothstep(30., 0., length(localPos.xz));
256+
${outputs.gsplat}.scales = mix(vec3(.002), scales, pow(effectResult.w, 12.));
257+
float s = effectResult.w;
258+
// Also apply a spin (self-rotation) so each splat rotates about its own center.
259+
float spin = -t * 0.3 * (1.0 - s);
260+
vec4 spinQ = vec4(0.0, sin(spin*0.5), 0.0, cos(spin*0.5));
261+
${outputs.gsplat}.quaternion = quatQuat(spinQ, ${inputs.gsplat}.quaternion);
258262
} else if (${inputs.effectType} == 5) {
259263
// Rain Effect: falling streaks
260264
vec4 effectResult = rain(localPos, scales, t);
261265
${outputs.gsplat}.center = effectResult.xyz;
262266
${outputs.gsplat}.scales = mix(vec3(.005), scales, pow(effectResult.w, 30.));
263-
${outputs.gsplat}.rgba.a = pow(effectResult.w, .7) * smoothstep(30., 0., length(localPos.xz));
267+
// Also apply a spin (self-rotation) so each splat rotates about its own center.
268+
float spin = -t*.3;
269+
vec4 spinQ = vec4(0.0, sin(spin*0.5), 0.0, cos(spin*0.5));
270+
${outputs.gsplat}.quaternion = quatQuat(spinQ, ${inputs.gsplat}.quaternion);
264271
}
265272
`),
266273
});

0 commit comments

Comments
 (0)