uniform sampler2D u_sampler;
+uniform vec3 u_fog_color;
+uniform float u_fog_start;
+uniform float u_fog_range;
+
+
in vec4 v_color;
in vec2 v_tex;
in float v_tex_enabled;
+in float v_dist;
out vec4 fragColor;
void main() {
- fragColor = vec4((v_color * mix(vec4(1), texture(u_sampler, v_tex), v_tex_enabled)).xyz, 1);
+ vec4 tile_color = vec4((v_color * mix(vec4(1), texture(u_sampler, v_tex), v_tex_enabled)).xyz, 1);
+
+ // Not going to rely on clamp() existing.
+ float fog = min(1.0f, max(0.0f, (v_dist - u_fog_start) / u_fog_range));
+
+ fragColor = mix(tile_color, vec4(u_fog_color, 1), fog);
}
out vec4 v_color;
out vec2 v_tex;
out float v_tex_enabled;
+out float v_dist;
void main() {
- gl_Position = u_view * u_world * u_model * vec4(a_pos, 1);
+ vec4 pos = u_world * u_model * vec4(a_pos, 1);
+ v_dist = length(pos);
+ gl_Position = u_view * pos;
vec3 block_color = vec3(
float((a_data & 0x0000FU) >> 0U) / 15.0,
"assets/shaders/world_fragment.glsl");
shader_link_world_matrix_block(world_shader);
+ shader_set_uniform(world_shader, #cstr "u_fog_start", 40.0f);
+ shader_set_uniform(world_shader, #cstr "u_fog_range", 5.0f);
font = font_lookup(.{"./assets/fonts/calibri.ttf", 32});
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader_use(world_shader);
+ shader_set_uniform(world_shader, #cstr "u_fog_color", Vector3.{ 0.7, 0.7, 0.9 });
shader_set_uniform(world_shader, #cstr "u_texture", 0);
world_draw(world);
font_print(font, 0, 96, "Facing: {}", camera.y_rot * 180 / math.PI);
font_print(font, 0, 128, "Looking at: {}", selected_block);
font_print(font, 0, 160, "Chunk: {}", player_chunk);
- font_print(font, 0, 192, "Chunks loading: {}", world.chunks_to_load.count);
+ // font_print(font, 0, 192, "Chunks loading: {}", world.chunks_to_load.count);
+ font_print(font, 0, 192, "Heap: {.2}MB Freed: {.2}MB\n", cast(f32) alloc.heap.get_watermark() / (1024 * 1024), cast(f32) alloc.heap.get_freed_size() / (1024 * 1024));
}
glfwSwapBuffers(window);
glUseProgram(shader.prog);
location := glGetUniformLocation(shader.prog, uniform);
- switch T {
- case i32, u32 do glUniform1i(location, value);
- case #default do assert(false, "Bad case.");
+ set_uniform_internal(location, value);
+
+ set_uniform_internal :: #match {
+ macro (location: GLint, value: u32) do glUniform1i(location, value); ,
+ macro (location: GLint, value: f32) do glUniform1f(location, value); ,
+ macro (location: GLint, value: Vector3) do glUniform3f(location, value.x, value.y, value.z); ,
+
+ macro (location: GLint, value: $T) {
+ buffer: [1024] u8;
+ assert(false, conv.format(buffer, "Bad shader_set_uniform case: {}", T));
+ }
}
}
use package core
#local perlin :: package perlin
-#local seed :: 1234
+#local seed :: 8675309
generate_chunk :: (world: ^World, chunk: ^Chunk) {
for cz: 32 do for cx: 32 {