From 168eb6ac3989fe8e3aa153b1879895bcf48d5a37 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Fri, 18 Dec 2020 06:07:53 -0500 Subject: [PATCH] CModelShaders: Split Thermal into ThermalModel, ThermalStatic extended shaders This semi-hacky approach will be replaced with future hsh work --- Runtime/Character/CModelData.cpp | 2 +- Runtime/Graphics/CBooRenderer.cpp | 3 ++- Runtime/Graphics/CModel.hpp | 3 ++- Runtime/Graphics/CModelBoo.cpp | 21 ++++++++++++++----- Runtime/Graphics/Shaders/CModelShaders.cpp | 16 ++++++++++++-- Runtime/Graphics/Shaders/CModelShaders.hpp | 5 ++++- .../Graphics/Shaders/CPhazonSuitFilter.cpp | 1 + Shaders/CModelShaders.frag.glsl | 12 ++++++++--- Shaders/CModelShaders.frag.hlsl | 4 ++-- Shaders/CModelShaders.frag.metal | 4 ++-- Shaders/CPhazonSuitFilter.shader | 7 ++++++- 11 files changed, 59 insertions(+), 19 deletions(-) diff --git a/Runtime/Character/CModelData.cpp b/Runtime/Character/CModelData.cpp index 34099fa5c..07385bbe8 100644 --- a/Runtime/Character/CModelData.cpp +++ b/Runtime/Character/CModelData.cpp @@ -292,7 +292,7 @@ void CModelData::RenderThermal(const zeus::CColor& mulColor, const zeus::CColor& CModelFlags drawFlags = flags; drawFlags.x4_color *= mulColor; drawFlags.addColor = addColor; - drawFlags.m_extendedShader = EExtendedShader::Thermal; + drawFlags.m_extendedShader = EExtendedShader::ThermalModel; if (x10_animData) { CSkinnedModel& model = PickAnimatedModel(EWhichModel::ThermalHot); diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index 8b29fdf5c..edf424ea4 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -1126,7 +1126,7 @@ void CBooRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float strength) { void CBooRenderer::DrawThermalModel(const CModel& model, const zeus::CColor& mulCol, const zeus::CColor& addCol) { SCOPED_GRAPHICS_DEBUG_GROUP("CBooRenderer::DrawThermalModel", zeus::skPurple); CModelFlags flags; - flags.m_extendedShader = EExtendedShader::Thermal; + flags.m_extendedShader = EExtendedShader::ThermalModel; flags.x4_color = mulCol; flags.addColor = addCol; model.UpdateLastFrame(); @@ -1181,6 +1181,7 @@ void CBooRenderer::SetThermal(bool thermal, float level, const zeus::CColor& col x2f4_thermColor = color; CDecal::SetMoveRedToAlphaBuffer(false); CElementGen::SetMoveRedToAlphaBuffer(false); + m_thermalHotPass = false; } void CBooRenderer::SetThermalColdScale(float scale) { x2f8_thermColdScale = zeus::clamp(0.f, scale, 1.f); } diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index 9f6918373..74cd59816 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -30,6 +30,7 @@ struct CModelFlags { u8 x1_matSetIdx = 0; EExtendedShader m_extendedShader = EExtendedShader::Lighting; bool m_noCull = false; + bool m_noZTest = false; bool m_noZWrite = false; bool m_depthGreater = false; u16 x2_flags = 0; /* Flags */ @@ -46,7 +47,7 @@ struct CModelFlags { } /* Flags - 0x1: depth equal + 0x1: depth lequal 0x2: depth update 0x4: render without texture lock 0x8: depth greater diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 6f0de5c38..7fbd27142 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -368,7 +368,10 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) { EExtendedShader idx{}; for (const auto& pipeline : *pipelines) { - if (idx == EExtendedShader::Thermal) { + if (idx == EExtendedShader::ThermalModel || + idx == EExtendedShader::ThermalModelNoZTestNoZWrite || + idx == EExtendedShader::ThermalStatic || + idx == EExtendedShader::ThermalStaticNoZWrite) { texs[8] = g_Renderer->x220_sphereRamp.get(); } else if (idx == EExtendedShader::MorphBallShadow) { texs[8] = g_Renderer->m_ballShadowId.get(); @@ -576,9 +579,11 @@ static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data, EExtendedShader extended = EExtendedShader::Flat; if (intermediateExtended == EExtendedShader::Lighting) { - /* Transform lighting into thermal cold if the thermal visor is active */ + /* Transform lighting into thermal if the thermal visor is active */ if (g_Renderer->IsThermalVisorHotPass()) - return noZWrite ? EExtendedShader::LightingAlphaWriteNoZTestNoZWrite : EExtendedShader::LightingAlphaWrite; + return flags.m_noZTest + ? EExtendedShader::LightingAlphaWriteNoZTestNoZWrite + : (noZWrite ? EExtendedShader::ThermalStaticNoZWrite : EExtendedShader::ThermalStatic); else if (g_Renderer->IsThermalVisorActive()) return EExtendedShader::ThermalCold; if (data.blendMode == MaterialSet::Material::BlendMaterial::BlendMode::Opaque) { @@ -621,6 +626,8 @@ static EExtendedShader ResolveExtendedShader(const MaterialSet::Material& data, } else { extended = EExtendedShader::Lighting; } + } else if (intermediateExtended == EExtendedShader::ThermalModel) { + extended = flags.m_noZTest ? EExtendedShader::ThermalModelNoZTestNoZWrite : EExtendedShader::ThermalModel; } else if (intermediateExtended < EExtendedShader::MAX) { extended = intermediateExtended; } @@ -810,7 +817,10 @@ void CBooModel::UVAnimationBuffer::Update(u8*& bufOut, const MaterialSet* matSet } std::optional> specialMtxOut; - if (flags.m_extendedShader == EExtendedShader::Thermal) { + if (flags.m_extendedShader == EExtendedShader::ThermalModel || + flags.m_extendedShader == EExtendedShader::ThermalModelNoZTestNoZWrite || + flags.m_extendedShader == EExtendedShader::ThermalStatic || + flags.m_extendedShader == EExtendedShader::ThermalStaticNoZWrite) { /* Special Mode0 matrix for exclusive Thermal Visor use */ specialMtxOut.emplace(); @@ -1022,7 +1032,8 @@ boo::ObjToken CBooModel::UpdateUniformData(const CModelFl u8* dataOut = reinterpret_cast(inst->m_uniformBuffer->map(m_uniformDataSize)); u8* dataCur = dataOut; - if (flags.m_extendedShader == EExtendedShader::Thermal) /* Thermal Model (same as UV Mode 0) */ + if (flags.m_extendedShader == EExtendedShader::ThermalModel || + flags.m_extendedShader == EExtendedShader::ThermalModelNoZTestNoZWrite) /* Thermal Model (same as UV Mode 0) */ { CModelShaders::ThermalUniform& thermalOut = *reinterpret_cast(dataCur); thermalOut.mulColor = flags.x4_color; diff --git a/Runtime/Graphics/Shaders/CModelShaders.cpp b/Runtime/Graphics/Shaders/CModelShaders.cpp index 3b185734a..e22628fd9 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.cpp +++ b/Runtime/Graphics/Shaders/CModelShaders.cpp @@ -86,9 +86,18 @@ static std::array g_ /* Normal lit shading */ {0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, - /* Thermal Visor shading */ + /* Thermal model shading */ {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, false, true}, + /* Thermal model shading without Z-test or Z-write */ + {1, ThermalTextures.data(), hecl::Backend::BlendFactor::One, hecl::Backend::BlendFactor::One, + hecl::Backend::ZTest::None, hecl::Backend::CullMode::Backface, true, false, false, true}, + /* Thermal static shading */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, + hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, false, true, false, false, true}, + /* Thermal static shading without Z-write */ + {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One, + hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, true, false, false, true, false, false, false}, /* Forced alpha shading */ {0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::InvSrcAlpha, hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Backface, false, false, true}, @@ -166,7 +175,10 @@ static std::array g_ constexpr std::array ShaderMacros{ "URDE_LIGHTING", "URDE_LIGHTING", - "URDE_THERMAL_HOT", + "URDE_THERMAL_MODEL", + "URDE_THERMAL_MODEL", + "URDE_THERMAL_STATIC", + "URDE_THERMAL_STATIC", "URDE_LIGHTING", "URDE_LIGHTING", "URDE_SOLID", diff --git a/Runtime/Graphics/Shaders/CModelShaders.hpp b/Runtime/Graphics/Shaders/CModelShaders.hpp index 22953feff..d279532da 100644 --- a/Runtime/Graphics/Shaders/CModelShaders.hpp +++ b/Runtime/Graphics/Shaders/CModelShaders.hpp @@ -24,7 +24,10 @@ class CLight; enum class EExtendedShader : uint8_t { Flat, Lighting, - Thermal, + ThermalModel, + ThermalModelNoZTestNoZWrite, + ThermalStatic, + ThermalStaticNoZWrite, ForcedAlpha, ForcedAdditive, SolidColor, diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp index 06185fa5a..4412897fa 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp @@ -2,6 +2,7 @@ #include +#include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" diff --git a/Shaders/CModelShaders.frag.glsl b/Shaders/CModelShaders.frag.glsl index 8cc8cdeb5..e9612afc5 100644 --- a/Shaders/CModelShaders.frag.glsl +++ b/Shaders/CModelShaders.frag.glsl @@ -146,7 +146,7 @@ vec3 LightingFunc() { } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) vec3 LightingFunc() { return vec3(1.0); } @@ -156,7 +156,7 @@ UBINDING2 uniform ThermalUniform { }; #endif -#if defined(URDE_THERMAL_COLD) +#if defined(URDE_THERMAL_COLD) || defined(URDE_THERMAL_STATIC) vec3 LightingFunc() { return vec3(1.0); } @@ -268,7 +268,7 @@ vec4 PostFunc(vec4 colorIn) { } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) vec4 PostFunc(vec4 colorIn) { return texture(extTex0, vtf.extUvs[0]).rrrr * tmulColor + taddColor; } @@ -280,6 +280,12 @@ vec4 PostFunc(vec4 colorIn) { } #endif +#if defined(URDE_THERMAL_STATIC) +vec4 PostFunc(vec4 colorIn) { + return colorIn; +} +#endif + #if defined(URDE_SOLID) vec4 PostFunc(vec4 colorIn) { return solidColor; diff --git a/Shaders/CModelShaders.frag.hlsl b/Shaders/CModelShaders.frag.hlsl index 4319dd212..538492534 100644 --- a/Shaders/CModelShaders.frag.hlsl +++ b/Shaders/CModelShaders.frag.hlsl @@ -145,7 +145,7 @@ float3 LightingFunc(in VertToFrag vtf) { } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) float3 LightingFunc(in VertToFrag vtf) { return float3(1.0, 1.0, 1.0); } @@ -267,7 +267,7 @@ float4 PostFunc(in VertToFrag vtf, float4 colorIn) { } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) float4 PostFunc(in VertToFrag vtf, float4 colorIn) { return extTex0.Sample(samp, vtf.extUvs[0]).rrrr * tmulColor + taddColor; } diff --git a/Shaders/CModelShaders.frag.metal b/Shaders/CModelShaders.frag.metal index 08065600e..817c83015 100644 --- a/Shaders/CModelShaders.frag.metal +++ b/Shaders/CModelShaders.frag.metal @@ -126,7 +126,7 @@ float3 LightingFunc(thread VertToFrag& vtf, constant LightingUniform& lu, textur } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) struct LightingUniform { float4 tmulColor; float4 taddColor; @@ -251,7 +251,7 @@ float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, } #endif -#if defined(URDE_THERMAL_HOT) +#if defined(URDE_THERMAL_MODEL) float4 PostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, texture2d extTex0, texture2d extTex1, texture2d extTex2, sampler samp, sampler clampSamp, sampler clampEdgeSamp, float4 colorIn) { diff --git a/Shaders/CPhazonSuitFilter.shader b/Shaders/CPhazonSuitFilter.shader index 79f109381..f18de24fa 100644 --- a/Shaders/CPhazonSuitFilter.shader +++ b/Shaders/CPhazonSuitFilter.shader @@ -265,7 +265,12 @@ fragment float4 fmain(VertToFrag vtf [[ stage_in ]], #srcfac one #dstfac zero #colorwrite false -#depthtest gequal +#alphawrite true +#depthwrite false +#culling none +#depthtest none +#primitive tristrips +#overwritealpha true #vertex glsl layout(location=0) in vec4 posIn;