Improved shadow mapping and refactored quakemap builder scene structure

This commit is contained in:
Antoine Pilote
2024-07-28 21:05:02 -04:00
parent 5125561756
commit 69d59266b9
4 changed files with 74 additions and 28 deletions

View File

@@ -350,8 +350,8 @@ namespace Nuake
Shader* shader = ShaderManager::GetShader("Resources/Shaders/shadowMap.shader");
shader->Bind();
RenderCommand::Enable(RendererEnum::FACE_CULL);
glCullFace(GL_BACK);
RenderCommand::Disable(RendererEnum::FACE_CULL);
glCullFace(GL_FRONT);
auto meshView = scene.m_Registry.view<TransformComponent, ModelComponent, VisibilityComponent>();
auto quakeView = scene.m_Registry.view<TransformComponent, BSPBrushComponent, VisibilityComponent>();
@@ -693,7 +693,20 @@ namespace Nuake
Ref<Environment> env = scene.GetEnvironment();
struct LightDistance
{
TransformComponent transform;
LightComponent light;
float distance;
};
std::vector<LightDistance> lightDistances;
auto view = scene.m_Registry.view<TransformComponent, LightComponent, ParentComponent>();
lightDistances.reserve(view.size_hint());
const Vector3 camPosition = scene.GetCurrentCamera()->Translation;
for (auto l : view)
{
auto [transform, light, parent] = view.get<TransformComponent, LightComponent, ParentComponent>(l);
@@ -707,7 +720,22 @@ namespace Nuake
light.Direction = transform.GetGlobalRotation() * Vector3(0, 0, 1);
}
Renderer::RegisterDeferredLight(transform, light);
Vector3 lightPosition = transform.GetGlobalPosition();
float distanceFromCam = glm::length(camPosition - lightPosition);
lightDistances.push_back({transform, light, distanceFromCam});
}
std::sort(lightDistances.begin(), lightDistances.end(),
[](const LightDistance& a, const LightDistance& b)
{
return a.distance < b.distance;
}
);
for (const auto& l : lightDistances)
{
Renderer::RegisterDeferredLight(l.transform, l.light);
}
mGBuffer->GetTexture(GL_DEPTH_ATTACHMENT)->Bind(5);

View File

@@ -69,7 +69,7 @@ namespace Nuake {
{
for (auto& b : BrushEntities)
{
if (name == b.Name)
if (String::ToLower(name) == String::ToLower(b.Name))
return b;
}
@@ -80,8 +80,10 @@ namespace Nuake {
{
for (auto& p : PointEntities)
{
if (name == p.Name)
if (String::ToLower(name) == String::ToLower(p.Name))
{
return p;
}
}
assert(false && "Point entity not found!");
@@ -91,13 +93,13 @@ namespace Nuake {
{
for (auto& b : BrushEntities)
{
if (b.Name == className)
if (String::ToLower(b.Name) == String::ToLower(className))
return EntityType::Brush;
}
for (auto& p : PointEntities)
{
if (p.Name == className)
if (String::ToLower(p.Name) == String::ToLower(className))
return EntityType::Point;
}

View File

@@ -52,8 +52,8 @@ namespace Nuake
glm::mat4 inverseViewProjection = glm::inverse(viewProjection);
// TODO: Automate this
const float nearClip = 0.0001f;
const float farClip = 800.0f;
const float nearClip = 0.01f;
const float farClip = 500.0f;
const float clipRange = farClip - nearClip;
const float mCascadeNearPlaneOffset = -100.0f;
@@ -73,7 +73,7 @@ namespace Nuake
mCascadeSplits[i] = (d - nearClip) / clipRange;
}
mCascadeSplits[0] = 0.01f;
//mCascadeSplits[0] = 0.01f;
//mCascadeSplits[1] = 0.45f;
//mCascadeSplits[2] = 1.0f;

View File

@@ -403,21 +403,17 @@ namespace Nuake {
geo_generator_run();
DefaultMaterial = MaterialManager::Get()->GetMaterial("default");
Entity worldspawnEntity = { (entt::entity)-1, m_Scene };
std::map<std::string, Entity> pointEntities = std::map<std::string, Entity>();
for (uint32_t e = 0; e < (uint32_t)entity_count; ++e)
{
entity* entity_inst = &entities[e];
entity_geometry* entity_geo_inst = &entity_geo[e];
Entity newEntity = m_Scene->CreateEntity("Brush " + std::to_string(e));
if (entity_inst->spawn_type == entity_spawn_type::EST_GROUP)
newEntity.GetComponent<NameComponent>().Name = "Group " + std::to_string(e);
bool isTrigger = false;
bool isFunc = false;
bool isPos = false;
ent.AddChild(newEntity);
std::string target = "";
std::string targetname = "";
FGDBrushEntity fgdBrush;
@@ -425,6 +421,7 @@ namespace Nuake {
bool isEntity = false;
bool isWorldSpawn = false;
bool isPointEntity = false;
Vector3 brushLocalPosition = { 0, 0, 0 };
for (int i = 0; i < entity_inst->property_count; i++)
{
property* prop = &(entity_inst->properties)[i];
@@ -439,7 +436,7 @@ namespace Nuake {
float z = String::ToFloat(splits[0]);
Vector3 position = Vector3(x, y, z) * ScaleFactor * (1.0f / 64.0f);
newEntity.GetComponent<TransformComponent>().SetLocalPosition(position);
brushLocalPosition = position;
}
if (key == "classname")
@@ -478,19 +475,37 @@ namespace Nuake {
if (key == "target")
target = value;
}
if (!worldspawnEntity.IsValid())
{
worldspawnEntity = m_Scene->CreateEntity("WorldSpawn");
ent.AddChild(worldspawnEntity);
}
if (!isWorldSpawn)
{
if (isPointEntity)
{
Entity newPEntity = Engine::GetCurrentScene()->CreateEntity("New prefab Entity");
newEntity.AddChild(newPEntity);
auto& prefabComponent = newPEntity.AddComponent<PrefabComponent>();
if (pointEntities.find(pointEntity.Name) == pointEntities.end())
{
Entity pointEntityParent = Engine::GetCurrentScene()->CreateEntity(pointEntity.Name);
pointEntities[pointEntity.Name] = pointEntityParent;
ent.AddChild(pointEntityParent);
}
Entity newPrefab = Engine::GetCurrentScene()->CreateEntity(pointEntity.Name);
pointEntities[pointEntity.Name].AddChild(newPrefab);
auto& prefabComponent = newPrefab.AddComponent<PrefabComponent>();
prefabComponent.SetPrefab(Prefab::New(pointEntity.Prefab));
newPrefab.GetComponent<TransformComponent>().SetLocalPosition(brushLocalPosition);
for (auto& e : prefabComponent.PrefabInstance->Entities)
{
if (!e.GetComponent<ParentComponent>().HasParent)
{
newPEntity.AddChild(e);
newPrefab.AddChild(e);
}
}
}
@@ -500,10 +515,10 @@ namespace Nuake {
brush* brush_inst = &entity_inst->brushes[b];
brush_geometry* brush_geo_inst = &entity_geo_inst->brushes[b];
if (isEntity)
CreateFuncBrush(brush_inst, brush_geo_inst, m_Scene, newEntity, target, targetname, fgdBrush);
else
CreateBrush(brush_inst, brush_geo_inst, m_Scene, newEntity, target, targetname);
//if (isEntity)
// CreateFuncBrush(brush_inst, brush_geo_inst, m_Scene, newEntity, target, targetname, fgdBrush);
//else
// CreateBrush(brush_inst, brush_geo_inst, m_Scene, newEntity, target, targetname);
}
}
else
@@ -511,10 +526,11 @@ namespace Nuake {
std::map<std::string, Ref<Material>> m_Materials;
std::map<Ref<Material>, std::vector<ProcessedMesh>> m_StaticWorld;
Entity brushEntity = m_Scene->CreateEntity("WorldSpawn");
newEntity.AddChild(brushEntity);
Entity brushEntity = m_Scene->CreateEntity("Brush " + std::to_string(e));
worldspawnEntity.AddChild(brushEntity);
auto& transformComponent = brushEntity.GetComponent<TransformComponent>();
transformComponent.SetLocalPosition(brushLocalPosition);
auto& bsp = brushEntity.AddComponent<BSPBrushComponent>();
quakeMapC.m_Brushes.push_back(brushEntity);