2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-08 14:24:56 +00:00

zeus constexpr refactor and thermal visor fixes

This commit is contained in:
Jack Andersen
2019-02-23 21:15:54 -10:00
parent 1186b8097c
commit 8df0a4913c
226 changed files with 1339 additions and 1305 deletions

View File

@@ -371,15 +371,15 @@ void CBooRenderer::RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel*
if (pass == 0) {
zeus::CAABox xfAABB = aabb.getTransformedAABox(modelMtx);
zeus::CUnitVector3f viewNormal(viewMtx.basis[1]);
zeus::CPlane planes[7] = {{zeus::CVector3f::skRight, xfAABB.min.x()},
{zeus::CVector3f::skLeft, -xfAABB.max.x()},
{zeus::CVector3f::skForward, xfAABB.min.y()},
{zeus::CVector3f::skBack, -xfAABB.max.y()},
{zeus::CVector3f::skUp, xfAABB.min.z()},
{zeus::CVector3f::skDown, -xfAABB.max.z()},
zeus::CPlane planes[7] = {{zeus::skRight, xfAABB.min.x()},
{zeus::skLeft, -xfAABB.max.x()},
{zeus::skForward, xfAABB.min.y()},
{zeus::skBack, -xfAABB.max.y()},
{zeus::skUp, xfAABB.min.z()},
{zeus::skDown, -xfAABB.max.z()},
{viewNormal, viewNormal.dot(viewMtx.origin) + 0.2f + 0.1f}};
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
CGraphics::SetModelMatrix(zeus::CTransform());
float longestAxis = std::max(std::max(xfAABB.max.x() - xfAABB.min.x(), xfAABB.max.y() - xfAABB.min.y()),
xfAABB.max.z() - xfAABB.min.z()) *
@@ -424,7 +424,7 @@ void CBooRenderer::RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel*
}
void CBooRenderer::SetupRendererStates() const {
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
CGraphics::SetModelMatrix(zeus::CTransform());
CGraphics::g_ColorRegs[1] = x2fc_tevReg1Color;
}
@@ -634,6 +634,7 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
} BooTrace);
LoadThermoPalette();
LoadBallFade();
m_thermColdFilter.emplace();
m_thermHotFilter.emplace();
Buckets::Init();
@@ -696,7 +697,7 @@ void CBooRenderer::UpdateAreaUniforms(int areaIdx, bool shadowRender, bool activ
int bufIdx;
if (shadowRender) {
flags.m_extendedShader = EExtendedShader::SolidColor;
flags.x4_color = zeus::CColor::skBlack;
flags.x4_color = zeus::skBlack;
bufIdx = 1;
} else {
flags.m_extendedShader = EExtendedShader::Lighting;
@@ -913,7 +914,7 @@ void CBooRenderer::AddPlaneObject(const void* obj, const zeus::CAABox& aabb, con
float closeDist = xb0_viewPlane.pointToPlaneDist(closePoint);
float farDist = xb0_viewPlane.pointToPlaneDist(farPoint);
if (closeDist >= 0.f || farDist >= 0.f) {
bool zOnly = plane.normal() == zeus::CVector3f::skUp;
bool zOnly = plane.normal() == zeus::skUp;
bool invert;
if (zOnly)
invert = CGraphics::g_ViewMatrix.origin.z() >= plane.d();
@@ -956,8 +957,8 @@ std::pair<zeus::CVector2f, zeus::CVector2f> CBooRenderer::SetViewportOrtho(bool
float right = centered ? g_Viewport.x4_top + g_Viewport.x10_halfWidth : g_Viewport.x8_width;
CGraphics::SetOrtho(left, right, top, bottom, znear, zfar);
CGraphics::SetViewPointMatrix(zeus::CTransform::Identity());
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
CGraphics::SetViewPointMatrix(zeus::CTransform());
CGraphics::SetModelMatrix(zeus::CTransform());
return {{left, bottom}, {right, top}};
}
@@ -974,7 +975,7 @@ void CBooRenderer::SetDebugOption(EDebugOption, int) {}
void CBooRenderer::BeginScene() {
CGraphics::SetViewport(0, 0, g_Viewport.x8_width, g_Viewport.xc_height);
CGraphics::SetPerspective(75.f, CGraphics::g_ProjAspect, 1.f, 4096.f);
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
CGraphics::SetModelMatrix(zeus::CTransform());
#if 0
if (x310_phazonSuitMaskCountdown != 0)
{
@@ -1090,8 +1091,8 @@ void CBooRenderer::SetThermal(bool thermal, float level, const zeus::CColor& col
void CBooRenderer::SetThermalColdScale(float scale) { x2f8_thermColdScale = zeus::clamp(0.f, scale, 1.f); }
void CBooRenderer::DoThermalBlendCold() {
zeus::CColor a = zeus::CColor::lerp(x2f4_thermColor, zeus::CColor::skWhite, x2f8_thermColdScale);
m_thermColdFilter.setColorA(a);
zeus::CColor a = zeus::CColor::lerp(x2f4_thermColor, zeus::skWhite, x2f8_thermColdScale);
m_thermColdFilter->setColorA(a);
float bFac = 0.f;
float bAlpha = 1.f;
if (x2f8_thermColdScale < 0.5f) {
@@ -1099,15 +1100,15 @@ void CBooRenderer::DoThermalBlendCold() {
bFac = (1.f - bAlpha) / 8.f;
}
zeus::CColor b{bFac, bFac, bFac, bAlpha};
m_thermColdFilter.setColorB(b);
zeus::CColor c = zeus::CColor::lerp(zeus::CColor::skBlack, zeus::CColor::skWhite,
m_thermColdFilter->setColorB(b);
zeus::CColor c = zeus::CColor::lerp(zeus::skBlack, zeus::skWhite,
zeus::clamp(0.f, (x2f8_thermColdScale - 0.25f) * 4.f / 3.f, 1.f));
m_thermColdFilter.setColorC(c);
m_thermColdFilter->setColorC(c);
m_thermColdFilter.setScale(x2f8_thermColdScale);
m_thermColdFilter->setScale(x2f8_thermColdScale);
m_thermColdFilter.setShift(x2a8_thermalRand.Next() % 32);
m_thermColdFilter.draw();
m_thermColdFilter->setNoiseOffset(x2a8_thermalRand.Next() % 32);
m_thermColdFilter->draw();
CElementGen::SetMoveRedToAlphaBuffer(true);
CDecal::SetMoveRedToAlphaBuffer(true);
}
@@ -1169,7 +1170,7 @@ void CBooRenderer::DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectM
/* Draw effect; subtracting binding 1 from binding 2 for the filter 'cutout' */
if (indTex && indTex.IsLoaded())
ReallyDrawPhazonSuitIndirectEffect(zeus::CColor::skWhite, *indTex, indirectMod, scale, offX, offY);
ReallyDrawPhazonSuitIndirectEffect(zeus::skWhite, *indTex, indirectMod, scale, offX, offY);
else
ReallyDrawPhazonSuitEffect(nonIndirectMod);
}

View File

@@ -132,7 +132,7 @@ class CBooRenderer final : public IRenderer {
std::list<CFogVolumeFilter>::iterator m_nextFogVolumeFilter;
std::list<std::pair<zeus::CVector3f, float>> x2c4_spaceWarps;
u32 x2dc_reflectionAge = 2;
zeus::CColor x2e0_ = zeus::CColor::skWhite;
zeus::CColor x2e0_ = zeus::skWhite;
zeus::CVector3f x2e4_ = {0.f, 1.f, 0.f};
CSpaceWarpFilter m_spaceWarpFilter;
@@ -141,7 +141,7 @@ class CBooRenderer final : public IRenderer {
zeus::CColor x2f4_thermColor;
float x2f8_thermColdScale = 0.f;
zeus::CColor x2fc_tevReg1Color = {1.f, 0.f, 1.f, 1.f};
CThermalColdFilter m_thermColdFilter;
rstl::optional<CThermalColdFilter> m_thermColdFilter;
rstl::optional<CThermalHotFilter> m_thermHotFilter;
std::vector<CLight> x300_dynamicLights;
@@ -292,6 +292,8 @@ public:
int DrawOverlappingWorldModelIDs(int alphaVal, const std::vector<u32>& modelBits, const zeus::CAABox& aabb) const;
void DrawOverlappingWorldModelShadows(int alphaVal, const std::vector<u32>& modelBits, const zeus::CAABox& aabb,
float alpha) const;
bool IsThermalVisorActive() const { return x318_29_thermalVisor; }
};
} // namespace urde

View File

@@ -21,7 +21,7 @@ ERglLightBits CGraphics::g_LightActive = ERglLightBits::None;
ERglLightBits CGraphics::g_LightsWereOn = ERglLightBits::None;
zeus::CTransform CGraphics::g_GXModelView;
zeus::CTransform CGraphics::g_GXModelViewInvXpose;
zeus::CTransform CGraphics::g_GXModelMatrix = zeus::CTransform::Identity();
zeus::CTransform CGraphics::g_GXModelMatrix = zeus::CTransform();
zeus::CTransform CGraphics::g_ViewMatrix;
zeus::CVector3f CGraphics::g_ViewPoint;
zeus::CTransform CGraphics::g_GXViewPointMatrix;

View File

@@ -22,8 +22,8 @@ class CLight {
friend class CGameLight;
zeus::CVector3f x0_pos;
zeus::CVector3f xc_dir = zeus::CVector3f::skDown;
zeus::CColor x18_color = zeus::CColor::skClear;
zeus::CVector3f xc_dir = zeus::skDown;
zeus::CColor x18_color = zeus::skClear;
ELightType x1c_type = ELightType::Custom;
float x20_spotCutoff = 0.f;
float x24_distC = 1.f;

View File

@@ -368,14 +368,18 @@ void CLineRenderer::Render(const zeus::CColor& moduColor) {
m_uniformBuf.access() = SDrawUniform{moduColor};
if (m_textured) {
memmove(m_vertBufTex.access(), g_StaticLineVertsTex.data(), sizeof(SDrawVertTex) * g_StaticLineVertsTex.size());
CGraphics::SetShaderDataBinding(m_shaderBind);
CGraphics::DrawArray(0, g_StaticLineVertsTex.size());
if (!g_StaticLineVertsTex.empty()) {
memmove(m_vertBufTex.access(), g_StaticLineVertsTex.data(), sizeof(SDrawVertTex) * g_StaticLineVertsTex.size());
CGraphics::SetShaderDataBinding(m_shaderBind);
CGraphics::DrawArray(0, g_StaticLineVertsTex.size());
}
} else {
memmove(m_vertBufNoTex.access(), g_StaticLineVertsNoTex.data(),
sizeof(SDrawVertNoTex) * g_StaticLineVertsNoTex.size());
CGraphics::SetShaderDataBinding(m_shaderBind);
CGraphics::DrawArray(0, g_StaticLineVertsNoTex.size());
if (!g_StaticLineVertsNoTex.empty()) {
memmove(m_vertBufNoTex.access(), g_StaticLineVertsNoTex.data(),
sizeof(SDrawVertNoTex) * g_StaticLineVertsNoTex.size());
CGraphics::SetShaderDataBinding(m_shaderBind);
CGraphics::DrawArray(0, g_StaticLineVertsNoTex.size());
}
}
}

View File

@@ -71,8 +71,8 @@ public:
void Reset();
void AddVertex(const zeus::CVector3f& position, const zeus::CColor& color, float width,
const zeus::CVector2f& uv = zeus::CVector2f::skZero);
void Render(const zeus::CColor& moduColor = zeus::CColor::skWhite);
const zeus::CVector2f& uv = zeus::skZero2f);
void Render(const zeus::CColor& moduColor = zeus::skWhite);
static void UpdateBuffers() {
s_vertPoolTex.updateBuffers();

View File

@@ -28,7 +28,7 @@ struct CModelFlags {
bool m_depthGreater = false;
u16 x2_flags = 0; /* Flags */
zeus::CColor x4_color; /* Set into kcolor slot specified by material */
zeus::CColor addColor = zeus::CColor::skClear;
zeus::CColor addColor = zeus::skClear;
zeus::CAABox mbShadowBox;
CModelFlags() = default;

View File

@@ -95,11 +95,11 @@ void CBooModel::EnsureViewDepStateCached(const CBooModel& model, const CBooSurfa
/* Reflection map matrix */
zeus::CVector3f v1 = playerToSurf * (1.f / surfSize);
zeus::CVector3f v2 = v1.cross(zeus::CVector3f::skUp);
zeus::CVector3f v2 = v1.cross(zeus::skUp);
if (v2.canBeNormalized())
v2.normalize();
else
v2 = zeus::CVector3f::skRight;
v2 = zeus::skRight;
float timeScale = 0.32258067f * (0.02f * distance + 1.f);
float f1 = timeScale * g_TransformedTime;
@@ -407,11 +407,11 @@ void CBooModel::MakeTexturesFromMats(std::vector<TCachedToken<CTexture>>& toksOu
void CBooModel::ActivateLights(const std::vector<CLight>& lights) { m_lightingData.ActivateLights(lights); }
void CBooModel::DisableAllLights() {
m_lightingData.ambient = zeus::CColor::skBlack;
m_lightingData.ambient = zeus::skBlack;
for (size_t curLight = 0; curLight < URDE_MAX_LIGHTS; ++curLight) {
CModelShaders::Light& lightOut = m_lightingData.lights[curLight];
lightOut.color = zeus::CColor::skClear;
lightOut.color = zeus::skClear;
lightOut.linAtt[0] = 1.f;
lightOut.angAtt[0] = 1.f;
}
@@ -529,6 +529,9 @@ static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data,
EExtendedShader extended = EExtendedShader::Flat;
if (flags.m_extendedShader == EExtendedShader::Lighting) {
/* Transform lighting into thermal cold if the thermal visor is active */
if (g_Renderer->IsThermalVisorActive())
return EExtendedShader::ThermalCold;
if (data.heclIr.m_blendSrc == boo::BlendFactor::One && data.heclIr.m_blendDst == boo::BlendFactor::Zero) {
/* Override shader if originally opaque (typical for FRME models) */
if (flags.x0_blendMode > 6) {
@@ -630,58 +633,58 @@ void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimati
switch (anim.mode) {
case UVAnimation::Mode::MvInvNoTranslation: {
texMtxOut = CGraphics::g_GXModelViewInvXpose.toMatrix4f();
texMtxOut.m[3].w() = 1.f;
postMtxOut.m[0].x() = 0.5f;
postMtxOut.m[1].y() = 0.5f;
postMtxOut.m[3].x() = 0.5f;
postMtxOut.m[3].y() = 0.5f;
texMtxOut[3].w() = 1.f;
postMtxOut[0].x() = 0.5f;
postMtxOut[1].y() = 0.5f;
postMtxOut[3].x() = 0.5f;
postMtxOut[3].y() = 0.5f;
break;
}
case UVAnimation::Mode::MvInv: {
texMtxOut = CGraphics::g_GXModelViewInvXpose.toMatrix4f();
texMtxOut.m[3] = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix.origin;
texMtxOut.m[3].w() = 1.f;
postMtxOut.m[0].x() = 0.5f;
postMtxOut.m[1].y() = 0.5f;
postMtxOut.m[3].x() = 0.5f;
postMtxOut.m[3].y() = 0.5f;
texMtxOut[3] = CGraphics::g_ViewMatrix.inverse() * CGraphics::g_GXModelMatrix.origin;
texMtxOut[3].w() = 1.f;
postMtxOut[0].x() = 0.5f;
postMtxOut[1].y() = 0.5f;
postMtxOut[3].x() = 0.5f;
postMtxOut[3].y() = 0.5f;
break;
}
case UVAnimation::Mode::Scroll: {
texMtxOut.m[3].x() = CGraphics::GetSecondsMod900() * anim.vals[2] + anim.vals[0];
texMtxOut.m[3].y() = CGraphics::GetSecondsMod900() * anim.vals[3] + anim.vals[1];
texMtxOut[3].x() = CGraphics::GetSecondsMod900() * anim.vals[2] + anim.vals[0];
texMtxOut[3].y() = CGraphics::GetSecondsMod900() * anim.vals[3] + anim.vals[1];
break;
}
case UVAnimation::Mode::Rotation: {
float angle = CGraphics::GetSecondsMod900() * anim.vals[1] + anim.vals[0];
float acos = std::cos(angle);
float asin = std::sin(angle);
texMtxOut.m[0].x() = acos;
texMtxOut.m[0].y() = asin;
texMtxOut.m[1].x() = -asin;
texMtxOut.m[1].y() = acos;
texMtxOut.m[3].x() = (1.0f - (acos - asin)) * 0.5f;
texMtxOut.m[3].y() = (1.0f - (asin + acos)) * 0.5f;
texMtxOut[0].x() = acos;
texMtxOut[0].y() = asin;
texMtxOut[1].x() = -asin;
texMtxOut[1].y() = acos;
texMtxOut[3].x() = (1.0f - (acos - asin)) * 0.5f;
texMtxOut[3].y() = (1.0f - (asin + acos)) * 0.5f;
break;
}
case UVAnimation::Mode::HStrip: {
float value = anim.vals[0] * anim.vals[2] * (anim.vals[3] + CGraphics::GetSecondsMod900());
texMtxOut.m[3].x() = std::trunc(anim.vals[1] * fmod(value, 1.0f)) * anim.vals[2];
texMtxOut[3].x() = std::trunc(anim.vals[1] * fmod(value, 1.0f)) * anim.vals[2];
break;
}
case UVAnimation::Mode::VStrip: {
float value = anim.vals[0] * anim.vals[2] * (anim.vals[3] + CGraphics::GetSecondsMod900());
texMtxOut.m[3].y() = std::trunc(anim.vals[1] * fmod(value, 1.0f)) * anim.vals[2];
texMtxOut[3].y() = std::trunc(anim.vals[1] * fmod(value, 1.0f)) * anim.vals[2];
break;
}
case UVAnimation::Mode::Model: {
texMtxOut = CGraphics::g_GXModelMatrix.toMatrix4f();
texMtxOut.m[3].zeroOut();
postMtxOut.m[0].x() = 0.5f;
postMtxOut.m[1].y() = 0.f;
postMtxOut.m[2].y() = 0.5f;
postMtxOut.m[3].x() = CGraphics::g_GXModelMatrix.origin.x() * 0.05f;
postMtxOut.m[3].y() = CGraphics::g_GXModelMatrix.origin.y() * 0.05f;
texMtxOut[3].zeroOut();
postMtxOut[0].x() = 0.5f;
postMtxOut[1].y() = 0.f;
postMtxOut[2].y() = 0.5f;
postMtxOut[3].x() = CGraphics::g_GXModelMatrix.origin.x() * 0.05f;
postMtxOut[3].y() = CGraphics::g_GXModelMatrix.origin.y() * 0.05f;
break;
}
case UVAnimation::Mode::CylinderEnvironment: {
@@ -770,18 +773,16 @@ void CBooModel::UVAnimationBuffer::Update(u8*& bufOut, const MaterialSet* matSet
/* Special Mode0 matrix for exclusive Thermal Visor use */
specialMtxOut.emplace();
/* This part handled in-shader
zeus::CMatrix4f& texMtxOut = (*specialMtxOut)[0];
texMtxOut = CGraphics::g_GXModelViewInvXpose.toMatrix4f();
texMtxOut.vec[3].zeroOut();
texMtxOut.vec[3].w = 1.f;
*/
texMtxOut[3].zeroOut();
texMtxOut[3].w() = 1.f;
zeus::CMatrix4f& postMtxOut = (*specialMtxOut)[1];
postMtxOut.m[0].x() = 0.5f;
postMtxOut.m[1].y() = 0.5f;
postMtxOut.m[3].x() = 0.5f;
postMtxOut.m[3].y() = 0.5f;
postMtxOut[0].x() = 0.5f;
postMtxOut[1].y() = 0.5f;
postMtxOut[3].x() = 0.5f;
postMtxOut[3].y() = 0.5f;
} else if (flags.m_extendedShader == EExtendedShader::WorldShadow) {
/* Special matrix for mapping world shadow */
specialMtxOut.emplace();
@@ -830,7 +831,7 @@ void GeometryUniformLayout::Update(const CModelFlags& flags, const CSkinRules* c
for (size_t w = 0; w < weightCount; ++w) {
zeus::CMatrix4f& obj = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
if (w >= bankTransforms.size())
obj = zeus::CMatrix4f::skIdentityMatrix4f;
obj = zeus::CMatrix4f();
else
obj = bankTransforms[w]->toMatrix4f();
dataCur += sizeof(zeus::CMatrix4f);
@@ -838,7 +839,7 @@ void GeometryUniformLayout::Update(const CModelFlags& flags, const CSkinRules* c
for (size_t w = 0; w < weightCount; ++w) {
zeus::CMatrix4f& objInv = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
if (w >= bankTransforms.size())
objInv = zeus::CMatrix4f::skIdentityMatrix4f;
objInv = zeus::CMatrix4f();
else
objInv = bankTransforms[w]->basis;
dataCur += sizeof(zeus::CMatrix4f);
@@ -848,12 +849,12 @@ void GeometryUniformLayout::Update(const CModelFlags& flags, const CSkinRules* c
} else {
for (size_t w = 0; w < weightCount; ++w) {
zeus::CMatrix4f& mv = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
mv = zeus::CMatrix4f::skIdentityMatrix4f;
mv = zeus::CMatrix4f();
dataCur += sizeof(zeus::CMatrix4f);
}
for (size_t w = 0; w < weightCount; ++w) {
zeus::CMatrix4f& mvinv = reinterpret_cast<zeus::CMatrix4f&>(*dataCur);
mvinv = zeus::CMatrix4f::skIdentityMatrix4f;
mvinv = zeus::CMatrix4f();
dataCur += sizeof(zeus::CMatrix4f);
}
}
@@ -947,7 +948,7 @@ boo::ObjToken<boo::IGraphicsBufferD> CBooModel::UpdateUniformData(const CModelFl
} else if (flags.m_extendedShader == EExtendedShader::MorphBallShadow) /* MorphBall shadow render */
{
CModelShaders::MBShadowUniform& shadowOut = *reinterpret_cast<CModelShaders::MBShadowUniform*>(dataCur);
shadowOut.shadowUp = CGraphics::g_GXModelView * zeus::CVector3f::skUp;
shadowOut.shadowUp = CGraphics::g_GXModelView * zeus::skUp;
shadowOut.shadowUp.w() = flags.x4_color.a();
shadowOut.shadowId = flags.x4_color.r();
} else if (flags.m_extendedShader == EExtendedShader::Disintegrate) {
@@ -992,7 +993,7 @@ void CBooModel::DrawAlpha(const CModelFlags& flags, const CSkinRules* cskr, cons
/* Check if we're overriding with RenderModelBlack */
if (g_RenderModelBlack) {
rFlags.m_extendedShader = EExtendedShader::SolidColor;
rFlags.x4_color = zeus::CColor::skBlack;
rFlags.x4_color = zeus::skBlack;
}
if (TryLockTextures()) {
@@ -1006,7 +1007,7 @@ void CBooModel::DrawNormal(const CModelFlags& flags, const CSkinRules* cskr, con
/* Check if we're overriding with RenderModelBlack */
if (g_RenderModelBlack) {
rFlags.m_extendedShader = EExtendedShader::SolidColor;
rFlags.x4_color = zeus::CColor::skBlack;
rFlags.x4_color = zeus::skBlack;
}
if (TryLockTextures()) {
UpdateUniformData(rFlags, cskr, pose);
@@ -1019,7 +1020,7 @@ void CBooModel::Draw(const CModelFlags& flags, const CSkinRules* cskr, const CPo
/* Check if we're overriding with RenderModelBlack */
if (g_RenderModelBlack) {
rFlags.m_extendedShader = EExtendedShader::SolidColor;
rFlags.x4_color = zeus::CColor::skBlack;
rFlags.x4_color = zeus::skBlack;
}
if (TryLockTextures()) {
@@ -1235,7 +1236,7 @@ void CModel::RestoreVerticesCPU(const boo::ObjToken<boo::IGraphicsBufferD>& vert
void CModel::_WarmupShaders() {
CBooModel::SetDummyTextures(true);
CBooModel::EnableShadowMaps(g_Renderer->x220_sphereRamp.get(), zeus::CTransform::Identity());
CBooModel::EnableShadowMaps(g_Renderer->x220_sphereRamp.get(), zeus::CTransform());
CGraphics::CProjectionState backupProj = CGraphics::GetProjectionState();
zeus::CTransform backupViewPoint = CGraphics::g_ViewMatrix;
zeus::CTransform backupModel = CGraphics::g_GXModelMatrix;

View File

@@ -151,7 +151,7 @@ u32 CRainSplashGenerator::GetNextBestPt(u32 pt, const std::vector<std::pair<zeus
auto idx = u32(rand.Range(0, int(vn.size() - 1)));
auto& vert = vn[idx];
float distSq = (refVert.first - vert.first).magSquared();
if (distSq > maxDist && vert.second.dot(zeus::CVector3f::skUp) >= 0.f &&
if (distSq > maxDist && vert.second.dot(zeus::skUp) >= 0.f &&
(vert.first.z() <= 0.f || vert.first.z() > minZ)) {
nextPt = idx;
maxDist = distSq;

View File

@@ -41,14 +41,14 @@ void CSimpleShadow::Render(const TLockedToken<CTexture>& tex) const {
{{radius, 0.f, -radius}, {0.f, 1.f}},
{{-radius, 0.f, radius}, {1.f, 0.f}},
{{radius, 0.f, radius}, {1.f, 1.f}}};
m_filter->drawVerts(zeus::CColor::skWhite, verts);
m_filter->drawVerts(zeus::skWhite, verts);
}
void CSimpleShadow::Calculate(const zeus::CAABox& aabb, const zeus::CTransform& xf, const CStateManager& mgr) {
x48_24_collision = false;
float halfHeight = (aabb.max.z() - aabb.min.z()) * 0.5f;
zeus::CVector3f pos = xf.origin + zeus::CVector3f(0.f, 0.f, halfHeight);
CRayCastResult res = mgr.RayStaticIntersection(pos, zeus::CVector3f::skDown, x40_maxObjHeight,
CRayCastResult res = mgr.RayStaticIntersection(pos, zeus::skDown, x40_maxObjHeight,
CMaterialFilter::MakeExclude({EMaterialTypes::SeeThrough}));
float height = x40_maxObjHeight;
if (res.IsValid()) {
@@ -60,7 +60,7 @@ void CSimpleShadow::Calculate(const zeus::CAABox& aabb, const zeus::CTransform&
TUniqueId cid = kInvalidUniqueId;
rstl::reserved_vector<TUniqueId, 1024> nearList;
CRayCastResult resD = CGameCollision::RayDynamicIntersection(
mgr, cid, pos, zeus::CVector3f::skDown, x40_maxObjHeight, CMaterialFilter::skPassEverything, nearList);
mgr, cid, pos, zeus::skDown, x40_maxObjHeight, CMaterialFilter::skPassEverything, nearList);
if (resD.IsValid() && resD.GetT() < height) {
x48_24_collision = true;
height = resD.GetT();
@@ -70,7 +70,7 @@ void CSimpleShadow::Calculate(const zeus::CAABox& aabb, const zeus::CTransform&
if (x48_24_collision) {
x3c_heightAlpha = 1.f - height / x40_maxObjHeight;
x0_xf = zeus::lookAt(res.GetPlane().normal(), zeus::CVector3f::skZero);
x0_xf = zeus::lookAt(res.GetPlane().normal(), zeus::skZero3f);
x0_xf.origin = res.GetPlane().normal() * x44_displacement + res.GetPoint();
if (x48_25_alwaysCalculateRadius || !x48_26_radiusCalculated) {
float xExtent = aabb.max.x() - aabb.min.x();

View File

@@ -7,7 +7,7 @@ namespace urde {
std::unordered_map<uint64_t, CModelShaders::ShaderPipelines> CModelShaders::g_ShaderPipelines;
void CModelShaders::LightingUniform::ActivateLights(const std::vector<CLight>& lts) {
ambient = zeus::CColor::skClear;
ambient = zeus::skClear;
size_t curLight = 0;
for (const CLight& light : lts) {
@@ -42,9 +42,9 @@ void CModelShaders::LightingUniform::ActivateLights(const std::vector<CLight>& l
for (; curLight < URDE_MAX_LIGHTS; ++curLight) {
CModelShaders::Light& lightOut = lights[curLight];
lightOut.pos = zeus::CVector3f::skZero;
lightOut.dir = zeus::CVector3f::skDown;
lightOut.color = zeus::CColor::skClear;
lightOut.pos = zeus::skZero3f;
lightOut.dir = zeus::skDown;
lightOut.color = zeus::skClear;
lightOut.linAtt[0] = 1.f;
lightOut.linAtt[1] = 0.f;
lightOut.linAtt[2] = 0.f;
@@ -144,7 +144,11 @@ static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = {
false, true, false, false, true},
/* Forced additive shading without culling or Z-write and greater depth test */
{1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One,
hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true}};
hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true},
/* Thermal cold shading */
{1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original,
false, false, true, false, false, false, true}};
extern const hecl::Backend::Function ExtensionLightingFuncsGLSL[];
extern const hecl::Backend::Function ExtensionPostFuncsGLSL[];

View File

@@ -35,6 +35,7 @@ enum EExtendedShader : uint8_t {
DepthGEqualNoZWrite,
Disintegrate,
ForcedAdditiveNoZWriteDepthGreater,
ThermalCold,
MAX
};
@@ -45,7 +46,7 @@ public:
struct Light {
zeus::CVector3f pos;
zeus::CVector3f dir;
zeus::CColor color = zeus::CColor::skClear;
zeus::CColor color = zeus::skClear;
float linAtt[4] = {1.f, 0.f, 0.f};
float angAtt[4] = {1.f, 0.f, 0.f};
};

View File

@@ -173,7 +173,7 @@ static std::string_view ThermalPostGLSL =
"};\n"
"vec4 ThermalPostFunc(vec4 colorIn)\n"
"{\n"
" return vec4(texture(extTex7, vtf.extTcgs[0]).rrr * tmulColor.rgb + taddColor.rgb, tmulColor.a + taddColor.a);\n"
" return texture(extTex7, vtf.extTcgs[0]).rrrr * tmulColor + taddColor;\n"
"}\n"
"\n"sv;
@@ -221,6 +221,13 @@ static std::string_view DisintegratePostGLSL = FOG_STRUCT_GLSL
"}\n"
"\n"sv;
static std::string_view ThermalColdPostGLSL =
"vec4 ThermalColdPostFunc(vec4 colorIn)\n"
"{\n"
" return colorIn * vec4(0.75);\n"
"}\n"
"\n"sv;
const hecl::Backend::Function ExtensionLightingFuncsGLSL[] = {
{},
{LightingGLSL, "LightingFunc"},
@@ -244,6 +251,7 @@ const hecl::Backend::Function ExtensionLightingFuncsGLSL[] = {
{LightingGLSL, "LightingFunc"},
{},
{LightingGLSL, "LightingFunc"},
{},
};
const hecl::Backend::Function ExtensionPostFuncsGLSL[] = {
@@ -269,6 +277,7 @@ const hecl::Backend::Function ExtensionPostFuncsGLSL[] = {
{MainPostGLSL, "MainPostFunc"},
{DisintegratePostGLSL, "DisintegratePostFunc"},
{MainPostGLSL, "MainPostFunc"},
{ThermalColdPostGLSL, "ThermalColdPostFunc"},
};
} // namespace urde

View File

@@ -166,8 +166,7 @@ static std::string_view ThermalPostHLSL =
"};\n"
"static float4 ThermalPostFunc(in VertToFrag vtf, float4 colorIn)\n"
"{\n"
" return float4(extTex7.Sample(samp, vtf.extTcgs[0]).rrr * tmulColor.rgb + taddColor.rgb, tmulColor.a + "
"taddColor.a);\n"
" return extTex7.Sample(samp, vtf.extTcgs[0]).rrrr * tmulColor + taddColor;\n"
"}\n"
"\n"sv;
@@ -215,6 +214,13 @@ static std::string_view DisintegratePostHLSL = FOG_STRUCT_HLSL
"}\n"
"\n"sv;
static std::string_view ThermalColdPostHLSL =
"static float4 ThermalColdPostFunc(in VertToFrag vtf, float4 colorIn)\n"
"{\n"
" return colorIn * float4(0.75, 0.75, 0.75, 0.75);\n"
"}\n"
"\n"sv;
const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = {{},
{LightingHLSL, "LightingFunc"},
{},
@@ -236,7 +242,8 @@ const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = {{},
{LightingHLSL, "LightingFunc"},
{LightingHLSL, "LightingFunc"},
{},
{LightingHLSL, "LightingFunc"}};
{LightingHLSL, "LightingFunc"},
{}};
const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
{},
@@ -261,6 +268,7 @@ const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
{MainPostHLSL, "MainPostFunc"},
{DisintegratePostHLSL, "DisintegratePostFunc"},
{MainPostHLSL, "MainPostFunc"},
{ThermalColdPostHLSL, "ThermalColdPostFunc"},
};
} // namespace urde

View File

@@ -168,9 +168,7 @@ static std::string_view ThermalPostMetal =
"static float4 EXTThermalPostFunc(thread VertToFrag& vtf, constant ThermalUniform& lu,\n"
" sampler samp, sampler clampSamp, texture2d<float> extTex7, float4 colorIn)\n"
"{\n"
" //return float4(vtf.extTcgs0.xy, 0.0, 1.0);\n"
" return float4(extTex7.sample(samp, vtf.extTcgs0).rrr * lu.tmulColor.rgb + lu.taddColor.rgb,\n"
" lu.tmulColor.a + lu.taddColor.a);\n"
" return extTex7.sample(samp, vtf.extTcgs0).rrrr * lu.tmulColor + lu.taddColor;\n"
"}\n"
"\n"sv;
@@ -221,6 +219,13 @@ static std::string_view DisintegratePostMetal = FOG_STRUCT_METAL
"}\n"
"\n"sv;
static std::string_view ThermalColdPostMetal =
"static float4 ThermalColdPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n"
"{\n"
" return colorIn * float4(0.75, 0.75, 0.75, 0.75);\n"
"}\n"
"\n"sv;
const hecl::Backend::Function ExtensionLightingFuncsMetal[] = {{},
{LightingMetal, "LightingFunc"},
{},
@@ -242,7 +247,8 @@ const hecl::Backend::Function ExtensionLightingFuncsMetal[] = {{},
{LightingMetal, "LightingFunc"},
{LightingMetal, "LightingFunc"},
{},
{LightingMetal, "LightingFunc"}};
{LightingMetal, "LightingFunc"},
{}};
const hecl::Backend::Function ExtensionPostFuncsMetal[] = {
{},
@@ -267,6 +273,7 @@ const hecl::Backend::Function ExtensionPostFuncsMetal[] = {
{MainPostMetal, "MainPostFunc"},
{DisintegratePostMetal, "EXTDisintegratePostFunc"},
{MainPostMetal, "MainPostFunc"},
{ThermalColdPostMetal, "ThermalColdPostFunc"},
};
} // namespace urde

View File

@@ -260,7 +260,7 @@ void CTexturedQuadFilter::drawVerts(const zeus::CColor& color, const Vert verts[
}
void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) {
m_uniform.m_matrix = zeus::CMatrix4f::skIdentityMatrix4f;
m_uniform.m_matrix = zeus::CMatrix4f();
m_uniform.m_lod = 0.f;
m_uniform.m_color = color;
m_uniBuf->load(&m_uniform, sizeof(m_uniform));

View File

@@ -1,6 +1,8 @@
#include "CThermalColdFilter.hpp"
#include "Graphics/CGraphics.hpp"
#include "Graphics/CBooRenderer.hpp"
#include "hecl/Pipeline.hpp"
#include "GameGlobalObjects.hpp"
namespace urde {
@@ -12,58 +14,34 @@ void CThermalColdFilter::Shutdown() { s_Pipeline.reset(); }
CThermalColdFilter::CThermalColdFilter() {
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
m_shiftTex = ctx.newDynamicTexture(8, 4, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat);
struct Vert {
zeus::CVector2f m_pos;
zeus::CVector2f m_uv;
zeus::CVector2f m_uvNoise;
} verts[4] = {
{{-1.f, -1.f}, {0.f, 0.f}},
{{-1.f, 1.f}, {0.f, 1.f}},
{{1.f, -1.f}, {1.f, 0.f}},
{{1.f, 1.f}, {1.f, 1.f}},
{{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}},
{{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}},
{{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}},
{{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}},
};
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4);
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 48, 4);
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
boo::ObjToken<boo::IGraphicsBuffer> bufs[] = {m_uniBuf.get()};
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
boo::ObjToken<boo::ITexture> texs[] = {CGraphics::g_SpareTexture.get(), m_shiftTex.get()};
boo::ObjToken<boo::ITexture> texs[] = {CGraphics::g_SpareTexture.get(),
g_Renderer->GetRandomStaticEntropyTex()};
m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr,
2, texs, nullptr, nullptr);
return true;
} BooTrace);
setShift(0);
setNoiseOffset(0);
setScale(0.f);
}
void CThermalColdFilter::setShift(unsigned shift) {
shift = std::min(shift, 31u);
for (unsigned y = 0; y < 4; ++y) {
unsigned bx = y * 8;
for (unsigned x = 0; x < 8; ++x) {
unsigned px = bx + x;
unsigned spx = px + shift;
unsigned ny = spx / 8;
if (ny > 3)
ny = 3;
unsigned nx = spx % 8;
m_shiftTexture[y][x][0] = u8(nx * 255 / 7);
m_shiftTexture[y][x][1] = u8(ny * 255 / 3);
}
}
m_shiftTex->load(m_shiftTexture[0][0], sizeof(m_shiftTexture));
}
void CThermalColdFilter::draw() {
CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport);
m_uniform.m_shiftTexMtx[0][0] = 80.f * (CGraphics::g_ProjAspect / 1.33f);
m_uniform.m_shiftTexMtx[1][1] = 120.f;
m_uniform.m_shiftTexScale[0] = 1.f / m_uniform.m_shiftTexMtx[0][0];
m_uniform.m_shiftTexScale[1] = 1.f / m_uniform.m_shiftTexMtx[1][1];
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
CGraphics::SetShaderDataBinding(m_dataBind);
CGraphics::DrawArray(0, 4);
}

View File

@@ -9,13 +9,10 @@ namespace urde {
class CThermalColdFilter {
struct Uniform {
zeus::CMatrix4f m_shiftTexMtx;
zeus::CMatrix4f m_indMtx;
zeus::CVector2f m_shiftTexScale;
zeus::CColor m_colorRegs[3];
float m_randOff = 0.f;
};
u8 m_shiftTexture[4][8][4] = {};
boo::ObjToken<boo::ITextureD> m_shiftTex;
boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
@@ -25,7 +22,7 @@ public:
static void Initialize();
static void Shutdown();
CThermalColdFilter();
void setShift(unsigned shift);
void setNoiseOffset(unsigned shift) { m_uniform.m_randOff = float(shift); }
void setColorA(const zeus::CColor& color) { m_uniform.m_colorRegs[0] = color; }
void setColorB(const zeus::CColor& color) { m_uniform.m_colorRegs[1] = color; }
void setColorC(const zeus::CColor& color) { m_uniform.m_colorRegs[2] = color; }

View File

@@ -40,7 +40,7 @@ void CWorldShadowShader::drawBase(float extent) {
m_vbo->load(verts, sizeof(zeus::CVector3f) * 4);
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
m_uniform.m_color = zeus::CColor::skWhite;
m_uniform.m_color = zeus::skWhite;
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
CGraphics::SetShaderDataBinding(m_zDataBind);