mirror of
https://github.com/Relintai/godot-lportal.git
synced 2025-02-20 01:04:19 +01:00
Fixed caster list per light
This commit is contained in:
parent
5e31db0b0c
commit
aa10d540cc
10
ldebug.h
10
ldebug.h
@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
//#define LPRINT_RUN(a, b) ;
|
||||
#define LPRINT_RUN(a, b) ;
|
||||
|
||||
#define LPRINT_RUN(a, b) {String sz;\
|
||||
for (int n=0; n<Lawn::LDebug::m_iTabDepth; n++)\
|
||||
sz += "\t";\
|
||||
LPRINT(a, sz + b);}
|
||||
//#define LPRINT_RUN(a, b) {String sz;\
|
||||
//for (int n=0; n<Lawn::LDebug::m_iTabDepth; n++)\
|
||||
//sz += "\t";\
|
||||
//LPRINT(a, sz + b);}
|
||||
|
||||
#define LPRINT(a, b) if (!Lawn::LDebug::m_bRunning) {\
|
||||
if (a >= Lawn::LDebug::m_iLoggingLevel)\
|
||||
|
@ -32,6 +32,9 @@ void LLight::SetDefaults()
|
||||
m_fSpread = 0.0f; // for spotlight
|
||||
m_fMaxDist = 100.0f;
|
||||
m_RoomID = -1;
|
||||
|
||||
m_FirstCaster = 0;
|
||||
m_NumCasters = 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,6 +57,10 @@ public:
|
||||
|
||||
// source room
|
||||
int m_RoomID; // or -1 for global lights
|
||||
|
||||
// shadow casters
|
||||
int m_FirstCaster;
|
||||
int m_NumCasters;
|
||||
};
|
||||
|
||||
|
||||
|
68
lroom.cpp
68
lroom.cpp
@ -208,44 +208,50 @@ void LRoom::AddShadowCasters(LRoomManager &manager)
|
||||
{
|
||||
manager.m_BF_ActiveLights.SetBit(lightID, true);
|
||||
manager.m_ActiveLights.push_back(lightID);
|
||||
|
||||
// add all shadow casters for this light (new method)
|
||||
const LLight &light = manager.m_Lights[lightID];
|
||||
int last_caster = light.m_FirstCaster + light.m_NumCasters;
|
||||
for (int c=light.m_FirstCaster; c<last_caster; c++)
|
||||
{
|
||||
int sobID = manager.m_LightCasters_SOB[c];
|
||||
|
||||
// only add to the caster list if not in it already (does this check need to happen, can this ever occur?)
|
||||
if (!manager.m_BF_caster_SOBs.GetBit(sobID))
|
||||
{
|
||||
//LPRINT(2, "\t" + itos(sobID) + ", " + manager.m_SOBs[sobID].GetSpatial()->get_name());
|
||||
manager.m_BF_caster_SOBs.SetBit(sobID, true);
|
||||
manager.m_CasterList_SOBs.push_back(sobID);
|
||||
}
|
||||
else
|
||||
{
|
||||
//LPRINT(2, "\t" + itos(sobID) + ", ALREADY CASTER " + manager.m_SOBs[sobID].GetSpatial()->get_name());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// new!! use precalced list of shadow casters
|
||||
int last = m_iFirstShadowCaster_SOB + m_iNumShadowCasters_SOB;
|
||||
for (int n=m_iFirstShadowCaster_SOB; n<last; n++)
|
||||
{
|
||||
int sobID = manager.m_ShadowCasters_SOB[n];
|
||||
// int last = m_iFirstShadowCaster_SOB + m_iNumShadowCasters_SOB;
|
||||
// for (int n=m_iFirstShadowCaster_SOB; n<last; n++)
|
||||
// {
|
||||
// int sobID = manager.m_ShadowCasters_SOB[n];
|
||||
|
||||
// only add to the caster list if not in it already
|
||||
if (!manager.m_BF_caster_SOBs.GetBit(sobID))
|
||||
{
|
||||
LPRINT(2, "\t" + itos(sobID) + ", " + manager.m_SOBs[sobID].GetSpatial()->get_name());
|
||||
manager.m_BF_caster_SOBs.SetBit(sobID, true);
|
||||
manager.m_CasterList_SOBs.push_back(sobID);
|
||||
}
|
||||
else
|
||||
{
|
||||
//LPRINT(2, "\t" + itos(sobID) + ", ALREADY CASTER " + manager.m_SOBs[sobID].GetSpatial()->get_name());
|
||||
}
|
||||
}
|
||||
// // only add to the caster list if not in it already
|
||||
// if (!manager.m_BF_caster_SOBs.GetBit(sobID))
|
||||
// {
|
||||
// LPRINT(2, "\t" + itos(sobID) + ", " + manager.m_SOBs[sobID].GetSpatial()->get_name());
|
||||
// manager.m_BF_caster_SOBs.SetBit(sobID, true);
|
||||
// manager.m_CasterList_SOBs.push_back(sobID);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// //LPRINT(2, "\t" + itos(sobID) + ", ALREADY CASTER " + manager.m_SOBs[sobID].GetSpatial()->get_name());
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
int last_sob = m_iFirstSOB + m_iNumSOBs;
|
||||
for (int n=m_iFirstSOB; n<last_sob; n++)
|
||||
{
|
||||
// bool bVisible = manager.m_BF_visible_SOBs.GetBit(n) != 0;
|
||||
|
||||
// // already in list
|
||||
// if (bVisible)
|
||||
// continue;
|
||||
|
||||
manager.m_BF_caster_SOBs.SetBit(n, true);
|
||||
manager.m_CasterList_SOBs.push_back(n);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -46,15 +46,11 @@ void LRoomConverter::Convert(LRoomManager &manager)
|
||||
|
||||
int count = CountRooms();
|
||||
|
||||
//LMAN->m_SOBs.clear();
|
||||
//LMAN->m_ShadowCasters_SOB.clear();
|
||||
int num_global_lights = LMAN->m_Lights.size();
|
||||
|
||||
// make sure bitfield is right size for number of rooms
|
||||
LMAN->m_BF_visible_rooms.Create(count);
|
||||
|
||||
|
||||
// LMAN->m_Rooms.clear(true);
|
||||
LMAN->m_Rooms.resize(count);
|
||||
|
||||
m_TempRooms.clear(true);
|
||||
@ -366,7 +362,10 @@ void LRoomConverter::Convert_Lights()
|
||||
|
||||
void LRoomConverter::Light_Trace(int iLightID)
|
||||
{
|
||||
// blank this each time as it is used to create the list of casters
|
||||
LMAN->m_BF_caster_SOBs.Blank();
|
||||
|
||||
// get the light
|
||||
LLight &l = LMAN->m_Lights[iLightID];
|
||||
|
||||
LPRINT(5,"\nLight_Trace " + itos (iLightID) + " direction " + l.m_ptDir);
|
||||
@ -388,7 +387,7 @@ void LRoomConverter::Light_Trace(int iLightID)
|
||||
}
|
||||
|
||||
|
||||
void LRoomConverter::Light_TraceRecursive(int depth, LRoom &lroom, const LLight &light, int iLightID, const LVector<Plane> &planes)
|
||||
void LRoomConverter::Light_TraceRecursive(int depth, LRoom &lroom, LLight &light, int iLightID, const LVector<Plane> &planes)
|
||||
{
|
||||
// prevent too much depth
|
||||
if (depth > 8)
|
||||
@ -418,6 +417,55 @@ void LRoomConverter::Light_TraceRecursive(int depth, LRoom &lroom, const LLight
|
||||
lroom.m_LocalLights.push_back(iLightID);
|
||||
}
|
||||
|
||||
// add each light caster that is within the planes to the light caster list
|
||||
// clip all objects in this room to the clipping planes
|
||||
int last_sob = lroom.m_iFirstSOB + lroom.m_iNumSOBs;
|
||||
for (int n=lroom.m_iFirstSOB; n<last_sob; n++)
|
||||
{
|
||||
LSob &sob = LMAN->m_SOBs[n];
|
||||
|
||||
//LPRINT_RUN(2, "sob " + itos(n) + " " + sob.GetSpatial()->get_name());
|
||||
// already determined to be visible through another portal
|
||||
// if (LMAN->m_BF_caster_SOBs.GetBit(n))
|
||||
// {
|
||||
// //LPRINT_RUN(2, "\talready visible");
|
||||
// continue;
|
||||
// }
|
||||
|
||||
bool bShow = true;
|
||||
|
||||
|
||||
// estimate the radius .. for now
|
||||
const AABB &bb = sob.m_aabb;
|
||||
|
||||
// print("\t\t\tculling object " + pObj->get_name());
|
||||
|
||||
for (int p=0; p<planes.size(); p++)
|
||||
{
|
||||
// float dist = planes[p].distance_to(pt);
|
||||
// print("\t\t\t\t" + itos(p) + " : dist " + String(Variant(dist)));
|
||||
|
||||
float r_min, r_max;
|
||||
bb.project_range_in_plane(planes[p], r_min, r_max);
|
||||
|
||||
// print("\t\t\t\t" + itos(p) + " : r_min " + String(Variant(r_min)) + ", r_max " + String(Variant(r_max)));
|
||||
|
||||
|
||||
if (r_min > 0.0f)
|
||||
{
|
||||
bShow = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bShow)
|
||||
{
|
||||
Light_AddCaster_SOB(light, n);
|
||||
}
|
||||
|
||||
} // for through sobs
|
||||
|
||||
|
||||
|
||||
// look through every portal out
|
||||
for (int n=0; n<lroom.m_iNumPortals; n++)
|
||||
@ -669,6 +717,27 @@ int LRoomConverter::CountRooms()
|
||||
// return;
|
||||
//}
|
||||
|
||||
void LRoomConverter::Light_AddCaster_SOB(LLight &light, int sobID)
|
||||
{
|
||||
// we will reuse the rendering bitflags for shadow casters for this ... to check for double entries (fnaa fnaa)
|
||||
if (LMAN->m_BF_caster_SOBs.GetBit(sobID))
|
||||
return;
|
||||
|
||||
|
||||
LPRINT_RUN(2, "\t\t\tLightCaster " + itos(sobID));
|
||||
|
||||
LMAN->m_BF_caster_SOBs.SetBit(sobID, true);
|
||||
|
||||
|
||||
// first?
|
||||
if (!light.m_NumCasters)
|
||||
light.m_FirstCaster = LMAN->m_LightCasters_SOB.size();
|
||||
|
||||
LMAN->m_LightCasters_SOB.push_back(sobID);
|
||||
light.m_NumCasters++;
|
||||
}
|
||||
|
||||
|
||||
void LRoomConverter::LRoom_AddShadowCaster_SOB(LRoom &lroom, int sobID)
|
||||
{
|
||||
// we will reuse the rendering bitflags for shadow casters for this ... to check for double entries (fnaa fnaa)
|
||||
|
@ -109,7 +109,8 @@ private:
|
||||
// lights
|
||||
void LRoom_DetectedLight(LRoom &lroom, Node * pNode);
|
||||
void Light_Trace(int iLightID);
|
||||
void Light_TraceRecursive(int depth, LRoom &lroom, const LLight &light, int iLightID, const LVector<Plane> &planes);
|
||||
void Light_TraceRecursive(int depth, LRoom &lroom, LLight &light, int iLightID, const LVector<Plane> &planes);
|
||||
void Light_AddCaster_SOB(LLight &light, int sobID);
|
||||
|
||||
// shadows
|
||||
// void LRoom_FindShadowCasters(LRoom &lroom, int lightID, const LLight &light);
|
||||
@ -117,6 +118,7 @@ private:
|
||||
void LRoom_FindShadowCasters_Recursive(LRoom &source_lroom, int depth, LRoom &lroom, const LLight &light, const LVector<Plane> &planes);
|
||||
void LRoom_AddShadowCaster_SOB(LRoom &lroom, int sobID);
|
||||
|
||||
|
||||
void TRoom_MakeOppositePortal(const LPortal &port, int iRoomOrig);
|
||||
|
||||
|
||||
|
@ -747,6 +747,7 @@ void LRoomManager::rooms_release()
|
||||
void LRoomManager::ReleaseResources(bool bPrepareConvert)
|
||||
{
|
||||
m_ShadowCasters_SOB.clear();
|
||||
m_LightCasters_SOB.clear();
|
||||
m_Rooms.clear(true);
|
||||
m_Portals.clear(true);
|
||||
m_SOBs.clear();
|
||||
@ -977,6 +978,7 @@ void LRoomManager::FrameUpdate_AddShadowCasters()
|
||||
m_Rooms[r].AddShadowCasters(*this);
|
||||
}
|
||||
|
||||
LPRINT(2, "TOTAL shadow casters " + itos(m_CasterList_SOBs.size()));
|
||||
}
|
||||
|
||||
void LRoomManager::FrameUpdate_FinalizeVisibility_SoftShow()
|
||||
|
@ -102,6 +102,9 @@ private:
|
||||
// master list of shadow casters for each room
|
||||
LVector<uint32_t> m_ShadowCasters_SOB;
|
||||
|
||||
// master list of casters for each light
|
||||
LVector<uint32_t> m_LightCasters_SOB;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
void _notification(int p_what);
|
||||
|
Loading…
Reference in New Issue
Block a user