Make biomes display work correctly

This commit is contained in:
2022-10-22 22:59:09 +02:00
parent e36ce58f75
commit e102332d0b
2 changed files with 69 additions and 21 deletions
+68 -20
View File
@@ -73,17 +73,21 @@ fn main() {
in uint index; in uint index;
in float altitude; in float altitude;
in uint biome;
in uvec2 chunk; in uvec2 chunk;
out vec2 v_tex_coords; out vec2 v_tex_coords;
flat out uint v_biome;
const uint TILE_SIZE = 4u; const uint TILE_SIZE = 4u;
void main() { void main() {
uint index_mod = index % 6u; uint index_mod = index % 6u;
uint index_div = index / 6u; uint index_div = index / 6u;
uint z = index_div / 250u; uint z = index_div / 250u;
uint x = index_div % 250u; uint x = index_div % 250u;
if(index_mod == 0u) if(index_mod == 0u)
v_tex_coords = vec2(0, 0); v_tex_coords = vec2(0, 0);
else if(index_mod == 1u || index_mod == 4u) else if(index_mod == 1u || index_mod == 4u)
@@ -102,6 +106,7 @@ fn main() {
x++; x++;
z++; z++;
} }
v_biome = biome;
x *= TILE_SIZE; x *= TILE_SIZE;
z *= TILE_SIZE; z *= TILE_SIZE;
@@ -116,10 +121,12 @@ fn main() {
fragment: " fragment: "
#version 140 #version 140
// warning: that way maybe have a null normal
flat in vec3 normal; flat in vec3 normal;
in vec2 v_tex_coords; in vec2 v_tex_coords;
flat in uint v_biome;
out vec4 f_color; out vec4 f_color;
flat in uint biome;
uniform sampler2D tex0, tex1, tex2, tex3, tex4, tex5, tex6, tex7, tex8, tex9, tex10, tex11, tex12, tex13, tex14, tex15, tex16, tex17, tex18; uniform sampler2D tex0, tex1, tex2, tex3, tex4, tex5, tex6, tex7, tex8, tex9, tex10, tex11, tex12, tex13, tex14, tex15, tex16, tex17, tex18;
@@ -127,26 +134,67 @@ fn main() {
void main() { void main() {
float lum = max(dot(normalize(normal), normalize(LIGHT)), 0.0); float lum = max(dot(normalize(normal), normalize(LIGHT)), 0.0);
vec4 tex;
if(biome == 0u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex0, v_tex_coords); switch (v_biome) {
else if(biome == 1u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex1, v_tex_coords); case 0u:
else if(biome == 2u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex2, v_tex_coords); tex = texture(tex0, v_tex_coords);
else if(biome == 3u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex3, v_tex_coords); break;
else if(biome == 4u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex4, v_tex_coords); case 1u:
else if(biome == 5u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex5, v_tex_coords); tex = texture(tex1, v_tex_coords);
else if(biome == 6u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex6, v_tex_coords); break;
else if(biome == 7u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex7, v_tex_coords); case 2u:
else if(biome == 8u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex8, v_tex_coords); tex = texture(tex2, v_tex_coords);
else if(biome == 9u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex9, v_tex_coords); break;
else if(biome == 10u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex10, v_tex_coords); case 3u:
else if(biome == 11u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex11, v_tex_coords); tex = texture(tex3, v_tex_coords);
else if(biome == 12u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex12, v_tex_coords); break;
else if(biome == 13u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex13, v_tex_coords); case 4u:
else if(biome == 14u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex14, v_tex_coords); tex = texture(tex4, v_tex_coords);
else if(biome == 15u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex15, v_tex_coords); break;
else if(biome == 16u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex16, v_tex_coords); case 5u:
else if(biome == 17u) f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex17, v_tex_coords); tex = texture(tex5, v_tex_coords);
else /*if(biome == 18u)*/ f_color = (0.3 + 0.7 * lum, 1.0) * texture(tex18, v_tex_coords); break;
case 6u:
tex = texture(tex6, v_tex_coords);
break;
case 7u:
tex = texture(tex7, v_tex_coords);
break;
case 8u:
tex = texture(tex8, v_tex_coords);
break;
case 9u:
tex = texture(tex9, v_tex_coords);
break;
case 10u:
tex = texture(tex10, v_tex_coords);
break;
case 11u:
tex = texture(tex11, v_tex_coords);
break;
case 12u:
tex = texture(tex12, v_tex_coords);
break;
case 13u:
tex = texture(tex13, v_tex_coords);
break;
case 14u:
tex = texture(tex14, v_tex_coords);
break;
case 15u:
tex = texture(tex15, v_tex_coords);
break;
case 16u:
tex = texture(tex16, v_tex_coords);
break;
case 17u:
tex = texture(tex17, v_tex_coords);
break;
default: // case 18u:
tex = texture(tex18, v_tex_coords);
}
f_color = (0.3 + 0.7 * lum, 1.0) * tex;
} }
" "
}, },
+1 -1
View File
@@ -18,7 +18,7 @@ impl CameraState {
CameraState { CameraState {
aspect_ratio: 1_024.0 / 768.0, aspect_ratio: 1_024.0 / 768.0,
// The second coordinate is for the altitude. // The second coordinate is for the altitude.
position: (3_646.41, 10.3622, 13_113.7), position: (3_646.41, 12.3622, 13_113.7),
direction: (0.0, 0.0, -1.0), direction: (0.0, 0.0, -1.0),
moving_up: false, moving_up: false,
moving_left: false, moving_left: false,