Skip to content

Commit

Permalink
Change background to enum in shader
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Dec 5, 2023
1 parent b53fb70 commit 36f9b39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/shaders/main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ uniform sampler2DArray _texture_array_normal : hint_normal, filter_linear_mipmap
uniform float _texture_uv_scale_array[32];
uniform float _texture_uv_rotation_array[32];
uniform vec4 _texture_color_array[32];
uniform bool _infinite_background = true;
uniform int _background_mode = 1; // NONE = 0, FLAT = 1, NOISE = 2
uniform bool _show_navigation = true;

// Public uniforms
Expand Down Expand Up @@ -105,7 +105,7 @@ void vertex() {
ivec3 ruv = get_region_uv(UV);
uint control = texelFetch(_control_maps, ruv, 0).r;
bool hole = bool(control >>2u & 0x1u);
if ( hole || (!_infinite_background && ruv.z < 0) ) {
if ( hole || (_background_mode == 0 && ruv.z < 0) ) {
VERTEX.x = 0./0.;
} else {
// UV coordinates in region space + texel offset. Values are 0 to 1 within regions
Expand Down
32 changes: 17 additions & 15 deletions src/shaders/world_noise.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,21 @@ float world_noise(vec2 p) {

//INSERT: WORLD_NOISE2
// World Noise
float weight = texture(_region_blend_map, (uv/float(_region_map_size))+0.5).r;
float rmap_half_size = float(_region_map_size)*.5;
if(abs(uv.x) > rmap_half_size+.5 || abs(uv.y) > rmap_half_size+.5) {
weight = 0.;
} else {
if(abs(uv.x) > rmap_half_size-.5) {
weight = mix(weight, 0., abs(uv.x) - (rmap_half_size-.5));
}
if(abs(uv.y) > rmap_half_size-.5) {
weight = mix(weight, 0., abs(uv.y) - (rmap_half_size-.5));
}
}
height = mix(height, world_noise((uv+world_noise_offset.xz) * world_noise_scale*.1) *
world_noise_height*10. + world_noise_offset.y*100.,
clamp(smoothstep(world_noise_blend_near, world_noise_blend_far, 1.0 - weight), 0.0, 1.0));
if(_background_mode == 2) {
float weight = texture(_region_blend_map, (uv/float(_region_map_size))+0.5).r;
float rmap_half_size = float(_region_map_size)*.5;
if(abs(uv.x) > rmap_half_size+.5 || abs(uv.y) > rmap_half_size+.5) {
weight = 0.;
} else {
if(abs(uv.x) > rmap_half_size-.5) {
weight = mix(weight, 0., abs(uv.x) - (rmap_half_size-.5));
}
if(abs(uv.y) > rmap_half_size-.5) {
weight = mix(weight, 0., abs(uv.y) - (rmap_half_size-.5));
}
}
height = mix(height, world_noise((uv+world_noise_offset.xz) * world_noise_scale*.1) *
world_noise_height*10. + world_noise_offset.y*100.,
clamp(smoothstep(world_noise_blend_near, world_noise_blend_far, 1.0 - weight), 0.0, 1.0));
}
)"
2 changes: 1 addition & 1 deletion src/terrain_3d_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void Terrain3DMaterial::_update_shader() {
}

// Set specific shader parameters
RS->material_set_param(_material, "_infinite_background", _world_background != NONE);
RS->material_set_param(_material, "_background_mode", _world_background);
RS->material_set_param(_material, "_show_navigation", _show_navigation);

// If no noise texture, generate one
Expand Down

0 comments on commit 36f9b39

Please sign in to comment.