mirror of https://github.com/AxioDL/metaforce.git
CColoredStripShader: Convert to hsh pipeline
This commit is contained in:
parent
8d15acb11d
commit
31bb006976
|
@ -56,4 +56,5 @@ runtime_add_hsh(Graphics
|
||||||
Shaders/CCameraBlurFilter.cpp
|
Shaders/CCameraBlurFilter.cpp
|
||||||
Shaders/CFogVolumePlaneShader.cpp
|
Shaders/CFogVolumePlaneShader.cpp
|
||||||
Shaders/CAABoxShader.cpp
|
Shaders/CAABoxShader.cpp
|
||||||
|
Shaders/CColoredStripShader.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,63 +6,58 @@
|
||||||
#include "Runtime/Graphics/CBooRenderer.hpp"
|
#include "Runtime/Graphics/CBooRenderer.hpp"
|
||||||
#include "Runtime/Graphics/CGraphics.hpp"
|
#include "Runtime/Graphics/CGraphics.hpp"
|
||||||
|
|
||||||
|
#include "CColoredStripShader.cpp.hshhead"
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
using namespace hsh::pipeline;
|
||||||
|
|
||||||
static const boo::ObjToken<boo::IShaderPipeline>& SelectPipeline(CColoredStripShader::Mode mode) {
|
template <CColoredStripShader::Mode Mode>
|
||||||
switch (mode) {
|
struct CColoredStripShaderColorAttachment : color_attachment<> {};
|
||||||
case CColoredStripShader::Mode::Alpha:
|
template <>
|
||||||
default:
|
struct CColoredStripShaderColorAttachment<CColoredStripShader::Mode::Alpha> : BlendAttachment<> {};
|
||||||
return s_Pipeline;
|
template <>
|
||||||
case CColoredStripShader::Mode::Additive:
|
struct CColoredStripShaderColorAttachment<CColoredStripShader::Mode::Additive> : AdditiveAttachment<> {};
|
||||||
return s_AdditivePipeline;
|
// TODO following are wrong
|
||||||
case CColoredStripShader::Mode::FullAdditive:
|
template <>
|
||||||
return s_FullAdditivePipeline;
|
struct CColoredStripShaderColorAttachment<CColoredStripShader::Mode::FullAdditive> : MultiplyAttachment<> {};
|
||||||
case CColoredStripShader::Mode::Subtractive:
|
template <>
|
||||||
return s_SubtractivePipeline;
|
struct CColoredStripShaderColorAttachment<CColoredStripShader::Mode::Subtractive> : SubtractAttachment<> {};
|
||||||
|
|
||||||
|
template <CColoredStripShader::Mode Mode>
|
||||||
|
// TODO typename == hsh bug?
|
||||||
|
struct CColoredStripShaderPipeline : pipeline<typename CColoredStripShaderColorAttachment<Mode>::color_attachment,
|
||||||
|
depth_compare<hsh::LEqual>, depth_write<false>> {
|
||||||
|
CColoredStripShaderPipeline(hsh::vertex_buffer<CColoredStripShader::Vert> vbo,
|
||||||
|
hsh::uniform_buffer<CColoredStripShader::Uniform> 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<float>(vbo->m_uv);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
template struct CColoredStripShaderPipeline<CColoredStripShader::Mode::Alpha>;
|
||||||
|
template struct CColoredStripShaderPipeline<CColoredStripShader::Mode::Additive>;
|
||||||
|
template struct CColoredStripShaderPipeline<CColoredStripShader::Mode::FullAdditive>;
|
||||||
|
template struct CColoredStripShaderPipeline<CColoredStripShader::Mode::Subtractive>;
|
||||||
|
|
||||||
void CColoredStripShader::BuildResources(boo::IGraphicsDataFactory::Context& ctx, size_t maxVerts, Mode mode,
|
CColoredStripShader::CColoredStripShader(size_t maxVerts, Mode mode, hsh::texture2d tex) {
|
||||||
boo::ObjToken<boo::ITexture> tex) {
|
m_vbo = hsh::create_dynamic_vertex_buffer<Vert>(maxVerts);
|
||||||
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Vert), maxVerts);
|
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
|
||||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
|
|
||||||
|
|
||||||
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
|
if (!tex) {
|
||||||
constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
|
tex = g_Renderer->GetWhiteTexture();
|
||||||
std::array<boo::ObjToken<boo::ITexture>, 1> texs;
|
|
||||||
if (tex) {
|
|
||||||
texs[0] = tex;
|
|
||||||
} else {
|
|
||||||
texs[0] = g_Renderer->GetWhiteTexture();
|
|
||||||
}
|
}
|
||||||
|
m_dataBind.hsh_bind(CColoredStripShaderPipeline<mode>(m_vbo.get(), m_uniBuf.get(), tex));
|
||||||
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<boo::ITexture> 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<boo::ITexture> tex) {
|
|
||||||
BuildResources(ctx, maxVerts, mode, tex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CColoredStripShader::draw(const zeus::CColor& color, size_t numVerts, const Vert* verts) {
|
void CColoredStripShader::draw(const zeus::CColor& color, size_t numVerts, const Vert* verts) {
|
||||||
SCOPED_GRAPHICS_DEBUG_GROUP("CColoredStripShader::draw", zeus::skMagenta);
|
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_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
|
||||||
m_uniform.m_color = color;
|
m_uniform.m_color = color;
|
||||||
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
m_uniBuf.load(m_uniform);
|
||||||
|
|
||||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
m_dataBind.draw(0, numVerts);
|
||||||
CGraphics::DrawArray(0, numVerts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace urde
|
||||||
|
|
|
@ -7,31 +7,26 @@ namespace urde {
|
||||||
|
|
||||||
class CColoredStripShader {
|
class CColoredStripShader {
|
||||||
public:
|
public:
|
||||||
enum class Mode {
|
enum class Mode { Alpha, Additive, FullAdditive, Subtractive };
|
||||||
Alpha,
|
|
||||||
Additive,
|
|
||||||
FullAdditive,
|
|
||||||
Subtractive
|
|
||||||
};
|
|
||||||
struct Vert {
|
struct Vert {
|
||||||
zeus::CVector3f m_pos;
|
hsh::float3 m_pos;
|
||||||
zeus::CColor m_color;
|
hsh::float4 m_color;
|
||||||
zeus::CVector2f m_uv;
|
hsh::float2 m_uv;
|
||||||
|
};
|
||||||
|
struct Uniform {
|
||||||
|
hsh::float4x4 m_matrix;
|
||||||
|
hsh::float4 m_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Uniform {
|
|
||||||
zeus::CMatrix4f m_matrix;
|
|
||||||
zeus::CColor m_color;
|
|
||||||
};
|
|
||||||
hsh::dynamic_owner<hsh::vertex_buffer<Vert>> m_vbo;
|
hsh::dynamic_owner<hsh::vertex_buffer<Vert>> m_vbo;
|
||||||
hsh::dynamic_owner<hsh::uniform_buffer<Uniform>> m_uniBuf;
|
hsh::dynamic_owner<hsh::uniform_buffer<Uniform>> m_uniBuf;
|
||||||
hsh::binding m_dataBind;
|
hsh::binding m_dataBind;
|
||||||
Uniform m_uniform;
|
Uniform m_uniform{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CColoredStripShader(size_t maxVerts, Mode mode, hsh::texture2d tex);
|
CColoredStripShader(size_t maxVerts, Mode mode, hsh::texture2d tex);
|
||||||
void draw(const zeus::CColor& color, size_t numVerts, const Vert* verts);
|
void draw(const zeus::CColor& color, size_t numVerts, const Vert* verts);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
} // namespace urde
|
||||||
|
|
Loading…
Reference in New Issue