diff --git a/assets/cubyz/shaders/item_drop.fs b/assets/cubyz/shaders/item_drop.fs index 29900a836..04734b3d8 100644 --- a/assets/cubyz/shaders/item_drop.fs +++ b/assets/cubyz/shaders/item_drop.fs @@ -81,7 +81,7 @@ void mainBlockDrop() { reflectivity = reflectivity*fixedCubeMapLookup(reflect(direction, faceNormal)).x; reflectivity = reflectivity*(1 - fresnelReflection) + fresnelReflection; - vec3 pixelLight = max(vec3(normalVariation), texture(emissionSampler, textureCoords).r*4); // TODO: light*normalVariation + vec3 pixelLight = ambientLight*max(vec3(normalVariation), texture(emissionSampler, textureCoords).r*4); fragColor = texture(texture_sampler, textureCoords)*vec4(pixelLight, 1); fragColor.rgb += reflectivity*pixelLight; diff --git a/src/itemdrop.zig b/src/itemdrop.zig index 457a0183c..34eb000cb 100644 --- a/src/itemdrop.zig +++ b/src/itemdrop.zig @@ -681,10 +681,11 @@ pub const ItemDropRenderer = struct { // MARK: ItemDropRenderer if(itemDrops.list.items(.itemStack)[i].item) |item| { var pos = itemDrops.list.items(.pos)[i]; const rot = itemDrops.list.items(.rot)[i]; - const light: u32 = 0xffffffff; // TODO: Get this light value from the mesh_storage. + const blockPos: Vec3i = @intFromFloat(@floor(pos)); + const light: [6]u8 = main.renderer.mesh_storage.getLight(blockPos[0], blockPos[1], blockPos[2]) orelse .{0} ** 6; c.glUniform3fv(itemUniforms.ambientLight, 1, @ptrCast(&@max( - ambientLight*@as(Vec3f, @splat(@as(f32, @floatFromInt(light >> 24))/255)), - Vec3f{light >> 16 & 255, light >> 8 & 255, light & 255}/@as(Vec3f, @splat(255)), + ambientLight*@as(Vec3f, @as(Vec3f, @floatFromInt(Vec3i{light[0], light[1], light[2]}))/@as(Vec3f, @splat(255))), + @as(Vec3f, @floatFromInt(Vec3i{light[3], light[4], light[5]}))/@as(Vec3f, @splat(255)), ))); pos -= playerPos; diff --git a/src/renderer/mesh_storage.zig b/src/renderer/mesh_storage.zig index 8fd7a01b2..c3f689372 100644 --- a/src/renderer/mesh_storage.zig +++ b/src/renderer/mesh_storage.zig @@ -175,6 +175,21 @@ pub fn getBlock(x: i32, y: i32, z: i32) ?blocks.Block { return block; } +pub fn getLight(wx: i32, wy: i32, wz: i32) ?[6]u8 { + const node = getNodePointer(.{.wx = wx, .wy = wy, .wz = wz, .voxelSize = 1}); + node.mutex.lock(); + defer node.mutex.unlock(); + const mesh = node.mesh orelse return null; + const x = (wx >> mesh.chunk.voxelSizeShift) & chunk.chunkMask; + const y = (wy >> mesh.chunk.voxelSizeShift) & chunk.chunkMask; + const z = (wz >> mesh.chunk.voxelSizeShift) & chunk.chunkMask; + mesh.lightingData[0].lock.lockRead(); + defer mesh.lightingData[0].lock.unlockRead(); + mesh.lightingData[1].lock.lockRead(); + defer mesh.lightingData[1].lock.unlockRead(); + return mesh.lightingData[1].getValue(x, y, z) ++ mesh.lightingData[0].getValue(x, y, z); +} + pub fn getBlockFromAnyLod(x: i32, y: i32, z: i32) blocks.Block { var lod: u5 = 0; while(lod < settings.highestLod) : (lod += 1) {