From 0358ae789a6aa5c161c3b9017651b7d2c2f28fd8 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 17 Mar 2018 12:10:16 +0300 Subject: Fix node-nodebox lighting difference in direct sunlight (#7061) --- src/content_mapblock.h | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'src/content_mapblock.h') diff --git a/src/content_mapblock.h b/src/content_mapblock.h index 7b90ce4b9..97947cdbe 100644 --- a/src/content_mapblock.h +++ b/src/content_mapblock.h @@ -26,21 +26,36 @@ struct MeshMakeData; struct MeshCollector; struct LightPair { - u8 lightA; - u8 lightB; + u8 lightDay; + u8 lightNight; LightPair() = default; - explicit LightPair(u16 value) : lightA(value & 0xff), lightB(value >> 8) {} - LightPair(u8 valueA, u8 valueB) : lightA(valueA), lightB(valueB) {} + explicit LightPair(u16 value) : lightDay(value & 0xff), lightNight(value >> 8) {} + LightPair(u8 valueA, u8 valueB) : lightDay(valueA), lightNight(valueB) {} LightPair(float valueA, float valueB) : - lightA(core::clamp(core::round32(valueA), 0, 255)), - lightB(core::clamp(core::round32(valueB), 0, 255)) {} - operator u16() const { return lightA | lightB << 8; } + lightDay(core::clamp(core::round32(valueA), 0, 255)), + lightNight(core::clamp(core::round32(valueB), 0, 255)) {} + operator u16() const { return lightDay | lightNight << 8; } +}; + +struct LightInfo { + float light_day; + float light_night; + float light_boosted; + + LightPair getPair(float sunlight_boost = 0.0) const + { + return LightPair( + (1 - sunlight_boost) * light_day + + sunlight_boost * light_boosted, + light_night); + } }; struct LightFrame { - f32 lightsA[8]; - f32 lightsB[8]; + f32 lightsDay[8]; + f32 lightsNight[8]; + bool sunlight[8]; }; class MapblockMeshGenerator @@ -69,7 +84,7 @@ public: // lighting void getSmoothLightFrame(); - LightPair blendLight(const v3f &vertex_pos); + LightInfo blendLight(const v3f &vertex_pos); video::SColor blendLightColor(const v3f &vertex_pos); video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal); @@ -85,7 +100,7 @@ public: // cuboid drawing! void drawCuboid(const aabb3f &box, TileSpec *tiles, int tilecount, - const LightPair *lights , const f32 *txc); + const LightInfo *lights , const f32 *txc); void generateCuboidTextureCoords(aabb3f const &box, f32 *coords); void drawAutoLightedCuboid(aabb3f box, const f32 *txc = NULL, TileSpec *tiles = NULL, int tile_count = 0); -- cgit v1.2.3