This Week In Veloren 176

3 minute read 13 June 2022

This week, we hear about more progress that has gone into the new weather system.

- AngelOnFira, TWiV Editor

Contributor Work

Thanks to this week's contributors, @Christof, @xMAC94x, @Isse, @zesterer, and @Sam!

Weather by @Isse

Weather is getting closer! 🌧️ 🌦️

There will be different weather in different parts of the world at the same time. And it will be consistent among all clients playing on a server. Right now, the only variables for weather are clouds, rain, and wind. So the existing clouds will now be controlled by the server. And you will also see rain, which is affected by wind. And also some other cool effects that come with this.

More technical: The weather is built up of a grid of weather cells. Where each cell has each of the variables cloud, rain, and wind. Each one of these weather cells covers 16x16 chunks. Meaning that on a default world there are 64x64 weather cells.

On the server, we have two new ECS systems for weather. One for simulating and one for syncing, which are both run at regular time intervals of 5 seconds.

  • The simulation in this first implementation is simplified to using noise to fill the weather cells with sensible values.
  • The syncing sends the weather grid to every connected client.

On the client-side, we store three weather grids, with the latter two being the last weather grids the server sent us. The third is created by linearly interpolating between the two grids sent from the server. This smooths out the weather between updates from the server. So now we have a grid of the current weather on the server, but we still have the problem of getting the weather at a specific location. This is done by bilinearly interpolating between the closest four weather cells for that position. This weather value can give us the values we need for playing sound, choosing music, etc.

The weather grid is also used to update a texture on the GPU. This texture is then used for when the clouds are raytraced, and displaying the new rain. One important thing when having a weather grid on both the GPU and CPU is making sure that weather at certain positions lines up correctly. Which, in this case, was solved by letting the world position (0, 0) be the center of the (0, 0) cell.

Rain is drawn in the second pass in the same shader as clouds, meaning that we have access to a depth buffer to make sure we don't draw rain in front of something when it should be behind. But there is another case where we shouldn't draw rain, that's when it should be blocked by something. We solve this by shadow mapping, yes the same shadow mapping we use for the sun.

Shadows are similar to rain occlusion

Much like sun light, rain can be simplified to a number of beams on a plane. So we render depth of terrain and entities to a texture with an orthographic projection rotated by the rain's falling direction (Not actually using an orthographic projection, but the same principle applies). Although in contrast to shadows from the sun that take all loaded chunks into consideration, rain occlusion only takes 9 chunks, and the entities in those chunks into consideration.

Support the project!

Veloren Open Collective