Godot Version
4.2.2.stable
Question
I’m creating an infinite procedural terrain generation system for a project. The terrain is split up into square chunks. For a given position in the world, the biome is determined by temperature, and moisture values which are based on perlin noise. When a chunk is generated, a biome map is also created which is an image that specifies what the biome is at a given point.
I’m creating a ShaderMaterial which will render the textures according to each biome. The biome map is passed to the ShaderMaterial of each chunk, and the chunk renders the texture corresponding to the biome at every position. The problem with my approach right now is there is no blending at all between bordering biomes.
This is the current state of the shader
My question is: What would be the best way to implement this preferably in the shader? I would like a nice gradient transition between the different biomes.
Here is my current shader code:
shader_type spatial;
uniform sampler2D biome_map : repeat_disable;
uniform sampler2D albedo_textures[3];
uniform sampler2D normal_textures[3];
uniform sampler2D roughness_textures[3];
uniform float cut_factor;
uniform float border;
uniform float height;
uniform float biome_size;
void fragment() {
float biome_count = 2.0;
float biome_index = texture(biome_map, UV).r * (biome_count - 1.0);
int biome_idx = int(floor(biome_index + 0.5));
vec3 albedo = texture(albedo_textures[biome_idx], UV).rgb;
vec3 normal = texture(normal_textures[biome_idx], UV).rgb;
float roughness = texture(roughness_textures[biome_idx], UV).r * 1.8;
// Assign shader outputs
ALBEDO = albedo;
NORMAL_MAP = normal;
ROUGHNESS = roughness;
}
Thanks for any help.
