mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Improve lighting of entities.
Pass correct natural & artificial light to the shaders Use natural/artificial light ratio for correct rendering of shadows
This commit is contained in:
parent
f2cccf8da7
commit
54dccc480e
5 changed files with 50 additions and 25 deletions
|
@ -864,7 +864,8 @@ void GenericCAO::updateLight(u32 day_night_ratio)
|
|||
if (m_glow < 0)
|
||||
return;
|
||||
|
||||
u8 light_at_pos = 0;
|
||||
u16 light_at_pos = 0;
|
||||
u8 light_at_pos_intensity = 0;
|
||||
bool pos_ok = false;
|
||||
|
||||
v3s16 pos[3];
|
||||
|
@ -873,28 +874,33 @@ void GenericCAO::updateLight(u32 day_night_ratio)
|
|||
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);
|
||||
u16 this_light = getInteriorLight(n, 0, m_client->ndef());
|
||||
u8 this_light_intensity = MYMAX(this_light & 0xFF, (this_light >> 8) && 0xFF);
|
||||
if (this_light_intensity > light_at_pos_intensity) {
|
||||
light_at_pos = this_light;
|
||||
light_at_pos_intensity = this_light_intensity;
|
||||
}
|
||||
pos_ok = true;
|
||||
}
|
||||
}
|
||||
if (!pos_ok)
|
||||
light_at_pos = blend_light(day_night_ratio, LIGHT_SUN, 0);
|
||||
light_at_pos = LIGHT_SUN;
|
||||
|
||||
video::SColor light = encode_light(light_at_pos, m_glow);
|
||||
if (!m_enable_shaders)
|
||||
final_color_blend(&light, light_at_pos, day_night_ratio);
|
||||
|
||||
u8 light = decode_light(light_at_pos + m_glow);
|
||||
if (light != m_last_light) {
|
||||
m_last_light = light;
|
||||
setNodeLight(light);
|
||||
}
|
||||
}
|
||||
|
||||
void GenericCAO::setNodeLight(u8 light)
|
||||
void GenericCAO::setNodeLight(const video::SColor &light_color)
|
||||
{
|
||||
video::SColor color(255, light, light, light);
|
||||
|
||||
if (m_prop.visual == "wielditem" || m_prop.visual == "item") {
|
||||
if (m_wield_meshnode)
|
||||
m_wield_meshnode->setNodeLightColor(color);
|
||||
m_wield_meshnode->setNodeLightColor(light_color);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -906,7 +912,7 @@ void GenericCAO::setNodeLight(u8 light)
|
|||
scene::IMesh *mesh = m_meshnode->getMesh();
|
||||
for (u32 i = 0; i < mesh->getMeshBufferCount(); ++i) {
|
||||
scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
|
||||
buf->getMaterial().EmissiveColor = color;
|
||||
buf->getMaterial().EmissiveColor = light_color;
|
||||
}
|
||||
} else {
|
||||
scene::ISceneNode *node = getSceneNode();
|
||||
|
@ -915,16 +921,16 @@ void GenericCAO::setNodeLight(u8 light)
|
|||
|
||||
for (u32 i = 0; i < node->getMaterialCount(); ++i) {
|
||||
video::SMaterial &material = node->getMaterial(i);
|
||||
material.EmissiveColor = color;
|
||||
material.EmissiveColor = light_color;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (m_meshnode) {
|
||||
setMeshColor(m_meshnode->getMesh(), color);
|
||||
setMeshColor(m_meshnode->getMesh(), light_color);
|
||||
} else if (m_animated_meshnode) {
|
||||
setAnimatedMeshColor(m_animated_meshnode, color);
|
||||
setAnimatedMeshColor(m_animated_meshnode, light_color);
|
||||
} else if (m_spritenode) {
|
||||
m_spritenode->setColor(color);
|
||||
m_spritenode->setColor(light_color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -125,7 +125,7 @@ private:
|
|||
std::string m_current_texture_modifier = "";
|
||||
bool m_visuals_expired = false;
|
||||
float m_step_distance_counter = 0.0f;
|
||||
u8 m_last_light = 255;
|
||||
video::SColor m_last_light = video::SColor(0xFFFFFFFF);
|
||||
bool m_is_visible = false;
|
||||
s8 m_glow = 0;
|
||||
// Material
|
||||
|
@ -245,7 +245,7 @@ public:
|
|||
|
||||
void updateLight(u32 day_night_ratio);
|
||||
|
||||
void setNodeLight(u8 light);
|
||||
void setNodeLight(const video::SColor &light);
|
||||
|
||||
/* Get light position(s).
|
||||
* returns number of positions written into pos[], which must have space
|
||||
|
|
|
@ -515,8 +515,9 @@ void WieldMeshSceneNode::setNodeLightColor(video::SColor color)
|
|||
material.EmissiveColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
setColor(color);
|
||||
else {
|
||||
setColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
void WieldMeshSceneNode::render()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue