This Week In Veloren 90
This week, we see how some of the combat animations are improving. @zesterer gives us an in-depth look into the new and improved cloud system.
- AngelOnFira, TWiV Editor
Thanks to this week's contributors, @Slipped, @xMAC94x, @jiminycrick, @Snowram, @UMR1352, @Sam, @zesterer, and @imbris!
@James has continued work on new attacks for the bow and axe. There is a new M1 combo for the axe, but it hasn't been merged just yet. @Sam and @imbris worked on the buff system that was started by @BottledByte over a month ago. It's almost ready to merge! @Namp007 contributed Dutch translations, which are on their way to being merged.
@James is also working on biome specific soundtracks. They were recently made possible along with separating ambient sounds from music. However, this probably won't be merged to master for a while until we have decided on a way to blend between biomes and have it work more efficiently.
Cloud Improvements by @zesterer
In current nightly builds of Veloren, we have clouds. I introduced clouds almost a year ago, to mixed responses. Although most people enjoy the more 'realistic' clouds that the game has, a common complaint is that they don't fit the voxel style of the game so well.
Although I appreciate and understand this perspective, I personally believe that the core reason for this nervousness about clouds lies in the uncanny way they look. It's clear that we aim for realism, but they often fall short. I'm also determined to see clouds take a bigger role in Veloren's atmospheric look and feel.
There are a few reasons for this:
- Our current technique uses an optimised form of raymarching that only works within a very narrow plane. As a result, clouds often appear as a thin layer to players close to the ground.
- The lighting and shader overhaul a few months ago 'broke' their appearance because much of the existing code fudged physical properties with magic constants in a rather unprincipled way.
- Clouds don't have effect lighting. This means that they feel disconnected from the world; a backdrop to fill space in the sky rather than an interactive part of the world.
I felt it was time to resolve this situation. First and foremost it gave me an excuse to put off more pressing work refactoring and improving the world generation and simulation code, but it also provided an opportunity for me to revisit the clouds (I've always felt that they don't live up to their potential).
I started by adapting the existing code. I figured that it might be possible to enhance the shaders by playing with magic constants until something that looked better appeared. I did have a little luck with this, as shown below.
These new clouds still didn't solve the underlying problems, however. I put things to the side for about 2 months.
Last week, I came back to them. I decided to almost entirely rewrite the ray marching code. Where previously we calculated very narrow bounds within which ray marching occurred, I removed those bounds and allowed rays to sample the entire sky. However, it quickly became clear that this was too expensive to be viable in the long term.
To alleviate the issue, I began experimenting with ways to more cheaply compute the procedural noise required to create the cloud density field. I found that with a few careful tricks I could tease shapes that felt realistic out of the code with just a fraction of the cost of the previous cloud code. I also discovered a very cheap way to compute low quality 3D noise several times faster than conventional techniques for generating noise in shaders using a small tiled 2D monochromatic texture and some careful interpolation.
The next thing I did was to move the location that cloud shaders were applied. On current nightly builds, cloud shading is computed in the fragment shader for all models (sprites, figures, terrain, LoD, the skybox, etc.). Although we've been careful to optimise our draw order as much as possible, overlapping fragments still meant that we were calculating cloud shading for fragments that simply didn't get shown on the screen.
To alleviate this, I moved cloud shading to the post-processing shader by extracting the depth buffer and using it as a texture input. I then used the inverse view/projection matrices, along with the depth from the depth buffer, to reconstruct the world position for each fragment (thanks to @Sharp for helping me fix a persistent bug along the way). I could then do cloud shading on only fragments that appear on the screen.
With these techniques, combined with a few extra mathematical shortcuts, I was able to make 'floor-to-ceiling' cloud tracing viable. Here are the results:
I still wasn't happy with it. Although having clouds appear at multiple z levels was a serious improvement on what was there before, I still felt that they didn't look appropriately realistic. To alleviate this, I ended up tearing up most of the raymarching code to rewrite it in a way that more closely mirrored how light scattering occurred in real life.
Although it's not a perfect representation of reality (a lot of calculations are still rough approximations of physical parameters), the end results speak for themselves. The new code...
- Uses the trapezium rule to approximate the integration of cloud density with respect to distance over the course of projected rays
- Includes a (poor) approximation of rayleigh scattering, making distant objects appear much further away than they looked before
- Has multiple graphical settings: None, Minimal, Low, Medium, and High. Minimal clouds should be fast enough for almost any hardware.
- Tracks cloud shadows on terrain; skies can look overcast now!
- Incorporates moving mist
- Performs significantly better than the currently nightly's cloud code on lower settings
Since clouds are now shaded in a (more) physically accurate way, they also continue to look good under differing environmental conditions. No hackery was required to make them look good during sunrise, sunset, or night: the results just fall out as a natural consequence of calculating them in a more accurate way!
The new clouds are not yet on the latest nightly build. There are still a few minor issues to address and it has not yet been fully reviewed. With any luck, they should be landing in the game within the next week or so.
Support our devs!