summaryrefslogtreecommitdiff
path: root/src/client/content_cao.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-06-07 19:58:09 +0200
committersfan5 <sfan5@live.de>2020-06-11 21:13:26 +0200
commit3f0cbbc372d5f359af18f5cbad37a1b165d3df4e (patch)
tree89bcba844f363ea4e1593fd72949b11ee0e6283d /src/client/content_cao.cpp
parentf89794108c49a7a9e992afb9431ae244e4a4fef1 (diff)
downloadminetest-3f0cbbc372d5f359af18f5cbad37a1b165d3df4e.tar.gz
minetest-3f0cbbc372d5f359af18f5cbad37a1b165d3df4e.tar.bz2
minetest-3f0cbbc372d5f359af18f5cbad37a1b165d3df4e.zip
Use multiple light positions for CAO lighting
Diffstat (limited to 'src/client/content_cao.cpp')
-rw-r--r--src/client/content_cao.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp
index 644a71e6e..eec4e3de0 100644
--- a/src/client/content_cao.cpp
+++ b/src/client/content_cao.cpp
@@ -182,7 +182,6 @@ public:
void addToScene(ITextureSource *tsrc);
void removeFromScene(bool permanent);
void updateLight(u32 day_night_ratio);
- v3s16 getLightPosition();
void updateNodePos();
void step(float dtime, ClientEnvironment *env);
@@ -258,11 +257,6 @@ void TestCAO::updateLight(u32 day_night_ratio)
{
}
-v3s16 TestCAO::getLightPosition()
-{
- return floatToInt(m_position, BS);
-}
-
void TestCAO::updateNodePos()
{
if (!m_node)
@@ -799,13 +793,20 @@ void GenericCAO::updateLight(u32 day_night_ratio)
return;
u8 light_at_pos = 0;
- bool pos_ok;
-
- v3s16 p = getLightPosition();
- MapNode n = m_env->getMap().getNode(p, &pos_ok);
- if (pos_ok)
- light_at_pos = n.getLightBlend(day_night_ratio, m_client->ndef());
- else
+ bool pos_ok = false;
+
+ v3s16 pos[3];
+ u16 npos = getLightPosition(pos);
+ for (u16 i = 0; i < npos; i++) {
+ bool this_ok;
+ MapNode n = m_env->getMap().getNode(pos[i], &this_ok);
+ if (this_ok) {
+ u8 this_light = n.getLightBlend(day_night_ratio, m_client->ndef());
+ light_at_pos = MYMAX(light_at_pos, this_light);
+ pos_ok = true;
+ }
+ }
+ if (!pos_ok)
light_at_pos = blend_light(day_night_ratio, LIGHT_SUN, 0);
u8 light = decode_light(light_at_pos + m_glow);
@@ -856,12 +857,17 @@ void GenericCAO::setNodeLight(u8 light)
}
}
-v3s16 GenericCAO::getLightPosition()
+u16 GenericCAO::getLightPosition(v3s16 *pos)
{
- if (m_is_player)
- return floatToInt(m_position + v3f(0, 0.5 * BS, 0), BS);
-
- return floatToInt(m_position, BS);
+ const auto &box = m_prop.collisionbox;
+ pos[0] = floatToInt(m_position + box.MinEdge * BS, BS);
+ pos[1] = floatToInt(m_position + box.MaxEdge * BS, BS);
+
+ // Skip center pos if it falls into the same node as Min or MaxEdge
+ if ((box.MaxEdge - box.MinEdge).getLengthSQ() < 3.0f)
+ return 2;
+ pos[2] = floatToInt(m_position + box.getCenter() * BS, BS);
+ return 3;
}
void GenericCAO::updateNametag()