2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Particle/CElementGen.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/GameGlobalObjects.hpp"
|
|
|
|
#include "Runtime/Character/CActorLights.hpp"
|
2022-02-25 07:45:25 +00:00
|
|
|
#include "Runtime/Graphics/CCubeRenderer.hpp"
|
2022-03-19 17:30:25 +00:00
|
|
|
#include "Runtime/Graphics/CGX.hpp"
|
2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/Graphics/CModel.hpp"
|
|
|
|
#include "Runtime/Graphics/Shaders/CElementGenShaders.hpp"
|
|
|
|
#include "Runtime/Particle/CElectricDescription.hpp"
|
|
|
|
#include "Runtime/Particle/CGenDescription.hpp"
|
|
|
|
#include "Runtime/Particle/CParticleGlobals.hpp"
|
|
|
|
#include "Runtime/Particle/CParticleElectric.hpp"
|
|
|
|
#include "Runtime/Particle/CParticleSwoosh.hpp"
|
|
|
|
#include "Runtime/Particle/CSwooshDescription.hpp"
|
|
|
|
#include "Runtime/Particle/CWarp.hpp"
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2016-02-14 03:42:36 +00:00
|
|
|
#define MAX_GLOBAL_PARTICLES 2560
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2020-03-09 16:37:15 +00:00
|
|
|
namespace {
|
2021-04-10 08:42:06 +00:00
|
|
|
logvisor::Module Log("metaforce::CElementGen");
|
2020-03-09 16:37:15 +00:00
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// constexpr std::array ShadClsSizes{
|
|
|
|
// sizeof(SParticleInstanceTex),
|
|
|
|
// sizeof(SParticleInstanceIndTex),
|
|
|
|
// sizeof(SParticleInstanceNoTex),
|
|
|
|
// };
|
2020-03-09 16:37:15 +00:00
|
|
|
} // Anonymous namespace
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2017-06-11 02:57:35 +00:00
|
|
|
u16 CElementGen::g_GlobalSeed = 99;
|
2017-09-05 03:00:19 +00:00
|
|
|
bool CElementGen::g_subtractBlend = false;
|
2017-03-24 05:30:16 +00:00
|
|
|
|
2016-02-09 22:52:33 +00:00
|
|
|
int CElementGen::g_ParticleAliveCount;
|
|
|
|
int CElementGen::g_ParticleSystemAliveCount;
|
2017-06-04 01:01:09 +00:00
|
|
|
bool CElementGen::g_ParticleSystemInitialized = false;
|
2017-01-22 17:36:25 +00:00
|
|
|
bool CElementGen::sMoveRedToAlphaBuffer = false;
|
2017-09-10 09:04:51 +00:00
|
|
|
CParticle* CElementGen::g_currentParticle = nullptr;
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// std::vector<SParticleInstanceTex> g_instTexData;
|
|
|
|
// std::vector<SParticleInstanceIndTex> g_instIndTexData;
|
|
|
|
// std::vector<SParticleInstanceNoTex> g_instNoTexData;
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::Initialize() {
|
|
|
|
if (g_ParticleSystemInitialized)
|
|
|
|
return;
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_ParticleAliveCount = 0;
|
|
|
|
g_ParticleSystemAliveCount = 0;
|
|
|
|
g_ParticleSystemInitialized = true;
|
2016-02-09 22:52:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
/* Compile shaders */
|
|
|
|
CElementGenShaders::Initialize();
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
2016-02-11 23:05:42 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::Shutdown() { CElementGenShaders::Shutdown(); }
|
2016-02-16 19:42:24 +00:00
|
|
|
|
2020-03-09 17:07:51 +00:00
|
|
|
CElementGen::CElementGen(TToken<CGenDescription> gen, EModelOrientationType orientType, EOptionalSystemFlags flags)
|
2020-04-11 04:39:49 +00:00
|
|
|
: x1c_genDesc(std::move(gen))
|
|
|
|
, x2c_orientType(orientType)
|
|
|
|
, x26d_27_enableOPTS(True(flags & EOptionalSystemFlags::Two))
|
|
|
|
, x27c_randState(x94_randomSeed) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
|
|
|
x28_loadedGenDesc = desc;
|
|
|
|
|
|
|
|
if (desc->x54_x40_TEXR)
|
|
|
|
desc->x54_x40_TEXR->GetValueTexture(0).GetObj();
|
|
|
|
if (desc->x58_x44_TIND)
|
|
|
|
desc->x58_x44_TIND->GetValueTexture(0).GetObj();
|
|
|
|
|
|
|
|
CGlobalRandom globRnd(x27c_randState);
|
|
|
|
if (CIntElement* seedElem = desc->x1c_x10_SEED.get()) {
|
|
|
|
int seedVal;
|
|
|
|
seedElem->GetValue(x74_curFrame, seedVal);
|
|
|
|
x94_randomSeed = seedVal;
|
|
|
|
}
|
|
|
|
x27c_randState.SetSeed(x94_randomSeed);
|
|
|
|
++g_ParticleSystemAliveCount;
|
|
|
|
x26c_25_LIT_ = desc->x44_29_x30_29_LIT_;
|
|
|
|
x26c_26_AAPH = desc->x44_26_x30_26_AAPH;
|
|
|
|
x26c_27_ZBUF = desc->x44_27_x30_27_ZBUF;
|
|
|
|
x26c_28_zTest = true;
|
|
|
|
x26c_29_ORNT = desc->x30_30_ORNT;
|
|
|
|
x26c_30_MBLR = x26c_29_ORNT ? false : desc->x44_30_x31_24_MBLR;
|
|
|
|
|
|
|
|
if (CIntElement* mbspElem = desc->x48_x34_MBSP.get())
|
|
|
|
mbspElem->GetValue(x74_curFrame, x270_MBSP);
|
|
|
|
|
2021-10-31 13:43:17 +00:00
|
|
|
// x280_VELSources' entries should be tightly packed
|
|
|
|
size_t idx = 0;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CModVectorElement* elem = desc->x7c_x68_VEL1.get()) {
|
2021-10-31 13:43:17 +00:00
|
|
|
x280_VELSources[idx] = elem;
|
|
|
|
x278_hasVMD[idx] = desc->x45_26_x31_28_VMD1;
|
|
|
|
idx++;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CModVectorElement* elem = desc->x80_x6c_VEL2.get()) {
|
2021-10-31 13:43:17 +00:00
|
|
|
x280_VELSources[idx] = elem;
|
|
|
|
x278_hasVMD[idx] = desc->x45_27_x31_29_VMD2;
|
|
|
|
idx++;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CModVectorElement* elem = desc->x84_x70_VEL3.get()) {
|
2021-10-31 13:43:17 +00:00
|
|
|
x280_VELSources[idx] = elem;
|
|
|
|
x278_hasVMD[idx] = desc->x45_28_x31_30_VMD3;
|
|
|
|
idx++;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CModVectorElement* elem = desc->x88_x74_VEL4.get()) {
|
2021-10-31 13:43:17 +00:00
|
|
|
x280_VELSources[idx] = elem;
|
|
|
|
x278_hasVMD[idx] = desc->x45_29_x31_31_VMD4;
|
|
|
|
idx++;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (desc->x10c_ADV1 || desc->x110_ADV2 || desc->x114_ADV3 || desc->x118_ADV4 || desc->x11c_ADV5 || desc->x120_ADV6 ||
|
|
|
|
desc->x124_ADV7 || desc->x128_ADV8)
|
|
|
|
x26d_28_enableADV = true;
|
|
|
|
|
|
|
|
if (CIntElement* cssdElem = desc->xa0_x8c_CSSD.get())
|
|
|
|
cssdElem->GetValue(0, x2a0_CSSD);
|
|
|
|
|
|
|
|
if (CIntElement* pisyElem = desc->xc8_xb4_PISY.get()) {
|
|
|
|
pisyElem->GetValue(0, x2a8_PISY);
|
|
|
|
if (x2a8_PISY <= 0)
|
|
|
|
x2a8_PISY = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CIntElement* sisyElem = desc->xcc_xb8_SISY.get())
|
|
|
|
sisyElem->GetValue(0, x2a4_SISY);
|
|
|
|
|
|
|
|
if (CIntElement* sssdElem = desc->xe4_xd0_SSSD.get())
|
|
|
|
sssdElem->GetValue(0, x2ac_SSSD);
|
|
|
|
|
|
|
|
if (CVectorElement* sspoElem = desc->xe8_xd4_SSPO.get()) {
|
|
|
|
sspoElem->GetValue(0, x2b0_SSPO);
|
|
|
|
if (!sspoElem->IsFastConstant())
|
|
|
|
x26c_24_translationDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CIntElement* sesdElem = desc->xf8_xe4_SESD.get())
|
|
|
|
sesdElem->GetValue(0, x2bc_SESD);
|
|
|
|
|
|
|
|
if (CVectorElement* sepoElem = desc->xfc_xe8_SEPO.get()) {
|
|
|
|
sepoElem->GetValue(0, x2c0_SEPO);
|
|
|
|
if (!sepoElem->IsFastConstant())
|
|
|
|
x26c_24_translationDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CVectorElement* pofsElem = desc->x18_xc_POFS.get()) {
|
|
|
|
pofsElem->GetValue(x74_curFrame, xf4_POFS);
|
|
|
|
if (!pofsElem->IsFastConstant())
|
|
|
|
x26c_24_translationDirty = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CIntElement* psltElem = desc->xc_x0_PSLT.get())
|
|
|
|
psltElem->GetValue(0, x268_PSLT);
|
|
|
|
else
|
|
|
|
x268_PSLT = INT_MAX;
|
|
|
|
|
|
|
|
if (CIntElement* maxpElem = desc->x28_x1c_MAXP.get()) {
|
|
|
|
maxpElem->GetValue(x74_curFrame, x90_MAXP);
|
|
|
|
}
|
|
|
|
|
2021-03-17 06:33:05 +00:00
|
|
|
s32 count = std::min(256, x90_MAXP);
|
|
|
|
x30_particles.reserve(count);
|
|
|
|
if (x26d_28_enableADV) {
|
|
|
|
x60_advValues.resize(count);
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x2c_orientType == EModelOrientationType::One)
|
2021-03-17 04:49:18 +00:00
|
|
|
x50_parentMatrices.resize(x90_MAXP);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
x26c_31_LINE = desc->x44_24_x30_24_LINE;
|
|
|
|
x26d_24_FXLL = desc->x44_25_x30_25_FXLL;
|
|
|
|
|
|
|
|
if (CIntElement* ltypElem = desc->x100_xec_LTYP.get()) {
|
|
|
|
int ltyp;
|
|
|
|
ltypElem->GetValue(x74_curFrame, ltyp);
|
|
|
|
switch (LightType(ltyp)) {
|
|
|
|
case LightType::None:
|
|
|
|
default:
|
|
|
|
x308_lightType = LightType::None;
|
|
|
|
break;
|
|
|
|
case LightType::Directional:
|
|
|
|
x308_lightType = LightType::Directional;
|
|
|
|
break;
|
|
|
|
case LightType::Custom:
|
|
|
|
x308_lightType = LightType::Custom;
|
|
|
|
break;
|
|
|
|
case LightType::Spot:
|
|
|
|
x308_lightType = LightType::Spot;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CIntElement* lfotElem = desc->x114_x100_LFOT.get()) {
|
|
|
|
int lfot;
|
|
|
|
lfotElem->GetValue(x74_curFrame, lfot);
|
|
|
|
switch (EFalloffType(lfot)) {
|
|
|
|
case EFalloffType::Constant:
|
|
|
|
x32c_falloffType = EFalloffType::Constant;
|
|
|
|
break;
|
|
|
|
case EFalloffType::Linear:
|
|
|
|
default:
|
|
|
|
x32c_falloffType = EFalloffType::Linear;
|
|
|
|
break;
|
|
|
|
case EFalloffType::Quadratic:
|
|
|
|
x32c_falloffType = EFalloffType::Quadratic;
|
|
|
|
break;
|
2017-06-12 18:20:07 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-06-12 18:20:07 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x26c_31_LINE) {
|
|
|
|
CUVElement* texr = desc->x54_x40_TEXR.get();
|
2022-03-04 07:47:21 +00:00
|
|
|
// TODO
|
2022-03-19 17:30:25 +00:00
|
|
|
// aurora::gfx::TextureHandle tex;
|
|
|
|
// if (texr)
|
|
|
|
// tex = texr->GetValueTexture(0).GetObj()->GetTexture();
|
2021-03-17 04:49:18 +00:00
|
|
|
int maxVerts = x90_MAXP;
|
2022-03-19 17:30:25 +00:00
|
|
|
// m_lineRenderer.reset(
|
|
|
|
// new CLineRenderer(CLineRenderer::EPrimitiveMode::Lines, maxVerts * 2, tex, x26c_26_AAPH, x26c_28_zTest));
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
m_shaderClass = CElementGenShaders::GetShaderClass(*this);
|
|
|
|
}
|
|
|
|
|
2021-04-18 23:53:51 +00:00
|
|
|
_RecreatePipelines();
|
2022-03-19 17:30:25 +00:00
|
|
|
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
|
|
|
|
// CElementGenShaders::BuildShaderDataBinding(ctx, *this);
|
|
|
|
// return true;
|
|
|
|
// } BooTrace);
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CElementGen::~CElementGen() {
|
|
|
|
--g_ParticleSystemAliveCount;
|
|
|
|
g_ParticleAliveCount -= x30_particles.size();
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CElementGen::Update(double t) {
|
2021-04-18 23:53:51 +00:00
|
|
|
s32 oldMax = x90_MAXP;
|
2021-05-06 18:27:29 +00:00
|
|
|
s32 oldMBSP = x270_MBSP;
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::SParticleSystem* prevSystem = CParticleGlobals::instance()->m_currentParticleSystem;
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticleGlobals::SParticleSystem thisSystem{FOURCC('PART'), this};
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_currentParticleSystem = &thisSystem;
|
2018-12-08 05:30:43 +00:00
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
|
|
|
CIntElement* pswtElem = desc->x10_x4_PSWT.get();
|
|
|
|
if (pswtElem && !x26d_25_warmedUp) {
|
|
|
|
int pswt = 0;
|
|
|
|
pswtElem->GetValue(x74_curFrame, pswt);
|
2021-04-21 01:00:03 +00:00
|
|
|
// Log.report(logvisor::Info, FMT_STRING("Running warmup on particle system 0x%08x for %d ticks."), desc, pswt);
|
2018-12-08 05:30:43 +00:00
|
|
|
InternalUpdate((1.f / 60.f) * pswt);
|
|
|
|
x26d_25_warmedUp = true;
|
|
|
|
}
|
|
|
|
bool ret = InternalUpdate(t);
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_currentParticleSystem = prevSystem;
|
2021-04-18 23:53:51 +00:00
|
|
|
|
2021-05-06 18:27:29 +00:00
|
|
|
if (oldMax < x90_MAXP || oldMBSP < x270_MBSP) {
|
|
|
|
//_RecreatePipelines();
|
2021-04-18 23:53:51 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
return ret;
|
2016-02-10 02:00:28 +00:00
|
|
|
}
|
2021-05-06 18:27:29 +00:00
|
|
|
|
2021-04-18 23:53:51 +00:00
|
|
|
void CElementGen::_RecreatePipelines() {
|
2021-06-07 19:29:18 +00:00
|
|
|
size_t maxInsts = x26c_30_MBLR ? 2560 * 2 : 2560; // x26c_30_MBLR ? (x270_MBSP * x90_MAXP) : x90_MAXP;
|
2021-04-18 23:53:51 +00:00
|
|
|
maxInsts = (maxInsts == 0 ? 256 : maxInsts);
|
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
|
|
|
|
// if (!x26c_31_LINE) {
|
|
|
|
// m_instBuf = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[size_t(m_shaderClass)], maxInsts);
|
|
|
|
// m_uniformBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1);
|
|
|
|
// }
|
|
|
|
// if (x28_loadedGenDesc->x45_24_x31_26_PMUS) {
|
|
|
|
// m_instBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Vertex, ShadClsSizes[size_t(m_shaderClass)], maxInsts);
|
|
|
|
// m_uniformBufPmus = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(SParticleUniforms), 1);
|
|
|
|
// }
|
|
|
|
// return true;
|
|
|
|
// } BooTrace);
|
2021-04-18 23:53:51 +00:00
|
|
|
}
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CElementGen::InternalUpdate(double dt) {
|
|
|
|
CGlobalRandom gr(x27c_randState);
|
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
double dt1 = 1.0 / 60.0;
|
|
|
|
if (std::fabs(dt - 1.0 / 60.0) >= 1.0 / 60000.0)
|
|
|
|
dt1 = dt;
|
|
|
|
double t = x74_curFrame / 60.0;
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetEmitterTime(x74_curFrame);
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CRealElement* pstsElem = desc->x14_x8_PSTS.get()) {
|
|
|
|
float psts;
|
|
|
|
pstsElem->GetValue(x74_curFrame, psts);
|
|
|
|
double dt1Scaled = psts * dt1;
|
|
|
|
dt1 = std::max(0.0, dt1Scaled);
|
|
|
|
}
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x78_curSeconds += dt1;
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x26c_30_MBLR && dt > 0.0) {
|
|
|
|
if (CIntElement* mbspElem = desc->x48_x34_MBSP.get())
|
|
|
|
mbspElem->GetValue(x74_curFrame, x270_MBSP);
|
|
|
|
}
|
|
|
|
|
|
|
|
int frameUpdateCount = 0;
|
|
|
|
while (t < x78_curSeconds && std::fabs(t - x78_curSeconds) >= 1.0 / 60000.0) {
|
|
|
|
x2d4_aabbMin.splat(FLT_MAX);
|
|
|
|
x2e0_aabbMax.splat(-FLT_MAX);
|
|
|
|
x2ec_maxSize = 0.f;
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetEmitterTime(x74_curFrame);
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateExistingParticles();
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetParticleLifetime(x268_PSLT);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (x74_curFrame < x268_PSLT && x88_particleEmission) {
|
|
|
|
float grte = 0.f;
|
|
|
|
if (CRealElement* grteElem = desc->x2c_x20_GRTE.get()) {
|
|
|
|
if (grteElem->GetValue(x74_curFrame, grte)) {
|
|
|
|
x30_particles.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
grte = std::max(0.f, grte * x98_generatorRate);
|
|
|
|
x8c_generatorRemainder += grte;
|
|
|
|
int genCount = floorf(x8c_generatorRemainder);
|
|
|
|
x8c_generatorRemainder = x8c_generatorRemainder - genCount;
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CIntElement* maxpElem = desc->x28_x1c_MAXP.get())
|
|
|
|
maxpElem->GetValue(x74_curFrame, x90_MAXP);
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CreateNewParticles(genCount);
|
|
|
|
}
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x26c_24_translationDirty)
|
|
|
|
UpdatePSTranslationAndOrientation();
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x308_lightType != LightType::None)
|
|
|
|
UpdateLightParameters();
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateChildParticleSystems(1 / 60.0);
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
++frameUpdateCount;
|
|
|
|
++x74_curFrame;
|
|
|
|
t += 1 / 60.0;
|
|
|
|
}
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (std::fabs(t - x78_curSeconds) < 1.0 / 60000.0) {
|
|
|
|
x78_curSeconds = t;
|
|
|
|
x80_timeDeltaScale = 1.f;
|
|
|
|
} else {
|
|
|
|
UpdateChildParticleSystems(dt1 - (frameUpdateCount / 60.0));
|
|
|
|
x80_timeDeltaScale = 1.f - (t - x78_curSeconds) * 60.f;
|
|
|
|
}
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
BuildParticleSystemBounds();
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return false;
|
2016-02-10 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::AccumulateBounds(const zeus::CVector3f& pos, float size) {
|
|
|
|
x2e0_aabbMax[0] = std::max(pos[0], float(x2e0_aabbMax[0]));
|
|
|
|
x2e0_aabbMax[1] = std::max(pos[1], float(x2e0_aabbMax[1]));
|
|
|
|
x2e0_aabbMax[2] = std::max(pos[2], float(x2e0_aabbMax[2]));
|
|
|
|
x2d4_aabbMin[0] = std::min(pos[0], float(x2d4_aabbMin[0]));
|
|
|
|
x2d4_aabbMin[1] = std::min(pos[1], float(x2d4_aabbMin[1]));
|
|
|
|
x2d4_aabbMin[2] = std::min(pos[2], float(x2d4_aabbMin[2]));
|
|
|
|
x2ec_maxSize = std::max(size, x2ec_maxSize);
|
2017-06-04 01:01:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 07:06:10 +00:00
|
|
|
void CElementGen::UpdateAdvanceAccessParameters(u32 activeParticleCount, s32 particleFrame) {
|
2021-03-17 04:49:18 +00:00
|
|
|
CGenDescription* desc = x28_loadedGenDesc;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2021-05-31 20:46:25 +00:00
|
|
|
if (activeParticleCount >= x60_advValues.size()) {
|
2021-06-07 19:29:18 +00:00
|
|
|
Log.report(logvisor::Fatal, FMT_STRING("activeParticleCount ({}) >= advValues size ({})"), activeParticleCount,
|
|
|
|
x60_advValues.size());
|
2021-05-06 18:35:02 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::array<float, 8>& arr = x60_advValues[activeParticleCount];
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_particleAccessParameters = &arr;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-04-25 07:06:10 +00:00
|
|
|
if (CRealElement* adv1 = desc->x10c_ADV1.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
adv1->GetValue(particleFrame, arr[0]);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
|
|
|
if (CRealElement* adv2 = desc->x110_ADV2.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
adv2->GetValue(particleFrame, arr[1]);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
|
|
|
if (CRealElement* adv3 = desc->x114_ADV3.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
adv3->GetValue(particleFrame, arr[2]);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
|
|
|
if (CRealElement* adv4 = desc->x118_ADV4.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
adv4->GetValue(particleFrame, arr[3]);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
|
|
|
if (CRealElement* adv5 = desc->x11c_ADV5.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
adv5->GetValue(particleFrame, arr[4]);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
|
|
|
if (CRealElement* adv6 = desc->x120_ADV6.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
adv6->GetValue(particleFrame, arr[5]);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
|
|
|
if (CRealElement* adv7 = desc->x124_ADV7.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
adv7->GetValue(particleFrame, arr[6]);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
|
|
|
if (CRealElement* adv8 = desc->x128_ADV8.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
adv8->GetValue(particleFrame, arr[7]);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
2017-06-04 01:01:09 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 07:06:10 +00:00
|
|
|
bool CElementGen::UpdateVelocitySource(size_t idx, s32 particleFrame, CParticle& particle) {
|
2018-12-08 05:30:43 +00:00
|
|
|
bool err;
|
|
|
|
if (x278_hasVMD[idx]) {
|
|
|
|
zeus::CVector3f localVel = x208_orientationInverse * particle.x1c_vel;
|
|
|
|
zeus::CVector3f localPos = x208_orientationInverse * (particle.x4_pos - xdc_translation);
|
|
|
|
err = x280_VELSources[idx]->GetValue(particleFrame, localVel, localPos);
|
|
|
|
particle.x1c_vel = x1d8_orientation.rotate(localVel);
|
2019-01-05 03:28:02 +00:00
|
|
|
particle.x4_pos = x1d8_orientation.rotate(localPos) + xdc_translation;
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
err = x280_VELSources[idx]->GetValue(particleFrame, particle.x1c_vel, particle.x4_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
particle.x0_endFrame = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-02-11 02:36:21 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::UpdateExistingParticles() {
|
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x25c_activeParticleCount = 0;
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetEmitterTime(x74_curFrame);
|
2021-03-17 04:49:18 +00:00
|
|
|
CParticleGlobals::instance()->m_particleAccessParameters = nullptr;
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (auto it = x30_particles.begin(); it != x30_particles.end();) {
|
|
|
|
CParticle& particle = *it;
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (particle.x0_endFrame < x74_curFrame) {
|
|
|
|
--g_ParticleAliveCount;
|
|
|
|
if (it + 1 == x30_particles.end()) {
|
|
|
|
x30_particles.pop_back();
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
particle = x30_particles.back();
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x2c_orientType == EModelOrientationType::One)
|
|
|
|
x50_parentMatrices[x25c_activeParticleCount] = x50_parentMatrices[x30_particles.size() - 1];
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2017-06-04 01:01:09 +00:00
|
|
|
if (x26d_28_enableADV)
|
2018-12-08 05:30:43 +00:00
|
|
|
x60_advValues[x25c_activeParticleCount] = x60_advValues[x30_particles.size() - 1];
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x30_particles.pop_back();
|
|
|
|
if (particle.x0_endFrame < x74_curFrame)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
particle.x10_prevPos = particle.x4_pos;
|
|
|
|
particle.x4_pos += particle.x1c_vel;
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
g_currentParticle = &particle;
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame - particle.x28_startFrame);
|
2020-04-25 07:06:10 +00:00
|
|
|
const int particleFrame = x74_curFrame - particle.x28_startFrame;
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(particleFrame);
|
2017-09-10 09:04:51 +00:00
|
|
|
|
2020-04-25 07:06:10 +00:00
|
|
|
if (x26d_28_enableADV) {
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateAdvanceAccessParameters(x25c_activeParticleCount, particleFrame);
|
2020-04-25 07:06:10 +00:00
|
|
|
}
|
2017-09-10 09:04:51 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
++x25c_activeParticleCount;
|
2016-02-10 02:00:28 +00:00
|
|
|
|
2020-03-09 16:37:15 +00:00
|
|
|
for (size_t i = 0; i < x280_VELSources.size(); ++i) {
|
|
|
|
if (!x280_VELSources[i]) {
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
2020-03-09 16:37:15 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
UpdateVelocitySource(i, particleFrame, particle);
|
|
|
|
}
|
2016-02-11 23:05:42 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x26c_31_LINE) {
|
|
|
|
if (CRealElement* leng = desc->x20_x14_LENG.get())
|
|
|
|
leng->GetValue(particleFrame, particle.x2c_lineLengthOrSize);
|
|
|
|
if (CRealElement* widt = desc->x24_x18_WIDT.get())
|
|
|
|
widt->GetValue(particleFrame, particle.x30_lineWidthOrRota);
|
|
|
|
} else {
|
|
|
|
if (CRealElement* rota = desc->x50_x3c_ROTA.get())
|
|
|
|
rota->GetValue(particleFrame, particle.x30_lineWidthOrRota);
|
|
|
|
if (CRealElement* size = desc->x4c_x38_SIZE.get())
|
|
|
|
size->GetValue(particleFrame, particle.x2c_lineLengthOrSize);
|
|
|
|
}
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CColorElement* colr = desc->x30_x24_COLR.get())
|
|
|
|
colr->GetValue(particleFrame, particle.x34_color);
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
AccumulateBounds(particle.x4_pos, particle.x2c_lineLengthOrSize);
|
|
|
|
++it;
|
|
|
|
}
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x30_particles.empty())
|
|
|
|
return;
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (CWarp* warp : x4_modifierList)
|
|
|
|
if (warp->UpdateWarp())
|
|
|
|
warp->ModifyParticles(x30_particles);
|
|
|
|
}
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::CreateNewParticles(int count) {
|
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2021-03-17 06:33:05 +00:00
|
|
|
if (!g_ParticleSystemInitialized) {
|
2018-12-08 05:30:43 +00:00
|
|
|
Initialize();
|
2021-03-17 06:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (x30_particles.size() >= x90_MAXP) {
|
2018-12-08 05:30:43 +00:00
|
|
|
return;
|
2021-03-17 06:33:05 +00:00
|
|
|
}
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2021-03-17 06:33:05 +00:00
|
|
|
if (count + x30_particles.size() > x90_MAXP) {
|
2018-12-08 05:30:43 +00:00
|
|
|
count = x90_MAXP - x30_particles.size();
|
2021-03-17 06:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_ParticleAliveCount + count > 2560) {
|
2018-12-08 05:30:43 +00:00
|
|
|
count = 2560 - g_ParticleAliveCount;
|
2021-03-17 06:33:05 +00:00
|
|
|
}
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGlobalRandom gr(x27c_randState);
|
2021-03-17 06:33:05 +00:00
|
|
|
x30_particles.reserve(count + x90_MAXP);
|
2021-05-31 20:46:25 +00:00
|
|
|
if (x26d_28_enableADV && x60_advValues.size() < count + x30_particles.size()) {
|
|
|
|
x60_advValues.resize(std::min(int(x60_advValues.size() * 2), x90_MAXP));
|
2021-03-17 06:33:05 +00:00
|
|
|
}
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_particleAccessParameters = nullptr;
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (int i = 0; i < count; ++i) {
|
2020-03-13 20:32:24 +00:00
|
|
|
CParticle& particle = x30_particles.emplace_back();
|
2018-12-08 05:30:43 +00:00
|
|
|
++g_ParticleAliveCount;
|
2021-03-17 04:49:18 +00:00
|
|
|
u32 particleCount = x30_particles.size() - 1;
|
2018-12-08 05:30:43 +00:00
|
|
|
++x25c_activeParticleCount;
|
|
|
|
++x260_cumulativeParticles;
|
2020-03-13 20:32:24 +00:00
|
|
|
if (x2c_orientType == EModelOrientationType::One) {
|
2018-12-08 05:30:43 +00:00
|
|
|
x50_parentMatrices[x30_particles.size() - 1] = x1d8_orientation.buildMatrix3f();
|
2020-03-13 20:32:24 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
particle.x28_startFrame = x74_curFrame;
|
2020-03-13 20:32:24 +00:00
|
|
|
if (CIntElement* ltme = desc->x34_x28_LTME.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
ltme->GetValue(0, particle.x0_endFrame);
|
2020-03-13 20:32:24 +00:00
|
|
|
}
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame);
|
|
|
|
CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(0);
|
2018-12-08 05:30:43 +00:00
|
|
|
g_currentParticle = &particle;
|
2021-03-17 04:49:18 +00:00
|
|
|
if (x26d_28_enableADV) {
|
|
|
|
UpdateAdvanceAccessParameters(particleCount, 0);
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
particle.x0_endFrame += x74_curFrame;
|
|
|
|
|
2021-03-17 04:49:18 +00:00
|
|
|
if (CColorElement* colr = desc->x30_x24_COLR.get()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
colr->GetValue(0, particle.x34_color);
|
2021-03-17 04:49:18 +00:00
|
|
|
} else {
|
2019-02-24 07:15:54 +00:00
|
|
|
particle.x34_color = zeus::skWhite;
|
2021-03-17 04:49:18 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (CEmitterElement* emtr = desc->x40_x2c_EMTR.get()) {
|
|
|
|
emtr->GetValue(x74_curFrame, particle.x4_pos, particle.x1c_vel);
|
|
|
|
zeus::CVector3f compXf1 = (x13c_globalScaleTransformInverse * x1a8_localScaleTransformInverse) * xdc_translation;
|
|
|
|
zeus::CVector3f compXf2 = x1d8_orientation.rotate(particle.x4_pos);
|
|
|
|
particle.x4_pos = compXf1 + compXf2 + xf4_POFS;
|
|
|
|
particle.x1c_vel = x1d8_orientation.rotate(particle.x1c_vel);
|
|
|
|
} else {
|
|
|
|
zeus::CVector3f compXf1 = (x13c_globalScaleTransformInverse * x1a8_localScaleTransformInverse) * xdc_translation;
|
|
|
|
particle.x4_pos = compXf1 + xf4_POFS;
|
|
|
|
particle.x1c_vel.zeroOut();
|
|
|
|
}
|
|
|
|
particle.x10_prevPos = particle.x4_pos;
|
|
|
|
|
|
|
|
if (x26c_31_LINE) {
|
|
|
|
if (CRealElement* leng = desc->x20_x14_LENG.get())
|
|
|
|
leng->GetValue(0, particle.x2c_lineLengthOrSize);
|
|
|
|
else
|
|
|
|
particle.x2c_lineLengthOrSize = 1.f;
|
|
|
|
|
|
|
|
if (CRealElement* widt = desc->x24_x18_WIDT.get())
|
|
|
|
widt->GetValue(0, particle.x30_lineWidthOrRota);
|
|
|
|
else
|
|
|
|
particle.x30_lineWidthOrRota = 1.f;
|
|
|
|
} else {
|
|
|
|
if (CRealElement* rota = desc->x50_x3c_ROTA.get())
|
|
|
|
rota->GetValue(0, particle.x30_lineWidthOrRota);
|
|
|
|
else
|
|
|
|
particle.x30_lineWidthOrRota = 0.f;
|
|
|
|
|
|
|
|
if (CRealElement* size = desc->x4c_x38_SIZE.get())
|
|
|
|
size->GetValue(0, particle.x2c_lineLengthOrSize);
|
|
|
|
else
|
|
|
|
particle.x2c_lineLengthOrSize = 0.1f;
|
|
|
|
}
|
|
|
|
|
|
|
|
AccumulateBounds(particle.x4_pos, particle.x2c_lineLengthOrSize);
|
|
|
|
}
|
2016-02-10 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::UpdatePSTranslationAndOrientation() {
|
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
2016-02-11 23:05:42 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGlobalRandom gr(x27c_randState);
|
|
|
|
if (x268_PSLT < x74_curFrame)
|
|
|
|
return;
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CVectorElement* pofs = desc->x18_xc_POFS.get())
|
|
|
|
pofs->GetValue(x74_curFrame, xf4_POFS);
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CVectorElement* sspo = desc->xe8_xd4_SSPO.get())
|
|
|
|
sspo->GetValue(x74_curFrame, x2b0_SSPO);
|
2016-02-11 02:36:21 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CVectorElement* sepo = desc->xfc_xe8_SEPO.get())
|
|
|
|
sepo->GetValue(x74_curFrame, x2c0_SEPO);
|
2016-02-10 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 10:04:11 +00:00
|
|
|
std::unique_ptr<CParticleGen> CElementGen::ConstructChildParticleSystem(const TToken<CGenDescription>& desc) const {
|
2021-04-03 16:48:39 +00:00
|
|
|
OPTICK_EVENT();
|
2019-09-12 03:50:38 +00:00
|
|
|
auto ret = std::make_unique<CElementGen>(desc, EModelOrientationType::Normal,
|
|
|
|
x26d_27_enableOPTS ? EOptionalSystemFlags::Two : EOptionalSystemFlags::One);
|
2018-12-08 05:30:43 +00:00
|
|
|
ret->x26d_26_modelsUseLights = x26d_26_modelsUseLights;
|
|
|
|
ret->SetGlobalTranslation(xe8_globalTranslation);
|
|
|
|
ret->SetGlobalOrientation(x22c_globalOrientation);
|
|
|
|
ret->SetGlobalScale(x100_globalScale);
|
|
|
|
ret->SetLocalScale(x16c_localScale);
|
|
|
|
ret->SetTranslation(xdc_translation);
|
|
|
|
ret->SetOrientation(x1d8_orientation);
|
|
|
|
ret->SetParticleEmission(x88_particleEmission);
|
|
|
|
ret->SetModulationColor(x338_moduColor);
|
2019-09-12 03:50:38 +00:00
|
|
|
return ret;
|
2016-02-11 06:58:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::UpdateChildParticleSystems(double dt) {
|
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
2016-02-11 23:05:42 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGlobalRandom gr(x27c_randState);
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
SChildGeneratorDesc& icts = desc->x8c_x78_ICTS;
|
2022-03-10 23:56:55 +00:00
|
|
|
if (icts && x84_prevFrame != x74_curFrame && x2a0_CSSD == x74_curFrame) {
|
2018-12-08 05:30:43 +00:00
|
|
|
int ncsyVal = 1;
|
|
|
|
if (CIntElement* ncsy = desc->x9c_x88_NCSY.get())
|
|
|
|
ncsy->GetValue(x74_curFrame, ncsyVal);
|
2016-02-11 06:58:33 +00:00
|
|
|
|
2022-03-10 23:56:55 +00:00
|
|
|
CGenDescription* ictsDesc = icts.GetObj();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!(x26d_27_enableOPTS && ictsDesc->x45_31_x32_25_OPTS)) {
|
|
|
|
x290_activePartChildren.reserve(ncsyVal + x290_activePartChildren.size());
|
|
|
|
for (int i = 0; i < ncsyVal; ++i) {
|
2022-03-10 23:56:55 +00:00
|
|
|
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(*icts);
|
2018-12-08 05:30:43 +00:00
|
|
|
x290_activePartChildren.emplace_back(std::move(chGen));
|
|
|
|
}
|
2016-02-11 06:58:33 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-11 06:58:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
SChildGeneratorDesc& iits = desc->xb8_xa4_IITS;
|
2022-03-10 23:56:55 +00:00
|
|
|
if (iits && x84_prevFrame != x74_curFrame && x74_curFrame < x268_PSLT && x88_particleEmission == 1 &&
|
2018-12-08 05:30:43 +00:00
|
|
|
x74_curFrame >= x2a4_SISY && ((x74_curFrame - x2a4_SISY) % x2a8_PISY) == 0) {
|
2022-03-10 23:56:55 +00:00
|
|
|
CGenDescription* iitsDesc = iits.GetObj();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!(x26d_27_enableOPTS && iitsDesc->x45_31_x32_25_OPTS)) {
|
2022-03-10 23:56:55 +00:00
|
|
|
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(*iits);
|
2018-12-08 05:30:43 +00:00
|
|
|
x290_activePartChildren.emplace_back(std::move(chGen));
|
2016-02-11 06:58:33 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-11 06:58:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CSpawnSystemKeyframeData* kssm = desc->xd0_xbc_KSSM.get();
|
|
|
|
if (kssm && x84_prevFrame != x74_curFrame && x74_curFrame < x268_PSLT) {
|
|
|
|
u16 backupSeed = g_GlobalSeed;
|
|
|
|
u16 incSeed = backupSeed;
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::vector<CSpawnSystemKeyframeData::CSpawnSystemKeyframeInfo>& systems =
|
2017-06-04 01:01:09 +00:00
|
|
|
kssm->GetSpawnedSystemsAtFrame(x74_curFrame);
|
2018-12-08 05:30:43 +00:00
|
|
|
x290_activePartChildren.reserve(x290_activePartChildren.size() + systems.size());
|
|
|
|
for (CSpawnSystemKeyframeData::CSpawnSystemKeyframeInfo& system : systems) {
|
|
|
|
TLockedToken<CGenDescription>& token = system.GetToken();
|
|
|
|
if (!(x26d_27_enableOPTS && token.GetObj()->x45_31_x32_25_OPTS)) {
|
|
|
|
g_GlobalSeed = incSeed;
|
|
|
|
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(token);
|
|
|
|
x290_activePartChildren.emplace_back(std::move(chGen));
|
|
|
|
}
|
|
|
|
incSeed += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_GlobalSeed = backupSeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
SChildGeneratorDesc& idts = desc->xa4_x90_IDTS;
|
2022-03-10 23:56:55 +00:00
|
|
|
if (idts && x74_curFrame == x268_PSLT && x84_prevFrame != x74_curFrame) {
|
2018-12-08 05:30:43 +00:00
|
|
|
int ndsyVal = 1;
|
|
|
|
if (CIntElement* ndsy = desc->xb4_xa0_NDSY.get())
|
|
|
|
ndsy->GetValue(0, ndsyVal);
|
|
|
|
|
2022-03-10 23:56:55 +00:00
|
|
|
CGenDescription* idtsDesc = idts.GetObj();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!(x26d_27_enableOPTS && idtsDesc->x45_31_x32_25_OPTS)) {
|
|
|
|
x290_activePartChildren.reserve(ndsyVal + x290_activePartChildren.size());
|
|
|
|
for (int i = 0; i < ndsyVal; ++i) {
|
2022-03-10 23:56:55 +00:00
|
|
|
std::unique_ptr<CParticleGen> chGen = ConstructChildParticleSystem(*idts);
|
2018-12-08 05:30:43 +00:00
|
|
|
x290_activePartChildren.emplace_back(std::move(chGen));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SSwooshGeneratorDesc& sswh = desc->xd4_xc0_SSWH;
|
2022-03-10 23:56:55 +00:00
|
|
|
if (sswh && x84_prevFrame != x74_curFrame && x74_curFrame == x2ac_SSSD) {
|
|
|
|
std::unique_ptr<CParticleGen> sswhGen = std::make_unique<CParticleSwoosh>(*sswh, 0);
|
2018-12-08 05:30:43 +00:00
|
|
|
sswhGen->SetGlobalTranslation(xe8_globalTranslation);
|
|
|
|
sswhGen->SetGlobalScale(x100_globalScale);
|
|
|
|
sswhGen->SetLocalScale(x16c_localScale);
|
|
|
|
sswhGen->SetTranslation(xdc_translation + x2b0_SSPO);
|
|
|
|
sswhGen->SetOrientation(x1d8_orientation);
|
|
|
|
sswhGen->SetParticleEmission(x88_particleEmission);
|
|
|
|
x290_activePartChildren.emplace_back(std::move(sswhGen));
|
|
|
|
}
|
|
|
|
|
|
|
|
SElectricGeneratorDesc& selc = desc->xec_xd8_SELC;
|
2022-03-10 23:56:55 +00:00
|
|
|
if (selc && x84_prevFrame != x74_curFrame && x74_curFrame == x2bc_SESD) {
|
|
|
|
std::unique_ptr<CParticleGen> selcGen = std::make_unique<CParticleElectric>(*selc);
|
2018-12-08 05:30:43 +00:00
|
|
|
selcGen->SetGlobalTranslation(xe8_globalTranslation);
|
|
|
|
selcGen->SetGlobalScale(x100_globalScale);
|
|
|
|
selcGen->SetLocalScale(x16c_localScale);
|
|
|
|
selcGen->SetTranslation(xdc_translation + x2c0_SEPO);
|
|
|
|
selcGen->SetOrientation(x1d8_orientation);
|
|
|
|
selcGen->SetParticleEmission(x88_particleEmission);
|
|
|
|
x290_activePartChildren.emplace_back(std::move(selcGen));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto p = x290_activePartChildren.begin(); p != x290_activePartChildren.end();) {
|
|
|
|
std::unique_ptr<CParticleGen>& ch = *p;
|
|
|
|
|
|
|
|
ch->Update(dt);
|
|
|
|
if (ch->IsSystemDeletable()) {
|
|
|
|
p = x290_activePartChildren.erase(p);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
|
|
|
|
x84_prevFrame = x74_curFrame;
|
2016-02-10 02:00:28 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::UpdateLightParameters() {
|
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
2016-02-11 23:05:42 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CColorElement* lclr = desc->x104_xf0_LCLR.get())
|
|
|
|
lclr->GetValue(x74_curFrame, x30c_LCLR);
|
2016-02-11 22:38:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CRealElement* lint = desc->x108_xf4_LINT.get())
|
|
|
|
lint->GetValue(x74_curFrame, x310_LINT);
|
2016-02-11 22:38:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
switch (x308_lightType) {
|
|
|
|
default:
|
|
|
|
case LightType::None:
|
|
|
|
case LightType::Custom:
|
|
|
|
case LightType::Spot: {
|
|
|
|
if (CVectorElement* loff = desc->x10c_xf8_LOFF.get())
|
|
|
|
loff->GetValue(x74_curFrame, x314_LOFF);
|
2016-02-11 22:38:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (CRealElement* lfor = desc->x118_x104_LFOR.get())
|
|
|
|
lfor->GetValue(x74_curFrame, x330_LFOR);
|
2016-02-11 22:38:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (x308_lightType == LightType::Spot) {
|
|
|
|
if (CRealElement* lsla = desc->x11c_x108_LSLA.get())
|
|
|
|
lsla->GetValue(x74_curFrame, x334_LSLA);
|
2016-02-11 22:38:25 +00:00
|
|
|
}
|
2019-02-18 05:47:46 +00:00
|
|
|
[[fallthrough]];
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
case LightType::Directional: {
|
|
|
|
if (x308_lightType != LightType::Custom) {
|
|
|
|
if (CVectorElement* ldir = desc->x110_xfc_LDIR.get())
|
|
|
|
ldir->GetValue(x74_curFrame, x320_LDIR);
|
2016-02-11 22:38:25 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-11 22:38:25 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 CElementGen::GetParticleCountAllInternal() const {
|
|
|
|
u32 ret = x25c_activeParticleCount;
|
2016-02-11 22:38:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
if (ch->Get4CharId() == FOURCC('PART'))
|
|
|
|
ret += static_cast<CElementGen&>(*ch).GetParticleCountAll();
|
2016-02-26 03:31:00 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
return ret;
|
2016-03-19 02:04:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::EndLifetime() {
|
|
|
|
x268_PSLT = 0;
|
|
|
|
for (std::unique_ptr<CParticleGen>& ch : x290_activePartChildren) {
|
|
|
|
if (ch->Get4CharId() == FOURCC('PART'))
|
|
|
|
static_cast<CElementGen&>(*ch).EndLifetime();
|
2016-02-11 22:38:25 +00:00
|
|
|
else
|
2018-12-08 05:30:43 +00:00
|
|
|
ch->SetParticleEmission(false);
|
|
|
|
}
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::ForceParticleCreation(int amount) {
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::SParticleSystem* prevSystem = CParticleGlobals::instance()->m_currentParticleSystem;
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticleGlobals::SParticleSystem thisSystem{FOURCC('PART'), this};
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_currentParticleSystem = &thisSystem;
|
|
|
|
CParticleGlobals::instance()->SetEmitterTime(x74_curFrame);
|
2018-12-08 05:30:43 +00:00
|
|
|
CreateNewParticles(amount);
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_currentParticleSystem = prevSystem;
|
2016-02-11 19:18:14 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::BuildParticleSystemBounds() {
|
|
|
|
zeus::CAABox aabb;
|
|
|
|
bool accumulated = false;
|
|
|
|
|
|
|
|
for (std::unique_ptr<CParticleGen>& ch : x290_activePartChildren) {
|
|
|
|
auto chBounds = ch->GetBounds();
|
|
|
|
if (chBounds) {
|
|
|
|
accumulated = true;
|
|
|
|
aabb.accumulateBounds(chBounds.value());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
x264_recursiveParticleCount = GetParticleCountAllInternal();
|
|
|
|
if (GetParticleCount() > 0) {
|
|
|
|
zeus::CVector3f scale = x100_globalScale * x2ec_maxSize;
|
|
|
|
zeus::CTransform xf = (x10c_globalScaleTransform * x22c_globalOrientation) * x178_localScaleTransform;
|
|
|
|
zeus::CAABox box = zeus::CAABox(x2d4_aabbMin, x2e0_aabbMax).getTransformedAABox(xf);
|
|
|
|
zeus::CVector3f min = box.min + xe8_globalTranslation - scale;
|
|
|
|
zeus::CVector3f max = box.max + xe8_globalTranslation + scale;
|
|
|
|
x2f0_systemBounds = zeus::CAABox(min, max);
|
|
|
|
} else
|
2019-02-24 07:15:54 +00:00
|
|
|
x2f0_systemBounds = zeus::CAABox();
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (accumulated)
|
|
|
|
x2f0_systemBounds.accumulateBounds(aabb);
|
2016-02-12 02:36:34 +00:00
|
|
|
}
|
|
|
|
|
2020-03-09 17:03:40 +00:00
|
|
|
u32 CElementGen::GetSystemCount() const {
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 ret = 0;
|
|
|
|
for (const std::unique_ptr<CParticleGen>& child : x290_activePartChildren) {
|
2020-03-09 17:03:40 +00:00
|
|
|
if (child->Get4CharId() == FOURCC('PART')) {
|
|
|
|
ret += static_cast<const CElementGen&>(*child).GetSystemCount();
|
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
ret += 1;
|
2020-03-09 17:03:40 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-25 06:23:35 +00:00
|
|
|
|
2020-03-09 17:03:40 +00:00
|
|
|
return ret + (x25c_activeParticleCount != 0);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
void CElementGen::Render() {
|
2021-04-21 01:00:03 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::Render {}"), *x1c_genDesc.GetObjectTag()).c_str(),
|
|
|
|
zeus::skYellow);
|
2019-07-21 08:42:52 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x274_backupLightActive = CGraphics::g_LightActive;
|
|
|
|
CGraphics::DisableAllLights();
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (std::unique_ptr<CParticleGen>& child : x290_activePartChildren)
|
2022-03-20 20:24:02 +00:00
|
|
|
child->Render();
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::SParticleSystem* prevSystem = CParticleGlobals::instance()->m_currentParticleSystem;
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticleGlobals::SParticleSystem thisSystem{FOURCC('PART'), this};
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_currentParticleSystem = &thisSystem;
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
if (!x30_particles.empty()) {
|
|
|
|
if (desc->x5c_x48_PMDL || desc->x45_24_x31_26_PMUS) {
|
|
|
|
RenderModels();
|
|
|
|
}
|
|
|
|
if (x26c_31_LINE) {
|
2018-12-08 05:30:43 +00:00
|
|
|
RenderLines();
|
2022-03-20 20:24:02 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
RenderParticles();
|
2022-03-20 20:24:02 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_currentParticleSystem = prevSystem;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
void CElementGen::RenderModels() {
|
2022-05-04 00:27:19 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::RenderModels")).c_str(), zeus::skYellow);
|
2022-03-27 00:23:16 +00:00
|
|
|
|
2021-03-17 04:49:18 +00:00
|
|
|
CParticleGlobals::instance()->m_particleAccessParameters = nullptr;
|
2022-03-19 17:30:25 +00:00
|
|
|
if (x26d_26_modelsUseLights) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetLightState(x274_backupLightActive);
|
2022-03-19 17:30:25 +00:00
|
|
|
} else {
|
|
|
|
CGraphics::SetAmbientColor(zeus::skWhite);
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
CGlobalRandom gr(x27c_randState);
|
|
|
|
|
2021-03-17 04:49:18 +00:00
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
SUVElementSet uvs = {0.f, 0.f, 1.f, 1.f};
|
|
|
|
CUVElement* texr = desc->x54_x40_TEXR.get();
|
|
|
|
CTexture* cachedTex = nullptr;
|
|
|
|
bool texConst = true;
|
|
|
|
bool moveRedToAlphaBuffer = false;
|
|
|
|
|
|
|
|
if (desc->x45_24_x31_26_PMUS) {
|
2022-03-19 17:30:25 +00:00
|
|
|
if (sMoveRedToAlphaBuffer && desc->x44_31_x31_25_PMAB && desc->x54_x40_TEXR) {
|
2018-12-08 05:30:43 +00:00
|
|
|
moveRedToAlphaBuffer = true;
|
2022-03-19 17:30:25 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (desc->x44_31_x31_25_PMAB) {
|
|
|
|
CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, false);
|
2022-03-19 17:30:25 +00:00
|
|
|
if (moveRedToAlphaBuffer) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One, ERglBlendFactor::One, ERglLogicOp::Clear);
|
2022-03-19 17:30:25 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::One,
|
|
|
|
ERglLogicOp::Clear);
|
2022-03-19 17:30:25 +00:00
|
|
|
CGraphics::SetAlphaCompare(ERglAlphaFunc::Greater, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
|
|
|
CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, true);
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha,
|
|
|
|
ERglLogicOp::Clear);
|
2022-03-19 17:30:25 +00:00
|
|
|
CGraphics::SetAlphaCompare(ERglAlphaFunc::Greater, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CGraphics::SetCullMode(ERglCullMode::None);
|
|
|
|
|
|
|
|
if (texr) {
|
|
|
|
CParticle& target = x30_particles[0];
|
|
|
|
int partFrame = x74_curFrame - target.x28_startFrame;
|
|
|
|
cachedTex = texr->GetValueTexture(partFrame).GetObj();
|
2022-07-29 20:16:55 +00:00
|
|
|
cachedTex->Load(GX_TEXMAP0, EClampMode::Repeat);
|
2022-03-19 17:30:25 +00:00
|
|
|
|
2022-08-15 22:50:20 +00:00
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (moveRedToAlphaBuffer) {
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_CPREV, GX_CC_APREV, GX_CC_ZERO);
|
|
|
|
CGX::SetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_TEXA, GX_CA_APREV, GX_CA_ZERO);
|
|
|
|
CGX::SetStandardTevColorAlphaOp(GX_TEVSTAGE1);
|
|
|
|
CGX::SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL);
|
|
|
|
GXSetTevSwapMode(GX_TEVSTAGE1, GX_TEV_SWAP0, GX_TEV_SWAP1);
|
2022-03-19 17:30:25 +00:00
|
|
|
CGX::SetNumTevStages(2);
|
|
|
|
constexpr std::array vtxDescList{
|
2022-07-29 20:16:55 +00:00
|
|
|
GXVtxDescList{GX_VA_POS, GX_DIRECT},
|
|
|
|
GXVtxDescList{GX_VA_CLR0, GX_DIRECT},
|
|
|
|
GXVtxDescList{GX_VA_TEX0, GX_DIRECT},
|
|
|
|
GXVtxDescList{GX_VA_NULL, GX_NONE},
|
2022-03-19 17:30:25 +00:00
|
|
|
};
|
|
|
|
CGX::SetVtxDescv(vtxDescList.data());
|
|
|
|
CGX::SetChanCtrl(CGX::EChannelId::Channel0, {});
|
|
|
|
CGX::SetNumChans(1);
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY);
|
|
|
|
CGX::SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
|
2022-03-19 17:30:25 +00:00
|
|
|
CGX::SetNumTexGens(1);
|
|
|
|
} else {
|
2022-08-15 22:50:20 +00:00
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2022-03-19 17:30:25 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
texConst = texr->HasConstantTexture();
|
|
|
|
texr->GetValueUV(partFrame, uvs);
|
2022-03-19 17:30:25 +00:00
|
|
|
} else {
|
2022-08-15 22:50:20 +00:00
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvPassthru);
|
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CTransform orient = zeus::CTransform();
|
2019-03-13 03:46:20 +00:00
|
|
|
if (!desc->x45_25_x31_27_PMOO)
|
2018-12-08 05:30:43 +00:00
|
|
|
orient = x1d8_orientation;
|
|
|
|
orient = orient * x22c_globalOrientation;
|
|
|
|
|
|
|
|
CVectorElement* pmrt = desc->x70_x5c_PMRT.get();
|
|
|
|
bool pmrtConst = false;
|
|
|
|
if (pmrt)
|
|
|
|
pmrtConst = pmrt->IsFastConstant();
|
|
|
|
|
|
|
|
zeus::CVector3f trans = (x13c_globalScaleTransformInverse * x1a8_localScaleTransformInverse) * xe8_globalTranslation;
|
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CTransform rot = zeus::CTransform();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (pmrtConst) {
|
|
|
|
zeus::CVector3f pmrtVal;
|
|
|
|
pmrt->GetValue(x74_curFrame, pmrtVal);
|
|
|
|
rot = zeus::CTransform::RotateZ(zeus::degToRad(pmrtVal[2]));
|
|
|
|
rot.rotateLocalY(zeus::degToRad(pmrtVal[1]));
|
|
|
|
rot.rotateLocalX(zeus::degToRad(pmrtVal[0]));
|
|
|
|
}
|
|
|
|
rot = orient * rot;
|
|
|
|
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetEmitterTime(x74_curFrame);
|
2020-04-19 03:41:35 +00:00
|
|
|
zeus::CColor col = x338_moduColor;
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
zeus::CVector3f pmopVec;
|
|
|
|
auto matrixIt = x50_parentMatrices.begin();
|
2020-03-09 16:54:59 +00:00
|
|
|
for (size_t i = 0; i < x30_particles.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticle& particle = x30_particles[i];
|
|
|
|
g_currentParticle = &particle;
|
|
|
|
|
|
|
|
if (particle.x0_endFrame == -1) {
|
|
|
|
if (x2c_orientType == EModelOrientationType::One)
|
|
|
|
++matrixIt;
|
|
|
|
continue;
|
|
|
|
}
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame - particle.x28_startFrame);
|
2018-12-08 05:30:43 +00:00
|
|
|
int partFrame = x74_curFrame - particle.x28_startFrame - 1;
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(partFrame);
|
2021-03-17 04:49:18 +00:00
|
|
|
if (x26d_28_enableADV) {
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->m_particleAccessParameters = &x60_advValues[i];
|
2021-03-17 04:49:18 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CVectorElement* pmop = desc->x6c_x58_PMOP.get();
|
|
|
|
if (pmop)
|
|
|
|
pmop->GetValue(partFrame, pmopVec);
|
|
|
|
|
|
|
|
zeus::CTransform partTrans = zeus::CTransform::Translate(particle.x4_pos + trans);
|
|
|
|
if (x2c_orientType == EModelOrientationType::One) {
|
|
|
|
zeus::CTransform partRot(*matrixIt);
|
|
|
|
zeus::CVector3f pmopRotateOffset = (orient * partRot) * pmopVec;
|
|
|
|
partTrans = partTrans * partRot;
|
|
|
|
partTrans += pmopRotateOffset;
|
|
|
|
} else {
|
|
|
|
partTrans += orient * pmopVec;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pmrtConst) {
|
|
|
|
partTrans = partTrans * rot;
|
|
|
|
} else {
|
|
|
|
if (pmrt) {
|
|
|
|
zeus::CVector3f pmrtVal;
|
|
|
|
pmrt->GetValue(partFrame, pmrtVal);
|
|
|
|
rot = zeus::CTransform::RotateZ(zeus::degToRad(pmrtVal[2]));
|
|
|
|
rot.rotateLocalY(zeus::degToRad(pmrtVal[1]));
|
|
|
|
rot.rotateLocalX(zeus::degToRad(pmrtVal[0]));
|
|
|
|
partTrans = partTrans * (orient * rot);
|
|
|
|
} else {
|
|
|
|
partTrans = partTrans * rot;
|
|
|
|
}
|
2016-02-13 00:57:09 +00:00
|
|
|
}
|
2016-02-12 02:36:34 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CVectorElement* pmsc = desc->x74_x60_PMSC.get();
|
|
|
|
if (pmsc) {
|
|
|
|
zeus::CVector3f pmscVal;
|
|
|
|
pmsc->GetValue(partFrame, pmscVal);
|
|
|
|
partTrans = partTrans * zeus::CTransform::Scale(pmscVal);
|
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CColorElement* pmcl = desc->x78_x64_PMCL.get();
|
2020-04-19 03:41:35 +00:00
|
|
|
if (pmcl) {
|
2018-12-08 05:30:43 +00:00
|
|
|
pmcl->GetValue(partFrame, col);
|
2020-04-19 03:41:35 +00:00
|
|
|
col *= x338_moduColor;
|
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetModelMatrix((x10c_globalScaleTransform * partTrans) * x178_localScaleTransform);
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (desc->x45_24_x31_26_PMUS) {
|
2022-03-19 17:30:25 +00:00
|
|
|
if (moveRedToAlphaBuffer) {
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::Begin(GX_QUADS, GX_VTXFMT0, 4);
|
2022-03-19 17:30:25 +00:00
|
|
|
GXPosition3f32(0.5f, 0.f, 0.5f);
|
|
|
|
GXColor4f32(col);
|
|
|
|
GXTexCoord2f32(uvs.xMax, uvs.yMax);
|
|
|
|
GXPosition3f32(-0.5f, 0.f, 0.5f);
|
|
|
|
GXColor4f32(col);
|
|
|
|
GXTexCoord2f32(uvs.xMin, uvs.yMax);
|
|
|
|
GXPosition3f32(-0.5f, 0.f, -0.5f);
|
|
|
|
GXColor4f32(col);
|
|
|
|
GXTexCoord2f32(uvs.xMin, uvs.yMin);
|
|
|
|
GXPosition3f32(0.5f, 0.f, -0.5f);
|
|
|
|
GXColor4f32(col);
|
|
|
|
GXTexCoord2f32(uvs.xMax, uvs.yMin);
|
|
|
|
CGX::End();
|
|
|
|
} else {
|
2022-07-29 20:16:55 +00:00
|
|
|
CGraphics::StreamBegin(GX_QUADS);
|
2022-03-19 17:30:25 +00:00
|
|
|
CGraphics::StreamColor(col);
|
|
|
|
CGraphics::StreamTexcoord(uvs.xMax, uvs.yMax);
|
|
|
|
CGraphics::StreamVertex(0.5f, 0.f, 0.5f);
|
|
|
|
CGraphics::StreamTexcoord(uvs.xMin, uvs.yMax);
|
|
|
|
CGraphics::StreamVertex(-0.5f, 0.f, 0.5f);
|
|
|
|
CGraphics::StreamTexcoord(uvs.xMin, uvs.yMin);
|
|
|
|
CGraphics::StreamVertex(-0.5f, 0.f, -0.5f);
|
|
|
|
CGraphics::StreamTexcoord(uvs.xMax, uvs.yMin);
|
|
|
|
CGraphics::StreamVertex(0.5f, 0.f, -0.5f);
|
|
|
|
CGraphics::StreamEnd();
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-03-10 23:56:55 +00:00
|
|
|
CModel* model = desc->x5c_x48_PMDL.GetObj();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (g_subtractBlend) {
|
2022-03-19 17:30:25 +00:00
|
|
|
model->Draw({5, 0, 1, zeus::CColor{1.f, 0.5f}});
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (desc->x44_31_x31_25_PMAB) {
|
2022-03-19 17:30:25 +00:00
|
|
|
model->Draw({7, 0, 1, col});
|
2020-04-19 03:41:35 +00:00
|
|
|
} else if (1.f == col.a()) {
|
|
|
|
model->Draw({0, 0, 3, zeus::skWhite});
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
2022-03-19 17:30:25 +00:00
|
|
|
model->Draw({5, 0, 1, zeus::CColor{1.f, col.a()}});
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (x2c_orientType == EModelOrientationType::One)
|
|
|
|
++matrixIt;
|
|
|
|
}
|
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
if (x26d_26_modelsUseLights) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::DisableAllLights();
|
2022-03-19 17:30:25 +00:00
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetCullMode(ERglCullMode::Front);
|
2022-03-20 20:24:02 +00:00
|
|
|
CTevCombiners::ResetStates();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (moveRedToAlphaBuffer) {
|
2022-07-29 20:16:55 +00:00
|
|
|
GXSetTevSwapMode(GX_TEVSTAGE1, GX_TEV_SWAP0, GX_TEV_SWAP0);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2022-03-19 17:30:25 +00:00
|
|
|
CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::RenderLines() {
|
2022-05-04 00:27:19 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::RenderLines")).c_str(), zeus::skYellow);
|
2022-03-27 00:23:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
|
|
|
CGlobalRandom gr(x27c_randState);
|
|
|
|
|
|
|
|
zeus::CTransform systemViewPointMatrix(CGraphics::g_ViewMatrix);
|
|
|
|
systemViewPointMatrix.origin.zeroOut();
|
|
|
|
zeus::CTransform systemCameraMatrix = systemViewPointMatrix.inverse() * x22c_globalOrientation;
|
|
|
|
systemViewPointMatrix =
|
|
|
|
((zeus::CTransform::Translate(xe8_globalTranslation) * x10c_globalScaleTransform) * systemViewPointMatrix) *
|
|
|
|
x178_localScaleTransform;
|
|
|
|
CGraphics::SetModelMatrix(systemViewPointMatrix);
|
|
|
|
|
|
|
|
CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);
|
|
|
|
|
|
|
|
if (x26c_26_AAPH) {
|
|
|
|
CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, false);
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::One, ERglLogicOp::Clear);
|
|
|
|
} else {
|
|
|
|
CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, true);
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha,
|
|
|
|
ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
|
|
|
|
CRealElement* widt = desc->x24_x18_WIDT.get();
|
|
|
|
bool widtConst = false;
|
|
|
|
if (widt)
|
|
|
|
widtConst = widt->IsConstant();
|
|
|
|
|
|
|
|
CUVElement* texr = desc->x54_x40_TEXR.get();
|
|
|
|
SUVElementSet uvs = {0.f, 0.f, 1.f, 1.f};
|
|
|
|
bool constTexr = true;
|
|
|
|
bool constUVs = true;
|
|
|
|
CTexture* cachedTex = nullptr;
|
2019-02-24 07:15:54 +00:00
|
|
|
zeus::CColor moduColor = zeus::skWhite;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (texr) {
|
|
|
|
CParticle& target = x30_particles[0];
|
|
|
|
int partFrame = x74_curFrame - target.x28_startFrame;
|
|
|
|
cachedTex = texr->GetValueTexture(partFrame).GetObj();
|
2022-07-29 20:16:55 +00:00
|
|
|
cachedTex->Load(GX_TEXMAP0, EClampMode::Repeat);
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
/* Set TEXC * RASC */
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2019-02-24 07:15:54 +00:00
|
|
|
if (x338_moduColor != zeus::skBlack) {
|
2018-12-08 05:30:43 +00:00
|
|
|
/* Add RASC * PREVC pass for MODU color loaded into channel mat-color */
|
|
|
|
moduColor = x338_moduColor;
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
constTexr = texr->HasConstantTexture();
|
|
|
|
texr->GetValueUV(partFrame, uvs);
|
|
|
|
constUVs = texr->HasConstantUV();
|
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
float constWidth = 1.f;
|
|
|
|
if (widtConst) {
|
|
|
|
widt->GetValue(0, constWidth);
|
|
|
|
constWidth = std::max(0.f, std::min(constWidth, 42.5f));
|
|
|
|
}
|
2016-02-18 02:42:32 +00:00
|
|
|
|
2022-03-09 07:32:01 +00:00
|
|
|
// m_lineRenderer->Reset();
|
2016-02-25 06:23:35 +00:00
|
|
|
|
2020-04-14 20:08:17 +00:00
|
|
|
for (auto& particle : x30_particles) {
|
2018-12-08 05:30:43 +00:00
|
|
|
g_currentParticle = &particle;
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
int partFrame = x74_curFrame - particle.x28_startFrame;
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!constTexr) {
|
|
|
|
CTexture* tex = texr->GetValueTexture(partFrame).GetObj();
|
|
|
|
if (tex != cachedTex) {
|
2022-07-29 20:16:55 +00:00
|
|
|
tex->Load(GX_TEXMAP0, EClampMode::Repeat);
|
2018-12-08 05:30:43 +00:00
|
|
|
cachedTex = tex;
|
|
|
|
}
|
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!constUVs)
|
|
|
|
texr->GetValueUV(partFrame, uvs);
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f dVec = particle.x4_pos - particle.x10_prevPos;
|
|
|
|
if (x26d_24_FXLL)
|
|
|
|
if (dVec.magSquared() >= 0.f)
|
|
|
|
dVec.normalize();
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f p1 = systemCameraMatrix * particle.x4_pos;
|
|
|
|
zeus::CVector3f p2 = systemCameraMatrix * (particle.x2c_lineLengthOrSize * dVec + particle.x4_pos);
|
|
|
|
|
|
|
|
if (widtConst) {
|
2022-03-09 07:32:01 +00:00
|
|
|
// m_lineRenderer->AddVertex(p1, particle.x34_color, constWidth, {uvs.xMin, uvs.yMin});
|
|
|
|
// m_lineRenderer->AddVertex(p2, particle.x34_color, constWidth, {uvs.xMax, uvs.yMax});
|
2018-12-08 05:30:43 +00:00
|
|
|
} else if (widt) {
|
|
|
|
float width = 1.f;
|
|
|
|
widt->GetValue(0, width);
|
|
|
|
width = std::max(0.f, std::min(width, 42.5f));
|
2022-03-09 07:32:01 +00:00
|
|
|
// m_lineRenderer->AddVertex(p1, particle.x34_color, width, {uvs.xMin, uvs.yMin});
|
|
|
|
// m_lineRenderer->AddVertex(p2, particle.x34_color, width, {uvs.xMax, uvs.yMax});
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
// m_lineRenderer->Render(g_Renderer->IsThermalVisorHotPass(), moduColor);
|
2016-02-12 02:36:34 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::RenderParticles() {
|
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
|
|
|
CGlobalRandom gr(x27c_randState);
|
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
if (IsIndirectTextured()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
RenderParticlesIndirectTexture();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-05-04 00:27:19 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::RenderParticles")).c_str(), zeus::skYellow);
|
2022-03-27 00:23:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CRealElement* size = desc->x4c_x38_SIZE.get();
|
|
|
|
if (size && size->IsConstant()) {
|
|
|
|
float sizeVal;
|
|
|
|
size->GetValue(0, sizeVal);
|
|
|
|
if (sizeVal == 0.f) {
|
|
|
|
size->GetValue(1, sizeVal);
|
|
|
|
if (sizeVal == 0.f)
|
2016-02-13 00:57:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2022-03-27 00:23:44 +00:00
|
|
|
bool hasModuColor = x338_moduColor != zeus::skWhite;
|
2022-03-20 20:24:02 +00:00
|
|
|
CGraphics::SetCullMode(ERglCullMode::None);
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CTransform systemModelMatrix(CGraphics::g_ViewMatrix);
|
|
|
|
systemModelMatrix.origin.zeroOut();
|
|
|
|
zeus::CTransform systemCameraMatrix = systemModelMatrix.inverse() * x22c_globalOrientation;
|
|
|
|
systemModelMatrix =
|
|
|
|
((zeus::CTransform::Translate(xe8_globalTranslation) * x10c_globalScaleTransform) * systemModelMatrix) *
|
|
|
|
x178_localScaleTransform;
|
|
|
|
if (x26c_29_ORNT)
|
|
|
|
CGraphics::SetModelMatrix(systemModelMatrix * systemCameraMatrix);
|
|
|
|
else
|
|
|
|
CGraphics::SetModelMatrix(systemModelMatrix);
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
CGraphics::SetAlphaCompare(ERglAlphaFunc::Greater, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
SUVElementSet uvs = {0.f, 0.f, 1.f, 1.f};
|
|
|
|
bool constUVs = true;
|
|
|
|
CTexture* cachedTex = nullptr;
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
auto* rota = x28_loadedGenDesc->x50_x3c_ROTA.get();
|
|
|
|
bool noRota = rota == nullptr;
|
|
|
|
if (rota != nullptr && rota->IsConstant()) {
|
|
|
|
float value = 1.f;
|
|
|
|
rota->GetValue(0, value);
|
|
|
|
if (value == 0.f) {
|
|
|
|
value = 1.f;
|
|
|
|
rota->GetValue(1, value);
|
|
|
|
if (value == 0.f) {
|
|
|
|
noRota = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
auto* texr = x28_loadedGenDesc->x54_x40_TEXR.get();
|
|
|
|
if (texr != nullptr) {
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticle& target = x30_particles[0];
|
|
|
|
int partFrame = x74_curFrame - target.x28_startFrame;
|
|
|
|
cachedTex = texr->GetValueTexture(partFrame).GetObj();
|
2022-07-29 20:16:55 +00:00
|
|
|
cachedTex->Load(GX_TEXMAP0, EClampMode::Repeat);
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2022-08-15 22:50:20 +00:00
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvModulate);
|
2022-03-20 20:24:02 +00:00
|
|
|
if (hasModuColor) {
|
2018-12-08 05:30:43 +00:00
|
|
|
/* Add RASC * PREVC pass for MODU color loaded into channel mat-color */
|
2022-08-15 22:50:20 +00:00
|
|
|
static const CTevCombiners::CTevPass kEnvModuColor{
|
|
|
|
{GX_CC_ZERO, GX_CC_CPREV, GX_CC_RASC, GX_CC_ZERO},
|
|
|
|
{GX_CA_ZERO, GX_CA_APREV, GX_CA_RASA, GX_CA_ZERO},
|
|
|
|
};
|
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage1, kEnvModuColor);
|
2022-03-20 20:24:02 +00:00
|
|
|
} else {
|
2022-08-15 22:50:20 +00:00
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru);
|
2016-02-13 00:57:09 +00:00
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
texr->GetValueUV(partFrame, uvs);
|
|
|
|
constUVs = texr->HasConstantUV();
|
2022-03-20 20:24:02 +00:00
|
|
|
} else {
|
2022-08-15 22:50:20 +00:00
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage0, CTevCombiners::kEnvPassthru);
|
|
|
|
CGraphics::SetTevOp(ERglTevStage::Stage1, CTevCombiners::kEnvPassthru);
|
2022-03-20 20:24:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr std::array vtxDescList{
|
2022-07-29 20:16:55 +00:00
|
|
|
GXVtxDescList{GX_VA_POS, GX_DIRECT},
|
|
|
|
GXVtxDescList{GX_VA_CLR0, GX_DIRECT},
|
|
|
|
GXVtxDescList{GX_VA_TEX0, GX_DIRECT},
|
|
|
|
GXVtxDescList{GX_VA_NULL, GX_NONE},
|
2022-03-20 20:24:02 +00:00
|
|
|
};
|
|
|
|
CGX::SetVtxDescv(vtxDescList.data());
|
2022-07-29 20:16:55 +00:00
|
|
|
GXTevStageID nextStage;
|
2022-03-20 20:24:02 +00:00
|
|
|
if (hasModuColor) {
|
|
|
|
CGX::SetNumChans(2);
|
2022-07-29 20:16:55 +00:00
|
|
|
nextStage = GX_TEVSTAGE2;
|
|
|
|
CGX::SetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR1A1);
|
2022-03-20 20:24:02 +00:00
|
|
|
CGX::SetChanAmbColor(CGX::EChannelId::Channel1, zeus::skBlack);
|
|
|
|
CGX::SetChanMatColor(CGX::EChannelId::Channel1, x338_moduColor);
|
|
|
|
CGX::SetChanCtrl(CGX::EChannelId::Channel1, {});
|
|
|
|
} else {
|
|
|
|
CGX::SetNumChans(1);
|
2022-07-29 20:16:55 +00:00
|
|
|
nextStage = GX_TEVSTAGE1;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
bool moveRedToAlphaBuffer = sMoveRedToAlphaBuffer;
|
|
|
|
if (g_subtractBlend) {
|
|
|
|
CGraphics::SetDepthWriteMode(x26c_28_zTest, ERglEnum::LEqual, false);
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetBlendMode(GX_BM_SUBTRACT, GX_BL_ONE, GX_BL_ZERO, GX_LO_CLEAR);
|
2022-03-20 20:24:02 +00:00
|
|
|
if (moveRedToAlphaBuffer) {
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetTevColorIn(nextStage, GX_CC_ZERO, GX_CC_CPREV, GX_CC_APREV, GX_CC_ZERO);
|
|
|
|
CGX::SetTevAlphaIn(nextStage, GX_CA_ZERO, GX_CA_TEXA, GX_CA_APREV, GX_CA_ZERO);
|
2022-03-20 20:24:02 +00:00
|
|
|
CGX::SetStandardTevColorAlphaOp(nextStage);
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetTevOrder(nextStage, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL);
|
|
|
|
GXSetTevSwapMode(nextStage, GX_TEV_SWAP0, GX_TEV_SWAP1);
|
|
|
|
nextStage = GXTevStageID(nextStage + 1);
|
2022-03-20 20:24:02 +00:00
|
|
|
}
|
|
|
|
} else if (moveRedToAlphaBuffer) {
|
|
|
|
CGraphics::SetDepthWriteMode(x26c_28_zTest, ERglEnum::LEqual, false);
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One, ERglBlendFactor::One, ERglLogicOp::Clear);
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetTevColorIn(nextStage, GX_CC_ZERO, GX_CC_CPREV, GX_CC_APREV, GX_CC_ZERO);
|
|
|
|
CGX::SetTevAlphaIn(nextStage, GX_CA_ZERO, GX_CA_TEXA, GX_CA_APREV, GX_CA_ZERO);
|
2022-03-20 20:24:02 +00:00
|
|
|
CGX::SetStandardTevColorAlphaOp(nextStage);
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetTevOrder(nextStage, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL);
|
|
|
|
GXSetTevSwapMode(nextStage, GX_TEV_SWAP0, GX_TEV_SWAP1);
|
|
|
|
nextStage = GXTevStageID(nextStage + 1);
|
2022-03-20 20:24:02 +00:00
|
|
|
} else if (x26c_26_AAPH) {
|
|
|
|
CGraphics::SetDepthWriteMode(x26c_28_zTest, ERglEnum::LEqual, false);
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::One, ERglLogicOp::Clear);
|
|
|
|
} else {
|
|
|
|
CGraphics::SetDepthWriteMode(x26c_28_zTest, ERglEnum::LEqual, x26c_27_ZBUF);
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha,
|
|
|
|
ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
CGX::SetNumTevStages(nextStage);
|
|
|
|
CGX::SetNumTexGens(1);
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
|
|
|
|
CGX::SetChanCtrl(CGX::EChannelId::Channel0, false, GX_SRC_REG, GX_SRC_VTX, {}, GX_DF_NONE, GX_AF_NONE);
|
|
|
|
CGX::SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY, false, GX_PTIDENTITY);
|
|
|
|
GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
|
|
|
|
GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0);
|
2022-05-19 07:57:30 +00:00
|
|
|
if (constUVs) {
|
2022-07-29 20:16:55 +00:00
|
|
|
GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_RGBA8, 1);
|
2022-05-19 07:57:30 +00:00
|
|
|
} else {
|
2022-07-29 20:16:55 +00:00
|
|
|
GXSetVtxAttrFmt(GX_VTXFMT6, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
|
2022-05-19 07:57:30 +00:00
|
|
|
}
|
2022-03-20 20:24:02 +00:00
|
|
|
|
|
|
|
int mbspVal = std::max(1, x270_MBSP);
|
|
|
|
if (x26c_30_MBLR) {
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::Begin(GX_QUADS, GX_VTXFMT6, mbspVal * x30_particles.size() * 4);
|
2022-03-20 20:24:02 +00:00
|
|
|
} else {
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::Begin(GX_QUADS, GX_VTXFMT6, mbspVal * 4);
|
2022-03-20 20:24:02 +00:00
|
|
|
}
|
2017-06-04 01:01:09 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::vector<CParticleListItem> sortItems;
|
|
|
|
if (desc->x44_28_x30_28_SORT) {
|
|
|
|
sortItems.reserve(x30_particles.size());
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2020-03-09 16:54:59 +00:00
|
|
|
for (size_t i = 0; i < x30_particles.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
const CParticle& particle = x30_particles[i];
|
2020-03-09 16:54:59 +00:00
|
|
|
sortItems.emplace_back(s16(i));
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticleListItem& sortItem = sortItems.back();
|
|
|
|
sortItem.x4_viewPoint =
|
|
|
|
systemCameraMatrix * ((particle.x4_pos - particle.x10_prevPos) * x80_timeDeltaScale + particle.x10_prevPos);
|
2016-02-13 00:57:09 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::sort(sortItems.begin(), sortItems.end(), [](const CParticleListItem& a, const CParticleListItem& b) -> bool {
|
|
|
|
return a.x4_viewPoint[1] > b.x4_viewPoint[1];
|
|
|
|
});
|
|
|
|
}
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetEmitterTime(x74_curFrame);
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!x26c_30_MBLR) {
|
2022-03-20 20:24:02 +00:00
|
|
|
if (!desc->x44_28_x30_28_SORT && constUVs && !x26c_29_ORNT) {
|
|
|
|
if (noRota) {
|
|
|
|
if (zeus::close_enough(x80_timeDeltaScale, 1.f)) {
|
|
|
|
RenderBasicParticlesNoRotNoTS(systemCameraMatrix);
|
|
|
|
} else {
|
|
|
|
RenderBasicParticlesNoRotTS(systemCameraMatrix);
|
2018-05-13 04:09:11 +00:00
|
|
|
}
|
2022-03-20 20:24:02 +00:00
|
|
|
} else if (zeus::close_enough(x80_timeDeltaScale, 1.f)) {
|
|
|
|
RenderBasicParticlesRotNoTS(systemCameraMatrix);
|
|
|
|
} else {
|
|
|
|
RenderBasicParticlesRotTS(systemCameraMatrix);
|
|
|
|
}
|
|
|
|
} else if (!x26c_29_ORNT) {
|
2020-03-09 16:54:59 +00:00
|
|
|
for (size_t i = 0; i < x30_particles.size(); ++i) {
|
|
|
|
const int partIdx = desc->x44_28_x30_28_SORT ? sortItems[i].x0_partIdx : int(i);
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticle& particle = x30_particles[partIdx];
|
|
|
|
g_currentParticle = &particle;
|
2016-02-13 00:57:09 +00:00
|
|
|
|
2020-03-09 16:54:59 +00:00
|
|
|
const int partFrame = x74_curFrame - particle.x28_startFrame - 1;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f viewPoint;
|
2020-03-09 16:54:59 +00:00
|
|
|
if (desc->x44_28_x30_28_SORT) {
|
2018-12-08 05:30:43 +00:00
|
|
|
viewPoint = sortItems[i].x4_viewPoint;
|
2020-03-09 16:54:59 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
viewPoint = systemCameraMatrix *
|
|
|
|
((particle.x4_pos - particle.x10_prevPos) * x80_timeDeltaScale + particle.x10_prevPos);
|
2020-03-09 16:54:59 +00:00
|
|
|
}
|
2018-05-13 04:09:11 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
const float size = 0.5f * particle.x2c_lineLengthOrSize;
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!constUVs) {
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame - particle.x28_startFrame);
|
|
|
|
CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(partFrame);
|
2018-12-08 05:30:43 +00:00
|
|
|
texr->GetValueUV(partFrame, uvs);
|
2016-02-13 00:57:09 +00:00
|
|
|
}
|
2018-05-13 04:09:11 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
if (noRota) {
|
|
|
|
GXPosition3f32(viewPoint.x() + size, viewPoint.y(), viewPoint.z() + size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(uvs.xMax, uvs.yMax);
|
|
|
|
GXPosition3f32(viewPoint.x() - size, viewPoint.y(), viewPoint.z() + size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(uvs.xMin, uvs.yMax);
|
|
|
|
GXPosition3f32(viewPoint.x() - size, viewPoint.y(), viewPoint.z() - size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(uvs.xMin, uvs.yMin);
|
|
|
|
GXPosition3f32(viewPoint.x() + size, viewPoint.y(), viewPoint.z() - size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(uvs.xMax, uvs.yMin);
|
2018-12-08 05:30:43 +00:00
|
|
|
} else {
|
2022-03-20 20:24:02 +00:00
|
|
|
const float theta = zeus::degToRad(particle.x30_lineWidthOrRota);
|
|
|
|
const float sinT = std::sin(theta) * size;
|
|
|
|
const float cosT = std::cos(theta) * size;
|
|
|
|
GXPosition3f32(viewPoint.x() + (sinT + cosT), viewPoint.y(), viewPoint.z() + (cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(uvs.xMax, uvs.yMax);
|
|
|
|
GXPosition3f32(viewPoint.x() + (sinT - cosT), viewPoint.y(), viewPoint.z() + (sinT + cosT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(uvs.xMin, uvs.yMax);
|
|
|
|
GXPosition3f32(viewPoint.x() - (sinT + cosT), viewPoint.y(), viewPoint.z() - (cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(uvs.xMin, uvs.yMin);
|
|
|
|
GXPosition3f32(viewPoint.x() + (-sinT + cosT), viewPoint.y(), viewPoint.z() + (-cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(uvs.xMax, uvs.yMin);
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-09 16:54:59 +00:00
|
|
|
for (size_t i = 0; i < x30_particles.size(); ++i) {
|
|
|
|
const int partIdx = desc->x44_28_x30_28_SORT ? sortItems[i].x0_partIdx : int(i);
|
2017-06-04 01:01:09 +00:00
|
|
|
CParticle& particle = x30_particles[partIdx];
|
2016-02-25 06:23:35 +00:00
|
|
|
g_currentParticle = &particle;
|
|
|
|
|
2020-03-09 16:54:59 +00:00
|
|
|
const int partFrame = x74_curFrame - particle.x28_startFrame - 1;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f viewPoint =
|
|
|
|
((particle.x4_pos - particle.x10_prevPos) * x80_timeDeltaScale + particle.x10_prevPos);
|
2020-03-09 16:54:59 +00:00
|
|
|
const float width = !desc->x50_x3c_ROTA ? 1.f : particle.x30_lineWidthOrRota;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f dir;
|
|
|
|
if (particle.x1c_vel.canBeNormalized()) {
|
|
|
|
dir = particle.x1c_vel.normalized();
|
|
|
|
} else {
|
|
|
|
zeus::CVector3f delta = particle.x4_pos - particle.x10_prevPos;
|
|
|
|
if (delta.canBeNormalized())
|
|
|
|
dir = delta.normalized();
|
|
|
|
else
|
2019-02-24 07:15:54 +00:00
|
|
|
dir = zeus::skUp;
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f foreVec = particle.x2c_lineLengthOrSize * dir;
|
|
|
|
zeus::CVector3f rightVec;
|
|
|
|
if (desc->x30_31_RSOP) {
|
|
|
|
rightVec = dir.cross(CGraphics::g_ViewMatrix.basis[1]);
|
|
|
|
if (rightVec.canBeNormalized()) {
|
|
|
|
rightVec = rightVec.normalized() * (particle.x2c_lineLengthOrSize * width);
|
|
|
|
} else {
|
|
|
|
rightVec = dir.cross((CGraphics::g_ViewMatrix.origin - particle.x4_pos).normalized());
|
|
|
|
if (rightVec.canBeNormalized()) {
|
|
|
|
rightVec = rightVec.normalized() * (particle.x2c_lineLengthOrSize * width);
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
rightVec = foreVec.cross(CGraphics::g_ViewMatrix.basis[1]) * width;
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!constUVs) {
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame - particle.x28_startFrame);
|
|
|
|
CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(partFrame);
|
2018-12-08 05:30:43 +00:00
|
|
|
texr->GetValueUV(partFrame, uvs);
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// switch (m_shaderClass) {
|
|
|
|
// case CElementGenShaders::EShaderClass::Tex: {
|
|
|
|
// SParticleInstanceTex& inst = g_instTexData.emplace_back();
|
|
|
|
// viewPoint += rightVec * 0.5f;
|
|
|
|
// inst.pos[0] = zeus::CVector4f{viewPoint + 0.5f * foreVec};
|
|
|
|
// inst.pos[1] = zeus::CVector4f{viewPoint - 0.5f * foreVec};
|
|
|
|
// viewPoint -= rightVec;
|
|
|
|
// inst.pos[2] = zeus::CVector4f{viewPoint + 0.5f * foreVec};
|
|
|
|
// inst.pos[3] = zeus::CVector4f{viewPoint - 0.5f * foreVec};
|
|
|
|
// inst.color = particle.x34_color;
|
|
|
|
// inst.uvs[0] = {uvs.xMax, uvs.yMax};
|
|
|
|
// inst.uvs[1] = {uvs.xMin, uvs.yMax};
|
|
|
|
// inst.uvs[2] = {uvs.xMax, uvs.yMin};
|
|
|
|
// inst.uvs[3] = {uvs.xMin, uvs.yMin};
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// case CElementGenShaders::EShaderClass::NoTex: {
|
|
|
|
// SParticleInstanceNoTex& inst = g_instNoTexData.emplace_back();
|
|
|
|
// viewPoint += rightVec * 0.5f;
|
|
|
|
// inst.pos[0] = zeus::CVector4f{viewPoint + 0.5f * foreVec};
|
|
|
|
// inst.pos[1] = zeus::CVector4f{viewPoint - 0.5f * foreVec};
|
|
|
|
// viewPoint -= rightVec;
|
|
|
|
// inst.pos[2] = zeus::CVector4f{viewPoint + 0.5f * foreVec};
|
|
|
|
// inst.pos[3] = zeus::CVector4f{viewPoint - 0.5f * foreVec};
|
|
|
|
// inst.color = particle.x34_color;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (m_shaderClass) {
|
|
|
|
case CElementGenShaders::EShaderClass::Tex:
|
2022-03-19 17:30:25 +00:00
|
|
|
// m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex));
|
|
|
|
// CGraphics::DrawInstances(0, 4, g_instTexData.size());
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case CElementGenShaders::EShaderClass::NoTex:
|
2022-03-19 17:30:25 +00:00
|
|
|
// m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex));
|
|
|
|
// CGraphics::DrawInstances(0, 4, g_instNoTexData.size());
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2022-03-19 17:30:25 +00:00
|
|
|
// switch (m_shaderClass) {
|
|
|
|
// case CElementGenShaders::EShaderClass::Tex:
|
|
|
|
// g_instTexData.clear();
|
|
|
|
// g_instTexData.reserve(x30_particles.size() * mbspVal);
|
|
|
|
// break;
|
|
|
|
// case CElementGenShaders::EShaderClass::NoTex:
|
|
|
|
// g_instNoTexData.clear();
|
|
|
|
// g_instNoTexData.reserve(x30_particles.size() * mbspVal);
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// Log.report(logvisor::Fatal, FMT_STRING("unexpected particle shader class"));
|
|
|
|
// break;
|
|
|
|
// }
|
2020-03-09 16:54:59 +00:00
|
|
|
const float mbspFac = 1.f / float(mbspVal);
|
|
|
|
for (size_t i = 0; i < x30_particles.size(); ++i) {
|
|
|
|
const int partIdx = desc->x44_28_x30_28_SORT ? sortItems[i].x0_partIdx : int(i);
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticle& particle = x30_particles[partIdx];
|
|
|
|
g_currentParticle = &particle;
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2020-03-09 16:54:59 +00:00
|
|
|
const int partFrame = x74_curFrame - particle.x28_startFrame - 1;
|
2016-02-15 04:00:26 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!constUVs) {
|
2019-12-03 08:47:05 +00:00
|
|
|
CParticleGlobals::instance()->SetParticleLifetime(particle.x0_endFrame - particle.x28_startFrame);
|
|
|
|
CParticleGlobals::instance()->UpdateParticleLifetimeTweenValues(partFrame);
|
2018-12-08 05:30:43 +00:00
|
|
|
texr->GetValueUV(partFrame, uvs);
|
|
|
|
}
|
|
|
|
|
|
|
|
zeus::CVector3f dVec = particle.x4_pos - particle.x10_prevPos;
|
|
|
|
zeus::CVector3f vec = dVec * x80_timeDeltaScale + particle.x10_prevPos;
|
|
|
|
zeus::CVector3f mbspVec = dVec * mbspFac;
|
|
|
|
float size = 0.5f * particle.x2c_lineLengthOrSize;
|
|
|
|
if (0.f == particle.x30_lineWidthOrRota) {
|
|
|
|
for (int j = 0; j < mbspVal; ++j) {
|
|
|
|
vec += mbspVec;
|
|
|
|
zeus::CVector3f vec2 = systemCameraMatrix * vec;
|
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// switch (m_shaderClass) {
|
|
|
|
// case CElementGenShaders::EShaderClass::Tex: {
|
|
|
|
// SParticleInstanceTex& inst = g_instTexData.emplace_back();
|
|
|
|
// inst.pos[0] = zeus::CVector4f{vec2.x() + size, vec2.y(), vec2.z() + size, 1.f};
|
|
|
|
// inst.pos[1] = zeus::CVector4f{vec2.x() - size, vec2.y(), vec2.z() + size, 1.f};
|
|
|
|
// inst.pos[2] = zeus::CVector4f{vec2.x() + size, vec2.y(), vec2.z() - size, 1.f};
|
|
|
|
// inst.pos[3] = zeus::CVector4f{vec2.x() - size, vec2.y(), vec2.z() - size, 1.f};
|
|
|
|
// inst.color = particle.x34_color;
|
|
|
|
// inst.uvs[0] = {uvs.xMax, uvs.yMax};
|
|
|
|
// inst.uvs[1] = {uvs.xMin, uvs.yMax};
|
|
|
|
// inst.uvs[2] = {uvs.xMax, uvs.yMin};
|
|
|
|
// inst.uvs[3] = {uvs.xMin, uvs.yMin};
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// case CElementGenShaders::EShaderClass::NoTex: {
|
|
|
|
// SParticleInstanceNoTex& inst = g_instNoTexData.emplace_back();
|
|
|
|
// inst.pos[0] = zeus::CVector4f{vec2.x() + size, vec2.y(), vec2.z() + size, 1.f};
|
|
|
|
// inst.pos[1] = zeus::CVector4f{vec2.x() - size, vec2.y(), vec2.z() + size, 1.f};
|
|
|
|
// inst.pos[2] = zeus::CVector4f{vec2.x() + size, vec2.y(), vec2.z() - size, 1.f};
|
|
|
|
// inst.pos[3] = zeus::CVector4f{vec2.x() - size, vec2.y(), vec2.z() - size, 1.f};
|
|
|
|
// inst.color = particle.x34_color;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
float theta = zeus::degToRad(particle.x30_lineWidthOrRota);
|
|
|
|
float sinT = std::sin(theta) * size;
|
|
|
|
float cosT = std::cos(theta) * size;
|
|
|
|
|
|
|
|
for (int j = 0; j < mbspVal; ++j) {
|
|
|
|
vec += mbspVec;
|
|
|
|
zeus::CVector3f vec2 = systemCameraMatrix * vec;
|
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// switch (m_shaderClass) {
|
|
|
|
// case CElementGenShaders::EShaderClass::Tex: {
|
|
|
|
// SParticleInstanceTex& inst = g_instTexData.emplace_back();
|
|
|
|
// inst.pos[0] = zeus::CVector4f{vec2.x() + sinT + cosT, vec2.y(), vec2.z() + cosT - sinT, 1.f};
|
|
|
|
// inst.pos[1] = zeus::CVector4f{vec2.x() + sinT - cosT, vec2.y(), vec2.z() + sinT + cosT, 1.f};
|
|
|
|
// inst.pos[2] = zeus::CVector4f{vec2.x() + (cosT - sinT), vec2.y(), vec2.z() + (-cosT - sinT), 1.f};
|
|
|
|
// inst.pos[3] = zeus::CVector4f{vec2.x() - (sinT + cosT), vec2.y(), vec2.z() - (cosT - sinT), 1.f};
|
|
|
|
// inst.color = particle.x34_color;
|
|
|
|
// inst.uvs[0] = {uvs.xMax, uvs.yMax};
|
|
|
|
// inst.uvs[1] = {uvs.xMin, uvs.yMax};
|
|
|
|
// inst.uvs[2] = {uvs.xMax, uvs.yMin};
|
|
|
|
// inst.uvs[3] = {uvs.xMin, uvs.yMin};
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// case CElementGenShaders::EShaderClass::NoTex: {
|
|
|
|
// SParticleInstanceNoTex& inst = g_instNoTexData.emplace_back();
|
|
|
|
// inst.pos[0] = zeus::CVector4f{vec2.x() + sinT + cosT, vec2.y(), vec2.z() + cosT - sinT, 1.f};
|
|
|
|
// inst.pos[1] = zeus::CVector4f{vec2.x() + sinT - cosT, vec2.y(), vec2.z() + sinT + cosT, 1.f};
|
|
|
|
// inst.pos[2] = zeus::CVector4f{vec2.x() + (cosT - sinT), vec2.y(), vec2.z() + (-cosT - sinT), 1.f};
|
|
|
|
// inst.pos[3] = zeus::CVector4f{vec2.x() - (sinT + cosT), vec2.y(), vec2.z() - (cosT - sinT), 1.f};
|
|
|
|
// inst.color = particle.x34_color;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// default:
|
|
|
|
// break;
|
|
|
|
// }
|
2018-11-04 01:08:44 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (m_shaderClass) {
|
|
|
|
case CElementGenShaders::EShaderClass::Tex:
|
2022-03-19 17:30:25 +00:00
|
|
|
// m_instBuf->load(g_instTexData.data(), g_instTexData.size() * sizeof(SParticleInstanceTex));
|
|
|
|
// CGraphics::DrawInstances(0, 4, g_instTexData.size());
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
case CElementGenShaders::EShaderClass::NoTex:
|
2022-03-19 17:30:25 +00:00
|
|
|
// m_instBuf->load(g_instNoTexData.data(), g_instNoTexData.size() * sizeof(SParticleInstanceNoTex));
|
|
|
|
// CGraphics::DrawInstances(0, 4, g_instNoTexData.size());
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-02-15 04:00:26 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2022-03-20 20:34:25 +00:00
|
|
|
|
|
|
|
CGX::End();
|
|
|
|
if (moveRedToAlphaBuffer) {
|
2022-07-29 20:16:55 +00:00
|
|
|
GXSetTevSwapMode(GXTevStageID(nextStage - 1), GX_TEV_SWAP0, GX_TEV_SWAP0);
|
2022-03-20 20:34:25 +00:00
|
|
|
}
|
2022-03-20 20:24:02 +00:00
|
|
|
CGraphics::SetCullMode(ERglCullMode::Front);
|
|
|
|
CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-25 02:55:38 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::RenderParticlesIndirectTexture() {
|
2022-05-04 00:27:19 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP(fmt::format(FMT_STRING("CElementGen::RenderParticlesIndirectTexture")).c_str(), zeus::skYellow);
|
2022-03-27 00:23:16 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGenDescription* desc = x1c_genDesc.GetObj();
|
|
|
|
|
|
|
|
zeus::CTransform systemViewPointMatrix(CGraphics::g_ViewMatrix);
|
|
|
|
systemViewPointMatrix.origin.zeroOut();
|
|
|
|
zeus::CTransform systemCameraMatrix = systemViewPointMatrix.inverse() * x22c_globalOrientation;
|
|
|
|
systemViewPointMatrix =
|
|
|
|
((zeus::CTransform::Translate(xe8_globalTranslation) * x10c_globalScaleTransform) * systemViewPointMatrix) *
|
|
|
|
x178_localScaleTransform;
|
|
|
|
CGraphics::SetModelMatrix(systemViewPointMatrix);
|
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// SParticleUniforms uniformData = {CGraphics::GetPerspectiveProjectionMatrix(/*true*/) *
|
|
|
|
// CGraphics::g_GXModelView.toMatrix4f(),
|
|
|
|
// {1.f, 1.f, 1.f, 1.f}};
|
|
|
|
// m_uniformBuf->load(&uniformData, sizeof(SParticleUniforms));
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
CGraphics::SetAlphaCompare(ERglAlphaFunc::Always, 0, ERglAlphaOp::And, ERglAlphaFunc::Always, 0);
|
|
|
|
|
|
|
|
if (x26c_26_AAPH) {
|
|
|
|
CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, true);
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::One, ERglLogicOp::Clear);
|
|
|
|
} else {
|
|
|
|
CGraphics::SetDepthWriteMode(true, ERglEnum::LEqual, x26c_27_ZBUF);
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha,
|
|
|
|
ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
|
|
|
|
CUVElement* texr = desc->x54_x40_TEXR.get();
|
|
|
|
CParticle& firstParticle = x30_particles[0];
|
|
|
|
int partFrame = x74_curFrame - firstParticle.x28_startFrame;
|
|
|
|
CTexture* cachedTex = texr->GetValueTexture(partFrame).GetObj();
|
2022-07-29 20:16:55 +00:00
|
|
|
cachedTex->Load(GX_TEXMAP0, EClampMode::Repeat);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
SUVElementSet uvs = {0.f, 0.f, 1.f, 1.f};
|
|
|
|
bool constTexr = texr->HasConstantTexture();
|
|
|
|
texr->GetValueUV(partFrame, uvs);
|
|
|
|
bool constUVs = texr->HasConstantUV();
|
|
|
|
|
|
|
|
CUVElement* tind = desc->x58_x44_TIND.get();
|
|
|
|
CTexture* cachedIndTex = tind->GetValueTexture(partFrame).GetObj();
|
2022-07-29 20:16:55 +00:00
|
|
|
cachedIndTex->Load(GX_TEXMAP2, EClampMode::Repeat);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
SUVElementSet uvsInd = {0.f, 0.f, 1.f, 1.f};
|
|
|
|
bool constIndTexr = tind->HasConstantTexture();
|
|
|
|
bool constIndUVs = tind->HasConstantUV();
|
|
|
|
tind->GetValueUV(partFrame, uvsInd);
|
|
|
|
|
|
|
|
std::vector<CParticleListItem> sortItems;
|
|
|
|
if (desc->x44_28_x30_28_SORT) {
|
|
|
|
sortItems.reserve(x30_particles.size());
|
|
|
|
|
2020-03-09 16:54:59 +00:00
|
|
|
for (size_t i = 0; i < x30_particles.size(); ++i) {
|
2018-12-08 05:30:43 +00:00
|
|
|
const CParticle& particle = x30_particles[i];
|
2020-03-09 16:54:59 +00:00
|
|
|
sortItems.emplace_back(s16(i));
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticleListItem& sortItem = sortItems.back();
|
|
|
|
sortItem.x4_viewPoint =
|
|
|
|
systemCameraMatrix * ((particle.x4_pos - particle.x10_prevPos) * x80_timeDeltaScale + particle.x10_prevPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(sortItems.begin(), sortItems.end(), [](const CParticleListItem& a, const CParticleListItem& b) -> bool {
|
|
|
|
return a.x4_viewPoint[1] >= b.x4_viewPoint[1];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// g_instIndTexData.clear();
|
|
|
|
// g_instIndTexData.reserve(x30_particles.size());
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// if (!x30_particles.empty())
|
|
|
|
// CGraphics::SetShaderDataBinding(m_normalDataBind[g_Renderer->IsThermalVisorHotPass()]);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-03-09 16:54:59 +00:00
|
|
|
for (size_t i = 0; i < x30_particles.size(); ++i) {
|
|
|
|
const int partIdx = desc->x44_28_x30_28_SORT ? sortItems[i].x0_partIdx : int(i);
|
2018-12-08 05:30:43 +00:00
|
|
|
CParticle& particle = x30_particles[partIdx];
|
|
|
|
g_currentParticle = &particle;
|
|
|
|
|
2020-03-09 16:54:59 +00:00
|
|
|
const int thisPartFrame = x74_curFrame - particle.x28_startFrame;
|
2018-12-08 05:30:43 +00:00
|
|
|
zeus::CVector3f viewPoint;
|
2020-03-09 16:54:59 +00:00
|
|
|
if (desc->x44_28_x30_28_SORT) {
|
2018-12-08 05:30:43 +00:00
|
|
|
viewPoint = sortItems[i].x4_viewPoint;
|
2020-03-09 16:54:59 +00:00
|
|
|
} else {
|
2018-12-08 05:30:43 +00:00
|
|
|
viewPoint =
|
|
|
|
systemCameraMatrix * ((particle.x4_pos - particle.x10_prevPos) * x80_timeDeltaScale + particle.x10_prevPos);
|
2020-03-09 16:54:59 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (!constTexr) {
|
2019-12-03 08:47:05 +00:00
|
|
|
CTexture* tex = texr->GetValueTexture(thisPartFrame).GetObj();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (tex != cachedTex) {
|
2022-07-29 20:16:55 +00:00
|
|
|
tex->Load(GX_TEXMAP0, EClampMode::Repeat);
|
2018-12-08 05:30:43 +00:00
|
|
|
cachedTex = tex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!constIndTexr) {
|
2019-12-03 08:47:05 +00:00
|
|
|
CTexture* tex = tind->GetValueTexture(thisPartFrame).GetObj();
|
2018-12-08 05:30:43 +00:00
|
|
|
if (tex != cachedIndTex) {
|
2022-07-29 20:16:55 +00:00
|
|
|
tex->Load(GX_TEXMAP2, EClampMode::Repeat);
|
2018-12-08 05:30:43 +00:00
|
|
|
cachedIndTex = tex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!constUVs)
|
2019-12-03 08:47:05 +00:00
|
|
|
texr->GetValueUV(thisPartFrame, uvs);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (!constIndUVs)
|
2019-12-03 08:47:05 +00:00
|
|
|
tind->GetValueUV(thisPartFrame, uvsInd);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
float size = 0.5f * particle.x2c_lineLengthOrSize;
|
|
|
|
zeus::CVector3f p1 = {viewPoint.x() - size, viewPoint.y(), viewPoint.z() - size};
|
|
|
|
zeus::CVector3f p2 = {viewPoint.x() + size, viewPoint.y(), viewPoint.z() + size};
|
|
|
|
SClipScreenRect clipRect = CGraphics::ClipScreenRectFromMS(p1, p2);
|
|
|
|
|
|
|
|
if (!clipRect.x0_valid)
|
|
|
|
continue;
|
|
|
|
|
2022-05-13 23:40:19 +00:00
|
|
|
// CGraphics::ResolveSpareTexture(clipRect);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2022-03-19 17:30:25 +00:00
|
|
|
// SParticleInstanceIndTex& inst = g_instIndTexData.emplace_back();
|
|
|
|
// inst.pos[0] = zeus::CVector4f{viewPoint.x() + size, viewPoint.y(), viewPoint.z() + size, 1.f};
|
|
|
|
// inst.pos[1] = zeus::CVector4f{viewPoint.x() - size, viewPoint.y(), viewPoint.z() + size, 1.f};
|
|
|
|
// inst.pos[2] = zeus::CVector4f{viewPoint.x() + size, viewPoint.y(), viewPoint.z() - size, 1.f};
|
|
|
|
// inst.pos[3] = zeus::CVector4f{viewPoint.x() - size, viewPoint.y(), viewPoint.z() - size, 1.f};
|
|
|
|
// inst.color = particle.x34_color;
|
|
|
|
// inst.texrTindUVs[0] = zeus::CVector4f{uvs.xMax, uvs.yMax, uvsInd.xMax, uvsInd.yMax};
|
|
|
|
// inst.texrTindUVs[1] = zeus::CVector4f{uvs.xMin, uvs.yMax, uvsInd.xMin, uvsInd.yMax};
|
|
|
|
// inst.texrTindUVs[2] = zeus::CVector4f{uvs.xMax, uvs.yMin, uvsInd.xMax, uvsInd.yMin};
|
|
|
|
// inst.texrTindUVs[3] = zeus::CVector4f{uvs.xMin, uvs.yMin, uvsInd.xMin, uvsInd.yMin};
|
|
|
|
// switch (CGraphics::g_BooPlatform) {
|
|
|
|
// case boo::IGraphicsDataFactory::Platform::OpenGL:
|
|
|
|
// inst.sceneUVs =
|
|
|
|
// zeus::CVector4f{clipRect.x18_uvXMin, clipRect.x24_uvYMax, clipRect.x1c_uvXMax, clipRect.x20_uvYMin};
|
|
|
|
// break;
|
|
|
|
// default:
|
|
|
|
// inst.sceneUVs =
|
|
|
|
// zeus::CVector4f{clipRect.x18_uvXMin, 1.f - clipRect.x24_uvYMax, clipRect.x1c_uvXMax, 1.f - clipRect.x20_uvYMin};
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// CGraphics::DrawInstances(0, 4, 1, g_instIndTexData.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if (g_instIndTexData.size()) {
|
|
|
|
// m_instBuf->load(g_instIndTexData.data(), g_instIndTexData.size() * sizeof(SParticleInstanceIndTex));
|
|
|
|
// TODO! this looks like a bug
|
2018-12-08 05:30:43 +00:00
|
|
|
// CGraphics::SetShaderDataBinding(m_normalDataBind);
|
|
|
|
// CGraphics::DrawInstances(0, 4, g_instIndTexData.size());
|
2022-03-19 17:30:25 +00:00
|
|
|
// }
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetOrientation(const zeus::CTransform& orientation) {
|
|
|
|
x1d8_orientation = orientation;
|
2020-04-23 09:06:14 +00:00
|
|
|
x208_orientationInverse = x1d8_orientation.basis.transposed();
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
ch->SetOrientation(orientation);
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetTranslation(const zeus::CVector3f& translation) {
|
|
|
|
xdc_translation = translation;
|
|
|
|
|
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren) {
|
2019-07-20 04:27:21 +00:00
|
|
|
switch (ch->Get4CharId().toUint32()) {
|
2019-10-03 13:35:15 +00:00
|
|
|
case SBIG('ELSC'):
|
2018-12-08 05:30:43 +00:00
|
|
|
ch->SetTranslation(translation + x2c0_SEPO);
|
|
|
|
break;
|
|
|
|
case SBIG('SWHC'):
|
|
|
|
ch->SetTranslation(translation + x2b0_SSPO);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ch->SetTranslation(translation);
|
|
|
|
break;
|
2017-06-04 01:01:09 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetGlobalOrientation(const zeus::CTransform& rotation) {
|
|
|
|
x22c_globalOrientation.setRotation(rotation);
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
ch->SetGlobalOrientation(x22c_globalOrientation);
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetGlobalTranslation(const zeus::CVector3f& translation) {
|
|
|
|
xe8_globalTranslation = translation;
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
ch->SetGlobalTranslation(translation);
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetGlobalScale(const zeus::CVector3f& scale) {
|
|
|
|
x100_globalScale = scale;
|
|
|
|
x10c_globalScaleTransform = zeus::CTransform::Scale(scale);
|
2019-02-24 07:15:54 +00:00
|
|
|
x13c_globalScaleTransformInverse = zeus::CTransform::Scale(zeus::skOne3f / scale);
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
ch->SetGlobalScale(scale);
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetLocalScale(const zeus::CVector3f& scale) {
|
|
|
|
x16c_localScale = scale;
|
|
|
|
x178_localScaleTransform = zeus::CTransform::Scale(scale);
|
2019-02-24 07:15:54 +00:00
|
|
|
x1a8_localScaleTransformInverse = zeus::CTransform::Scale(zeus::skOne3f / scale);
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
ch->SetLocalScale(scale);
|
2017-06-04 01:01:09 +00:00
|
|
|
}
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetGlobalOrientAndTrans(const zeus::CTransform& xf) {
|
|
|
|
SetGlobalOrientation(xf);
|
|
|
|
SetGlobalTranslation(xf.origin);
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetParticleEmission(bool enabled) {
|
|
|
|
x88_particleEmission = enabled;
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
ch->SetParticleEmission(enabled);
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetModulationColor(const zeus::CColor& color) {
|
|
|
|
x338_moduColor = color;
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
ch->SetModulationColor(color);
|
2017-06-04 01:01:09 +00:00
|
|
|
}
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetGeneratorRate(float rate) {
|
|
|
|
if (rate >= 0.0f)
|
|
|
|
x98_generatorRate = rate;
|
|
|
|
else
|
|
|
|
x98_generatorRate = 0.0f;
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (std::unique_ptr<CParticleGen>& child : x290_activePartChildren) {
|
|
|
|
if (child->Get4CharId() == FOURCC('PART'))
|
|
|
|
child->SetGeneratorRate(x98_generatorRate);
|
|
|
|
}
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CTransform& CElementGen::GetOrientation() const { return x1d8_orientation; }
|
2016-02-08 05:10:17 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& CElementGen::GetTranslation() const { return xdc_translation; }
|
2016-02-09 22:52:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CTransform& CElementGen::GetGlobalOrientation() const { return x22c_globalOrientation; }
|
2016-02-13 05:49:59 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& CElementGen::GetGlobalTranslation() const { return xe8_globalTranslation; }
|
2016-02-13 05:49:59 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CVector3f& CElementGen::GetGlobalScale() const { return x100_globalScale; }
|
2016-02-09 22:52:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
const zeus::CColor& CElementGen::GetModulationColor() const { return x338_moduColor; }
|
2016-02-09 22:52:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CElementGen::IsSystemDeletable() const {
|
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
if (!ch->IsSystemDeletable())
|
|
|
|
return false;
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2019-06-20 21:17:03 +00:00
|
|
|
return x268_PSLT < x74_curFrame && x25c_activeParticleCount == 0;
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 02:05:17 +00:00
|
|
|
std::optional<zeus::CAABox> CElementGen::GetBounds() const {
|
2018-12-08 05:30:43 +00:00
|
|
|
if (GetParticleCountAll() == 0)
|
2019-06-12 02:05:17 +00:00
|
|
|
return std::nullopt;
|
2018-12-08 05:30:43 +00:00
|
|
|
else
|
|
|
|
return {x2f0_systemBounds};
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
u32 CElementGen::GetParticleCount() const { return x25c_activeParticleCount; }
|
|
|
|
|
|
|
|
bool CElementGen::SystemHasLight() const { return x308_lightType != LightType::None; }
|
|
|
|
|
|
|
|
CLight CElementGen::GetLight() const {
|
|
|
|
switch (x308_lightType) {
|
|
|
|
case LightType::Directional:
|
|
|
|
return CLight::BuildDirectional(x320_LDIR.normalized(), x30c_LCLR * x310_LINT);
|
|
|
|
case LightType::Spot:
|
|
|
|
return CLight::BuildSpot(x314_LOFF, x320_LDIR.normalized(), x30c_LCLR * x310_LINT, x334_LSLA);
|
|
|
|
default: {
|
|
|
|
float quad = x32c_falloffType == EFalloffType::Quadratic ? x330_LFOR : 0.f;
|
|
|
|
float linear = x32c_falloffType == EFalloffType::Linear ? x330_LFOR : 0.f;
|
|
|
|
float constant = x32c_falloffType == EFalloffType::Constant ? 1.f : 0.f;
|
|
|
|
return CLight::BuildCustom(x314_LOFF, {1.f, 0.f, 0.f}, x30c_LCLR, constant, linear, quad, x310_LINT, 0.f, 0.f);
|
|
|
|
}
|
|
|
|
}
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
bool CElementGen::GetParticleEmission() const { return x88_particleEmission; }
|
2016-02-09 22:52:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::DestroyParticles() {
|
|
|
|
g_ParticleAliveCount -= x30_particles.size();
|
|
|
|
x30_particles.clear();
|
|
|
|
x50_parentMatrices.clear();
|
2016-02-09 22:52:33 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const std::unique_ptr<CParticleGen>& ch : x290_activePartChildren)
|
|
|
|
ch->DestroyParticles();
|
2016-02-13 05:49:59 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::Reset() {
|
|
|
|
x30_particles.clear();
|
|
|
|
x50_parentMatrices.clear();
|
|
|
|
x290_activePartChildren.clear();
|
2016-02-13 05:16:39 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
x74_curFrame = 0;
|
|
|
|
x78_curSeconds = 0.f;
|
|
|
|
x84_prevFrame = -1;
|
|
|
|
x25c_activeParticleCount = 0;
|
|
|
|
x26d_25_warmedUp = false;
|
2016-02-09 22:52:33 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CElementGen::SetMoveRedToAlphaBuffer(bool move) { sMoveRedToAlphaBuffer = move; }
|
2017-01-22 17:36:25 +00:00
|
|
|
|
2022-03-20 20:24:02 +00:00
|
|
|
void CElementGen::RenderBasicParticlesNoRotNoTS(const zeus::CTransform& xf) noexcept {
|
|
|
|
for (const auto& particle : x30_particles) {
|
|
|
|
const auto pos = xf * particle.x4_pos;
|
|
|
|
const auto size = 0.5f * particle.x2c_lineLengthOrSize;
|
|
|
|
GXPosition3f32(pos.x() + size, pos.y(), pos.z() + size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(1.f, 1.f);
|
|
|
|
GXPosition3f32(pos.x() - size, pos.y(), pos.z() + size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(0.f, 1.f);
|
|
|
|
GXPosition3f32(pos.x() - size, pos.y(), pos.z() - size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(0.f, 0.f);
|
|
|
|
GXPosition3f32(pos.x() + size, pos.y(), pos.z() - size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(1.f, 0.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CElementGen::RenderBasicParticlesNoRotTS(const zeus::CTransform& xf) noexcept {
|
|
|
|
for (const auto& particle : x30_particles) {
|
|
|
|
const auto pos = xf * (x80_timeDeltaScale * (particle.x4_pos - particle.x10_prevPos) + particle.x10_prevPos);
|
|
|
|
const auto size = 0.5f * particle.x2c_lineLengthOrSize;
|
|
|
|
GXPosition3f32(pos.x() + size, pos.y(), pos.z() + size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(1.f, 1.f);
|
|
|
|
GXPosition3f32(pos.x() - size, pos.y(), pos.z() + size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(0.f, 1.f);
|
|
|
|
GXPosition3f32(pos.x() - size, pos.y(), pos.z() - size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(0.f, 0.f);
|
|
|
|
GXPosition3f32(pos.x() + size, pos.y(), pos.z() - size);
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(1.f, 0.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CElementGen::RenderBasicParticlesRotNoTS(const zeus::CTransform& xf) noexcept {
|
|
|
|
for (const auto& particle : x30_particles) {
|
|
|
|
const auto pos = xf * particle.x4_pos;
|
|
|
|
const auto size = 0.5f * particle.x2c_lineLengthOrSize;
|
|
|
|
const float theta = zeus::degToRad(particle.x30_lineWidthOrRota);
|
|
|
|
const float sinT = std::sin(theta) * size;
|
|
|
|
const float cosT = std::cos(theta) * size;
|
|
|
|
GXPosition3f32(pos.x() + (sinT + cosT), pos.y(), pos.z() + (cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(1.f, 1.f);
|
|
|
|
GXPosition3f32(pos.x() + (sinT - cosT), pos.y(), pos.z() + (sinT + cosT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(0.f, 1.f);
|
|
|
|
GXPosition3f32(pos.x() - (sinT + cosT), pos.y(), pos.z() - (cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(0.f, 0.f);
|
|
|
|
GXPosition3f32(pos.x() + (-sinT + cosT), pos.y(), pos.z() + (-cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(1.f, 0.f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CElementGen::RenderBasicParticlesRotTS(const zeus::CTransform& xf) noexcept {
|
|
|
|
for (const auto& particle : x30_particles) {
|
|
|
|
const auto pos = xf * (x80_timeDeltaScale * (particle.x4_pos - particle.x10_prevPos) + particle.x10_prevPos);
|
|
|
|
const auto size = 0.5f * particle.x2c_lineLengthOrSize;
|
|
|
|
const float theta = zeus::degToRad(particle.x30_lineWidthOrRota);
|
|
|
|
const float sinT = std::sin(theta) * size;
|
|
|
|
const float cosT = std::cos(theta) * size;
|
|
|
|
GXPosition3f32(pos.x() + (sinT + cosT), pos.y(), pos.z() + (cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(1.f, 1.f);
|
|
|
|
GXPosition3f32(pos.x() + (sinT - cosT), pos.y(), pos.z() + (sinT + cosT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(0.f, 1.f);
|
|
|
|
GXPosition3f32(pos.x() - (sinT + cosT), pos.y(), pos.z() - (cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(0.f, 0.f);
|
|
|
|
GXPosition3f32(pos.x() + (-sinT + cosT), pos.y(), pos.z() + (-cosT - sinT));
|
|
|
|
GXColor4f32(particle.x34_color);
|
|
|
|
GXTexCoord2f32(1.f, 0.f);
|
|
|
|
}
|
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|