diff --git a/Runtime/Graphics/CMakeLists.txt b/Runtime/Graphics/CMakeLists.txt index ad7ad5cfa..6052e3168 100644 --- a/Runtime/Graphics/CMakeLists.txt +++ b/Runtime/Graphics/CMakeLists.txt @@ -56,4 +56,5 @@ runtime_add_hsh(Graphics Shaders/CCameraBlurFilter.cpp Shaders/CFogVolumePlaneShader.cpp Shaders/CAABoxShader.cpp + Shaders/CColoredStripShader.cpp ) diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.cpp b/Runtime/Graphics/Shaders/CColoredStripShader.cpp index 730ae2b6f..7e07ef312 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.cpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.cpp @@ -6,63 +6,58 @@ #include "Runtime/Graphics/CBooRenderer.hpp" #include "Runtime/Graphics/CGraphics.hpp" +#include "CColoredStripShader.cpp.hshhead" + namespace urde { +using namespace hsh::pipeline; -static const boo::ObjToken& SelectPipeline(CColoredStripShader::Mode mode) { - switch (mode) { - case CColoredStripShader::Mode::Alpha: - default: - return s_Pipeline; - case CColoredStripShader::Mode::Additive: - return s_AdditivePipeline; - case CColoredStripShader::Mode::FullAdditive: - return s_FullAdditivePipeline; - case CColoredStripShader::Mode::Subtractive: - return s_SubtractivePipeline; +template +struct CColoredStripShaderColorAttachment : color_attachment<> {}; +template <> +struct CColoredStripShaderColorAttachment : BlendAttachment<> {}; +template <> +struct CColoredStripShaderColorAttachment : AdditiveAttachment<> {}; +// TODO following are wrong +template <> +struct CColoredStripShaderColorAttachment : MultiplyAttachment<> {}; +template <> +struct CColoredStripShaderColorAttachment : SubtractAttachment<> {}; + +template +// TODO typename == hsh bug? +struct CColoredStripShaderPipeline : pipeline::color_attachment, + depth_compare, depth_write> { + CColoredStripShaderPipeline(hsh::vertex_buffer vbo, + hsh::uniform_buffer uniBuf, hsh::texture2d tex) { + this->position = uniBuf->m_matrix * hsh::float4(vbo->m_pos, 1.f); + this->color_out[0] = vbo->m_color * uniBuf->m_color * tex.sample(vbo->m_uv); } -} +}; +template struct CColoredStripShaderPipeline; +template struct CColoredStripShaderPipeline; +template struct CColoredStripShaderPipeline; +template struct CColoredStripShaderPipeline; -void CColoredStripShader::BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, - boo::ObjToken tex) { - m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vert), maxVerts); - m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1); +CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, hsh::texture2d tex) { + m_vbo = hsh::create_dynamic_vertex_buffer(maxVerts); + m_uniBuf = hsh::create_dynamic_uniform_buffer(); - const std::array, 1> bufs{m_uniBuf.get()}; - constexpr std::array stages{boo::PipelineStage::Vertex}; - std::array, 1> texs; - if (tex) { - texs[0] = tex; - } else { - texs[0] = g_Renderer->GetWhiteTexture(); + if (!tex) { + tex = g_Renderer->GetWhiteTexture(); } - - m_dataBind = ctx.newShaderDataBinding(SelectPipeline(mode), m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(), - stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr); -} - -CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, boo::ObjToken tex) { - CGraphics::CommitResources([this, maxVerts, mode, tex](boo::IGraphicsDataFactory::Context& ctx) { - BuildResources(ctx, maxVerts, mode, tex); - return true; - } BooTrace); -} - -CColoredStripShader::CColoredStripShader(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode, - boo::ObjToken tex) { - BuildResources(ctx, maxVerts, mode, tex); + m_dataBind.hsh_bind(CColoredStripShaderPipeline(m_vbo.get(), m_uniBuf.get(), tex)); } void CColoredStripShader::draw(const zeus::CColor& color, size_t numVerts, const Vert* verts) { SCOPED_GRAPHICS_DEBUG_GROUP("CColoredStripShader::draw", zeus::skMagenta); - m_vbo->load(verts, sizeof(Vert) * numVerts); + m_vbo.load(hsh::detail::ArrayProxy{verts, numVerts}); m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(); m_uniform.m_color = color; - m_uniBuf->load(&m_uniform, sizeof(m_uniform)); + m_uniBuf.load(m_uniform); - CGraphics::SetShaderDataBinding(m_dataBind); - CGraphics::DrawArray(0, numVerts); + m_dataBind.draw(0, numVerts); } -} +} // namespace urde diff --git a/Runtime/Graphics/Shaders/CColoredStripShader.hpp b/Runtime/Graphics/Shaders/CColoredStripShader.hpp index cc5b073f7..acdaad0c0 100644 --- a/Runtime/Graphics/Shaders/CColoredStripShader.hpp +++ b/Runtime/Graphics/Shaders/CColoredStripShader.hpp @@ -7,31 +7,26 @@ namespace urde { class CColoredStripShader { public: - enum class Mode { - Alpha, - Additive, - FullAdditive, - Subtractive - }; + enum class Mode { Alpha, Additive, FullAdditive, Subtractive }; struct Vert { - zeus::CVector3f m_pos; - zeus::CColor m_color; - zeus::CVector2f m_uv; + hsh::float3 m_pos; + hsh::float4 m_color; + hsh::float2 m_uv; + }; + struct Uniform { + hsh::float4x4 m_matrix; + hsh::float4 m_color; }; private: - struct Uniform { - zeus::CMatrix4f m_matrix; - zeus::CColor m_color; - }; hsh::dynamic_owner> m_vbo; hsh::dynamic_owner> m_uniBuf; hsh::binding m_dataBind; - Uniform m_uniform; + Uniform m_uniform{}; public: CColoredStripShader(size_t maxVerts, Mode mode, hsh::texture2d tex); void draw(const zeus::CColor& color, size_t numVerts, const Vert* verts); }; -} +} // namespace urde