Falling Leaves (Fabric)

Falling Leaves (Fabric)

22M Downloads

Feature Idea: Wind

Fourmisain opened this issue ยท 8 comments

commented

Old idea, just thought I'd put it here so we don't forget about it:

It should be easy enough (conceptionally) to simulate global wind as an acceleration that smoothly and randomly changes over time (e.g. using Perlin noise); it could even be affected by weather.

It'd be mind-blowing (no pun intended) to have local wind that can swirl leaves around, though that's probably too computationally complex and it'd also only really work when there are many leaves with a high life time, so scratch that for now.

commented

Just built this:
smoothstep

The points are randomly chosen and interpolated between using a Smoothstep function.

The range goes from -1 to 1 and could be used as the leaf acceleration in one axis.
If you imagine the X-axis of the graph being time, at each point in time we only need two points to interpolate between, making this very efficient.

commented

Hm... there's a few things that don't make this work well:

  • there's basically always wind - I added a bias towards 0 if the last value was near 0 and that made it a bit better, but it's still basically impossible to have dead calm for more than a few seconds

One idea might be to have states like "calm", "windy" and "stormy" which will last for a much longer time.

  • wind can change directions fast and often - fast wind change is alright in my book, but constantly changing directions feels wrong

All in all: modeling wind is hard.

commented

Wind now has states and instead of using smooth noise for both axes, it uses noise for the wind strength and direction.

The strength (distribution) is decided by the state, while the direction follows a "trend" that very slowly changes and also has some fast changing variation.

The "calm" and "windy" states look pretty good to me, not so sure about the "stormy" one, because it's not much different from windy; it also needs to be locked behind a weather condition.

It's annoying that particles get permanently stopped on the ground while they barely slow down when floating on water.
There's probably no way around implementing our own move() method.

Currently there's a debug key H to change the state.

commented

Alright, Wind.tick() was called before Wind.init() because the latter was simply not called when joining a server.
Fixed in d5cc5ac and rebased the wind branch.

commented

Currently, wind is modeled as a global acceleration and since I removed the drag force, I believe that leaves now have an unbounded velocity.
This is not a huge issue since leaves always fall down so they are mostly limited in the speed they can gain until they reach the ground.
They do like skating on water with ever increasing speeds, though.

I'm still thinking about how to approach this, maybe wind should just be a kind of target velocity that each leaf is approaching, e.g. like
velocity += 0.05 * (targetVelocity - velocity);

So leaves initially speed up fast but the closer they get to the target velocity / wind speed, the less the velocity changes; so it closely (but not perfectly) follows the wind speed.

That should be close to a full acceleration/drag simulation while being cheap to compute.


Also, it is still not clear why Wind.tick() can be called before Wind.init() and cause a crash - it's easy to fix, but better to find out why.

commented

Wind is now a target velocity that is approached by the particles, I also removed the collision workaround (and fade-in) again for now.
Wind.init() should be in a much more reliable place now, though I still left the initial call to it.
Particles also slow down in water.

I found that particles do not move with moving water, though that is a really small detail that might not even be worth it.

commented

I feel wind should probably be disabled in the nether and possibly the end, it doesn't feel right in those dimensions.
The nether has a ceiling and can be pretty closed off while the end is like a "space" dimension - though it does have breathable air.

commented

Finally merged the wind branch 20ce059!