Skip to content

Commit

Permalink
Various bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackoalan committed Jan 5, 2019
1 parent d60fcc9 commit f9b0614
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 104 deletions.
2 changes: 1 addition & 1 deletion DataSpec/DNAMP1/ScriptObjects/NewIntroBoss.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct NewIntroBoss : IScriptObject {
Value<atVec3f> scale;
PatternedInfo patternedInfo;
ActorParameters actorParameters;
Value<float> turnRadius;
Value<float> minTurnAngle;
UniqueID32 weaponDesc;
DamageInfo damageInfo;
UniqueID32 beamContactFxId;
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Camera/CFirstPersonCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void CFirstPersonCamera::UpdateTransform(CStateManager& mgr, float dt) {

zeus::CTransform playerXf = player->GetTransform();
zeus::CVector3f rVec = playerXf.rotate(
{0.f, std::min(std::fabs(std::cos(x1c0_pitch)), 1.0f), std::min(std::fabs(std::sin(x1c0_pitch)), 1.0f)});
{0.f, zeus::clamp(-1.f, std::cos(x1c0_pitch), 1.0f), zeus::clamp(-1.f, std::sin(x1c0_pitch), 1.0f)});
if (player->x3dc_inFreeLook) {
float angle = player->x3ec_freeLookPitchAngle;
float angleClamp = g_tweakPlayer->GetVerticalFreeLookAngleVel() - std::fabs(x1c0_pitch);
Expand Down
1 change: 1 addition & 0 deletions Runtime/Graphics/CModel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 14 additions & 10 deletions Runtime/Graphics/CModelBoo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions Runtime/Graphics/Shaders/CColoredStripShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}

Expand Down
3 changes: 2 additions & 1 deletion Runtime/Graphics/Shaders/CColoredStripShader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ class CColoredStripShader {
enum class Mode {
Alpha,
Additive,
FullAdditive
FullAdditive,
Subtractive
};
private:
struct Uniform {
Expand Down
5 changes: 4 additions & 1 deletion Runtime/Graphics/Shaders/CModelShaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
1 change: 1 addition & 0 deletions Runtime/Graphics/Shaders/CModelShaders.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum EExtendedShader : uint8_t {
ForcedAdditiveNoCullNoZWrite,
DepthGEqualNoZWrite,
Disintegrate,
ForcedAdditiveNoZWriteDepthGreater,
MAX
};

Expand Down
2 changes: 2 additions & 0 deletions Runtime/Graphics/Shaders/CModelShadersGLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ const hecl::Backend::Function ExtensionLightingFuncsGLSL[] = {
{LightingGLSL, "LightingFunc"},
{LightingGLSL, "LightingFunc"},
{},
{LightingGLSL, "LightingFunc"},
};

const hecl::Backend::Function ExtensionPostFuncsGLSL[] = {
Expand All @@ -262,6 +263,7 @@ const hecl::Backend::Function ExtensionPostFuncsGLSL[] = {
{MainPostGLSL, "MainPostFunc"},
{MainPostGLSL, "MainPostFunc"},
{DisintegratePostGLSL, "DisintegratePostFunc"},
{MainPostGLSL, "MainPostFunc"},
};

} // namespace urde
98 changes: 61 additions & 37 deletions Runtime/Graphics/Shaders/CModelShadersHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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"},
{},
Expand All @@ -212,6 +232,8 @@ const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = {{},
{LightingHLSL, "LightingFunc"},
{LightingHLSL, "LightingFunc"},
{LightingHLSL, "LightingFunc"},
{LightingHLSL, "LightingFunc"},
{},
{LightingHLSL, "LightingFunc"}};

const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
Expand All @@ -235,6 +257,8 @@ const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
{MainPostHLSL, "MainPostFunc"},
{MainPostHLSL, "MainPostFunc"},
{MainPostHLSL, "MainPostFunc"},
{DisintegratePostHLSL, "DisintegratePostFunc"},
{MainPostHLSL, "MainPostFunc"},
};

} // namespace urde
Loading

0 comments on commit f9b0614

Please sign in to comment.