diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index 80a80e7ba..3284d36b3 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -67,4 +67,5 @@ runtime_add_hsh(Graphics Shaders/CMapSurfaceShader.cpp Shaders/CParticleSwooshShaders.cpp Shaders/CPhazonSuitFilter.cpp + Shaders/CRadarPaintShader.cpp ) diff --git a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp index f355403b1..5d9aeff2d 100644 --- a/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp +++ b/Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp @@ -107,6 +107,7 @@ void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) { m_dataBindBlurY.hsh_blury_bind( CPhazonSuitFilterBlurPipeline(m_blurVbo.get(), m_uniBufBlurY.get(), CGraphics::g_SpareTexture.get_color(2))); + // FIXME hsh bug: can't bind all constant values bool hasIndTex = m_indTex != nullptr; if (hasIndTex) { hsh::texture2d tex = m_indTex->GetBooTexture(); diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp index 6332f24cd..a96346ece 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.cpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.cpp @@ -1,45 +1,38 @@ #include "Runtime/Graphics/Shaders/CRadarPaintShader.hpp" -#include - #include "Runtime/Graphics/CGraphics.hpp" #include "Runtime/Graphics/CTexture.hpp" +#include "CRadarPaintShader.cpp.hshhead" + namespace urde { +using namespace hsh::pipeline; + +struct CRadarPaintShaderPipeline : pipeline, AdditiveAttachment<>, depth_write> { + CRadarPaintShaderPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer ubo, hsh::texture2d tex) { + this->position = ubo->xf * hsh::float4(vbo->pos[this->vertex_id], 1.f); + this->color_out[0] = vbo->color * tex.sample(vbo->uv[this->vertex_id]); + } +}; void CRadarPaintShader::draw(const std::vector& instances, const CTexture* tex) { - if (!instances.size()) + if (instances.empty()) { return; + } + SCOPED_GRAPHICS_DEBUG_GROUP("CRadarPaintShader::draw", zeus::skMagenta); if (instances.size() > m_maxInsts) { m_maxInsts = instances.size(); m_tex = tex; - CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1); - - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - const std::array, 1> texs{m_tex->GetBooTexture()}; - - m_dataBind = - ctx.newShaderDataBinding(s_Pipeline, nullptr, m_vbo.get(), nullptr, bufs.size(), bufs.data(), stages.data(), - nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); - return true; - } BooTrace); + hsh::texture2d tex2d = m_tex->GetBooTexture(); + m_dataBind.hsh_bind(CRadarPaintShaderPipeline(m_vbo.get(), m_uniBuf.get(), tex2d)); } - zeus::CMatrix4f uniMtx = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); - m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f)); - - size_t mapSz = sizeof(Instance) * instances.size(); - Instance* insts = reinterpret_cast(m_vbo->map(mapSz)); - memmove(insts, instances.data(), mapSz); - m_vbo->unmap(); - - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawInstances(0, 4, instances.size()); + m_uniBuf.load({CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f()}); + m_vbo.load(instances); + m_dataBind.draw_instanced(0, 4, instances.size()); } } // namespace urde diff --git a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp index 20758e7a3..8df43282b 100644 --- a/Runtime/Graphics/Shaders/CRadarPaintShader.hpp +++ b/Runtime/Graphics/Shaders/CRadarPaintShader.hpp @@ -3,9 +3,7 @@ #include #include -#include "zeus/CColor.hpp" -#include "zeus/CVector2f.hpp" -#include "zeus/CVector3f.hpp" +#include "hsh/hsh.h" namespace urde { class CTexture; @@ -13,9 +11,9 @@ class CTexture; class CRadarPaintShader { public: struct Instance { - std::array pos; - std::array uv; - zeus::CColor color; + std::array pos; + std::array uv; + hsh::float4 color; }; struct Uniform { hsh::float4x4 xf;