All CEnvFxManager effects working

This commit is contained in:
Jack Andersen 2018-11-02 22:46:12 -10:00
parent 97f18efd27
commit d140f35886
9 changed files with 81 additions and 31 deletions

View File

@ -204,7 +204,8 @@ void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo,
TLockedToken<CTexture> tex = g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), iconRes}); TLockedToken<CTexture> tex = g_SimplePool->GetObj(SObjectTag{FOURCC('TXTR'), iconRes});
if (!m_texQuadFilter || m_texQuadFilter->GetTex().GetObj() != tex.GetObj()) if (!m_texQuadFilter || m_texQuadFilter->GetTex().GetObj() != tex.GetObj())
const_cast<CMappableObject*>(this)->m_texQuadFilter.emplace(EFilterType::Add, tex); const_cast<CMappableObject*>(this)->m_texQuadFilter.emplace(EFilterType::Add, tex,
CTexturedQuadFilter::ZTest::GEqual);
CTexturedQuadFilter::Vert verts[4] = CTexturedQuadFilter::Vert verts[4] =
{ {

View File

@ -435,8 +435,11 @@ void CAreaOctTree::Node::LineTestExInternal(const zeus::CLine& line, const CMate
if (child.x20_nodeType != ETreeType::Invalid) if (child.x20_nodeType != ETreeType::Invalid)
child.LineTestExInternal(line, filter, res, tmpLoT, tmpHiT, maxT, dirRecip); child.LineTestExInternal(line, filter, res, tmpLoT, tmpHiT, maxT, dirRecip);
if (res.x10_surface) if (res.x10_surface)
{
if (res.x3c_t > highT) if (res.x3c_t > highT)
res = SRayResult(); res = SRayResult();
break;
}
} }
tmpLoT = tmpHiT; tmpLoT = tmpHiT;
} }

View File

@ -22,18 +22,12 @@ public:
class TriListReference class TriListReference
{ {
u16 m_count; const u16* m_ptr;
std::unique_ptr<u16[]> m_refs;
public: public:
TriListReference(const u16* ptr) TriListReference(const u16* ptr)
: m_count(ptr[0]) : m_ptr(ptr) {}
{ u16 GetAt(int idx) const { return m_ptr[idx+1]; }
m_refs.reset(new u16[m_count]); u16 GetSize() const { return m_ptr[0]; }
for (u16 i=0 ; i<m_count ; ++i)
m_refs[i] = ptr[i+1];
}
u16 GetAt(int idx) const { return m_refs[idx]; }
u16 GetSize() const { return m_count; }
}; };
class Node class Node

View File

@ -19,7 +19,8 @@ public:
}; };
struct Uniform struct Uniform
{ {
zeus::CMatrix4f mvp; zeus::CMatrix4f mv;
zeus::CMatrix4f proj;
zeus::CMatrix4f envMtx; zeus::CMatrix4f envMtx;
zeus::CColor moduColor; zeus::CColor moduColor;
}; };

View File

@ -187,7 +187,7 @@ void CEnvFxManager::CalculateSnowForces(const CVectorFixed8_8& zVec,
{ {
CVectorFixed8_8 vecf; CVectorFixed8_8 vecf;
zeus::CVector3f vec; zeus::CVector3f vec;
for (int i = 255; i >= 0; ++i) for (int i = 255; i >= 0; --i)
{ {
const zeus::CVector2f& force = g_SnowForces[i]; const zeus::CVector2f& force = g_SnowForces[i];
zeus::CVector3f delta = zeus::CVector3f(force * dt) * oopbtws; zeus::CVector3f delta = zeus::CVector3f(force * dt) * oopbtws;
@ -392,7 +392,7 @@ void CEnvFxManager::Update(float dt, CStateManager& mgr)
zeus::CVector3f oopbtws = 1.f / pbtws; zeus::CVector3f oopbtws = 1.f / pbtws;
zeus::CVector3f forwardPoint = camXf.basis[1] * 23.8125f + camXf.origin; zeus::CVector3f forwardPoint = camXf.basis[1] * 23.8125f + camXf.origin;
float modX = std::fmod(forwardPoint.x, 7.9375f); float modX = std::fmod(forwardPoint.x, 7.9375f);
float modY = std::fmod(forwardPoint.x, 7.9375f); float modY = std::fmod(forwardPoint.y, 7.9375f);
s32 moveX = (x18_focusCellPosition.x - (forwardPoint.x - modX)) / 7.9375f; s32 moveX = (x18_focusCellPosition.x - (forwardPoint.x - modX)) / 7.9375f;
x18_focusCellPosition.x = forwardPoint.x - modX; x18_focusCellPosition.x = forwardPoint.x - modX;
s32 moveY = (x18_focusCellPosition.y - (forwardPoint.y - modY)) / 7.9375f; s32 moveY = (x18_focusCellPosition.y - (forwardPoint.y - modY)) / 7.9375f;
@ -430,10 +430,37 @@ void CEnvFxManager::Update(float dt, CStateManager& mgr)
} }
} }
static zeus::CColor GetFlakeColor(const zeus::CMatrix4f& mvp, const CEnvFxShaders::Instance& inst)
{
float screenHeight = std::fabs(mvp.multiplyOneOverW(inst.positions[1]).y -
mvp.multiplyOneOverW(inst.positions[0]).y);
screenHeight -= (32.f / 480.f);
screenHeight /= (32.f / 480.f);
return zeus::CColor(1.f - zeus::clamp(0.f, screenHeight, 1.f), 1.f);
}
void CEnvFxManagerGrid::RenderSnowParticles(const zeus::CTransform& camXf) const void CEnvFxManagerGrid::RenderSnowParticles(const zeus::CTransform& camXf) const
{ {
zeus::CVector3f xVec = 0.2f * camXf.basis[0]; zeus::CVector3f xVec = 0.2f * camXf.basis[0];
zeus::CVector3f zVec = 0.2f * camXf.basis[2]; zeus::CVector3f zVec = 0.2f * camXf.basis[2];
zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(false) *
CGraphics::g_GXModelView.toMatrix4f();
auto* bufOut = m_instBuf.access();
for (const auto& particle : x1c_particles)
{
bufOut->positions[0] = particle.toVec3f();
bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f);
bufOut->positions[1] = bufOut->positions[0] + zVec;
bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f);
bufOut->positions[3] = bufOut->positions[1] + xVec;
bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f);
bufOut->positions[2] = bufOut->positions[3] - zVec;
bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f);
bufOut->color = GetFlakeColor(mvp, *bufOut);
++bufOut;
}
CGraphics::SetShaderDataBinding(m_snowBinding);
CGraphics::DrawInstances(0, 4, x1c_particles.size());
} }
void CEnvFxManagerGrid::RenderRainParticles(const zeus::CTransform& camXf) const void CEnvFxManagerGrid::RenderRainParticles(const zeus::CTransform& camXf) const
@ -456,7 +483,26 @@ void CEnvFxManagerGrid::RenderRainParticles(const zeus::CTransform& camXf) const
void CEnvFxManagerGrid::RenderUnderwaterParticles(const zeus::CTransform& camXf) const void CEnvFxManagerGrid::RenderUnderwaterParticles(const zeus::CTransform& camXf) const
{ {
zeus::CVector3f xVec = 0.5f * camXf.basis[0];
zeus::CVector3f zVec = 0.5f * camXf.basis[2];
zeus::CMatrix4f mvp = CGraphics::GetPerspectiveProjectionMatrix(false) *
CGraphics::g_GXModelView.toMatrix4f();
auto* bufOut = m_instBuf.access();
for (const auto& particle : x1c_particles)
{
bufOut->positions[0] = particle.toVec3f();
bufOut->uvs[0] = zeus::CVector2f(0.f, 0.f);
bufOut->positions[1] = bufOut->positions[0] + zVec;
bufOut->uvs[1] = zeus::CVector2f(0.f, 1.f);
bufOut->positions[3] = bufOut->positions[1] + xVec;
bufOut->uvs[3] = zeus::CVector2f(1.f, 1.f);
bufOut->positions[2] = bufOut->positions[3] - zVec;
bufOut->uvs[2] = zeus::CVector2f(1.f, 0.f);
bufOut->color = GetFlakeColor(mvp, *bufOut);
++bufOut;
}
CGraphics::SetShaderDataBinding(m_underwaterBinding);
CGraphics::DrawInstances(0, 4, x1c_particles.size());
} }
void CEnvFxManagerGrid::Render(const zeus::CTransform& xf, const zeus::CTransform& invXf, void CEnvFxManagerGrid::Render(const zeus::CTransform& xf, const zeus::CTransform& invXf,
@ -466,9 +512,8 @@ void CEnvFxManagerGrid::Render(const zeus::CTransform& xf, const zeus::CTransfor
if (!x1c_particles.empty() && x14_block.first) if (!x1c_particles.empty() && x14_block.first)
{ {
CGraphics::SetModelMatrix(xf * zeus::CTransform::Translate(x4_position.toVec2f() / 256.f)); CGraphics::SetModelMatrix(xf * zeus::CTransform::Translate(x4_position.toVec2f() / 256.f));
parent.m_uniformData.mvp = parent.m_uniformData.mv = CGraphics::g_GXModelView.toMatrix4f();
CGraphics::GetPerspectiveProjectionMatrix(true) * parent.m_uniformData.proj = CGraphics::GetPerspectiveProjectionMatrix(true);
CGraphics::g_GXModelView.toMatrix4f();
switch (fxType) switch (fxType)
{ {
case EEnvFxType::Snow: case EEnvFxType::Snow:
@ -608,6 +653,9 @@ void CEnvFxManager::Render(const CStateManager& mgr) const
for (const auto& grid : x50_grids) for (const auto& grid : x50_grids)
grid.Render(xf, invXf, camXf, x30_fxDensity, fxType, *this); grid.Render(xf, invXf, camXf, x30_fxDensity, fxType, *this);
// Backface cull // Backface cull
m_uniformPool.updateBuffers();
m_instPool.updateBuffers();
} }
} }
} }

View File

@ -98,6 +98,12 @@ class CEnvFxManager
{ {
friend class CEnvFxManagerGrid; friend class CEnvFxManagerGrid;
friend class CEnvFxShaders; friend class CEnvFxShaders;
mutable hecl::VertexBufferPool<CEnvFxShaders::Instance> m_instPool;
mutable hecl::UniformBufferPool<CEnvFxShaders::Uniform> m_uniformPool;
mutable CEnvFxShaders::Uniform m_uniformData;
boo::ObjToken<boo::IGraphicsBufferD> m_fogUniformBuf;
zeus::CAABox x0_particleBounds = zeus::CAABox(-63.5f, 63.5f); zeus::CAABox x0_particleBounds = zeus::CAABox(-63.5f, 63.5f);
zeus::CVector3f x18_focusCellPosition = zeus::CVector3f::skZero; zeus::CVector3f x18_focusCellPosition = zeus::CVector3f::skZero;
bool x24_enableSplash = false; bool x24_enableSplash = false;
@ -122,11 +128,6 @@ class CEnvFxManager
TLockedToken<CTexture> xc48_underwaterFlake; TLockedToken<CTexture> xc48_underwaterFlake;
bool xc54_ = true; bool xc54_ = true;
hecl::VertexBufferPool<CEnvFxShaders::Instance> m_instPool;
hecl::UniformBufferPool<CEnvFxShaders::Uniform> m_uniformPool;
mutable CEnvFxShaders::Uniform m_uniformData;
boo::ObjToken<boo::IGraphicsBufferD> m_fogUniformBuf;
void SetSplashEffectRate(float f, const CStateManager& mgr); void SetSplashEffectRate(float f, const CStateManager& mgr);
void UpdateRainSounds(const CStateManager& mgr); void UpdateRainSounds(const CStateManager& mgr);
zeus::CVector3f GetParticleBoundsToWorldScale() const; zeus::CVector3f GetParticleBoundsToWorldScale() const;

View File

@ -40,7 +40,7 @@ struct VertToFrag
SBINDING(0) out VertToFrag vtf; SBINDING(0) out VertToFrag vtf;
void main() void main()
{ {
vec4 pos = posIn[gl_VertexID]; vec4 pos = vec4(posIn[gl_VertexID].xyz, 1.0);
vtf.color = colorIn * moduColor; vtf.color = colorIn * moduColor;
vtf.uvFlake = uvsIn[gl_VertexID].xy; vtf.uvFlake = uvsIn[gl_VertexID].xy;
vtf.uvEnv = (envMtx * pos).xy; vtf.uvEnv = (envMtx * pos).xy;
@ -134,8 +134,9 @@ VertToFrag main(in VertData v, in uint vertId : SV_VertexID)
VertToFrag vtf; VertToFrag vtf;
vtf.color = v.colorIn * moduColor; vtf.color = v.colorIn * moduColor;
vtf.uvFlake = v.uvsIn[vertId].xy; vtf.uvFlake = v.uvsIn[vertId].xy;
vtf.uvEnv = mul(envMtx, v.posIn[vertId]).xy; float4 pos = float4(v.posIn[vertId].xyz, 1.0);
vtf.mvPos = mul(mv, v.posIn[vertId]); vtf.uvEnv = mul(envMtx, pos).xy;
vtf.mvPos = mul(mv, pos);
vtf.position = mul(proj, vtf.mvPos); vtf.position = mul(proj, vtf.mvPos);
return vtf; return vtf;
} }
@ -229,8 +230,9 @@ vertex VertToFrag vmain(constant VertData* va [[ buffer(1) ]],
constant VertData& v = va[instId]; constant VertData& v = va[instId];
vtf.color = v.colorIn * particle.moduColor; vtf.color = v.colorIn * particle.moduColor;
vtf.uvFlake = v.uvsIn[vertId].xy; vtf.uvFlake = v.uvsIn[vertId].xy;
vtf.uvEnv = (envMtx * v.posIn[vertId]).xy; float4 pos = float4(v.posIn[vertId].xyz, 1.0);
vtf.mvPos = particle.mv * v.posIn[vertId]; vtf.uvEnv = (envMtx * pos).xy;
vtf.mvPos = particle.mv * pos;
vtf.position = particle.proj * vtf.mvPos; vtf.position = particle.proj * vtf.mvPos;
return vtf; return vtf;
} }

View File

@ -78,7 +78,7 @@ VertToFrag main(in VertData v)
} }
#fragment hlsl #fragment hlsl
SamplerState samp : register(s0); SamplerState samp : register(s3);
Texture2D tex0 : register(t0); Texture2D tex0 : register(t0);
struct VertToFrag struct VertToFrag
{ {
@ -133,7 +133,7 @@ struct VertToFrag
}; };
fragment float4 fmain(VertToFrag vtf [[ stage_in ]], fragment float4 fmain(VertToFrag vtf [[ stage_in ]],
sampler samp [[ sampler(0) ]], sampler samp [[ sampler(3) ]],
texture2d<float> tex0 [[ texture(0) ]]) texture2d<float> tex0 [[ texture(0) ]])
{ {
return vtf.color * tex0.sample(samp, vtf.uv); return vtf.color * tex0.sample(samp, vtf.uv);

@ -1 +1 @@
Subproject commit 6475d4ad284a6106f55313f86d8fdc2ac13a381b Subproject commit 3b901a237a161551c6fe98c617f5c1f209730d8f