mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-17 04:47:09 +00:00
Implement GX lighting API (need to update shader generation)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
#include "Runtime/Graphics/CGraphics.hpp"
|
||||
|
||||
#include "Runtime/CTimeProvider.hpp"
|
||||
#include "Runtime/Graphics/CLight.hpp"
|
||||
#include "Runtime/Graphics/CLineRenderer.hpp"
|
||||
#include "Runtime/Graphics/CTexture.hpp"
|
||||
#include "Runtime/Graphics/Shaders/CTextSupportShader.hpp"
|
||||
@@ -19,6 +18,8 @@ u32 CGraphics::g_FlippingState;
|
||||
bool CGraphics::g_LastFrameUsedAbove = false;
|
||||
bool CGraphics::g_InterruptLastFrameUsedAbove = false;
|
||||
GX::LightMask CGraphics::g_LightActive{};
|
||||
std::array<GX::LightObj, GX::MaxLights> CGraphics::g_LightObjs;
|
||||
std::array<ELightType, GX::MaxLights> CGraphics::g_LightTypes;
|
||||
zeus::CTransform CGraphics::g_GXModelView;
|
||||
zeus::CTransform CGraphics::g_GXModelViewInvXpose;
|
||||
zeus::CTransform CGraphics::g_GXModelMatrix = zeus::CTransform();
|
||||
@@ -80,6 +81,45 @@ void CGraphics::DisableAllLights() {
|
||||
|
||||
void CGraphics::LoadLight(ERglLight light, const CLight& info) {
|
||||
const auto lightId = static_cast<GX::LightID>(1 << light);
|
||||
|
||||
#if 0
|
||||
zeus::CVector3f pos = info.GetPosition();
|
||||
zeus::CVector3f dir = info.GetDirection();
|
||||
if (info.GetType() == ELightType::Directional) {
|
||||
return;
|
||||
dir = -(g_CameraMatrix.buildMatrix3f() * dir);
|
||||
GXInitLightPos(&g_LightObjs[static_cast<u32>(light)], dir.x() * 1048576.f, dir.y() * 1048576.f, dir.z() * 1048576.f);
|
||||
GXInitLightAttn(&g_LightObjs[static_cast<u32>(light)], 1.f, 0.f, 0.f, 1.f, 0.f, 0.f);
|
||||
} else if (info.GetType() == ELightType::Spot) {
|
||||
pos = g_CameraMatrix * pos;
|
||||
GX::LightObj* obj = &g_LightObjs[static_cast<u32>(light)];
|
||||
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.GetAngleAttenuationLinear(),
|
||||
info.GetAttenuationQuadratic());
|
||||
GXInitLightSpot(obj, info.GetSpotCutoff(), GX::SP_COS2);
|
||||
} else if (info.GetType() == ELightType::Custom) {
|
||||
pos = g_CameraMatrix * pos;
|
||||
GX::LightObj* obj = &g_LightObjs[static_cast<u32>(light)];
|
||||
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(),
|
||||
info.GetAngleAttenuationQuadratic(), info.GetAttenuationConstant(),
|
||||
info.GetAngleAttenuationLinear(), info.GetAttenuationQuadratic());
|
||||
} else if (info.GetType() == ELightType::LocalAmbient) {
|
||||
pos = g_CameraMatrix * pos;
|
||||
GXInitLightPos(&g_LightObjs[static_cast<u32>(light)], pos.x(), pos.y(), pos.z());
|
||||
GXInitLightAttn(&g_LightObjs[static_cast<u32>(light)], 1.f, 0.f, 0.f, info.GetAttenuationConstant(),
|
||||
info.GetAngleAttenuationLinear(), info.GetAttenuationQuadratic());
|
||||
}
|
||||
|
||||
g_LightTypes[static_cast<u32>(light)] = info.GetType();
|
||||
GX::Color col(info.GetColor().r(), info.GetColor().g(), info.GetColor().b());
|
||||
GXInitLightColor(&g_LightObjs[static_cast<u32>(light)], col);
|
||||
GXLoadLightObjImm(&g_LightObjs[static_cast<u32>(light)], lightId);
|
||||
#else
|
||||
switch (info.GetType()) {
|
||||
case ELightType::LocalAmbient:
|
||||
aurora::gfx::load_light_ambient(lightId, info.GetColor());
|
||||
@@ -103,6 +143,7 @@ void CGraphics::LoadLight(ERglLight light, const CLight& info) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void CGraphics::EnableLight(ERglLight light) {
|
||||
@@ -674,7 +715,14 @@ void CGraphics::Startup() {
|
||||
}
|
||||
|
||||
void CGraphics::InitGraphicsVariables() {
|
||||
// g_lightTypes[0..n] = Directional;
|
||||
g_LightTypes[0] = ELightType::Directional;
|
||||
g_LightTypes[1] = ELightType::Directional;
|
||||
g_LightTypes[2] = ELightType::Directional;
|
||||
g_LightTypes[3] = ELightType::Directional;
|
||||
g_LightTypes[4] = ELightType::Directional;
|
||||
g_LightTypes[5] = ELightType::Directional;
|
||||
g_LightTypes[6] = ELightType::Directional;
|
||||
g_LightTypes[7] = ELightType::Directional;
|
||||
g_LightActive = {};
|
||||
SetDepthWriteMode(false, g_depthFunc, false);
|
||||
SetCullMode(ERglCullMode::None);
|
||||
@@ -682,8 +730,8 @@ void CGraphics::InitGraphicsVariables() {
|
||||
g_IsGXModelMatrixIdentity = false;
|
||||
// SetIdentityViewPointMatrix();
|
||||
// SetIdentityModelMatrix();
|
||||
// SetViewport(...);
|
||||
// SetPerspective(...);
|
||||
SetViewport(0, 0, g_Viewport.x8_width, g_Viewport.xc_height);
|
||||
SetPerspective(60.f, g_Viewport.x8_width / g_Viewport.xc_height, g_Proj.x14_near, g_Proj.x18_far);
|
||||
SetCopyClear(g_ClearColor, 1.f);
|
||||
CGX::SetChanMatColor(CGX::EChannelId::Channel0, zeus::skWhite);
|
||||
// g_RenderState.ResetFlushAll();
|
||||
|
||||
Reference in New Issue
Block a user