diff --git a/src/content_mapblock.cpp b/src/content_mapblock.cpp index bb84faa..a004626 100644 --- a/src/content_mapblock.cpp +++ b/src/content_mapblock.cpp @@ -732,7 +732,6 @@ static void meshgen_build_nodebox(MeshMakeData *data, v3s16 p, MapNode &n, bool } } -/* TODO: calculate faces better, or pass faces as argument */ static void meshgen_rooftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3f pos, TileSpec &tile, bool selected, s16 rot, v3s16 face) { // vertices for top and bottom tri @@ -807,7 +806,6 @@ static void meshgen_rooftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners } } -/* TODO: calculate faces better, or pass faces as argument */ static void meshgen_leaftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners[3], v3f pos, TileSpec &tile, bool selected, s16 rot) { // vertices @@ -848,13 +846,9 @@ static void meshgen_leaftri(MeshMakeData *data, MapNode &n, v3s16 p, v3f corners void meshgen_preset_smooth_lights(MeshMakeData *data, v3s16 p) { - u8 dl; - u8 nl; v3s16 pos = data->m_blockpos_nodes+p; for (u16 i=0; i<8; i++) { - dl = getSmoothLight(pos,corners[i],data->m_vmanip,LIGHTBANK_DAY); - nl = getSmoothLight(pos,corners[i],data->m_vmanip,LIGHTBANK_NIGHT); - smooth_lights[i] = ((nl<<4)&0xF0)|(dl&0x0F); + smooth_lights[i] = getSmoothLight(pos,corners[i],data->m_vmanip); } } diff --git a/src/mapblock_mesh.cpp b/src/mapblock_mesh.cpp index b28567b..4a30110 100644 --- a/src/mapblock_mesh.cpp +++ b/src/mapblock_mesh.cpp @@ -299,10 +299,11 @@ v3s16 dirs8[8] = { }; // Calculate lighting at the given corner of p -u8 getSmoothLight(v3s16 p, v3s16 corner, VoxelManipulator &vmanip, LightBank bank) +u8 getSmoothLight(v3s16 p, v3s16 corner, VoxelManipulator &vmanip) { float ambient_occlusion = 0; - float light = 0; + float dl = 0; + float nl = 0; u16 light_count = 0; if (corner.X == 1) @@ -317,7 +318,8 @@ u8 getSmoothLight(v3s16 p, v3s16 corner, VoxelManipulator &vmanip, LightBank ban if ( content_features(n).param_type == CPT_LIGHT ) { - light += n.getLight(bank); + dl += n.getLight(LIGHTBANK_DAY); + nl += n.getLight(LIGHTBANK_NIGHT); light_count++; }else if (content_features(n).draw_type == CDT_CUBELIKE) { ambient_occlusion += 1.0; @@ -329,17 +331,26 @@ u8 getSmoothLight(v3s16 p, v3s16 corner, VoxelManipulator &vmanip, LightBank ban if (light_count == 0) return 0; - light /= light_count; + dl /= light_count; + nl /= light_count; if (ambient_occlusion > 4) { - ambient_occlusion -= 4; - light = light / (ambient_occlusion * 0.4 + 1.0); + ambient_occlusion = (ambient_occlusion-4) * 0.4 + 1.0; + dl /= ambient_occlusion; + nl /= ambient_occlusion; } - if (light >= LIGHT_SUN) - return LIGHT_SUN; + u8 idl; + u8 inl; - return ceilf(light); + if (dl >= LIGHT_SUN) { + idl = LIGHT_SUN; + }else{ + idl = ceilf(dl); + } + inl = ceilf(nl); + + return ((inl<<4)&0xF0)|(idl&0x0F);; } MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): diff --git a/src/mapblock_mesh.h b/src/mapblock_mesh.h index 6393bdb..0771c6e 100644 --- a/src/mapblock_mesh.h +++ b/src/mapblock_mesh.h @@ -38,7 +38,7 @@ // Helper functions TileSpec getNodeTile(MapNode mn, v3s16 p, v3s16 face_dir, NodeModMap &temp_mods, NodeMetadata *meta = NULL); TileSpec getMetaTile(MapNode mn, v3s16 p, v3s16 face_dir, NodeModMap &temp_mods); -u8 getSmoothLight(v3s16 p, v3s16 corner, VoxelManipulator &vmanip, LightBank bank); +u8 getSmoothLight(v3s16 p, v3s16 corner, VoxelManipulator &vmanip); class MapBlock; class Environment;