vlad2305m / Sound-Physics-Fabric

A Minecraft mod that provides realistic sound attenuation, reverberation, and absorption through blocks.
GNU General Public License v3.0
39 stars 6 forks source link

Sound Absorption by Air and the effect of Humidity #14

Closed thedocruby closed 2 years ago

thedocruby commented 2 years ago

The sound absorption by air is significantly affected by things like smoke and humidity. While smoke might be a challenge to code, humidity is much easier since weather is universal. First of all, a biome check could be made, since minecraft biomes contain humidity values (this part would work with modded biomes as well iirc). This could be used to adjust the value of the base absorption multiplier from the config. A modifier could be applied based on altitude, since the air gets thinner and so absorbs more as elevation rises. In addition, raindrops severely increase absorption, and increase the humidity for many minutes after the rain has stopped. For these I suggest using a similar implementation to that of mods such as Iris and Optifine. For the raindrop absorption, the vanilla rain strength implementation is used, as described below:

A value from 0.0 to 1.0 representing the current strength of the rain. A value of 0.0 indicates no rain at all, while a value of 1.0 indicates full rain. Values from 0.0 to 0.2 indicate that no rain is falling, but that rainy weather exists.

For every tick that the world exists in a state of rainy weather, the strength increases by 0.01, up to 1.0. For every tick that rainy weather does not exist, the strength decreases by 0.01, down to 0.0. Thus, transitions to and from rainy weather take 5 seconds (100 ticks)

For our purposes we could subtract 0.2 and scale by 1/0.8 = 1.25. That would give a smooth representation of how much rain is falling.

The air humidity caused by rainy weather is a bit more complex. To calculate the wetness value used in other mods, the vanilla rain strength value is smoothed out with a half life of 60 seconds. So, for example, if it has just stopped raining and the smoothed value is at 1 while the vanilla value is at zero, it would take 60 seconds for the humidity/wetness value to drop to 0.5, then another 60 to drop to 0.25, and after 5 or 6 minutes it gets low enough to barely be noticeable. This is how things like rainy fog and shiny puddles are calculated in shaders, and why they stay for so long after it stops raining and slowly fade away. Since the humidity typically rises before it starts raining, whereas things like puddles accumulate over time. I say you take the min of the vanilla rain strength and smoothed wetness value. that way the humidity rises as soon as the rain starts, and falls off slowly. It's as close as you can get to a weather-accurate humidity prediction. This humidity would then be used to adjust the absorption value just like the rain strength, altitude. and biome humidity. And of course all of these humidity features would be toggleable in the config.

Let me know if you have any questions, I'd be happy to answer them. Also, I can provide Iris's code implementation of the smoothed wetness value if necessary.