1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-15 19:42:10 +00:00

Optimize lighting calculation (#12797)

This commit is contained in:
Jude Melton-Houghton 2022-10-09 10:50:26 -04:00 committed by GitHub
parent 440d966b93
commit 9676364c1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 188 additions and 220 deletions

View file

@ -527,8 +527,8 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step,
{
v3s16 p = floatToInt(p0 /*+ dir * 3*BS*/, BS);
MapNode n = map->getNode(p);
if(ndef->get(n).param_type == CPT_LIGHT &&
!ndef->get(n).sunlight_propagates)
if(ndef->getLightingFlags(n).has_light &&
!ndef->getLightingFlags(n).sunlight_propagates)
allow_allowing_non_sunlight_propagates = true;
}
// If would start at CONTENT_IGNORE, start closer
@ -549,15 +549,13 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step,
v3s16 p = floatToInt(pf, BS);
MapNode n = map->getNode(p);
ContentLightingFlags f = ndef->getLightingFlags(n);
if (allow_allowing_non_sunlight_propagates && i == 0 &&
ndef->get(n).param_type == CPT_LIGHT &&
!ndef->get(n).sunlight_propagates) {
f.has_light && !f.sunlight_propagates) {
allow_non_sunlight_propagates = true;
}
if (ndef->get(n).param_type != CPT_LIGHT ||
(!ndef->get(n).sunlight_propagates &&
!allow_non_sunlight_propagates)){
if (!f.has_light || (!f.sunlight_propagates && !allow_non_sunlight_propagates)){
nonlight_seen = true;
noncount++;
if(noncount >= 4)
@ -566,10 +564,10 @@ static bool getVisibleBrightness(Map *map, const v3f &p0, v3f dir, float step,
}
if (distance >= sunlight_min_d && !*sunlight_seen && !nonlight_seen)
if (n.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
if (n.getLight(LIGHTBANK_DAY, f) == LIGHT_SUN)
*sunlight_seen = true;
noncount = 0;
brightness_sum += decode_light(n.getLightBlend(daylight_factor, ndef));
brightness_sum += decode_light(n.getLightBlend(daylight_factor, f));
brightness_count++;
}
*result = 0;
@ -653,8 +651,9 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
int ret = 0;
if(brightness_count == 0){
MapNode n = getNode(floatToInt(m_camera_position, BS));
if(m_nodedef->get(n).param_type == CPT_LIGHT){
ret = decode_light(n.getLightBlend(daylight_factor, m_nodedef));
ContentLightingFlags f = m_nodedef->getLightingFlags(n);
if(f.has_light){
ret = decode_light(n.getLightBlend(daylight_factor, f));
} else {
ret = oldvalue;
}

View file

@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "clientenvironment.h"
#include "client.h"
#include "map.h"
#include "nodedef.h"
class SmokePuffCSO: public ClientSimpleObject
{
@ -50,7 +51,7 @@ public:
bool pos_ok;
MapNode n = env->getMap().getNode(floatToInt(pos, BS), &pos_ok);
light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(),
env->getGameDef()->ndef()))
env->getGameDef()->ndef()->getLightingFlags(n)))
: 64;
video::SColor color(255,light,light,light);
m_spritenode->setColor(color);

View file

@ -472,7 +472,7 @@ void MapblockMeshGenerator::prepareLiquidNodeDrawing()
// it at what it emits, for an increased effect
u8 e = decode_light(f->light_source);
light = LightPair(std::max(e, light.lightDay), std::max(e, light.lightNight));
} else if (nodedef->get(ntop).param_type == CPT_LIGHT) {
} else if (nodedef->getLightingFlags(ntop).has_light) {
// Otherwise, use the light of the node on top if possible
light = LightPair(getInteriorLight(ntop, 0, nodedef));
}

View file

@ -102,7 +102,7 @@ void MeshMakeData::setSmoothLighting(bool smooth_lighting)
static u8 getInteriorLight(enum LightBank bank, MapNode n, s32 increment,
const NodeDefManager *ndef)
{
u8 light = n.getLight(bank, ndef);
u8 light = n.getLight(bank, ndef->getLightingFlags(n));
if (light > 0)
light = rangelim(light + increment, 0, LIGHT_SUN);
return decode_light(light);
@ -126,17 +126,19 @@ u16 getInteriorLight(MapNode n, s32 increment, const NodeDefManager *ndef)
static u8 getFaceLight(enum LightBank bank, MapNode n, MapNode n2,
v3s16 face_dir, const NodeDefManager *ndef)
{
ContentLightingFlags f1 = ndef->getLightingFlags(n);
ContentLightingFlags f2 = ndef->getLightingFlags(n2);
u8 light;
u8 l1 = n.getLight(bank, ndef);
u8 l2 = n2.getLight(bank, ndef);
u8 l1 = n.getLight(bank, f1);
u8 l2 = n2.getLight(bank, f2);
if(l1 > l2)
light = l1;
else
light = l2;
// Boost light level for light sources
u8 light_source = MYMAX(ndef->get(n).light_source,
ndef->get(n2).light_source);
u8 light_source = MYMAX(f1.light_source, f2.light_source);
if(light_source > light)
light = light_source;
@ -184,8 +186,8 @@ static u16 getSmoothLightCombined(const v3s16 &p,
light_source_max = f.light_source;
// Check f.solidness because fast-style leaves look better this way
if (f.param_type == CPT_LIGHT && f.solidness != 2) {
u8 light_level_day = n.getLightNoChecks(LIGHTBANK_DAY, &f);
u8 light_level_night = n.getLightNoChecks(LIGHTBANK_NIGHT, &f);
u8 light_level_day = n.getLight(LIGHTBANK_DAY, f.getLightingFlags());
u8 light_level_night = n.getLight(LIGHTBANK_NIGHT, f.getLightingFlags());
if (light_level_day == LIGHT_SUN)
direct_sunlight = true;
light_day += decode_light(light_level_day);

View file

@ -265,7 +265,8 @@ void Particle::updateLight()
);
MapNode n = m_env->getClientMap().getNode(p, &pos_ok);
if (pos_ok)
light = n.getLightBlend(m_env->getDayNightRatio(), m_gamedef->ndef());
light = n.getLightBlend(m_env->getDayNightRatio(),
m_gamedef->ndef()->getLightingFlags(n));
else
light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0);