summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt2
-rw-r--r--src/Math/MVP.cpp8
-rw-r--r--src/World/Generation/ChunkMeshing.cpp35
-rw-r--r--src/main.cpp7
4 files changed, 28 insertions, 24 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 810f981..1591197 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -22,7 +22,7 @@ add_executable(meowcraft
     src/GFX/Shading/Shader.cpp src/GFX/Shading/Shader.hpp
     src/GFX/Shading/Program.cpp src/GFX/Shading/Program.hpp
     src/Math/Matrix.hpp
-    src/Math/MVP.cpp src/Math/MVP.hpp
+    src/Math/MVP.hpp
     src/GFX/Camera.cpp src/GFX/Camera.hpp
     src/Math/Rotation.hpp
     src/GFX/Shading/Uniform.cpp src/GFX/Shading/Uniform.hpp
diff --git a/src/Math/MVP.cpp b/src/Math/MVP.cpp
deleted file mode 100644
index 2f00b8e..0000000
--- a/src/Math/MVP.cpp
+++ /dev/null
@@ -1,8 +0,0 @@
-#include <cmath>
-#include "MVP.hpp"
-#include "Common.hpp"
-
-namespace Math::MVP {
-
-
-}
diff --git a/src/World/Generation/ChunkMeshing.cpp b/src/World/Generation/ChunkMeshing.cpp
index 8944c53..130bbad 100644
--- a/src/World/Generation/ChunkMeshing.cpp
+++ b/src/World/Generation/ChunkMeshing.cpp
@@ -118,44 +118,55 @@ std::array<Vector<3, F32>, 4> face_normals(BlockSide side) {
     return {normal, normal, normal, normal};
 }
 
-Bool is_face_visible(Chunk& chunk, const ChunkMeshing::ChunkNeighbors& neighbors, U32 x, U32 y, U32 z, BlockSide side) {
 std::array<F32, 4> face_ao_values(Chunk& chunk, const ChunkNeighbors& neighbors, U32 x, U32 y, U32 z, BlockSide side) {
-    std::array<Vector<3, I32>, 4> offsets{};
+    std::array<Vector<3, I32>, 8> offsets{};
+    // Given a block position, these offsets can be added to it to get the 8 blocks necessary to calculate AO.
+    // There are 4 corners and 4 sides, corners are visually distinguished by the lack of spaces and
+    // but you can recognize them by the fact that they have no 0 offsets.
+    // Note: Is there a way to compute these? I tried but I couldn't... If the vertex windings ever change again I don't want to hardcode these...
+    auto nowhere = Vector<3, I32>::max();
     switch (side) {
     case BlockSide::Front:
-        offsets = {{{0, 1, 1}, {-1, 0, 1}, {0, -1, 1}, {1, 0, 1}}}; // works!
+        offsets = {{{0, 1, 1}, {-1,1,1}, {-1, 0, 1}, {-1,-1,1}, {0, -1, 1}, {1,-1,1}, {1, 0, 1}, {1,1,1}}};
         break;
     case BlockSide::Back:
-        offsets = {{{-1, 0, -1}, {0, 1, -1}, {1, 0, -1}, {0, -1, -1}}}; // works!
+        offsets = {{{-1, 0, -1}, {-1,1,-1}, {0, 1, -1}, {1,1,-1}, {1, 0, -1}, {1,-1,-1}, {0, -1, -1}, {-1,-1,-1}}};
         break;
     case BlockSide::Top:
-        offsets = {{{-1, 1, 0}, {0, 1, 1}, {1, 1, 0}, {0, 1, -1}}};
+        offsets = {{{-1, 1, 0}, {-1,1,1}, {0, 1, 1}, {1,1,1}, {1, 1, 0}, {1,1,-1}, {0, 1, -1}, {-1,1,-1}}};
         break;
     case BlockSide::Bottom:
-        offsets = {{{0, -1, 1}, {-1, -1, 0}, {0, -1, -1},  {1, -1, 0}}};
+        offsets = {{{0, -1, 1}, {-1,-1,1}, {-1, -1, 0}, {-1,-1,-1}, {0, -1, -1}, {1,-1,-1},  {1, -1, 0}, {1,-1,1}}};
         break;
     case BlockSide::Right:
-        offsets = {{{1, 0, -1}, {1, 1, 0}, {1, 0, 1},  {1, -1, 0}}};
+        offsets = {{{1, 0, -1}, {1,1,-1}, {1, 1, 0}, {1,1,1}, {1, 0, 1}, {1,-1,1},  {1, -1, 0}, {1,-1,-1}}};
         break;
     case BlockSide::Left:
-        offsets = {{{-1, 1, 0}, {-1, 0, -1}, {-1, -1, 0},  {-1, 0, 1}}};
+        offsets = {{{-1, 1, 0}, {-1,1,-1}, {-1, 0, -1}, {-1,-1,-1}, {-1, -1, 0}, {-1,-1,1},  {-1, 0, 1}, {-1,1,1}}};
         break;
     }
 
-
     std::array<F32, 4> vertex_ao{};
 
+    UInt offset_index = 0;
     for (UInt vertex = 0; vertex < 4; vertex++) {
-        auto a = offsets[vertex];
-        auto b = offsets[(vertex + 1) % 4];
+        auto a = offsets[offset_index];
+        auto b = offsets[++offset_index]; // corner
+        auto c = offsets[++offset_index % 8];
 
         auto block_a = get_block_wrapping(chunk, neighbors, {x + a.x(), y + a.y(), z + a.z()});
         auto block_b = get_block_wrapping(chunk, neighbors, {x + b.x(), y + b.y(), z + b.z()});
+        auto block_c = get_block_wrapping(chunk, neighbors, {x + c.x(), y + c.y(), z + c.z()});
 
         F32 occlusion_a = block_a.empty() ? 0 : 1;
         F32 occlusion_b = block_b.empty() ? 0 : 1;
+        F32 occlusion_c = block_c.empty() ? 0 : 1;
 
-        vertex_ao[vertex] = (occlusion_a + occlusion_b) / 2;
+        if (occlusion_a + occlusion_c == 2.0f) {
+            vertex_ao[vertex] = 1.0f;
+        } else {
+            vertex_ao[vertex] = (occlusion_a + occlusion_b + occlusion_c) / 3;
+        }
     }
 
     return vertex_ao;
diff --git a/src/main.cpp b/src/main.cpp
index c690391..9b88986 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -56,7 +56,7 @@ void run() {
     MC::World::World world;
 
     MC::GFX::Camera camera{};
-    camera.set_position({0.0f, MC::World::Chunk::Height / 2.0f, 0.0f});
+    camera.set_position({0, MC::World::Chunk::Height / 2.0, 0});
 
     MC::GFX::Shading::Program program(
         MC::GFX::Shading::Shader::create_vertex(),
@@ -73,10 +73,10 @@ void run() {
     auto projection = Math::MVP::perspective_projection<F32>(ASPECT, FOV, 0.1f, 1000.0f);
     projection_uniform.set(projection);
 
-    Vector<3, F32> sun_direction{1.0f, -1.0f, 0.0f};
+    Vector<3, F32> sun_direction{1, -1, 0};
     sun_direction_uniform.set(sun_direction);
 
-    Vector<3, F32> sky_color{0.85f, 0.85f, 0.85f}; // #DBDBDB
+    Vector<3, F32> sky_color{0.85, 0.85, 0.85}; // #DBDBDB
     sky_color_uniform.set(sky_color);
 
     glEnable(GL_DEPTH_TEST);
@@ -104,6 +104,7 @@ void run() {
 
         glClearColor(sky_color.x(), sky_color.y(), sky_color.z(), 1.0f); // #DBDBDB
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
         for (auto chunk : world.get_visible_chunks(camera.position())) {
             auto model = Math::MVP::model<F32>(chunk->chunk.value().position(), {});
             model_uniform.set(model);