Use multiple light positions for CAO lighting

This commit is contained in:
sfan5 2020-06-07 19:58:09 +02:00
parent f89794108c
commit 3f0cbbc372
3 changed files with 26 additions and 18 deletions

View File

@ -43,7 +43,6 @@ public:
virtual void removeFromScene(bool permanent) {} virtual void removeFromScene(bool permanent) {}
virtual void updateLight(u32 day_night_ratio) {} virtual void updateLight(u32 day_night_ratio) {}
virtual v3s16 getLightPosition() { return v3s16(0, 0, 0); }
virtual bool getCollisionBox(aabb3f *toset) const { return false; } virtual bool getCollisionBox(aabb3f *toset) const { return false; }
virtual bool getSelectionBox(aabb3f *toset) const { return false; } virtual bool getSelectionBox(aabb3f *toset) const { return false; }

View File

@ -182,7 +182,6 @@ public:
void addToScene(ITextureSource *tsrc); void addToScene(ITextureSource *tsrc);
void removeFromScene(bool permanent); void removeFromScene(bool permanent);
void updateLight(u32 day_night_ratio); void updateLight(u32 day_night_ratio);
v3s16 getLightPosition();
void updateNodePos(); void updateNodePos();
void step(float dtime, ClientEnvironment *env); 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() void TestCAO::updateNodePos()
{ {
if (!m_node) if (!m_node)
@ -799,13 +793,20 @@ void GenericCAO::updateLight(u32 day_night_ratio)
return; return;
u8 light_at_pos = 0; u8 light_at_pos = 0;
bool pos_ok; bool pos_ok = false;
v3s16 p = getLightPosition(); v3s16 pos[3];
MapNode n = m_env->getMap().getNode(p, &pos_ok); u16 npos = getLightPosition(pos);
if (pos_ok) for (u16 i = 0; i < npos; i++) {
light_at_pos = n.getLightBlend(day_night_ratio, m_client->ndef()); bool this_ok;
else 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); light_at_pos = blend_light(day_night_ratio, LIGHT_SUN, 0);
u8 light = decode_light(light_at_pos + m_glow); 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) const auto &box = m_prop.collisionbox;
return floatToInt(m_position + v3f(0, 0.5 * BS, 0), BS); pos[0] = floatToInt(m_position + box.MinEdge * BS, BS);
pos[1] = floatToInt(m_position + box.MaxEdge * BS, BS);
return floatToInt(m_position, 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() void GenericCAO::updateNametag()

View File

@ -240,7 +240,10 @@ public:
void setNodeLight(u8 light); void setNodeLight(u8 light);
v3s16 getLightPosition(); /* Get light position(s).
* returns number of positions written into pos[], which must have space
* for at least 3 vectors. */
u16 getLightPosition(v3s16 *pos);
void updateNametag(); void updateNametag();