From b6eefb8c93243d32d2ffe2e2615271f39226de29 Mon Sep 17 00:00:00 2001 From: CobaltXII Date: Mon, 31 Dec 2018 17:24:14 -0500 Subject: [PATCH] Added animated water --- glsl/block_vertex.glsl | 18 ++++++++++++++++++ src/inc/image.hpp | 32 ++++++++++++++++---------------- src/inc/mesh.hpp | 12 ++++++------ src/main.cpp | 8 ++++++-- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/glsl/block_vertex.glsl b/glsl/block_vertex.glsl index d85a5d3..20b2c2b 100644 --- a/glsl/block_vertex.glsl +++ b/glsl/block_vertex.glsl @@ -16,6 +16,10 @@ uniform mat4 matrix_view; uniform mat4 matrix_model; +// Input time (in seconds). + +uniform float time_in_seconds; + // Output to the fragment shader. out vec3 frag_texture; @@ -38,6 +42,20 @@ void main() frag_texture = vertex_texture; + if (frag_texture.z < 0.0f) + { + // Animate the water. + + float frame = mod(floor(time_in_seconds * 10.0f), 61.0f); + + if (frame > 30.0f) + { + frame = 61.0f - frame; + } + + frag_texture.z = abs(frag_texture.z) + frame; + } + frag_lighting = vertex_lighting; // Pass the distance to the origin squared to the fragment shader, so that diff --git a/src/inc/image.hpp b/src/inc/image.hpp index a650dca..09e1c92 100644 --- a/src/inc/image.hpp +++ b/src/inc/image.hpp @@ -73,6 +73,22 @@ std::vector all_tex = "water_1", + "water_2", + + "water_3", + + "water_4", + + "water_5", + + "water_6", + + "water_7", + + "water_8", + + "water_9", + "water_10", "water_11", @@ -93,8 +109,6 @@ std::vector all_tex = "water_19", - "water_2", - "water_20", "water_21", @@ -115,24 +129,10 @@ std::vector all_tex = "water_29", - "water_3", - "water_30", "water_31", - "water_4", - - "water_5", - - "water_6", - - "water_7", - - "water_8", - - "water_9", - "wool_colored_black", "wool_colored_blue", diff --git a/src/inc/mesh.hpp b/src/inc/mesh.hpp index f6514e0..6092a0c 100644 --- a/src/inc/mesh.hpp +++ b/src/inc/mesh.hpp @@ -266,17 +266,17 @@ void world_subset_to_water_mesh // Get the layer (w coordinate) corresponding to each face of // the current voxel. - float layer_top = cube_face_info->l_top; + float layer_top = -cube_face_info->l_top; - float layer_bottom = cube_face_info->l_bottom; + float layer_bottom = -cube_face_info->l_bottom; - float layer_left = cube_face_info->l_left; + float layer_left = -cube_face_info->l_left; - float layer_right = cube_face_info->l_right; + float layer_right = -cube_face_info->l_right; - float layer_front = cube_face_info->l_front; + float layer_front = -cube_face_info->l_front; - float layer_back = cube_face_info->l_back; + float layer_back = -cube_face_info->l_back; // Get the natural and artificial floating-point lighting // values of the current voxel. diff --git a/src/main.cpp b/src/main.cpp index 6460c3c..4336e0d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char** argv) SDL_Window* sdl_window = SDL_CreateWindow ( - "Minceraft 0.0.0", + "Minceraft 0.2.45", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, @@ -455,7 +455,11 @@ int main(int argc, char** argv) // Pass the fog distance to the block_shader_program. - glUniform1f(glGetUniformLocation(block_shader_program, "fog_distance"), float(the_world->x_res * the_world->x_res) / 2.0f); + glUniform1f(glGetUniformLocation(block_shader_program, "fog_distance"), the_world->x_res * the_world->x_res / 2.0f); + + // Pass the current time (in seconds) to the block_shader_program. + + glUniform1f(glGetUniformLocation(block_shader_program, "time_in_seconds"), SDL_GetTicks() / 1000.0f); // Bind the block_texture_array to the current state.