mirror of https://github.com/AxioDL/metaforce.git
CRadarPaintShader: Convert to hsh pipeline
This commit is contained in:
parent
c4e175bd64
commit
ee1462ba30
|
@ -67,4 +67,5 @@ runtime_add_hsh(Graphics
|
||||||
Shaders/CMapSurfaceShader.cpp
|
Shaders/CMapSurfaceShader.cpp
|
||||||
Shaders/CParticleSwooshShaders.cpp
|
Shaders/CParticleSwooshShaders.cpp
|
||||||
Shaders/CPhazonSuitFilter.cpp
|
Shaders/CPhazonSuitFilter.cpp
|
||||||
|
Shaders/CRadarPaintShader.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -107,6 +107,7 @@ void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex) {
|
||||||
m_dataBindBlurY.hsh_blury_bind(
|
m_dataBindBlurY.hsh_blury_bind(
|
||||||
CPhazonSuitFilterBlurPipeline(m_blurVbo.get(), m_uniBufBlurY.get(), CGraphics::g_SpareTexture.get_color(2)));
|
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;
|
bool hasIndTex = m_indTex != nullptr;
|
||||||
if (hasIndTex) {
|
if (hasIndTex) {
|
||||||
hsh::texture2d tex = m_indTex->GetBooTexture();
|
hsh::texture2d tex = m_indTex->GetBooTexture();
|
||||||
|
|
|
@ -1,45 +1,38 @@
|
||||||
#include "Runtime/Graphics/Shaders/CRadarPaintShader.hpp"
|
#include "Runtime/Graphics/Shaders/CRadarPaintShader.hpp"
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
|
|
||||||
#include "Runtime/Graphics/CGraphics.hpp"
|
#include "Runtime/Graphics/CGraphics.hpp"
|
||||||
#include "Runtime/Graphics/CTexture.hpp"
|
#include "Runtime/Graphics/CTexture.hpp"
|
||||||
|
|
||||||
|
#include "CRadarPaintShader.cpp.hshhead"
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
using namespace hsh::pipeline;
|
||||||
|
|
||||||
|
struct CRadarPaintShaderPipeline : pipeline<topology<hsh::TriangleStrip>, AdditiveAttachment<>, depth_write<false>> {
|
||||||
|
CRadarPaintShaderPipeline(hsh::vertex_buffer<CRadarPaintShader::Instance> vbo,
|
||||||
|
hsh::uniform_buffer<CRadarPaintShader::Uniform> 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<float>(vbo->uv[this->vertex_id]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void CRadarPaintShader::draw(const std::vector<Instance>& instances, const CTexture* tex) {
|
void CRadarPaintShader::draw(const std::vector<Instance>& instances, const CTexture* tex) {
|
||||||
if (!instances.size())
|
if (instances.empty()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
SCOPED_GRAPHICS_DEBUG_GROUP("CRadarPaintShader::draw", zeus::skMagenta);
|
SCOPED_GRAPHICS_DEBUG_GROUP("CRadarPaintShader::draw", zeus::skMagenta);
|
||||||
|
|
||||||
if (instances.size() > m_maxInsts) {
|
if (instances.size() > m_maxInsts) {
|
||||||
m_maxInsts = instances.size();
|
m_maxInsts = instances.size();
|
||||||
m_tex = tex;
|
m_tex = tex;
|
||||||
CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
|
hsh::texture2d tex2d = m_tex->GetBooTexture();
|
||||||
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(Instance), m_maxInsts);
|
m_dataBind.hsh_bind(CRadarPaintShaderPipeline(m_vbo.get(), m_uniBuf.get(), tex2d));
|
||||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CMatrix4f), 1);
|
|
||||||
|
|
||||||
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
|
|
||||||
constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
|
|
||||||
const std::array<boo::ObjToken<boo::ITexture>, 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
zeus::CMatrix4f uniMtx = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
|
m_uniBuf.load({CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f()});
|
||||||
m_uniBuf->load(&uniMtx, sizeof(zeus::CMatrix4f));
|
m_vbo.load(instances);
|
||||||
|
m_dataBind.draw_instanced(0, 4, instances.size());
|
||||||
size_t mapSz = sizeof(Instance) * instances.size();
|
|
||||||
Instance* insts = reinterpret_cast<Instance*>(m_vbo->map(mapSz));
|
|
||||||
memmove(insts, instances.data(), mapSz);
|
|
||||||
m_vbo->unmap();
|
|
||||||
|
|
||||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
|
||||||
CGraphics::DrawInstances(0, 4, instances.size());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "zeus/CColor.hpp"
|
#include "hsh/hsh.h"
|
||||||
#include "zeus/CVector2f.hpp"
|
|
||||||
#include "zeus/CVector3f.hpp"
|
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
class CTexture;
|
class CTexture;
|
||||||
|
@ -13,9 +11,9 @@ class CTexture;
|
||||||
class CRadarPaintShader {
|
class CRadarPaintShader {
|
||||||
public:
|
public:
|
||||||
struct Instance {
|
struct Instance {
|
||||||
std::array<zeus::CVector3f, 4> pos;
|
std::array<hsh::float3, 4> pos;
|
||||||
std::array<zeus::CVector2f, 4> uv;
|
std::array<hsh::float2, 4> uv;
|
||||||
zeus::CColor color;
|
hsh::float4 color;
|
||||||
};
|
};
|
||||||
struct Uniform {
|
struct Uniform {
|
||||||
hsh::float4x4 xf;
|
hsh::float4x4 xf;
|
||||||
|
|
Loading…
Reference in New Issue