From 712a26ab93dbc88f4bfeb0e873dd829e64a6ad46 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Thu, 12 May 2022 01:57:24 -0400 Subject: [PATCH] CGraphics: Handle Point type in LoadLight Also removes shadowRender parameter from DrawUnsortedGeometry, it's now unused. --- Runtime/Graphics/CCubeRenderer.cpp | 7 +-- Runtime/Graphics/CCubeRenderer.hpp | 2 +- Runtime/Graphics/CGraphics.cpp | 70 +++++++++--------------------- Runtime/Graphics/IRenderer.hpp | 2 +- 4 files changed, 27 insertions(+), 54 deletions(-) diff --git a/Runtime/Graphics/CCubeRenderer.cpp b/Runtime/Graphics/CCubeRenderer.cpp index bbe2363cc..837fa972c 100644 --- a/Runtime/Graphics/CCubeRenderer.cpp +++ b/Runtime/Graphics/CCubeRenderer.cpp @@ -286,10 +286,11 @@ void CCubeRenderer::RemoveStaticGeometry(const std::vector* geometry) override; - void DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask, bool shadowRender = false) override; + void DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) override; void DrawSortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) override; void DrawStaticGeometry(s32 areaIdx, s32 mask, s32 targetMask) override; void DrawAreaGeometry(s32 areaIdx, s32 mask, s32 targetMask) override; diff --git a/Runtime/Graphics/CGraphics.cpp b/Runtime/Graphics/CGraphics.cpp index db566ab48..8a2a79196 100644 --- a/Runtime/Graphics/CGraphics.cpp +++ b/Runtime/Graphics/CGraphics.cpp @@ -82,69 +82,41 @@ void CGraphics::DisableAllLights() { void CGraphics::LoadLight(ERglLight light, const CLight& info) { const auto lightId = static_cast(1 << light); -#if 1 + auto& obj = g_LightObjs[light]; zeus::CVector3f pos = info.GetPosition(); zeus::CVector3f dir = info.GetDirection(); - if (info.GetType() == ELightType::Directional) { - return; + const auto type = info.GetType(); + if (type == ELightType::Directional) { dir = -(g_CameraMatrix.buildMatrix3f() * dir); - GXInitLightPos(&g_LightObjs[static_cast(light)], dir.x() * 1048576.f, dir.y() * 1048576.f, - dir.z() * 1048576.f); - GXInitLightAttn(&g_LightObjs[static_cast(light)], 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); - } else if (info.GetType() == ELightType::Spot) { + GXInitLightPos(&obj, dir.x() * 1048576.f, dir.y() * 1048576.f, dir.z() * 1048576.f); + GXInitLightAttn(&obj, 1.f, 0.f, 0.f, 1.f, 0.f, 0.f); + } else if (type == ELightType::Spot) { pos = g_CameraMatrix * pos; - GX::LightObj* obj = &g_LightObjs[static_cast(light)]; - GXInitLightPos(obj, pos.x(), pos.y(), pos.z()); + GXInitLightPos(&obj, pos.x(), pos.y(), pos.z()); dir = g_CameraMatrix.buildMatrix3f() * dir; - GXInitLightDir(obj, dir.x(), dir.y(), dir.z()); - GXInitLightAttn(obj, 1.f, 0.f, 0.f, info.GetAttenuationConstant(), info.GetAttenuationLinear(), + GXInitLightDir(&obj, dir.x(), dir.y(), dir.z()); + GXInitLightAttn(&obj, 1.f, 0.f, 0.f, info.GetAttenuationConstant(), info.GetAttenuationLinear(), info.GetAttenuationQuadratic()); - GXInitLightSpot(obj, info.GetSpotCutoff(), GX::SP_COS2); - } else if (info.GetType() == ELightType::Custom) { + GXInitLightSpot(&obj, info.GetSpotCutoff(), GX::SP_COS2); + } else if (type == ELightType::Custom) { pos = g_CameraMatrix * pos; - GX::LightObj* obj = &g_LightObjs[static_cast(light)]; - GXInitLightPos(obj, pos.x(), pos.y(), pos.z()); + GXInitLightPos(&obj, pos.x(), pos.y(), pos.z()); dir = g_CameraMatrix.buildMatrix3f() * dir; - GXInitLightDir(obj, dir.x(), dir.y(), dir.z()); - GXInitLightAttn(obj, info.GetAngleAttenuationConstant(), info.GetAngleAttenuationLinear(), + GXInitLightDir(&obj, dir.x(), dir.y(), dir.z()); + GXInitLightAttn(&obj, info.GetAngleAttenuationConstant(), info.GetAngleAttenuationLinear(), info.GetAngleAttenuationQuadratic(), info.GetAttenuationConstant(), info.GetAttenuationLinear(), info.GetAttenuationQuadratic()); - } else if (info.GetType() == ELightType::LocalAmbient) { + } else if (type == ELightType::LocalAmbient || type == ELightType::Point) { pos = g_CameraMatrix * pos; - GXInitLightPos(&g_LightObjs[static_cast(light)], pos.x(), pos.y(), pos.z()); - GXInitLightAttn(&g_LightObjs[static_cast(light)], 1.f, 0.f, 0.f, info.GetAttenuationConstant(), - info.GetAttenuationLinear(), info.GetAttenuationQuadratic()); + GXInitLightPos(&obj, pos.x(), pos.y(), pos.z()); + GXInitLightAttn(&obj, 1.f, 0.f, 0.f, info.GetAttenuationConstant(), info.GetAttenuationLinear(), + info.GetAttenuationQuadratic()); } - g_LightTypes[static_cast(light)] = info.GetType(); + g_LightTypes[light] = type; GX::Color col(info.GetColor().r(), info.GetColor().g(), info.GetColor().b()); - GXInitLightColor(&g_LightObjs[static_cast(light)], col); - GXLoadLightObjImm(&g_LightObjs[static_cast(light)], lightId); -#else - switch (info.GetType()) { - case ELightType::LocalAmbient: - aurora::gfx::load_light_ambient(lightId, info.GetColor()); - break; - case ELightType::Point: - case ELightType::Spot: - case ELightType::Custom: - case ELightType::Directional: { - aurora::gfx::Light lightOut{ - .pos = CGraphics::g_CameraMatrix * info.GetPosition(), - .dir = (CGraphics::g_CameraMatrix.basis * info.GetDirection()).normalized(), - .color = info.GetColor(), - .linAtt = {info.GetAttenuationConstant(), info.GetAttenuationLinear(), info.GetAttenuationQuadratic()}, - .angAtt = {info.GetAngleAttenuationConstant(), info.GetAngleAttenuationLinear(), - info.GetAngleAttenuationQuadratic()}, - }; - if (info.GetType() == ELightType::Directional) { - lightOut.pos = (-lightOut.dir) * 1048576.f; - } - aurora::gfx::load_light(lightId, lightOut); - break; - } - } -#endif + GXInitLightColor(&obj, col); + GXLoadLightObjImm(&obj, lightId); } void CGraphics::EnableLight(ERglLight light) { diff --git a/Runtime/Graphics/IRenderer.hpp b/Runtime/Graphics/IRenderer.hpp index ff9a9344b..897ab85df 100644 --- a/Runtime/Graphics/IRenderer.hpp +++ b/Runtime/Graphics/IRenderer.hpp @@ -46,7 +46,7 @@ public: virtual void EnablePVS(const CPVSVisSet& set, u32 areaIdx) = 0; virtual void DisablePVS() = 0; virtual void RemoveStaticGeometry(const std::vector* geometry) = 0; - virtual void DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask, bool shadowRender = false) = 0; + virtual void DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) = 0; virtual void DrawSortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) = 0; virtual void DrawStaticGeometry(s32 areaIdx, s32 mask, s32 targetMask) = 0; virtual void DrawAreaGeometry(s32 areaIdx, s32 mask, s32 targetMask) = 0;