1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
This commit is contained in:
DS 2025-06-27 13:06:10 +00:00 committed by GitHub
commit adf5ab45cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 882 additions and 104 deletions

View file

@ -151,11 +151,10 @@ u16 getFaceLight(MapNode n, MapNode n2, const NodeDefManager *ndef)
Calculate smooth lighting at the XYZ- corner of p.
Both light banks
*/
template <typename F>
static u16 getSmoothLightCombined(const v3s16 &p,
const std::array<v3s16,8> &dirs, MeshMakeData *data)
const std::array<v3s16,8> &dirs, const NodeDefManager *ndef, F &&get_node)
{
const NodeDefManager *ndef = data->m_nodedef;
u16 ambient_occlusion = 0;
u16 light_count = 0;
u8 light_source_max = 0;
@ -168,7 +167,7 @@ static u16 getSmoothLightCombined(const v3s16 &p,
ambient_occlusion++;
return false;
}
MapNode n = data->m_vmanip.getNodeNoExNoEmerge(p + dirs[i]);
MapNode n = get_node(p + dirs[i]);
if (n.getContent() == CONTENT_IGNORE)
return true;
const ContentFeatures &f = ndef->get(n);
@ -255,22 +254,14 @@ static u16 getSmoothLightCombined(const v3s16 &p,
return light_day | (light_night << 8);
}
/*
Calculate smooth lighting at the given corner of p.
Both light banks.
Node at p is solid, and thus the lighting is face-dependent.
*/
u16 getSmoothLightSolid(const v3s16 &p, const v3s16 &face_dir, const v3s16 &corner, MeshMakeData *data)
{
return getSmoothLightTransparent(p + face_dir, corner - 2 * face_dir, data);
}
/*
Calculate smooth lighting at the given corner of p.
Both light banks.
Node at p is not solid, and the lighting is not face-dependent.
*/
u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner, MeshMakeData *data)
template <typename F>
static u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner,
const NodeDefManager *ndef, F &&get_node)
{
const std::array<v3s16,8> dirs = {{
// Always shine light
@ -285,7 +276,35 @@ u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner, MeshMakeData
v3s16(0,corner.Y,corner.Z),
v3s16(corner.X,corner.Y,corner.Z)
}};
return getSmoothLightCombined(p, dirs, data);
return getSmoothLightCombined(p, dirs, ndef, std::forward<F>(get_node));
}
u16 getSmoothLightTransparent(const v3s16 &p, const v3s16 &corner, MeshMakeData *data)
{
return getSmoothLightTransparent(p, corner, data->m_nodedef,
[data](v3s16 p) -> MapNode {
return data->m_vmanip.getNodeNoExNoEmerge(p);
}
);
}
/*
Calculate smooth lighting at the given corner of p.
Both light banks.
Node at p is solid, and thus the lighting is face-dependent.
*/
u16 getSmoothLightSolid(const v3s16 &p, const v3s16 &face_dir, const v3s16 &corner,
MeshMakeData *data)
{
return getSmoothLightTransparent(p + face_dir, corner - 2 * face_dir, data);
}
u16 getSmoothLightSolid(const v3s16 &p, const v3s16 &face_dir, const v3s16 &corner,
const NodeDefManager *ndef, const std::function<MapNode(v3s16)> &get_node)
{
return getSmoothLightTransparent(p + face_dir, corner - 2 * face_dir,
ndef, get_node);
}
void get_sunlight_color(video::SColorf *sunlight, u32 daynight_ratio)