Dev Blog

Hi, this is the Stranded III development blog (see also Forum Thread, Comment Thread).

Overview (115 Entries)

Entry 105 - Clusters & Wind Sway Intensity - December 22, 2021

Advent IV
Three candles! Wait! No, it's four already! Looks like someone totally didn't manage to write a blog post in time! Oops!
IMG:https://stuff.unrealsoftware.de/pics/s3dev/advent4.png


Procedual Map Generation: Clusters
In real landscapes you often see clusters of plants. That's why I thought it would be nice to support clusters in the procedual map generation for Stranded III as well.
This is how you define stuff which should be spawned inside a biome:
1
2
3
4
entitySpawner {
     entityPattern = ^fern
     block = 1
}

entityPattern defines a regular expression which is used to find matching entities. In this case all entities with IDs starting with (that's what the ^ stands for) "fern" will be included. You can also manually define single or multiple entities for an entitySpawner. block says that the field (1x1 meter = 1m²) the entity is spawned on will be blocked and not be used to spawn any other entities. Higher values than 1 can be used to also block surrounding fields.
This is just a single entitySpawner. You can have as many of these as you want (per biome) and they also have many more settings like weights/ratios, terrain height and steepness etc.

A couple of additional new settings comes with the cluster feature I now implemented. Of course these only have to be set if you want to use the cluster system. Here is a cluster example. It's the above fern stuff with extra cluster settings:
1
2
3
4
5
6
7
entitySpawner {
     entityPattern = ^fern
     block = 1
     clusterCount = 4,5
     clusterRadius = 3,4
     clusterMinDistance = 0.75
}

clusterCount is a random range which says how many ferns the game should try to spawn per cluster. In this example it will always be 4 to 5 as opposed to the previous example where it will always be one solitary fern. In some cases the clusters may have less ferns e.g. if there is not enough space.
clusterRadius is also a random range. It defines the radius of the cluster. In this case 3 to 4 meters. So here 4 to 5 ferns will be spawned within a radius of 3 to 4 meters.
clusterMinDistance defines the minimum distance between objects. All ferns within this cluster will have a distance of at least 0.75 meters to each other. In general the Stranded III procedual map generation uses a 1x1 meter grid and the above mentioned blocking system. So there's only max 1 entity per m² (if block = 1 is used). Clusters allow more dense placement and this is why there is this min distance setting. It helps to reduce ugly overlapping of entities within clusters. Note however that this entitySpawner also has block set to 1. So all 1x1 meter fields which contain a fern will be blocked for other entities. The blocking will only be applied AFTER spawning all cluster entities so they don't block each other. Otherwise it would not be possible to have higher densities in clusters while also using the blocking system.

Shader: Wind Sway
One of my goals in Stranded III is to have a fast and simple asset creation pipeline. Otherwise content creation would simply take too long. One example for this is that foliage of plants should sway in the wind. I don't want to invest additional time for each 3D model to make that work. Therefore I'm using a shader which uses the UV-coordinates for wind sway effects. On the bottom of the texture there's no swaying. On the top there's maximum swaying. So when creating new textures you only have to care about proper orientation and placement of shaking things in thex texture. When creating new models you only have to choose the right shader to make shaking work properly! Hooray
This is what textures using this shader commonly look like:
IMG:https://stuff.unrealsoftware.de/pics/s3dev/swayshader_y_pre.jpg

> Texture with swaying based on Y-coordinate. Click for bigger version


In many cases however I want to store a lot of swaying stuff in a single texture. Using the Y-coordinate for swaying intensity limits me a lot when arranging stuff inside the texture. Therefore I made an additional shader. It comes with a second texture which contains the sway intensity. It's a bit more work to create textures for this shader because I need that additional texture with sway intensities. It allows me to optmize stuff better and to make better use of texture space though. Here's an example of a texture and the sway intensity texture:
IMG:https://stuff.unrealsoftware.de/pics/s3dev/swayshader_tex_pre.png

> Texture & matching sway intensity texture. Click for bigger version


To make that shader work I had to access the sway texture inside the vertex shader. I didn't know that this was possible but luckily it is (unless you're using an old shader model). I found this thread which describes how to do it in Unity. At first it seemed like it didn't work properly because some of my leaves didn't sway as expected. Turned out that I had to set the "wrap mode" to "clamp" for the sway intensity texture. That fixed my issues!

Disqus

blog comments powered by Disqus