2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-05-15 02:31:20 +00:00

Various bug fixes

This commit is contained in:
Jack Andersen 2018-10-20 18:14:00 -10:00
parent 395e5c191b
commit 8fb77eac2c
20 changed files with 256 additions and 118 deletions

View File

@ -131,7 +131,7 @@ void AROTBuilder::Node::addChild(int level, int minChildren, const std::vector<z
compareSets(4, 5) || compareSets(4, 5) ||
compareSets(2, 3) || compareSets(2, 3) ||
compareSets(6, 7)) compareSets(6, 7))
compSubdivs |= 0x4; compSubdivs |= 0x1;
if (compareSets(0, 2) || if (compareSets(0, 2) ||
compareSets(1, 3) || compareSets(1, 3) ||
compareSets(4, 6) || compareSets(4, 6) ||
@ -141,7 +141,7 @@ void AROTBuilder::Node::addChild(int level, int minChildren, const std::vector<z
compareSets(1, 5) || compareSets(1, 5) ||
compareSets(2, 6) || compareSets(2, 6) ||
compareSets(3, 7)) compareSets(3, 7))
compSubdivs |= 0x1; compSubdivs |= 0x4;
if (!compSubdivs) if (!compSubdivs)
{ {
@ -175,11 +175,11 @@ void AROTBuilder::Node::nodeCount(size_t& sz, size_t& idxRefs, BitmapPool& bmpPo
curOff += nodeSz; curOff += nodeSz;
if (childNodes.size()) if (childNodes.size())
{ {
for (int k=0 ; k < 1 + ((compSubdivs & 0x1) != 0) ; ++k) for (int k=0 ; k < 1 + ((compSubdivs & 0x4) != 0) ; ++k)
{ {
for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j) for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j)
{ {
for (int i=0 ; i < 1 + ((compSubdivs & 0x4) != 0) ; ++i) for (int i=0 ; i < 1 + ((compSubdivs & 0x1) != 0) ; ++i)
{ {
int idx = k*4 + j*2 + i; int idx = k*4 + j*2 + i;
childNodes[idx].nodeCount(sz, idxRefs, bmpPool, curOff); childNodes[idx].nodeCount(sz, idxRefs, bmpPool, curOff);
@ -195,11 +195,11 @@ void AROTBuilder::Node::writeIndirectionTable(athena::io::MemoryWriter& w)
w.writeUint32Big(nodeOff); w.writeUint32Big(nodeOff);
if (childNodes.size()) if (childNodes.size())
{ {
for (int k=0 ; k < 1 + ((compSubdivs & 0x1) != 0) ; ++k) for (int k=0 ; k < 1 + ((compSubdivs & 0x4) != 0) ; ++k)
{ {
for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j) for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j)
{ {
for (int i=0 ; i < 1 + ((compSubdivs & 0x4) != 0) ; ++i) for (int i=0 ; i < 1 + ((compSubdivs & 0x1) != 0) ; ++i)
{ {
int idx = k*4 + j*2 + i; int idx = k*4 + j*2 + i;
childNodes[idx].writeIndirectionTable(w); childNodes[idx].writeIndirectionTable(w);
@ -222,11 +222,11 @@ void AROTBuilder::Node::writeNodes(athena::io::MemoryWriter& w, int nodeIdx)
int childIndices[8]; int childIndices[8];
for (int k=0 ; k < 1 + ((compSubdivs & 0x1) != 0) ; ++k) for (int k=0 ; k < 1 + ((compSubdivs & 0x4) != 0) ; ++k)
{ {
for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j) for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j)
{ {
for (int i=0 ; i < 1 + ((compSubdivs & 0x4) != 0) ; ++i) for (int i=0 ; i < 1 + ((compSubdivs & 0x1) != 0) ; ++i)
{ {
int idx = k*4 + j*2 + i; int idx = k*4 + j*2 + i;
w.writeUint16Big(curIdx); w.writeUint16Big(curIdx);
@ -236,11 +236,11 @@ void AROTBuilder::Node::writeNodes(athena::io::MemoryWriter& w, int nodeIdx)
} }
} }
for (int k=0 ; k < 1 + ((compSubdivs & 0x1) != 0) ; ++k) for (int k=0 ; k < 1 + ((compSubdivs & 0x4) != 0) ; ++k)
{ {
for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j) for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j)
{ {
for (int i=0 ; i < 1 + ((compSubdivs & 0x4) != 0) ; ++i) for (int i=0 ; i < 1 + ((compSubdivs & 0x1) != 0) ; ++i)
{ {
int idx = k*4 + j*2 + i; int idx = k*4 + j*2 + i;
childNodes[idx].writeNodes(w, childIndices[idx]); childNodes[idx].writeNodes(w, childIndices[idx]);
@ -255,11 +255,11 @@ void AROTBuilder::Node::advanceIndex(int& nodeIdx)
++nodeIdx; ++nodeIdx;
if (childNodes.size()) if (childNodes.size())
{ {
for (int k=0 ; k < 1 + ((compSubdivs & 0x1) != 0) ; ++k) for (int k=0 ; k < 1 + ((compSubdivs & 0x4) != 0) ; ++k)
{ {
for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j) for (int j=0 ; j < 1 + ((compSubdivs & 0x2) != 0) ; ++j)
{ {
for (int i=0 ; i < 1 + ((compSubdivs & 0x4) != 0) ; ++i) for (int i=0 ; i < 1 + ((compSubdivs & 0x1) != 0) ; ++i)
{ {
int idx = k*4 + j*2 + i; int idx = k*4 + j*2 + i;
childNodes[idx].advanceIndex(nodeIdx); childNodes[idx].advanceIndex(nodeIdx);

View File

@ -310,7 +310,10 @@ void ELSM<IDType>::_read(athena::io::YAMLDocReader& r)
LogModule.report(logvisor::Warning, "short FourCC in element '%s'", elem.first.c_str()); LogModule.report(logvisor::Warning, "short FourCC in element '%s'", elem.first.c_str());
continue; continue;
} }
switch(*reinterpret_cast<const uint32_t*>(elem.first.data()))
if (auto rec = r.enterSubRecord(elem.first.c_str()))
{
switch (*reinterpret_cast<const uint32_t*>(elem.first.data()))
{ {
case SBIG('LIFE'): case SBIG('LIFE'):
x0_LIFE.read(r); x0_LIFE.read(r);
@ -372,6 +375,9 @@ void ELSM<IDType>::_read(athena::io::YAMLDocReader& r)
case SBIG('ZERY'): case SBIG('ZERY'):
x70_ZERY.read(r); x70_ZERY.read(r);
break; break;
default:
break;
}
} }
} }
} }

View File

@ -108,6 +108,8 @@ void SWSH<IDType>::_read(typename BigDNA::ReadYaml::StreamT& r)
case SBIG('CRND'): case SBIG('CRND'):
x45_26_CRND = r.readBool(nullptr); x45_26_CRND = r.readBool(nullptr);
break; break;
default:
break;
} }
} }
} }

View File

@ -160,7 +160,7 @@ static void OutputOctreeNode(hecl::blender::PyOutStream& os, athena::io::MemoryR
static const uint32_t AROTChildCounts[] = { 0, 2, 2, 4, 2, 4, 4, 8 }; static const uint32_t AROTChildCounts[] = { 0, 2, 2, 4, 2, 4, 4, 8 };
/* AROT octree dumper */ /* AROT octree dumper */
static void OutputOctreeNode(hecl::blender::PyOutStream& os, athena::io::MemoryReader& r, static void OutputOctreeNode(hecl::blender::PyOutStream& os, athena::io::IStreamReader& r,
const zeus::CAABox& aabb) const zeus::CAABox& aabb)
{ {
r.readUint16Big(); r.readUint16Big();
@ -171,19 +171,19 @@ static void OutputOctreeNode(hecl::blender::PyOutStream& os, athena::io::MemoryR
r.seek(2 * childCount); r.seek(2 * childCount);
zeus::CAABox Z[2] = {aabb}; zeus::CAABox Z[2] = {aabb};
if ((flags & 0x1) != 0) if ((flags & 0x4) != 0)
aabb.splitZ(Z[0], Z[1]); aabb.splitZ(Z[0], Z[1]);
for (int k=0 ; k < 1 + ((flags & 0x1) != 0) ; ++k) for (int k=0 ; k < 1 + ((flags & 0x4) != 0) ; ++k)
{ {
zeus::CAABox Y[2] = {Z[0]}; zeus::CAABox Y[2] = {Z[k]};
if ((flags & 0x2) != 0) if ((flags & 0x2) != 0)
Z[k].splitY(Y[0], Y[1]); Z[k].splitY(Y[0], Y[1]);
for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j) for (int j=0 ; j < 1 + ((flags & 0x2) != 0) ; ++j)
{ {
zeus::CAABox X[2] = {Y[0]}; zeus::CAABox X[2] = {Y[j]};
if ((flags & 0x4) != 0) if ((flags & 0x1) != 0)
Y[j].splitX(X[0], X[1]); Y[j].splitX(X[0], X[1]);
for (int i=0 ; i < 1 + ((flags & 0x4) != 0) ; ++i) for (int i=0 ; i < 1 + ((flags & 0x1) != 0) ; ++i)
{ {
OutputOctreeNode(os, r, X[i]); OutputOctreeNode(os, r, X[i]);
} }

View File

@ -23,13 +23,13 @@ namespace urde
static logvisor::Module Log("CBooRenderer"); static logvisor::Module Log("CBooRenderer");
static rstl::reserved_vector<CDrawable, 4096> sDataHolder; static rstl::reserved_vector<CDrawable, 512> sDataHolder;
static rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50> sBucketsHolder; static rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50> sBucketsHolder;
static rstl::reserved_vector<CDrawablePlaneObject, 8> sPlaneObjectDataHolder; static rstl::reserved_vector<CDrawablePlaneObject, 8> sPlaneObjectDataHolder;
static rstl::reserved_vector<u16, 8> sPlaneObjectBucketHolder; static rstl::reserved_vector<u16, 8> sPlaneObjectBucketHolder;
rstl::reserved_vector<u16, 50> Buckets::sBucketIndex; rstl::reserved_vector<u16, 50> Buckets::sBucketIndex;
rstl::reserved_vector<CDrawable, 4096>* Buckets::sData = nullptr; rstl::reserved_vector<CDrawable, 512>* Buckets::sData = nullptr;
rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50>* Buckets::sBuckets = nullptr; rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50>* Buckets::sBuckets = nullptr;
rstl::reserved_vector<CDrawablePlaneObject, 8>* Buckets::sPlaneObjectData = nullptr; rstl::reserved_vector<CDrawablePlaneObject, 8>* Buckets::sPlaneObjectData = nullptr;
rstl::reserved_vector<u16, 8>* Buckets::sPlaneObjectBucket = nullptr; rstl::reserved_vector<u16, 8>* Buckets::sPlaneObjectBucket = nullptr;
@ -119,6 +119,8 @@ void Buckets::Sort()
rstl::reserved_vector<CDrawable*, 128>& bucket = (*sBuckets)[slot]; rstl::reserved_vector<CDrawable*, 128>& bucket = (*sBuckets)[slot];
if (bucket.size() < bucket.capacity()) if (bucket.size() < bucket.capacity())
bucket.push_back(&drawable); bucket.push_back(&drawable);
//else
// Log.report(logvisor::Fatal, "Full bucket!!!");
} }
u16 bucketIdx = u16(sBuckets->size()); u16 bucketIdx = u16(sBuckets->size());

View File

@ -31,7 +31,7 @@ class Buckets
friend class CBooRenderer; friend class CBooRenderer;
static rstl::reserved_vector<u16, 50> sBucketIndex; static rstl::reserved_vector<u16, 50> sBucketIndex;
static rstl::reserved_vector<CDrawable, 4096>* sData; static rstl::reserved_vector<CDrawable, 512>* sData;
static rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50>* sBuckets; static rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50>* sBuckets;
static rstl::reserved_vector<CDrawablePlaneObject, 8>* sPlaneObjectData; static rstl::reserved_vector<CDrawablePlaneObject, 8>* sPlaneObjectData;
static rstl::reserved_vector<u16, 8>* sPlaneObjectBucket; static rstl::reserved_vector<u16, 8>* sPlaneObjectBucket;

View File

@ -626,21 +626,10 @@ void CBooModel::DrawSurfaces(const CModelFlags& flags) const
} }
} }
void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data, const CModelFlags& flags)
{ {
//if (m_uniUpdateCount == 0)
// Log.report(logvisor::Fatal, "UpdateUniformData() not called");
if (m_uniUpdateCount == 0 || m_uniUpdateCount > m_instances.size())
return;
const ModelInstance& inst = m_instances[m_uniUpdateCount-1];
const MaterialSet::Material& data = GetMaterialByIndex(surf.m_data.matIdx);
if (data.flags.shadowOccluderMesh() && !g_DrawingOccluders)
return;
bool noZWrite = flags.m_noZWrite || !data.flags.depthWrite(); bool noZWrite = flags.m_noZWrite || !data.flags.depthWrite();
const std::vector<boo::ObjToken<boo::IShaderDataBinding>>& extendeds = inst.m_shaderDataBindings[surf.selfIdx];
EExtendedShader extended = EExtendedShader::Flat; EExtendedShader extended = EExtendedShader::Flat;
if (flags.m_extendedShader == EExtendedShader::Lighting) if (flags.m_extendedShader == EExtendedShader::Lighting)
{ {
@ -698,11 +687,29 @@ void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) c
extended = EExtendedShader::Lighting; extended = EExtendedShader::Lighting;
} }
} }
else if (flags.m_extendedShader < extendeds.size()) else if (flags.m_extendedShader < EExtendedShader::MAX)
{ {
extended = flags.m_extendedShader; extended = flags.m_extendedShader;
} }
return extended;
}
void CBooModel::DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const
{
//if (m_uniUpdateCount == 0)
// Log.report(logvisor::Fatal, "UpdateUniformData() not called");
if (m_uniUpdateCount == 0 || m_uniUpdateCount > m_instances.size())
return;
const ModelInstance& inst = m_instances[m_uniUpdateCount-1];
const MaterialSet::Material& data = GetMaterialByIndex(surf.m_data.matIdx);
if (data.flags.shadowOccluderMesh() && !g_DrawingOccluders)
return;
const std::vector<boo::ObjToken<boo::IShaderDataBinding>>& extendeds = inst.m_shaderDataBindings[surf.selfIdx];
EExtendedShader extended = ResolveExtendedShader(data, flags);
boo::ObjToken<boo::IShaderDataBinding> binding = extendeds[extended]; boo::ObjToken<boo::IShaderDataBinding> binding = extendeds[extended];
CGraphics::SetShaderDataBinding(binding); CGraphics::SetShaderDataBinding(binding);
CGraphics::DrawArrayIndexed(surf.m_data.idxStart, surf.m_data.idxCount); CGraphics::DrawArrayIndexed(surf.m_data.idxStart, surf.m_data.idxCount);

View File

@ -279,7 +279,8 @@ void CFluidPlaneShader::prepareDraw(const RenderSetupInfo& info,
for (i=0 ; i<3 ; ++i) for (i=0 ; i<3 ; ++i)
uni.m_lighting.colorRegs[i] = info.kColors[i]; uni.m_lighting.colorRegs[i] = info.kColors[i];
uni.m_lighting.mulColor = info.kColors[3]; uni.m_lighting.mulColor = info.kColors[3];
uni.m_lighting.fog.m_rangeScale = info.indScale; uni.m_lighting.fog = CGraphics::g_Fog;
uni.m_pad2.x = info.indScale;
m_uniBuf->unmap(); m_uniBuf->unmap();
} }

View File

@ -103,7 +103,7 @@ private:
zeus::CVector4f m_colorMul; zeus::CVector4f m_colorMul;
zeus::CVector4f m_pad[3]; // rippleNormResolution, Pad out to 1280 bytes zeus::CVector4f m_pad[3]; // rippleNormResolution, Pad out to 1280 bytes
CModelShaders::LightingUniform m_lighting; CModelShaders::LightingUniform m_lighting;
zeus::CVector3f m_pad2; // Pad out to 768 bytes zeus::CVector3f m_pad2; // Pad out to 768 bytes, also holds ind scale
}; };
TLockedToken<CTexture> m_patternTex1; TLockedToken<CTexture> m_patternTex1;

View File

@ -148,7 +148,11 @@ static std::string_view MainPostGLSL =
" fogZ = 0.0;\n" " fogZ = 0.0;\n"
" break;\n" " break;\n"
" }\n" " }\n"
" return mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0));\n" "#ifdef BLEND_DST_ONE\n"
" return vec4(mix(colorIn, vec4(0.0), clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a);\n"
"#else\n"
" return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a);\n"
"#endif\n"
"}\n" "}\n"
"\n"sv; "\n"sv;

View File

@ -144,7 +144,11 @@ static std::string_view MainPostHLSL =
" fogZ = 0.0;\n" " fogZ = 0.0;\n"
" break;\n" " break;\n"
" }\n" " }\n"
" return lerp(colorIn, fog.color, saturate(fogZ));\n" "#ifdef BLEND_DST_ONE\n"
" return float4(lerp(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a);\n"
"#else\n"
" return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a);\n"
"#endif\n"
"}\n" "}\n"
"\n"sv; "\n"sv;

View File

@ -145,7 +145,11 @@ static std::string_view MainPostMetal =
" fogZ = 0.0;\n" " fogZ = 0.0;\n"
" break;\n" " break;\n"
" }\n" " }\n"
" return mix(colorIn, lu.fog.color, saturate(fogZ));\n" "#ifdef BLEND_DST_ONE\n"
" return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a);\n"
"#else\n"
" return float4(mix(colorIn, lu.fog.color, saturate(fogZ)).rgb, colorIn.a);\n"
"#endif\n"
"}\n" "}\n"
"\n"sv; "\n"sv;

View File

@ -18,6 +18,8 @@ u16 CParticleElectric::g_GlobalSeed = 99;
CParticleElectric::CParticleElectric(const TToken<CElectricDescription>& token) CParticleElectric::CParticleElectric(const TToken<CElectricDescription>& token)
: x1c_elecDesc(token), x14c_randState(g_GlobalSeed++) : x1c_elecDesc(token), x14c_randState(g_GlobalSeed++)
{ {
x1bc_allocated.resize(32);
x450_24_emitting = true; x450_24_emitting = true;
x450_29_transformDirty = true; x450_29_transformDirty = true;
CElectricDescription* desc = x1c_elecDesc.GetObj(); CElectricDescription* desc = x1c_elecDesc.GetObj();

View File

@ -49,8 +49,8 @@ private:
zeus::CTransform x74_invOrientation; zeus::CTransform x74_invOrientation;
zeus::CVector3f xa4_globalTranslation; zeus::CVector3f xa4_globalTranslation;
zeus::CTransform xb0_globalOrientation; zeus::CTransform xb0_globalOrientation;
zeus::CVector3f xe0_globalScale; zeus::CVector3f xe0_globalScale = zeus::CVector3f::skOne;
zeus::CVector3f xec_localScale; zeus::CVector3f xec_localScale = zeus::CVector3f::skOne;
zeus::CTransform xf8_cachedXf; zeus::CTransform xf8_cachedXf;
float x128 = 0.f; float x128 = 0.f;
float x12c = 0.f; float x12c = 0.f;

View File

@ -2139,7 +2139,7 @@ void CMorphBall::CollidedWith(TUniqueId id, const CCollisionInfoList& list, CSta
} }
if (wakeMaterial == EMaterialTypes::NoStepLogic && x1c0c_wakeEffectIdx != -1) if (wakeMaterial == EMaterialTypes::NoStepLogic && x1c0c_wakeEffectIdx != -1)
x1bc8_wakeEffectGens[int(wakeMaterial)]->SetParticleEmission(false); x1bc8_wakeEffectGens[int(x1c0c_wakeEffectIdx)]->SetParticleEmission(false);
x1954_isProjectile = false; x1954_isProjectile = false;

View File

@ -132,7 +132,7 @@ void CScriptEffect::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId uid, CSt
if (x104_particleSystem && x104_particleSystem->SystemHasLight()) if (x104_particleSystem && x104_particleSystem->SystemHasLight())
{ {
x108_lightId = mgr.AllocateUniqueId(); x108_lightId = mgr.AllocateUniqueId();
mgr.AddObject(new CGameLight(x108_lightId, GetAreaIdAlways(), true, mgr.AddObject(new CGameLight(x108_lightId, GetAreaIdAlways(), GetActive(),
std::string("EffectPLight_") + GetName().data(), x34_transform, GetUniqueId(), std::string("EffectPLight_") + GetName().data(), x34_transform, GetUniqueId(),
x104_particleSystem->GetLight(), x10c_partId.Value(), 1, 0.f)); x104_particleSystem->GetLight(), x10c_partId.Value(), 1, 0.f));
} }

View File

@ -179,8 +179,9 @@ static const char* FS =
"{\n" "{\n"
" int mode;\n" " int mode;\n"
" vec4 color;\n" " vec4 color;\n"
" float indScale;\n" " float rangeScale;\n"
" float start;\n" " float start;\n"
" float indScale;\n"
"};\n" "};\n"
"\n" "\n"
"UBINDING2 uniform LightingUniform\n" "UBINDING2 uniform LightingUniform\n"
@ -226,12 +227,46 @@ static const char* FS =
"};\n" "};\n"
"\n" "\n"
"SBINDING(0) in VertToFrag vtf;\n" "SBINDING(0) in VertToFrag vtf;\n"
"vec4 MainPostFunc(vec4 colorIn)\n"
"{\n"
" float fogZ, temp;\n"
" switch (fog.mode)\n"
" {\n"
" case 2:\n"
" fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" break;\n"
" case 4:\n"
" fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - fog.start) * fog.rangeScale);\n"
" break;\n"
" case 5:\n"
" temp = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" fogZ = 1.0 - exp2(-8.0 * temp * temp);\n"
" break;\n"
" case 6:\n"
" fogZ = exp2(-8.0 * (fog.start + vtf.mvPos.z) * fog.rangeScale);\n"
" break;\n"
" case 7:\n"
" temp = (fog.start + vtf.mvPos.z) * fog.rangeScale;\n"
" fogZ = exp2(-8.0 * temp * temp);\n"
" break;\n"
" default:\n"
" fogZ = 0.0;\n"
" break;\n"
" }\n"
"#if %d\n"
" return vec4(mix(colorIn, vec4(0.0), clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a);\n"
"#else\n"
" return vec4(mix(colorIn, fog.color, clamp(fogZ, 0.0, 1.0)).rgb, colorIn.a);\n"
"#endif\n"
"}\n"
"\n"
"layout(location=0) out vec4 colorOut;\n" "layout(location=0) out vec4 colorOut;\n"
"%s" // Textures here "%s" // Textures here
"void main()\n" "void main()\n"
"{\n" "{\n"
" vec4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n" " vec4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n"
"%s" // Combiner expression here "%s" // Combiner expression here
" colorOut = MainPostFunc(colorOut);\n"
"}\n"; "}\n";
static const char* FSDoor = static const char* FSDoor =
@ -248,8 +283,9 @@ static const char* FSDoor =
"{\n" "{\n"
" int mode;\n" " int mode;\n"
" vec4 color;\n" " vec4 color;\n"
" float indScale;\n" " float rangeScale;\n"
" float start;\n" " float start;\n"
" float indScale;\n"
"};\n" "};\n"
"\n" "\n"
"UBINDING2 uniform LightingUniform\n" "UBINDING2 uniform LightingUniform\n"
@ -592,7 +628,7 @@ static std::string _BuildFS(const SFluidPlaneShaderInfo& info)
combiner += " colorOut.a = kColor0.a;\n"; combiner += " colorOut.a = kColor0.a;\n";
char *finalFSs; char *finalFSs;
asprintf(&finalFSs, FS, textures.c_str(), combiner.c_str()); asprintf(&finalFSs, FS, int(info.m_additive), textures.c_str(), combiner.c_str());
std::string ret(finalFSs); std::string ret(finalFSs);
free(finalFSs); free(finalFSs);
return ret; return ret;

View File

@ -215,8 +215,9 @@ static const char* FS =
"{\n" "{\n"
" int mode;\n" " int mode;\n"
" float4 color;\n" " float4 color;\n"
" float indScale;\n" " float rangeScale;\n"
" float start;\n" " float start;\n"
" float indScale;\n"
"};\n" "};\n"
"\n" "\n"
"cbuffer LightingUniform : register(b2)\n" "cbuffer LightingUniform : register(b2)\n"
@ -262,6 +263,39 @@ static const char* FS =
" float2 uvs[7] : UV;\n" " float2 uvs[7] : UV;\n"
"};\n" "};\n"
"\n" "\n"
"static float4 MainPostFunc(in VertToFrag vtf, float4 colorIn)\n"
"{\n"
" float fogZ, temp;\n"
" switch (fog.mode)\n"
" {\n"
" case 2:\n"
" fogZ = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" break;\n"
" case 4:\n"
" fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - fog.start) * fog.rangeScale);\n"
" break;\n"
" case 5:\n"
" temp = (-vtf.mvPos.z - fog.start) * fog.rangeScale;\n"
" fogZ = 1.0 - exp2(-8.0 * temp * temp);\n"
" break;\n"
" case 6:\n"
" fogZ = exp2(-8.0 * (fog.start + vtf.mvPos.z) * fog.rangeScale);\n"
" break;\n"
" case 7:\n"
" temp = (fog.start + vtf.mvPos.z) * fog.rangeScale;\n"
" fogZ = exp2(-8.0 * temp * temp);\n"
" break;\n"
" default:\n"
" fogZ = 0.0;\n"
" break;\n"
" }\n"
"#if %d\n"
" return float4(lerp(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a);\n"
"#else\n"
" return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a);\n"
"#endif\n"
"}\n"
"\n"
"SamplerState samp : register(s0);\n" "SamplerState samp : register(s0);\n"
"%s" // Textures here "%s" // Textures here
"float4 main(in VertToFrag vtf) : SV_Target0\n" "float4 main(in VertToFrag vtf) : SV_Target0\n"
@ -269,7 +303,7 @@ static const char* FS =
" float4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n" " float4 lighting = LightingFunc(vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n"
" float4 colorOut;\n" " float4 colorOut;\n"
"%s" // Combiner expression here "%s" // Combiner expression here
" return colorOut;\n" " return MainPostFunc(vtf, colorOut);\n"
"}\n"; "}\n";
static const char* FSDoor = static const char* FSDoor =
@ -285,8 +319,9 @@ static const char* FSDoor =
"{\n" "{\n"
" int mode;\n" " int mode;\n"
" float4 color;\n" " float4 color;\n"
" float indScale;\n" " float rangeScale;\n"
" float start;\n" " float start;\n"
" float indScale;\n"
"};\n" "};\n"
"\n" "\n"
"cbuffer LightingUniform : register(b2)\n" "cbuffer LightingUniform : register(b2)\n"
@ -622,7 +657,7 @@ static std::string _BuildFS(const SFluidPlaneShaderInfo& info)
combiner += " colorOut.a = kColor0.a;\n"; combiner += " colorOut.a = kColor0.a;\n";
char *finalFS; char *finalFS;
asprintf(&finalFS, FS, textures.c_str(), combiner.c_str()); asprintf(&finalFS, FS, int(info.m_additive), textures.c_str(), combiner.c_str());
std::string ret(finalFS); std::string ret(finalFS);
free(finalFS); free(finalFS);
return ret; return ret;

View File

@ -199,8 +199,9 @@ static const char* FS =
"{\n" "{\n"
" int mode;\n" " int mode;\n"
" float4 color;\n" " float4 color;\n"
" float indScale;\n" " float rangeScale;\n"
" float start;\n" " float start;\n"
" float indScale;\n"
"};\n" "};\n"
"\n" "\n"
"struct LightingUniform\n" "struct LightingUniform\n"
@ -252,6 +253,39 @@ static const char* FS =
" float2 uv6;\n" " float2 uv6;\n"
"};\n" "};\n"
"\n" "\n"
"float4 MainPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n"
"{\n"
" float fogZ, temp;\n"
" switch (lu.fog.mode)\n"
" {\n"
" case 2:\n"
" fogZ = (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale;\n"
" break;\n"
" case 4:\n"
" fogZ = 1.0 - exp2(-8.0 * (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale);\n"
" break;\n"
" case 5:\n"
" temp = (-vtf.mvPos.z - lu.fog.start) * lu.fog.rangeScale;\n"
" fogZ = 1.0 - exp2(-8.0 * temp * temp);\n"
" break;\n"
" case 6:\n"
" fogZ = exp2(-8.0 * (lu.fog.start + vtf.mvPos.z) * lu.fog.rangeScale);\n"
" break;\n"
" case 7:\n"
" temp = (lu.fog.start + vtf.mvPos.z) * lu.fog.rangeScale;\n"
" fogZ = exp2(-8.0 * temp * temp);\n"
" break;\n"
" default:\n"
" fogZ = 0.0;\n"
" break;\n"
" }\n"
"#if %d\n"
" return float4(mix(colorIn, float4(0.0), saturate(fogZ)).rgb, colorIn.a);\n"
"#else\n"
" return float4(mix(colorIn, lu.fog.color, saturate(fogZ)).rgb, colorIn.a);\n"
"#endif\n"
"}\n"
"\n"
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" "fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
" sampler samp [[ sampler(0) ]],\n" " sampler samp [[ sampler(0) ]],\n"
" constant LightingUniform& lu [[ buffer(4) ]]%s)\n" // Textures here " constant LightingUniform& lu [[ buffer(4) ]]%s)\n" // Textures here
@ -259,7 +293,7 @@ static const char* FS =
" float4 lighting = LightingFunc(lu, vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n" " float4 lighting = LightingFunc(lu, vtf.mvPos.xyz, normalize(vtf.mvNorm.xyz));\n"
" float4 colorOut;\n" " float4 colorOut;\n"
"%s" // Combiner expression here "%s" // Combiner expression here
" return colorOut;\n" " return MainPostFunc(vtf, lu, colorOut);\n"
"}\n"; "}\n";
static const char* FSDoor = static const char* FSDoor =
@ -275,8 +309,9 @@ static const char* FSDoor =
"{\n" "{\n"
" int mode;\n" " int mode;\n"
" float4 color;\n" " float4 color;\n"
" float indScale;\n" " float rangeScale;\n"
" float start;\n" " float start;\n"
" float indScale;\n"
"};\n" "};\n"
"\n" "\n"
"struct LightingUniform\n" "struct LightingUniform\n"
@ -614,7 +649,7 @@ static std::string _BuildFS(const SFluidPlaneShaderInfo& info)
combiner += " colorOut.a = lu.kColor0.a;\n"; combiner += " colorOut.a = lu.kColor0.a;\n";
char *finalFS; char *finalFS;
asprintf(&finalFS, FS, textures.c_str(), combiner.c_str()); asprintf(&finalFS, FS, int(info.m_additive), textures.c_str(), combiner.c_str());
std::string ret(finalFS); std::string ret(finalFS);
free(finalFS); free(finalFS);
return ret; return ret;

2
hecl

@ -1 +1 @@
Subproject commit 0d7f6d7f5b5fba3ec79abaa754ed589b3705763a Subproject commit e83f40f5ca9c5f0bc7664bbda19c43574172f42e