From 23d88e5f1c8f0c8652a07050fcfa8ff126e85d4a Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 21 Jul 2023 02:17:03 +0200 Subject: Extremely simple chunk-limited lighting --- src/World/Generation/ChunkMeshing.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/World/Generation/ChunkMeshing.hpp') diff --git a/src/World/Generation/ChunkMeshing.hpp b/src/World/Generation/ChunkMeshing.hpp index 7e202ab..fb5fea9 100644 --- a/src/World/Generation/ChunkMeshing.hpp +++ b/src/World/Generation/ChunkMeshing.hpp @@ -2,15 +2,12 @@ #include "../../GFX/Mesh.hpp" #include "../../GFX/Util/MeshBuilder.hpp" +#include "../BlockSide.hpp" #include "../Chunk.hpp" +#include "ChunkNeighbors.hpp" namespace MC::World::Generation::ChunkMeshing { -struct ChunkNeighbors { - Chunk *north, *east, *south, *west; - Chunk *north_east, *south_east, *south_west, *north_west; -}; - struct ChunkMesh { GFX::Mesh land_mesh, water_mesh; }; ChunkMesh mesh_chunk(Chunk& chunk, const ChunkNeighbors& neighbors); @@ -19,6 +16,7 @@ namespace Detail { using Vertex = Vector<3, F32>; using Normal = Vector<3, F32>; using TexCoord = Vector<2, F32>; +using Light = F32; using AO = F32; template @@ -26,12 +24,12 @@ using Face = std::array; template GFX::Mesh create_mesh(Chunk& chunk, const ChunkNeighbors& neighbors) { - GFX::Util::MeshBuilder builder; + GFX::Util::MeshBuilder builder; for (Int x = 0; x < Chunk::Width; x++) { for (Int y = 0; y < Chunk::Height; y++) { for (Int z = 0; z < Chunk::Width; z++) { - auto block = chunk.get(x, y, z); + auto block = chunk.at(x, y, z); if (Decisions::should_ignore_block(block)) continue; @@ -44,7 +42,8 @@ GFX::Mesh create_mesh(Chunk& chunk, const ChunkNeighbors& neighbors) { builder.positions(Decisions::face_positions(side, x, y, z)); builder.attributes<0>(Decisions::face_normals(side)); builder.attributes<1>(Decisions::face_tex_coords(block.type, side)); - builder.attributes<2>(Decisions::face_ao_values(chunk, neighbors, x, y, z, side)); + builder.attributes<2>(Decisions::face_light(chunk, neighbors, x, y, z, side)); + builder.attributes<3>(Decisions::face_ao_values(chunk, neighbors, x, y, z, side)); builder.indices(std::array{ s + 0, s + 1, s + 2, s + 2, s + 3, s + 0 }); } } @@ -59,10 +58,11 @@ public: static Face face_positions(BlockSide side, U32 x, U32 y, U32 z); static Face face_tex_coords(BlockType type, BlockSide side); static Face face_normals(BlockSide side); + static Face face_light(Chunk& chunk, const ChunkNeighbors& neighbors, U32 x, U32 y, U32 z, BlockSide side); static Face face_ao_values(Chunk& chunk, const ChunkNeighbors& neighbors, U32 x, U32 y, U32 z, BlockSide side); - static Chunk::BlockData get_block_wrapping(const Chunk& chunk, const ChunkNeighbors& neighbors, Vector<3, I32> pos); static Vector<3, I32> get_face_normal(BlockSide side); + static Chunk::BlockData get_opposing_neighbor(const Chunk& chunk, const ChunkNeighbors& neighbors, U32 x, U32 y, U32 z, BlockSide side); static Bool is_face_visible(Chunk& chunk, const ChunkNeighbors& neighbors, U32 x, U32 y, U32 z, BlockSide side); static Bool should_ignore_block(Chunk::BlockData block); -- cgit 1.4.1