2019-09-29 00:30:53 +00:00
|
|
|
#include "Runtime/Graphics/Shaders/CAABoxShader.hpp"
|
|
|
|
|
2019-09-29 02:22:12 +00:00
|
|
|
#include <array>
|
2020-09-29 04:58:21 +00:00
|
|
|
#include <zeus/CAABox.hpp>
|
2019-09-29 02:22:12 +00:00
|
|
|
|
2019-09-29 00:30:53 +00:00
|
|
|
#include "Runtime/Graphics/CGraphics.hpp"
|
2020-09-29 04:58:21 +00:00
|
|
|
#include "CAABoxShader.cpp.hshhead"
|
2017-09-03 05:53:38 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
namespace urde {
|
2020-09-29 04:58:21 +00:00
|
|
|
using namespace hsh::pipeline;
|
|
|
|
|
2020-09-30 05:58:28 +00:00
|
|
|
template <ERglCullMode CullMode, ERglEnum Compare, bool DepthWrite, ERglBlendMode Mode, ERglBlendFactor SrcFac,
|
|
|
|
ERglBlendFactor DstFac, ERglLogicOp Op, bool AlphaWrite>
|
2020-09-29 04:58:21 +00:00
|
|
|
struct CAABoxShaderPipeline
|
2020-09-30 05:58:28 +00:00
|
|
|
: pipeline<topology<hsh::TriangleStrip>, ERglBlendModeAttachment<Mode, SrcFac, DstFac, Op, AlphaWrite>,
|
|
|
|
ERglCullModeAttachment<CullMode>, ERglDepthCompareAttachment<Compare>, depth_write<DepthWrite>> {
|
2020-09-29 04:58:21 +00:00
|
|
|
CAABoxShaderPipeline(hsh::vertex_buffer<CAABoxShader::Vert> vbo, hsh::uniform_buffer<CAABoxShader::Uniform> uniBuf) {
|
|
|
|
this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f);
|
|
|
|
this->color_out[0] = uniBuf->m_color;
|
|
|
|
}
|
|
|
|
};
|
2020-10-02 22:58:57 +00:00
|
|
|
template struct CAABoxShaderPipeline<ERglCullMode::None, ERglEnum::LEqual, true, ERglBlendMode::Blend,
|
2020-09-30 05:58:28 +00:00
|
|
|
ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear, true>;
|
2020-09-29 04:58:21 +00:00
|
|
|
|
2020-10-02 22:58:57 +00:00
|
|
|
constexpr size_t VertexCount = 34;
|
|
|
|
|
2020-09-30 05:58:28 +00:00
|
|
|
CAABoxShader::CAABoxShader(const zeus::CAABox& aabb) {
|
2020-10-02 22:58:57 +00:00
|
|
|
const std::array<Vert, VertexCount> verts{{
|
2020-09-29 04:58:21 +00:00
|
|
|
{{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()}},
|
|
|
|
|
|
|
|
{{aabb.min.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.min.z()}},
|
|
|
|
{{aabb.max.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
|
|
|
|
{{aabb.max.x(), aabb.max.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.max.y(), aabb.max.z()}},
|
|
|
|
|
|
|
|
{{aabb.min.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.min.z()}},
|
|
|
|
{{aabb.min.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
|
|
|
|
{{aabb.min.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.max.z()}},
|
|
|
|
|
|
|
|
{{aabb.min.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.min.z()}},
|
|
|
|
{{aabb.max.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.max.z()}},
|
|
|
|
{{aabb.max.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.min.y(), aabb.max.z()}},
|
|
|
|
|
|
|
|
{{aabb.min.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.max.z()}},
|
|
|
|
{{aabb.max.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
|
|
|
|
{{aabb.max.x(), aabb.max.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.max.y(), aabb.max.z()}},
|
|
|
|
|
|
|
|
{{aabb.min.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.min.z()}},
|
|
|
|
{{aabb.max.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.min.z()}},
|
|
|
|
{{aabb.max.x(), aabb.max.y(), aabb.min.z()}},
|
2019-09-29 02:22:12 +00:00
|
|
|
}};
|
2017-09-03 05:53:38 +00:00
|
|
|
|
2020-09-29 04:58:21 +00:00
|
|
|
m_vbo = hsh::create_vertex_buffer(verts);
|
|
|
|
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
|
2020-09-30 05:58:28 +00:00
|
|
|
m_dataBind.hsh_bind(CAABoxShaderPipeline<gx_CullMode, gx_DepthTest, gx_DepthWrite, gx_BlendMode, gx_BlendSrcFac,
|
|
|
|
gx_BlendDstFac, gx_BlendOp, gx_AlphaWrite>(m_vbo.get(), m_uniBuf.get()));
|
2017-09-03 05:53:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CAABoxShader::draw(const zeus::CColor& color) {
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CAABoxShader::draw", zeus::skMagenta);
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
|
|
|
|
m_uniform.m_color = color;
|
2020-09-29 04:58:21 +00:00
|
|
|
m_uniBuf.load(m_uniform);
|
2017-09-03 05:53:38 +00:00
|
|
|
|
2020-10-02 22:58:57 +00:00
|
|
|
m_dataBind.draw(0, VertexCount);
|
2017-09-03 05:53:38 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
} // namespace urde
|