mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-08 13:44:56 +00:00
Various bug fixes
This commit is contained in:
@@ -25,6 +25,7 @@ struct CModelFlags {
|
||||
EExtendedShader m_extendedShader = EExtendedShader::Lighting;
|
||||
bool m_noCull = false;
|
||||
bool m_noZWrite = false;
|
||||
bool m_depthGreater = false;
|
||||
u16 x2_flags = 0; /* Flags */
|
||||
zeus::CColor x4_color; /* Set into kcolor slot specified by material */
|
||||
zeus::CColor addColor = zeus::CColor::skClear;
|
||||
|
||||
@@ -531,19 +531,23 @@ static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data,
|
||||
if (flags.m_extendedShader == EExtendedShader::Lighting) {
|
||||
if (data.heclIr.m_blendSrc == boo::BlendFactor::One && data.heclIr.m_blendDst == boo::BlendFactor::Zero) {
|
||||
/* Override shader if originally opaque (typical for FRME models) */
|
||||
if (flags.x0_blendMode > 6)
|
||||
extended =
|
||||
if (flags.x0_blendMode > 6) {
|
||||
if (flags.m_depthGreater)
|
||||
extended = EExtendedShader::ForcedAdditiveNoZWriteDepthGreater;
|
||||
else
|
||||
extended =
|
||||
flags.m_noCull
|
||||
? (noZWrite ? EExtendedShader::ForcedAdditiveNoCullNoZWrite : EExtendedShader::ForcedAdditiveNoCull)
|
||||
: (noZWrite ? EExtendedShader::ForcedAdditiveNoZWrite : EExtendedShader::ForcedAdditive);
|
||||
else if (flags.x0_blendMode > 4)
|
||||
? (noZWrite ? EExtendedShader::ForcedAdditiveNoCullNoZWrite : EExtendedShader::ForcedAdditiveNoCull)
|
||||
: (noZWrite ? EExtendedShader::ForcedAdditiveNoZWrite : EExtendedShader::ForcedAdditive);
|
||||
} else if (flags.x0_blendMode > 4) {
|
||||
extended = flags.m_noCull
|
||||
? (noZWrite ? EExtendedShader::ForcedAlphaNoCullNoZWrite : EExtendedShader::ForcedAlphaNoCull)
|
||||
: (noZWrite ? EExtendedShader::ForcedAlphaNoZWrite : EExtendedShader::ForcedAlpha);
|
||||
else
|
||||
? (noZWrite ? EExtendedShader::ForcedAlphaNoCullNoZWrite : EExtendedShader::ForcedAlphaNoCull)
|
||||
: (noZWrite ? EExtendedShader::ForcedAlphaNoZWrite : EExtendedShader::ForcedAlpha);
|
||||
} else {
|
||||
extended = flags.m_noCull
|
||||
? (noZWrite ? EExtendedShader::ForcedAlphaNoCullNoZWrite : EExtendedShader::ForcedAlphaNoCull)
|
||||
: (noZWrite ? EExtendedShader::ForcedAlphaNoZWrite : EExtendedShader::Lighting);
|
||||
? (noZWrite ? EExtendedShader::ForcedAlphaNoCullNoZWrite : EExtendedShader::ForcedAlphaNoCull)
|
||||
: (noZWrite ? EExtendedShader::ForcedAlphaNoZWrite : EExtendedShader::Lighting);
|
||||
}
|
||||
} else if (flags.m_noCull && noZWrite) {
|
||||
/* Substitute no-cull,no-zwrite pipeline if available */
|
||||
if (data.heclIr.m_blendDst == boo::BlendFactor::One)
|
||||
|
||||
@@ -9,17 +9,20 @@ namespace urde {
|
||||
static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
|
||||
static boo::ObjToken<boo::IShaderPipeline> s_AdditivePipeline;
|
||||
static boo::ObjToken<boo::IShaderPipeline> s_FullAdditivePipeline;
|
||||
static boo::ObjToken<boo::IShaderPipeline> s_SubtractivePipeline;
|
||||
|
||||
void CColoredStripShader::Initialize() {
|
||||
s_Pipeline = hecl::conv->convert(Shader_CColoredStripShader{});
|
||||
s_AdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderAdditive{});
|
||||
s_FullAdditivePipeline = hecl::conv->convert(Shader_CColoredStripShaderFullAdditive{});
|
||||
s_SubtractivePipeline = hecl::conv->convert(Shader_CColoredStripShaderSubtractive{});
|
||||
}
|
||||
|
||||
void CColoredStripShader::Shutdown() {
|
||||
s_Pipeline.reset();
|
||||
s_AdditivePipeline.reset();
|
||||
s_FullAdditivePipeline.reset();
|
||||
s_SubtractivePipeline.reset();
|
||||
}
|
||||
|
||||
static const boo::ObjToken<boo::IShaderPipeline>& SelectPipeline(CColoredStripShader::Mode mode) {
|
||||
@@ -31,6 +34,8 @@ static const boo::ObjToken<boo::IShaderPipeline>& SelectPipeline(CColoredStripSh
|
||||
return s_AdditivePipeline;
|
||||
case CColoredStripShader::Mode::FullAdditive:
|
||||
return s_FullAdditivePipeline;
|
||||
case CColoredStripShader::Mode::Subtractive:
|
||||
return s_SubtractivePipeline;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ public:
|
||||
enum class Mode {
|
||||
Alpha,
|
||||
Additive,
|
||||
FullAdditive
|
||||
FullAdditive,
|
||||
Subtractive
|
||||
};
|
||||
private:
|
||||
struct Uniform {
|
||||
|
||||
@@ -140,7 +140,10 @@ static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = {
|
||||
/* Disintegration */
|
||||
{1, BlockNames, 2, DisintegrateTextures, hecl::Backend::BlendFactor::SrcAlpha,
|
||||
hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::LEqual, hecl::Backend::CullMode::Original, false,
|
||||
false, true, false, false, true}};
|
||||
false, true, false, false, true},
|
||||
/* Forced additive shading without culling or Z-write and greater depth test */
|
||||
{1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One,
|
||||
hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true}};
|
||||
|
||||
extern const hecl::Backend::Function ExtensionLightingFuncsGLSL[];
|
||||
extern const hecl::Backend::Function ExtensionPostFuncsGLSL[];
|
||||
|
||||
@@ -34,6 +34,7 @@ enum EExtendedShader : uint8_t {
|
||||
ForcedAdditiveNoCullNoZWrite,
|
||||
DepthGEqualNoZWrite,
|
||||
Disintegrate,
|
||||
ForcedAdditiveNoZWriteDepthGreater,
|
||||
MAX
|
||||
};
|
||||
|
||||
|
||||
@@ -238,6 +238,7 @@ const hecl::Backend::Function ExtensionLightingFuncsGLSL[] = {
|
||||
{LightingGLSL, "LightingFunc"},
|
||||
{LightingGLSL, "LightingFunc"},
|
||||
{},
|
||||
{LightingGLSL, "LightingFunc"},
|
||||
};
|
||||
|
||||
const hecl::Backend::Function ExtensionPostFuncsGLSL[] = {
|
||||
@@ -262,6 +263,7 @@ const hecl::Backend::Function ExtensionPostFuncsGLSL[] = {
|
||||
{MainPostGLSL, "MainPostFunc"},
|
||||
{MainPostGLSL, "MainPostFunc"},
|
||||
{DisintegratePostGLSL, "DisintegratePostFunc"},
|
||||
{MainPostGLSL, "MainPostFunc"},
|
||||
};
|
||||
|
||||
} // namespace urde
|
||||
|
||||
@@ -6,6 +6,46 @@ using namespace std::literals;
|
||||
extern const hecl::Backend::Function ExtensionLightingFuncsHLSL[];
|
||||
extern const hecl::Backend::Function ExtensionPostFuncsHLSL[];
|
||||
|
||||
#define FOG_STRUCT_HLSL \
|
||||
"struct Fog\n" \
|
||||
"{\n" \
|
||||
" int mode;\n" \
|
||||
" float4 color;\n" \
|
||||
" float rangeScale;\n" \
|
||||
" float start;\n" \
|
||||
"};\n"
|
||||
|
||||
#define FOG_ALGORITHM_HLSL \
|
||||
" 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" \
|
||||
"#ifdef BLEND_DST_ONE\n" \
|
||||
" return float4(lerp(colorIn, float4(0.0, 0.0, 0.0, 0.0), saturate(fogZ)).rgb, colorIn.a);\n" \
|
||||
"#else\n" \
|
||||
" return float4(lerp(colorIn, fog.color, saturate(fogZ)).rgb, colorIn.a);\n" \
|
||||
"#endif\n"
|
||||
|
||||
static std::string_view LightingHLSL =
|
||||
"struct Light\n"
|
||||
"{\n"
|
||||
@@ -15,13 +55,7 @@ static std::string_view LightingHLSL =
|
||||
" float4 linAtt;\n"
|
||||
" float4 angAtt;\n"
|
||||
"};\n"
|
||||
"struct Fog\n"
|
||||
"{\n"
|
||||
" int mode;\n"
|
||||
" float4 color;\n"
|
||||
" float rangeScale;\n"
|
||||
" float start;\n"
|
||||
"};\n"
|
||||
FOG_STRUCT_HLSL
|
||||
"\n"
|
||||
"cbuffer LightingUniform : register(b2)\n"
|
||||
"{\n"
|
||||
@@ -118,36 +152,7 @@ static std::string_view LightingShadowHLSL =
|
||||
|
||||
static std::string_view MainPostHLSL =
|
||||
"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"
|
||||
"#ifdef BLEND_DST_ONE\n"
|
||||
" return float4(lerp(colorIn, float4(0.0, 0.0, 0.0, 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" FOG_ALGORITHM_HLSL
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
@@ -193,6 +198,21 @@ static std::string_view MBShadowPostHLSL =
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
static std::string_view DisintegratePostHLSL = FOG_STRUCT_HLSL
|
||||
"cbuffer DisintegrateUniform : register(b2)\n"
|
||||
"{\n"
|
||||
" float4 addColor;\n"
|
||||
" Fog fog;\n"
|
||||
"};\n"
|
||||
"float4 DisintegratePostFunc(float4 colorIn)\n"
|
||||
"{\n"
|
||||
" float4 texel0 = extTex7.Sample(samp, vtf.extTcgs[0]);\n"
|
||||
" float4 texel1 = extTex7.Sample(samp, vtf.extTcgs[1]);\n"
|
||||
" colorIn = mix(float4(0.0), texel1, texel0);\n"
|
||||
" colorIn.rgb += addColor.rgb;\n" FOG_ALGORITHM_HLSL
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = {{},
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{},
|
||||
@@ -212,6 +232,8 @@ const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = {{},
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{},
|
||||
{LightingHLSL, "LightingFunc"}};
|
||||
|
||||
const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
|
||||
@@ -235,6 +257,8 @@ const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
|
||||
{MainPostHLSL, "MainPostFunc"},
|
||||
{MainPostHLSL, "MainPostFunc"},
|
||||
{MainPostHLSL, "MainPostFunc"},
|
||||
{DisintegratePostHLSL, "DisintegratePostFunc"},
|
||||
{MainPostHLSL, "MainPostFunc"},
|
||||
};
|
||||
|
||||
} // namespace urde
|
||||
|
||||
@@ -6,6 +6,46 @@ using namespace std::literals;
|
||||
extern const hecl::Backend::Function ExtensionLightingFuncsMetal[];
|
||||
extern const hecl::Backend::Function ExtensionPostFuncsMetal[];
|
||||
|
||||
#define FOG_STRUCT_METAL \
|
||||
"struct Fog\n" \
|
||||
"{\n" \
|
||||
" int mode;\n" \
|
||||
" float4 color;\n" \
|
||||
" float rangeScale;\n" \
|
||||
" float start;\n" \
|
||||
"};\n"
|
||||
|
||||
#define FOG_ALGORITHM_METAL \
|
||||
" 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" \
|
||||
"#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"
|
||||
|
||||
static std::string_view LightingMetal =
|
||||
"struct Light\n"
|
||||
"{\n"
|
||||
@@ -15,13 +55,7 @@ static std::string_view LightingMetal =
|
||||
" float4 linAtt;\n"
|
||||
" float4 angAtt;\n"
|
||||
"};\n"
|
||||
"struct Fog\n"
|
||||
"{\n"
|
||||
" int mode;\n"
|
||||
" float4 color;\n"
|
||||
" float rangeScale;\n"
|
||||
" float start;\n"
|
||||
"};\n"
|
||||
FOG_STRUCT_METAL
|
||||
"\n"
|
||||
"struct LightingUniform\n"
|
||||
"{\n"
|
||||
@@ -119,36 +153,7 @@ static std::string_view LightingShadowMetal =
|
||||
|
||||
static std::string_view MainPostMetal =
|
||||
"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"
|
||||
"#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" FOG_ALGORITHM_METAL
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
@@ -184,10 +189,9 @@ static std::string_view MBShadowPostMetal =
|
||||
" float4 shadowUp;\n"
|
||||
" float shadowId;\n"
|
||||
"};\n"
|
||||
"static float4 EXTMBShadowPostFunc(thread VertToFrag& vtf, constant MBShadowUniform& su, sampler samp, sampler "
|
||||
"clampSamp,\n"
|
||||
" texture2d<float> extTex0, texture2d<float> extTex1, texture2d<float> extTex2, "
|
||||
"float4 colorIn)\n"
|
||||
"static float4 EXTMBShadowPostFunc(thread VertToFrag& vtf, constant MBShadowUniform& su, sampler samp,\n"
|
||||
" sampler clampSamp, texture2d<float> extTex0, texture2d<float> extTex1,\n"
|
||||
" texture2d<float> extTex2, float4 colorIn)\n"
|
||||
"{\n"
|
||||
" float idTexel = extTex0.sample(samp, vtf.extTcgs0).a;\n"
|
||||
" float sphereTexel = extTex1.sample(samp, vtf.extTcgs1).a;\n"
|
||||
@@ -199,6 +203,22 @@ static std::string_view MBShadowPostMetal =
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
static std::string_view DisintegratePostMetal = FOG_STRUCT_METAL
|
||||
"struct DisintegrateUniform\n"
|
||||
"{\n"
|
||||
" float4 addColor;\n"
|
||||
" Fog fog;\n"
|
||||
"};\n"
|
||||
"static float4 EXTDisintegratePostFunc(thread VertToFrag& vtf, constant DisintegrateUniform& lu, sampler samp,\n"
|
||||
" sampler clampSamp, texture2d<float> extTex7, float4 colorIn)\n"
|
||||
"{\n"
|
||||
" float4 texel0 = extTex7.sample(samp, vtf.extTcgs[0]);\n"
|
||||
" float4 texel1 = extTex7.sample(samp, vtf.extTcgs[1]);\n"
|
||||
" colorIn = mix(float4(0.0), texel1, texel0);\n"
|
||||
" colorIn.rgb += addColor.rgb;\n" FOG_ALGORITHM_METAL
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
const hecl::Backend::Function ExtensionLightingFuncsMetal[] = {{},
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{},
|
||||
@@ -218,6 +238,8 @@ const hecl::Backend::Function ExtensionLightingFuncsMetal[] = {{},
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{},
|
||||
{LightingMetal, "LightingFunc"}};
|
||||
|
||||
const hecl::Backend::Function ExtensionPostFuncsMetal[] = {
|
||||
@@ -241,6 +263,8 @@ const hecl::Backend::Function ExtensionPostFuncsMetal[] = {
|
||||
{MainPostMetal, "MainPostFunc"},
|
||||
{MainPostMetal, "MainPostFunc"},
|
||||
{MainPostMetal, "MainPostFunc"},
|
||||
{DisintegratePostMetal, "EXTDisintegratePostFunc"},
|
||||
{MainPostMetal, "MainPostFunc"},
|
||||
};
|
||||
|
||||
static const char* BlockNames[] = {"LightingUniform"};
|
||||
|
||||
Reference in New Issue
Block a user