Added animated water
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -73,6 +73,22 @@ std::vector<std::string> 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<std::string> all_tex =
|
||||
|
||||
"water_19",
|
||||
|
||||
"water_2",
|
||||
|
||||
"water_20",
|
||||
|
||||
"water_21",
|
||||
@@ -115,24 +129,10 @@ std::vector<std::string> 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",
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user