each chunk “block” should store both the BlockType and the light level. so update the blocks array to store a struct or something

struct ChunkBlock {
    BlockType type;
    int light;
}
 
std::array<ChunkBlock, 65536> m_blocks;

copying Minecraft, light levels range from 0 to 15. we can use this in the shader later to determine the diffuse term. maybe divide by 15? so 15/15 = 1, meaning it’s fully lit. and this means 0/15 results in a diffuse term of 0. from a light source, anyway. there are other sources for the diffuse term:

  • shadow mapping
  • sunlight

clamp diffuse term from 0.0 to 1.0. different sources can/will contribute, but max shading should always be 1.0.

calculating light levels

need to wait for block data to finish generating in order to start. this is because we need to check whether a block is EMPTY or transparent when calculating light.

when iterating through each block, we check if it’s a light source. possible blocks/sources:

  • lava
  • glowstone
  • torches

add a new std::vector to each Chunk that stores the coordinates of each light source within its borders. push_back() to this vector during block generation for each additional light source we discover. probably use a glm::ivec3 because coords are not floats.

std::vector<glm::ivec3> m_lightSources

every time a block change occurs in a chunk, we only recalculate light levels if block placed/destroyed is a light source? check via if statement.