From 354a49d852d8f9ed9b66d7780ba43ce3a9ec59d7 Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 10 Jul 2023 04:42:49 +0200 Subject: Separate transparent water mesh (not sorted, bad) --- src/main.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 9b88986..3d193c2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,6 +68,7 @@ void run() { auto projection_uniform = program.uniform("projection_matrix"); auto sun_direction_uniform = program.uniform("sun_direction"); auto sky_color_uniform = program.uniform("sky_color"); + auto mesh_alpha_uniform = program.uniform("mesh_alpha"); program.bind(); auto projection = Math::MVP::perspective_projection(ASPECT, FOV, 0.1f, 1000.0f); @@ -82,6 +83,9 @@ void run() { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); @@ -106,9 +110,15 @@ void run() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); for (auto chunk : world.get_visible_chunks(camera.position())) { - auto model = Math::MVP::model(chunk->chunk.value().position(), {}); - model_uniform.set(model); - render(chunk->mesh.value(), texture); + mesh_alpha_uniform.set(1.0); + auto land_model = Math::MVP::model(chunk->chunk.value().position(), {}); + model_uniform.set(land_model); + render(chunk->land_mesh.value(), texture); + + mesh_alpha_uniform.set(0.4); + auto water_model = Math::MVP::model(chunk->chunk.value().position() - Vector<3>{0, 0.2, 0}, {}); + model_uniform.set(water_model); + render(chunk->water_mesh.value(), texture); } time++; -- cgit 1.4.1