diff --git a/Runtime/Graphics/CBooRenderer.cpp b/Runtime/Graphics/CBooRenderer.cpp index 04eaa58de..8d632f5c1 100644 --- a/Runtime/Graphics/CBooRenderer.cpp +++ b/Runtime/Graphics/CBooRenderer.cpp @@ -577,7 +577,8 @@ void CBooRenderer::ReallyRenderFogVolume(const zeus::CColor& color, const zeus:: } void CBooRenderer::GenerateFogVolumeRampTex() { - x1b8_fogVolumeRamp = hsh::create_texture2d({FOGVOL_RAMP_RES, FOGVOL_RAMP_RES}, hsh::R16_UNORM, 1, [&](u16* data, std::size_t size) { + x1b8_fogVolumeRamp = hsh::create_texture2d({FOGVOL_RAMP_RES, FOGVOL_RAMP_RES}, hsh::R16_UNORM, 1, [&](void* data, std::size_t size) { + auto* out = static_cast(data); for (size_t y = 0; y < FOGVOL_RAMP_RES; ++y) { for (size_t x = 0; x < FOGVOL_RAMP_RES; ++x) { const int tmp = int(y << 16 | x << 8 | 0x7f); @@ -586,19 +587,20 @@ void CBooRenderer::GenerateFogVolumeRampTex() { (-150.0 / (tmp / double(0xffffff) * (FOGVOL_FAR - FOGVOL_NEAR) - FOGVOL_FAR) - FOGVOL_NEAR) * 3.0 / (FOGVOL_FAR - FOGVOL_NEAR), 1.0); - data[x + y * FOGVOL_RAMP_RES] = u16((a * a + a) / 2.0 * 65535); + out[x + y * FOGVOL_RAMP_RES] = u16((a * a + a) / 2.0 * 65535); } } }); } void CBooRenderer::GenerateSphereRampTex() { - x220_sphereRamp = hsh::create_texture2d({SPHERE_RAMP_RES, SPHERE_RAMP_RES}, hsh::R8_UNORM, 1, [&](u8* data, std::size_t size) { + x220_sphereRamp = hsh::create_texture2d({SPHERE_RAMP_RES, SPHERE_RAMP_RES}, hsh::R8_UNORM, 1, [&](void* data, std::size_t size) { + auto* out = static_cast(data); constexpr float halfRes = SPHERE_RAMP_RES / 2.f; for (size_t y = 0; y < SPHERE_RAMP_RES; ++y) { for (size_t x = 0; x < SPHERE_RAMP_RES; ++x) { const zeus::CVector2f vec((float(x) - halfRes) / halfRes, (float(y) - halfRes) / halfRes); - data[x + y * SPHERE_RAMP_RES] = 255 - zeus::clamp(0.f, vec.canBeNormalized() ? vec.magnitude() : 0.f, 1.f) * 255; + out[x + y * SPHERE_RAMP_RES] = 255 - zeus::clamp(0.f, vec.canBeNormalized() ? vec.magnitude() : 0.f, 1.f) * 255; } } }); @@ -647,8 +649,9 @@ hsh::texture2d CBooRenderer::GetColorTexture(const zeus::CColor& color) { return search->second; } - m_colorTextures.emplace(color, hsh::create_texture2d({1, 1}, hsh::RGBA8_UNORM, 1, [&](zeus::Comp8* data, std::size_t size) { - color.toRGBA8(data[0], data[1], data[2], data[3]); + m_colorTextures.emplace(color, hsh::create_texture2d({1, 1}, hsh::RGBA8_UNORM, 1, [&](void* data, std::size_t size) { + auto* out = static_cast(data); + color.toRGBA8(out[0], out[1], out[2], out[3]); })); return m_colorTextures[color].get(); } @@ -690,7 +693,7 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac) GenerateFogVolumeRampTex(); GenerateSphereRampTex(); - m_ballShadowId = hsh::create_render_texture2d({m_ballShadowIdW, m_ballShadowIdH}, hsh::RGBA8_UNORM, 1, 0); + m_ballShadowId = hsh::create_render_texture2d({skBallShadowIdSize, skBallShadowIdSize}, hsh::RGBA8_UNORM, 1, 0); x14c_reflectionTex = hsh::create_render_texture2d({256, 256}, hsh::RGBA8_UNORM, 1, 0); GenerateScanLinesVBO(); diff --git a/Runtime/Graphics/CBooRenderer.hpp b/Runtime/Graphics/CBooRenderer.hpp index 7ad7eecf7..96718ab12 100644 --- a/Runtime/Graphics/CBooRenderer.hpp +++ b/Runtime/Graphics/CBooRenderer.hpp @@ -289,15 +289,15 @@ public: void ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const CModel* model, const CSkinnedModel* sModel); - auto GetThermoPalette() const { return x288_thermoPalette.get(); } - auto GetFogRampTex() const { return x1b8_fogVolumeRamp.get(); } - auto GetRandomStaticEntropyTex() const { return m_staticEntropy->GetBooTexture(); } + hsh::texture2d GetThermoPalette() const { return x288_thermoPalette; } + hsh::texture2d GetFogRampTex() const { return x1b8_fogVolumeRamp.get(); } + hsh::texture2d GetRandomStaticEntropyTex() const { return m_staticEntropy->GetBooTexture(); } auto GetScanLinesEvenVBO() const { return m_scanLinesEvenVBO.get(); } auto GetScanLinesOddVBO() const { return m_scanLinesOddVBO.get(); } - auto GetClearTexture() const { return m_clearTexture.get(); } - auto GetBlackTexture() const { return m_blackTexture.get(); } - auto GetWhiteTexture() const { return m_whiteTexture.get(); } + hsh::texture2d GetClearTexture() const { return m_clearTexture.get(); } + hsh::texture2d GetBlackTexture() const { return m_blackTexture.get(); } + hsh::texture2d GetWhiteTexture() const { return m_whiteTexture.get(); } hsh::texture2d GetColorTexture(const zeus::CColor& color); diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index 67a258dc7..f976126fe 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -59,4 +59,7 @@ runtime_add_hsh(Graphics Shaders/CColoredStripShader.cpp Shaders/CDecalShaders.cpp Shaders/CEnergyBarShader.cpp + Shaders/CThermalColdFilter.cpp + Shaders/CThermalHotFilter.cpp + Shaders/CElementGenShaders.cpp ) diff --git a/Runtime/Graphics/CRainSplashGenerator.cpp b/Runtime/Graphics/CRainSplashGenerator.cpp index 22340971e..27b1d20fe 100644 --- a/Runtime/Graphics/CRainSplashGenerator.cpp +++ b/Runtime/Graphics/CRainSplashGenerator.cpp @@ -12,12 +12,7 @@ CRainSplashGenerator::CRainSplashGenerator(const zeus::CVector3f& scale, u32 max : x14_scale(scale), x2c_minZ(minZ) { x30_alpha = std::min(1.f, alpha); x44_genRate = std::min(maxSplashes, genRate); - x0_rainSplashes.reserve(maxSplashes); - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - for (u32 i = 0; i < maxSplashes; ++i) - x0_rainSplashes.emplace_back(ctx); - return true; - } BooTrace); + x0_rainSplashes.resize(maxSplashes); } void CRainSplashGenerator::SSplashLine::Draw(float alpha, float dt, const zeus::CVector3f& pos) { @@ -73,13 +68,11 @@ void CRainSplashGenerator::Draw(const zeus::CTransform& xf) { DoDraw(xf); } -CRainSplashGenerator::SSplashLine::SSplashLine(boo::IGraphicsDataFactory::Context& ctx) -: m_renderer(ctx, CLineRenderer::EPrimitiveMode::LineStrip, 3, nullptr, false) {} +CRainSplashGenerator::SSplashLine::SSplashLine() +: m_renderer(CLineRenderer::EPrimitiveMode::LineStrip, 3, hsh::texture2d{}, false, hsh::LEqual) {} -CRainSplashGenerator::SRainSplash::SRainSplash(boo::IGraphicsDataFactory::Context& ctx) { - for (size_t i = 0; i < x0_lines.capacity(); ++i) { - x0_lines.emplace_back(ctx); - } +CRainSplashGenerator::SRainSplash::SRainSplash() { + x0_lines.resize(x0_lines.capacity()); } void CRainSplashGenerator::SSplashLine::Update(float dt, CStateManager& mgr) { @@ -158,8 +151,7 @@ u32 CRainSplashGenerator::GetNextBestPt(u32 pt, const std::vector maxDist && vert.second.dot(zeus::skUp) >= 0.f && - (vert.first.z() <= 0.f || vert.first.z() > minZ)) { + if (distSq > maxDist && vert.second.dot(zeus::skUp) >= 0.f && (vert.first.z() <= 0.f || vert.first.z() > minZ)) { nextPt = idx; maxDist = distSq; } diff --git a/Runtime/Graphics/CSkinnedModel.cpp b/Runtime/Graphics/CSkinnedModel.cpp index 785f67c2f..562db8d89 100644 --- a/Runtime/Graphics/CSkinnedModel.cpp +++ b/Runtime/Graphics/CSkinnedModel.cpp @@ -32,20 +32,20 @@ void CSkinnedModel::Calculate(const CPoseAsTransforms& pose, const CModelFlags& const std::optional& morphEffect, const float* morphMagnitudes) { if (morphEffect || g_PointGenFunc) { - if (auto vertBuf = m_modelInst->UpdateUniformData(drawFlags, nullptr, nullptr)) { + if (auto* vertBuf = m_modelInst->UpdateUniformData(drawFlags, nullptr, nullptr)) { x10_skinRules->TransformVerticesCPU(m_vertWorkspace, pose, *x4_model); if (morphEffect) morphEffect->MorphVertices(m_vertWorkspace, morphMagnitudes, x10_skinRules, pose); if (g_PointGenFunc) g_PointGenFunc(g_PointGenCtx, m_vertWorkspace); - x4_model->ApplyVerticesCPU(vertBuf, m_vertWorkspace); + x4_model->ApplyVerticesCPU(*vertBuf, m_vertWorkspace); m_modifiedVBO = true; } } else { - if (auto vertBuf = + if (auto* vertBuf = m_modelInst->UpdateUniformData(drawFlags, x10_skinRules.GetObj(), &pose)) { if (m_modifiedVBO) { - x4_model->RestoreVerticesCPU(vertBuf); + x4_model->RestoreVerticesCPU(*vertBuf); m_modifiedVBO = false; } } diff --git a/Runtime/Graphics/Shaders/CAABoxShader.cpp b/Runtime/Graphics/Shaders/CAABoxShader.cpp index 568443278..68b93f77b 100644 --- a/Runtime/Graphics/Shaders/CAABoxShader.cpp +++ b/Runtime/Graphics/Shaders/CAABoxShader.cpp @@ -19,11 +19,13 @@ struct CAABoxShaderPipeline this->color_out[0] = uniBuf->m_color; } }; -template struct CAABoxShaderPipeline; +constexpr size_t VertexCount = 34; + CAABoxShader::CAABoxShader(const zeus::CAABox& aabb) { - const std::array verts{{ + const std::array verts{{ {{aabb.max.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.max.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.max.x(), aabb.max.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.min.y(), aabb.max.z()}}, @@ -62,7 +64,7 @@ void CAABoxShader::draw(const zeus::CColor& color) { m_uniform.m_color = color; m_uniBuf.load(m_uniform); - m_dataBind.draw(0, 34); + m_dataBind.draw(0, VertexCount); } } // namespace urde diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp index 8a69f1720..f5612aa21 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp @@ -7,6 +7,8 @@ namespace urde { class CCameraBlurFilter { friend struct CCameraBlurFilterPipeline; + +public: struct Vert { hsh::float2 m_pos; hsh::float2 m_uv; @@ -16,6 +18,7 @@ class CCameraBlurFilter { float m_opacity = 1.f; }; +private: hsh::dynamic_owner> m_vbo; hsh::dynamic_owner> m_uniBuf; hsh::binding m_dataBind; diff --git a/Runtime/Graphics/Shaders/CDecalShaders.cpp b/Runtime/Graphics/Shaders/CDecalShaders.cpp index e2ec9c79b..f65d6c7d0 100644 --- a/Runtime/Graphics/Shaders/CDecalShaders.cpp +++ b/Runtime/Graphics/Shaders/CDecalShaders.cpp @@ -31,7 +31,7 @@ template struct CDecalShaderTexPipeline; template struct CDecalShaderNoTexPipeline : pipeline, BlendAttachment<>>, depth_compare, depth_write> { - CDecalShaderNoTexPipeline(hsh::vertex_buffer vbo, + CDecalShaderNoTexPipeline(hsh::vertex_buffer vbo, hsh::uniform_buffer uniBuf) { this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; this->color_out[0] = vbo->color * uniBuf->moduColor; diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.cpp b/Runtime/Graphics/Shaders/CElementGenShaders.cpp index 56b86e3a1..e2aef0bab 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.cpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.cpp @@ -1,274 +1,133 @@ #include "Runtime/Graphics/Shaders/CElementGenShaders.hpp" -#include - +#include "Runtime/GameGlobalObjects.hpp" +#include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Particle/CElementGen.hpp" -#include +enum class BlendMode { + Regular, + Additive, + Subtract, +}; + +#include "CElementGenShaders.cpp.hshhead" namespace urde { +using namespace hsh::pipeline; -void CElementGenShaders::Initialize() { - m_texZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderTexZTestZWrite{})}; - m_texNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderTexNoZTestZWriteAWrite{})}; - m_texZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteAWrite{})}; - m_texNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteAWrite{})}; - m_texAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTest{}), - hecl::conv->convert(Shader_CElementGenShaderTexAdditiveZTestAWrite{})}; - m_texAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTest{}), - hecl::conv->convert(Shader_CElementGenShaderTexAdditiveNoZTestAWrite{})}; - m_texRedToAlphaZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTest{}), - hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestAWrite{})}; - m_texRedToAlphaNoZTest = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTest{}), - hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestAWrite{})}; - m_texZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSub{}), - hecl::conv->convert(Shader_CElementGenShaderTexZTestNoZWriteSubAWrite{})}; - m_texNoZTestNoZWriteSub = {hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSub{}), - hecl::conv->convert(Shader_CElementGenShaderTexNoZTestNoZWriteSubAWrite{})}; - m_texRedToAlphaZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSub{}), - hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaZTestSubAWrite{})}; - m_texRedToAlphaNoZTestSub = {hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSub{}), - hecl::conv->convert(Shader_CElementGenShaderTexRedToAlphaNoZTestSubAWrite{})}; +template +struct BlendModeAttachmentExt { + using type = BlendAttachment; +}; +template +struct BlendModeAttachmentExt { + using type = AdditiveAttachment; +}; +template +struct BlendModeAttachmentExt { + using type = SubtractAttachment; +}; +template +using BlendModeAttachment = typename BlendModeAttachmentExt::type; - m_indTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderIndTexZWriteAWrite{})}; - m_indTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderIndTexNoZWriteAWrite{})}; - m_indTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderIndTexAdditive{}), - hecl::conv->convert(Shader_CElementGenShaderIndTexAdditiveAWrite{})}; +template +struct CElementGenShadersTexPipeline : pipeline, BlendModeAttachment, + depth_compare, depth_write> { + CElementGenShadersTexPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer uniBuf, hsh::texture2d tex) { + this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; + this->color_out[0] = vbo->color * uniBuf->moduColor * tex.sample(vbo->uvs[this->vertex_id]); + if constexpr (RedToAlpha) { + this->color_out[0].w = this->color_out[0].x; + } + } +}; +template struct CElementGenShadersTexPipeline; +template struct CElementGenShadersTexPipeline; +template struct CElementGenShadersTexPipeline; - m_cindTexZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderCindTexZWriteAWrite{})}; - m_cindTexNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderCindTexNoZWriteAWrite{})}; - m_cindTexAdditive = {hecl::conv->convert(Shader_CElementGenShaderCindTexAdditive{}), - hecl::conv->convert(Shader_CElementGenShaderCindTexAdditiveAWrite{})}; +template +struct CElementGenShadersIndTexPipeline +: pipeline, BlendModeAttachment, + depth_compare, depth_write> { + CElementGenShadersIndTexPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer uniBuf, hsh::texture2d texrTex, + hsh::texture2d tindTex, hsh::render_texture2d sceneTex) { + this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; + hsh::float4 texrTexel = texrTex.sample(vbo->texrTindUVs[this->vertex_id].xy()); + hsh::float2 tindTexel = tindTex.sample(vbo->texrTindUVs[this->vertex_id].zw()).xy(); + hsh::float4 sceneTexel = sceneTex.sample(hsh::lerp(vbo->sceneUVs.xy(), vbo->sceneUVs.zw(), tindTexel)); + if constexpr (ColoredIndirect) { + this->color_out[0] = vbo->color * hsh::float4(sceneTexel.xyz(), 1.f) * texrTexel; + } else { + this->color_out[0] = vbo->color * hsh::float4(sceneTexel.xyz(), 1.f) + texrTexel; + this->color_out[0].w *= texrTexel.x; + } + } +}; +template struct CElementGenShadersIndTexPipeline; +template struct CElementGenShadersIndTexPipeline; - m_noTexZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexZTestZWriteAWrite{})}; - m_noTexNoZTestZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestZWriteAWrite{})}; - m_noTexZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexZTestNoZWriteAWrite{})}; - m_noTexNoZTestNoZWrite = {hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWrite{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexNoZTestNoZWriteAWrite{})}; - m_noTexAdditiveZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTest{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveZTestAWrite{})}; - m_noTexAdditiveNoZTest = {hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTest{}), - hecl::conv->convert(Shader_CElementGenShaderNoTexAdditiveNoZTestAWrite{})}; -} - -void CElementGenShaders::Shutdown() { - for (auto& s : m_texZTestZWrite) s.reset(); - for (auto& s : m_texNoZTestZWrite) s.reset(); - for (auto& s : m_texZTestNoZWrite) s.reset(); - for (auto& s : m_texNoZTestNoZWrite) s.reset(); - for (auto& s : m_texAdditiveZTest) s.reset(); - for (auto& s : m_texAdditiveNoZTest) s.reset(); - for (auto& s : m_texRedToAlphaZTest) s.reset(); - for (auto& s : m_texRedToAlphaNoZTest) s.reset(); - for (auto& s : m_texZTestNoZWriteSub) s.reset(); - for (auto& s : m_texNoZTestNoZWriteSub) s.reset(); - for (auto& s : m_texRedToAlphaZTestSub) s.reset(); - for (auto& s : m_texRedToAlphaNoZTestSub) s.reset(); - - for (auto& s : m_indTexZWrite) s.reset(); - for (auto& s : m_indTexNoZWrite) s.reset(); - for (auto& s : m_indTexAdditive) s.reset(); - - for (auto& s : m_cindTexZWrite) s.reset(); - for (auto& s : m_cindTexNoZWrite) s.reset(); - for (auto& s : m_cindTexAdditive) s.reset(); - - for (auto& s : m_noTexZTestZWrite) s.reset(); - for (auto& s : m_noTexNoZTestZWrite) s.reset(); - for (auto& s : m_noTexZTestNoZWrite) s.reset(); - for (auto& s : m_noTexNoZTestNoZWrite) s.reset(); - for (auto& s : m_noTexAdditiveZTest) s.reset(); - for (auto& s : m_noTexAdditiveNoZTest) s.reset(); -} +template +struct CElementGenShadersNoTexPipeline +: pipeline, BlendModeAttachment, + depth_compare, depth_write> { + CElementGenShadersNoTexPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer uniBuf) { + this->position = uniBuf->mvp * vbo->pos[this->vertex_id]; + this->color_out[0] = vbo->color * uniBuf->moduColor; + } +}; +template struct CElementGenShadersNoTexPipeline; +template struct CElementGenShadersNoTexPipeline; +template struct CElementGenShadersNoTexPipeline; CElementGenShaders::EShaderClass CElementGenShaders::GetShaderClass(CElementGen& gen) { - CGenDescription* desc = gen.x1c_genDesc.GetObj(); - - if (desc->x54_x40_TEXR) { - if (desc->x58_x44_TIND) - return EShaderClass::IndTex; - else - return EShaderClass::Tex; - } else - return EShaderClass::NoTex; -} - -void CElementGenShaders::BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CElementGen& gen) { - CGenDescription* desc = gen.x1c_genDesc.GetObj(); - std::array, 2>* regPipeline = nullptr; - std::array, 2>* regPipelineSub = nullptr; - std::array, 2>* redToAlphaPipeline = nullptr; - std::array, 2>* redToAlphaPipelineSub = nullptr; - std::array, 2>* regPipelinePmus = nullptr; - std::array, 2>* redToAlphaPipelinePmus = nullptr; - + const auto* desc = gen.x1c_genDesc.GetObj(); if (desc->x54_x40_TEXR) { if (desc->x58_x44_TIND) { - if (desc->x45_30_x32_24_CIND) { - if (gen.x26c_26_AAPH) - regPipeline = &m_cindTexAdditive; - else { - if (gen.x26c_27_ZBUF) - regPipeline = &m_cindTexZWrite; - else - regPipeline = &m_cindTexNoZWrite; - } - } else { - if (gen.x26c_26_AAPH) - regPipeline = &m_indTexAdditive; - else { - if (gen.x26c_27_ZBUF) - regPipeline = &m_indTexZWrite; - else - regPipeline = &m_indTexNoZWrite; - } - } - } else { - if (gen.x26c_28_zTest) { - redToAlphaPipeline = &m_texRedToAlphaZTest; - regPipelineSub = &m_texZTestNoZWriteSub; - redToAlphaPipelineSub = &m_texRedToAlphaZTestSub; - } else { - redToAlphaPipeline = &m_texRedToAlphaNoZTest; - regPipelineSub = &m_texNoZTestNoZWriteSub; - redToAlphaPipelineSub = &m_texRedToAlphaNoZTestSub; - } - - if (gen.x26c_26_AAPH) { - if (gen.x26c_28_zTest) - regPipeline = &m_texAdditiveZTest; - else - regPipeline = &m_texAdditiveNoZTest; - } else { - if (gen.x26c_28_zTest) { - if (gen.x26c_27_ZBUF) - regPipeline = &m_texZTestZWrite; - else - regPipeline = &m_texZTestNoZWrite; - } else { - if (gen.x26c_27_ZBUF) - regPipeline = &m_texNoZTestZWrite; - else - regPipeline = &m_texNoZTestNoZWrite; - } - } - } - } else { - if (gen.x26c_26_AAPH) { - if (gen.x26c_28_zTest) - regPipeline = &m_noTexAdditiveZTest; - else - regPipeline = &m_noTexAdditiveNoZTest; - } else { - if (gen.x26c_28_zTest) { - if (gen.x26c_27_ZBUF) - regPipeline = &m_noTexZTestZWrite; - else - regPipeline = &m_noTexZTestNoZWrite; - } else { - if (gen.x26c_27_ZBUF) - regPipeline = &m_noTexNoZTestZWrite; - else - regPipeline = &m_noTexNoZTestNoZWrite; - } + return EShaderClass::IndTex; } + return EShaderClass::Tex; } + return EShaderClass::NoTex; +} - if (desc->x45_24_x31_26_PMUS) { - if (desc->x54_x40_TEXR) { - redToAlphaPipelinePmus = &m_texRedToAlphaZTest; - if (desc->x44_31_x31_25_PMAB) - regPipelinePmus = &m_texAdditiveZTest; - else - regPipelinePmus = &m_texZTestZWrite; - } else { - if (desc->x44_31_x31_25_PMAB) - regPipelinePmus = &m_noTexAdditiveZTest; - else - regPipelinePmus = &m_noTexZTestZWrite; - } +hsh::binding& CElementGenShaders::BuildShaderDataBinding(CElementGen& gen, bool pmus) { + const auto& desc = gen.x1c_genDesc; + BlendMode mode = BlendMode::Regular; + if (CElementGen::g_subtractBlend) { + mode = BlendMode::Subtract; + } else if (gen.x26c_26_AAPH) { + mode = BlendMode::Additive; } - - const CUVElement* const texr = desc->x54_x40_TEXR.get(); - const CUVElement* const tind = desc->x58_x44_TIND.get(); - int texCount = 0; - std::array, 3> textures; - - if (texr) { - textures[0] = texr->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 1; - if (gen.m_instBuf) { - if (tind) { - textures[1] = CGraphics::g_SpareTexture.get(); - textures[2] = tind->GetValueTexture(0).GetObj()->GetBooTexture(); - texCount = 3; - } - } + hsh::vertex_buffer_typeless instBuf = pmus ? gen.m_instBufPmus.get() : gen.m_instBuf.get(); + hsh::uniform_buffer_typeless uniBuf = pmus ? gen.m_uniformBufPmus.get() : gen.m_uniformBuf.get(); + switch (GetShaderClass(gen)) { + case EShaderClass::Tex: { + hsh::texture2d tex = desc->x54_x40_TEXR->GetValueTexture(0)->GetBooTexture(); + m_shaderBind.hsh_tex_bind( + CElementGenShadersTexPipelineIsThermalVisorHotPass(), gen.x26c_28_zTest, gen.x26c_27_ZBUF, + CElementGen::sMoveRedToAlphaBuffer>(instBuf, uniBuf, tex)); + break; } - - if (gen.m_instBuf) { - const std::array, 1> uniforms{gen.m_uniformBuf.get()}; - - if (regPipeline != nullptr) { - for (size_t i = 0; i < gen.m_normalDataBind.size(); ++i) { - gen.m_normalDataBind[i] = - ctx.newShaderDataBinding((*regPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - if (regPipelineSub != nullptr) { - for (size_t i = 0; i < gen.m_normalSubDataBind.size(); ++i) { - gen.m_normalSubDataBind[i] = - ctx.newShaderDataBinding((*regPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - if (redToAlphaPipeline != nullptr) { - for (size_t i = 0; i < gen.m_redToAlphaDataBind.size(); ++i) { - gen.m_redToAlphaDataBind[i] = - ctx.newShaderDataBinding((*redToAlphaPipeline)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - if (redToAlphaPipelineSub != nullptr) { - for (size_t i = 0; i < gen.m_redToAlphaSubDataBind.size(); ++i) { - gen.m_redToAlphaSubDataBind[i] = ctx.newShaderDataBinding( - (*redToAlphaPipelineSub)[i], nullptr, gen.m_instBuf.get(), nullptr, uniforms.size(), uniforms.data(), - nullptr, texCount, textures.data(), nullptr, nullptr); - } - } + case EShaderClass::IndTex: { + hsh::texture2d texrTex = desc->x54_x40_TEXR->GetValueTexture(0)->GetBooTexture(); + hsh::texture2d tindTex = desc->x58_x44_TIND->GetValueTexture(0)->GetBooTexture(); + hsh::render_texture2d sceneTex = CGraphics::g_SpareTexture.get_color(0); + m_shaderBind.hsh_indtex_bind( + CElementGenShadersIndTexPipelineIsThermalVisorHotPass(), gen.x26c_28_zTest, gen.x26c_27_ZBUF, + desc->x45_30_x32_24_CIND>(instBuf, uniBuf, texrTex, tindTex, sceneTex)); + break; } - - if (gen.m_instBufPmus) { - const std::array, 1> uniforms{gen.m_uniformBufPmus.get()}; - texCount = std::min(texCount, 1); - - if (regPipelinePmus != nullptr) { - for (size_t i = 0; i < gen.m_normalDataBindPmus.size(); ++i) { - gen.m_normalDataBindPmus[i] = - ctx.newShaderDataBinding((*regPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), - uniforms.data(), nullptr, texCount, textures.data(), nullptr, nullptr); - } - } - if (redToAlphaPipelinePmus != nullptr) { - for (size_t i = 0; i < gen.m_redToAlphaDataBindPmus.size(); ++i) { - gen.m_redToAlphaDataBindPmus[i] = ctx.newShaderDataBinding( - (*redToAlphaPipelinePmus)[i], nullptr, gen.m_instBufPmus.get(), nullptr, uniforms.size(), uniforms.data(), - nullptr, texCount, textures.data(), nullptr, nullptr); - } - } + case EShaderClass::NoTex: { + m_shaderBind.hsh_notex_bind( + CElementGenShadersNoTexPipelineIsThermalVisorHotPass(), gen.x26c_28_zTest, gen.x26c_27_ZBUF>( + instBuf, uniBuf)); + break; } + } + return m_shaderBind; } } // namespace urde diff --git a/Runtime/Graphics/Shaders/CElementGenShaders.hpp b/Runtime/Graphics/Shaders/CElementGenShaders.hpp index 00e103f5c..629098fab 100644 --- a/Runtime/Graphics/Shaders/CElementGenShaders.hpp +++ b/Runtime/Graphics/Shaders/CElementGenShaders.hpp @@ -8,11 +8,12 @@ class CElementGen; class CElementGenShaders { hsh::binding m_shaderBind; + public: enum class EShaderClass { Tex, IndTex, NoTex }; static EShaderClass GetShaderClass(CElementGen& gen); - hsh::binding& BuildShaderDataBinding(CElementGen& gen); + hsh::binding& BuildShaderDataBinding(CElementGen& gen, bool pmus); }; } // namespace urde diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp index 3c505eed3..6e6a8225e 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.cpp @@ -4,31 +4,54 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include "zeus/CVector2f.hpp" +#include "CThermalColdFilter.cpp.hshhead" namespace urde { +using namespace hsh::pipeline; + +struct CThermalColdFilterPipeline : pipeline, + ERglBlendModeAttachment, + depth_write> { + CThermalColdFilterPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer ubo, hsh::render_texture2d sceneTex, + hsh::texture2d noiseTex) { + static hsh::float4 kRGBToYPrime = {0.257f, 0.504f, 0.098f, 0.f}; + + this->position = hsh::float4(vbo->m_pos, 0.f, 1.f); + hsh::float4 noiseTexel = noiseTex.read(Lookup8BPP(vbo->m_uvNoise, ubo->m_randOff)); + hsh::float2 indCoord = (hsh::float3x3(ubo->m_indMtx[0].xyz(), ubo->m_indMtx[1].xyz(), ubo->m_indMtx[2].xyz()) * + hsh::float3(noiseTexel.x - 0.5f, noiseTexel.w - 0.5f, 1.f)) + .xy(); + hsh::float2 sceneUv = vbo->m_uv + indCoord; + sceneUv.y = 1.f - sceneUv.y; + float indScene = hsh::dot(sceneTex.sample(sceneUv), kRGBToYPrime) + 16.f / 255.f; + this->color_out[0] = ubo->m_colorRegs[0] * indScene + ubo->m_colorRegs[2] - ubo->m_colorRegs[1] * noiseTexel.x; + this->color_out[0].w = ubo->m_colorRegs[1].x + ubo->m_colorRegs[1].w * noiseTexel.x + ubo->m_colorRegs[2].w; + } + + static constexpr hsh::uint2 Lookup8BPP(hsh::float2 uv, float randOff) { + int bx = int(uv.x) >> 3; + int rx = int(uv.x) & 0x7; + int by = int(uv.y) >> 2; + int ry = int(uv.y) & 0x3; + int bidx = by * 128 + bx; + int addr = bidx * 32 + ry * 8 + rx + int(randOff); + return hsh::uint2(addr & 0x3ff, addr >> 10); + } +}; CThermalColdFilter::CThermalColdFilter() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - const std::array verts{{ - {{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}}, - {{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}}, - {{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}}, - {{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}}, - }}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 48, verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 2> texs{ - CGraphics::g_SpareTexture.get(), - g_Renderer->GetRandomStaticEntropyTex(), - }; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); + const std::array verts{{ + {{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}}, + {{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}}, + {{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}}, + {{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}}, + }}; + m_vbo = hsh::create_vertex_buffer(verts); + m_uniBuf = hsh::create_dynamic_uniform_buffer(); + m_dataBind.hsh_bind(CThermalColdFilterPipeline(m_vbo.get(), m_uniBuf.get(), CGraphics::g_SpareTexture.get_color(0), + g_Renderer->GetRandomStaticEntropyTex())); setNoiseOffset(0); setScale(0.f); @@ -38,9 +61,8 @@ void CThermalColdFilter::draw() { SCOPED_GRAPHICS_DEBUG_GROUP("CThermalColdFilter::draw", zeus::skMagenta); CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport); - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); + m_uniBuf.load(m_uniform); + m_dataBind.draw(0, 4); } } // namespace urde diff --git a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp index d7789ee1c..2194d214c 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilter.hpp @@ -8,20 +8,23 @@ namespace urde { class CThermalColdFilter { +public: struct Uniform { - zeus::CMatrix4f m_indMtx; - std::array m_colorRegs; + hsh::float4x4 m_indMtx; + std::array m_colorRegs; float m_randOff = 0.f; }; struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; - zeus::CVector2f m_uvNoise; + hsh::float2 m_pos; + hsh::float2 m_uv; + hsh::float2 m_uvNoise; }; + +private: hsh::owner> m_vbo; hsh::dynamic_owner> m_uniBuf; hsh::binding m_dataBind; - Uniform m_uniform; + Uniform m_uniform{}; public: CThermalColdFilter(); diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp index 8ba84d22a..7ebb397e8 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.cpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.cpp @@ -4,42 +4,49 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" -#include "zeus/CVector2f.hpp" +#include "CThermalHotFilter.cpp.hshhead" namespace urde { +using namespace hsh::pipeline; + +struct CThermalHotFilterPipeline +: pipeline, + depth_write> { + CThermalHotFilterPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer ubo, hsh::render_texture2d sceneTex, + hsh::texture2d paletteTex) { + static hsh::float4 kRGBToYPrime = {0.257f, 0.504f, 0.098f, 0.f}; + + this->position = hsh::float4(vbo->m_pos, 0.f, 1.f); + + hsh::float2 sceneUv = vbo->m_uv; + sceneUv.y = 1.f - sceneUv.y; + float sceneSample = hsh::dot(sceneTex.sample(sceneUv), kRGBToYPrime) + 16.f / 255.f; + hsh::float4 colorSample = paletteTex.sample(hsh::float2(sceneSample / 16.f, 0.5f)); + this->color_out[0] = hsh::float4(colorSample.xyz(), 0.f); + } +}; CThermalHotFilter::CThermalHotFilter() { - CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) { - const std::array verts{{ - {{-1.0, -1.0}, {0.0, 0.0}}, - {{-1.0, 1.0}, {0.0, 1.0}}, - {{1.0, -1.0}, {1.0, 0.0}}, - {{1.0, 1.0}, {1.0, 1.0}}, - }}; - m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), 32, verts.size()); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 2> texs{ - CGraphics::g_SpareTexture.get(), - g_Renderer->GetThermoPalette(), - }; - m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); + const std::array verts{{ + {{-1.0, -1.0}, {0.0, 0.0}}, + {{-1.0, 1.0}, {0.0, 1.0}}, + {{1.0, -1.0}, {1.0, 0.0}}, + {{1.0, 1.0}, {1.0, 1.0}}, + }}; + m_vbo = hsh::create_vertex_buffer(verts); + m_uniBuf = hsh::create_dynamic_uniform_buffer(); + m_dataBind.hsh_bind(CThermalHotFilterPipeline(m_vbo.get(), m_uniBuf.get(), CGraphics::g_SpareTexture.get_color(0), + g_Renderer->GetThermoPalette())); } void CThermalHotFilter::draw() { SCOPED_GRAPHICS_DEBUG_GROUP("CThermalHotFilter::draw", zeus::skMagenta); CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport); - - // m_uniBuf->load(&m_uniform, sizeof(m_uniform)); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, 4); + m_uniBuf.load(m_uniform); + m_dataBind.draw(0, 4); } } // namespace urde diff --git a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp index 34601ee47..46f6e722d 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilter.hpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilter.hpp @@ -2,22 +2,26 @@ #include +#include "hsh/hsh.h" #include "zeus/CColor.hpp" namespace urde { class CThermalHotFilter { +public: struct Uniform { - std::array m_colorRegs; + std::array m_colorRegs; }; struct Vert { - zeus::CVector2f m_pos; - zeus::CVector2f m_uv; + hsh::float2 m_pos; + hsh::float2 m_uv; }; + +private: hsh::owner> m_vbo; hsh::dynamic_owner> m_uniBuf; hsh::binding m_dataBind; - Uniform m_uniform; + Uniform m_uniform{}; public: CThermalHotFilter(); diff --git a/Runtime/GuiSys/CGuiFrame.cpp b/Runtime/GuiSys/CGuiFrame.cpp index f8b90f7f4..c30213274 100644 --- a/Runtime/GuiSys/CGuiFrame.cpp +++ b/Runtime/GuiSys/CGuiFrame.cpp @@ -200,8 +200,8 @@ void CGuiFrame::ProcessUserInput(const CFinalInput& input) const { bool CGuiFrame::ProcessMouseInput(const CFinalInput& input, const CGuiWidgetDrawParms& parms) { if (const auto& kbm = input.GetKBM()) { - zeus::CVector2f point(kbm->m_mouseCoord.norm[0] * 2.f - 1.f, - kbm->m_mouseCoord.norm[1] * 2.f - 1.f); + zeus::CVector2f point(kbm->m_mouseCoord.x * 2.f - 1.f, + kbm->m_mouseCoord.y * 2.f - 1.f); CGuiWidget* hit = BestCursorHit(point, parms); if (hit != m_lastMouseOverWidget) { if (m_inMouseDown && m_mouseDownWidget != hit) { @@ -220,14 +220,14 @@ bool CGuiFrame::ProcessMouseInput(const CFinalInput& input, const CGuiWidgetDraw m_lastMouseOverWidget = hit; } if (hit && hit->m_lastScroll) { - boo::SScrollDelta delta = kbm->m_accumScroll - *hit->m_lastScroll; + auto delta = kbm->m_accumScroll - *hit->m_lastScroll; hit->m_lastScroll.emplace(kbm->m_accumScroll); - if (!delta.isZero()) { + if (delta.x != 0.0 || delta.y != 0.0) { hit->m_integerScroll += delta; if (m_mouseScrollCb) - m_mouseScrollCb(hit, delta, int(hit->m_integerScroll.delta[0]), int(hit->m_integerScroll.delta[1])); - hit->m_integerScroll.delta[0] -= std::trunc(hit->m_integerScroll.delta[0]); - hit->m_integerScroll.delta[1] -= std::trunc(hit->m_integerScroll.delta[1]); + m_mouseScrollCb(hit, delta, int(hit->m_integerScroll.x), int(hit->m_integerScroll.y)); + hit->m_integerScroll.x -= std::trunc(hit->m_integerScroll.x); + hit->m_integerScroll.y -= std::trunc(hit->m_integerScroll.y); } } if (!m_inMouseDown && kbm->m_mouseButtons[size_t(boo2::MouseButton::Primary)]) { diff --git a/Runtime/Particle/CElementGen.cpp b/Runtime/Particle/CElementGen.cpp index e53c5f487..c471c883a 100644 --- a/Runtime/Particle/CElementGen.cpp +++ b/Runtime/Particle/CElementGen.cpp @@ -213,22 +213,28 @@ CElementGen::CElementGen(TToken gen, EModelOrientationType orie if (!x26c_31_LINE) { switch (m_shaderClass) { case CElementGenShaders::EShaderClass::Tex: - m_instBuf = hsh::create_dynamic_vertex_buffer(maxInsts); break; + m_instBuf = hsh::create_dynamic_vertex_buffer(maxInsts); + break; case CElementGenShaders::EShaderClass::IndTex: - m_instBuf = hsh::create_dynamic_vertex_buffer(maxInsts); break; + m_instBuf = hsh::create_dynamic_vertex_buffer(maxInsts); + break; case CElementGenShaders::EShaderClass::NoTex: - m_instBuf = hsh::create_dynamic_vertex_buffer(maxInsts); break; + m_instBuf = hsh::create_dynamic_vertex_buffer(maxInsts); + break; } m_uniformBuf = hsh::create_dynamic_uniform_buffer(); } if (desc->x45_24_x31_26_PMUS) { switch (m_shaderClass) { case CElementGenShaders::EShaderClass::Tex: - m_instBufPmus = hsh::create_dynamic_vertex_buffer(maxInsts); break; + m_instBufPmus = hsh::create_dynamic_vertex_buffer(maxInsts); + break; case CElementGenShaders::EShaderClass::IndTex: - m_instBufPmus = hsh::create_dynamic_vertex_buffer(maxInsts); break; + m_instBufPmus = hsh::create_dynamic_vertex_buffer(maxInsts); + break; case CElementGenShaders::EShaderClass::NoTex: - m_instBufPmus = hsh::create_dynamic_vertex_buffer(maxInsts); break; + m_instBufPmus = hsh::create_dynamic_vertex_buffer(maxInsts); + break; } m_uniformBufPmus = hsh::create_dynamic_uniform_buffer(); } @@ -907,14 +913,6 @@ void CElementGen::RenderModels(const CActorLights* actorLights) { } m_uniformBufPmus.load({CGraphics::GetPerspectiveProjectionMatrix(true), {1.f, 1.f, 1.f, 1.f}}); - - // TODO: Implement in builder -#if 0 - if (moveRedToAlphaBuffer) - CGraphics::SetShaderDataBinding(m_redToAlphaDataBindPmus[g_Renderer->IsThermalVisorHotPass()]); - else - CGraphics::SetShaderDataBinding(m_normalDataBindPmus[g_Renderer->IsThermalVisorHotPass()]); -#endif } zeus::CTransform orient = zeus::CTransform(); @@ -1064,11 +1062,11 @@ void CElementGen::RenderModels(const CActorLights* actorLights) { switch (m_shaderClass) { case CElementGenShaders::EShaderClass::Tex: m_instBufPmus.load(g_instTexData); - m_shaderBuilder.BuildShaderDataBinding(*this).draw_instanced(0, 4, g_instTexData.size()); + m_shaderBuilder.BuildShaderDataBinding(*this, true).draw_instanced(0, 4, g_instTexData.size()); break; case CElementGenShaders::EShaderClass::NoTex: m_instBufPmus.load(g_instNoTexData); - m_shaderBuilder.BuildShaderDataBinding(*this).draw_instanced(0, 4, g_instNoTexData.size()); + m_shaderBuilder.BuildShaderDataBinding(*this, true).draw_instanced(0, 4, g_instNoTexData.size()); break; default: break; @@ -1194,12 +1192,12 @@ void CElementGen::RenderParticles() { return; } - CRealElement* size = desc->x4c_x38_SIZE.get(); - if (size && size->IsConstant()) { + CRealElement* sizeElem = desc->x4c_x38_SIZE.get(); + if (sizeElem && sizeElem->IsConstant()) { float sizeVal; - size->GetValue(0, sizeVal); + sizeElem->GetValue(0, sizeVal); if (sizeVal == 0.f) { - size->GetValue(1, sizeVal); + sizeElem->GetValue(1, sizeVal); if (sizeVal == 0.f) return; } @@ -1263,22 +1261,6 @@ void CElementGen::RenderParticles() { if (sMoveRedToAlphaBuffer && x26c_26_AAPH) moveRedToAlphaBuffer = true; - // TODO: Implement in builder -#if 0 - if (g_subtractBlend) { - // FIXME should there be NoTex specializations for RedToAlpha? - if (moveRedToAlphaBuffer && desc->x54_x40_TEXR) - CGraphics::SetShaderDataBinding(m_redToAlphaSubDataBind[g_Renderer->IsThermalVisorHotPass()]); - else - CGraphics::SetShaderDataBinding(m_normalSubDataBind[g_Renderer->IsThermalVisorHotPass()]); - } else { - if (moveRedToAlphaBuffer && desc->x54_x40_TEXR) - CGraphics::SetShaderDataBinding(m_redToAlphaDataBind[g_Renderer->IsThermalVisorHotPass()]); - else - CGraphics::SetShaderDataBinding(m_normalDataBind[g_Renderer->IsThermalVisorHotPass()]); - } -#endif - int mbspVal = std::max(1, x270_MBSP); CParticleGlobals::instance()->SetEmitterTime(x74_curFrame); @@ -1490,11 +1472,11 @@ void CElementGen::RenderParticles() { switch (m_shaderClass) { case CElementGenShaders::EShaderClass::Tex: m_instBuf.load(g_instTexData); - m_shaderBuilder.BuildShaderDataBinding(*this).draw_instanced(0, 4, g_instTexData.size()); + m_shaderBuilder.BuildShaderDataBinding(*this, false).draw_instanced(0, 4, g_instTexData.size()); break; case CElementGenShaders::EShaderClass::NoTex: m_instBuf.load(g_instNoTexData); - m_shaderBuilder.BuildShaderDataBinding(*this).draw_instanced(0, 4, g_instNoTexData.size()); + m_shaderBuilder.BuildShaderDataBinding(*this, false).draw_instanced(0, 4, g_instNoTexData.size()); break; default: break; @@ -1604,11 +1586,11 @@ void CElementGen::RenderParticles() { switch (m_shaderClass) { case CElementGenShaders::EShaderClass::Tex: m_instBuf.load(g_instTexData); - m_shaderBuilder.BuildShaderDataBinding(*this).draw_instanced(0, 4, g_instTexData.size()); + m_shaderBuilder.BuildShaderDataBinding(*this, false).draw_instanced(0, 4, g_instTexData.size()); break; case CElementGenShaders::EShaderClass::NoTex: m_instBuf.load(g_instNoTexData); - m_shaderBuilder.BuildShaderDataBinding(*this).draw_instanced(0, 4, g_instNoTexData.size()); + m_shaderBuilder.BuildShaderDataBinding(*this, false).draw_instanced(0, 4, g_instNoTexData.size()); break; default: break; @@ -1681,12 +1663,6 @@ void CElementGen::RenderParticlesIndirectTexture() { g_instIndTexData.clear(); g_instIndTexData.reserve(x30_particles.size()); - // TODO: move to builder -#if 0 - if (!x30_particles.empty()) - CGraphics::SetShaderDataBinding(m_normalDataBind[g_Renderer->IsThermalVisorHotPass()]); -#endif - for (size_t i = 0; i < x30_particles.size(); ++i) { const int partIdx = desc->x44_28_x30_28_SORT ? sortItems[i].x0_partIdx : int(i); CParticle& particle = x30_particles[partIdx]; @@ -1743,9 +1719,9 @@ void CElementGen::RenderParticlesIndirectTexture() { inst.texrTindUVs[1] = zeus::CVector4f{uvs.xMin, uvs.yMax, uvsInd.xMin, uvsInd.yMax}; inst.texrTindUVs[2] = zeus::CVector4f{uvs.xMax, uvs.yMin, uvsInd.xMax, uvsInd.yMin}; inst.texrTindUVs[3] = zeus::CVector4f{uvs.xMin, uvs.yMin, uvsInd.xMin, uvsInd.yMin}; - inst.sceneUVs = zeus::CVector4f{clipRect.x18_uvXMin, 1.f - clipRect.x24_uvYMax, clipRect.x1c_uvXMax, - 1.f - clipRect.x20_uvYMin}; - m_shaderBuilder.BuildShaderDataBinding(*this).draw_instanced(0, 4, g_instIndTexData.size() - 1); + inst.sceneUVs = + zeus::CVector4f{clipRect.x18_uvXMin, 1.f - clipRect.x24_uvYMax, clipRect.x1c_uvXMax, 1.f - clipRect.x20_uvYMin}; + m_shaderBuilder.BuildShaderDataBinding(*this, false).draw_instanced(0, 4, g_instIndTexData.size() - 1); } if (!g_instIndTexData.empty()) {