2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-21 14:59:13 +00:00

CParticleSwooshShaders: Convert to hsh pipeline

This commit is contained in:
2020-10-03 00:27:25 -04:00
parent 6fa9d39cd6
commit 315ac7d6d7
4 changed files with 80 additions and 78 deletions

View File

@@ -5,57 +5,65 @@
#include "Runtime/Particle/CParticleSwoosh.hpp"
#include "Runtime/Particle/CSwooshDescription.hpp"
#include "CParticleSwooshShaders.cpp.hshhead"
namespace urde {
using namespace hsh::pipeline;
template <bool Additive, bool AlphaWrite, bool ZWrite>
struct CParticleSwooshShadersTexPipeline
: pipeline<topology<hsh::TriangleStrip>,
std::conditional_t<Additive, AdditiveAttachment<AlphaWrite>, BlendAttachment<AlphaWrite>>,
depth_compare<hsh::LEqual>, depth_write<ZWrite>> {
CParticleSwooshShadersTexPipeline(hsh::vertex_buffer<CParticleSwooshShaders::Vert> vbo,
hsh::uniform_buffer<CParticleSwooshShaders::Uniform> uniBuf, hsh::texture2d tex) {
this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f);
this->color_out[0] = vbo->m_color * tex.sample<float>(vbo->m_uv);
}
};
template struct CParticleSwooshShadersTexPipeline<true, true, false>;
template struct CParticleSwooshShadersTexPipeline<false, true, true>;
template <bool Additive, bool AlphaWrite, bool ZWrite>
struct CParticleSwooshShadersNoTexPipeline
: pipeline<topology<hsh::TriangleStrip>,
std::conditional_t<Additive, AdditiveAttachment<AlphaWrite>, BlendAttachment<AlphaWrite>>,
depth_compare<hsh::LEqual>, depth_write<ZWrite>> {
CParticleSwooshShadersNoTexPipeline(hsh::vertex_buffer<CParticleSwooshShaders::Vert> vbo,
hsh::uniform_buffer<CParticleSwooshShaders::Uniform> uniBuf) {
this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f);
this->color_out[0] = vbo->m_color;
}
};
template struct CParticleSwooshShadersNoTexPipeline<true, true, false>;
template struct CParticleSwooshShadersNoTexPipeline<false, true, true>;
CParticleSwooshShaders::EShaderClass CParticleSwooshShaders::GetShaderClass(CParticleSwoosh& gen) {
CSwooshDescription* desc = gen.GetDesc();
if (desc->x3c_TEXR)
return EShaderClass::Tex;
else
return EShaderClass::NoTex;
return gen.GetDesc()->x3c_TEXR ? EShaderClass::Tex : EShaderClass::NoTex;
}
void CParticleSwooshShaders::BuildShaderDataBinding(CParticleSwoosh& gen) {
CSwooshDescription* desc = gen.GetDesc();
std::array<boo::ObjToken<boo::IShaderPipeline>, 2>* pipeline = nullptr;
if (desc->x3c_TEXR) {
if (desc->x44_31_AALP) {
if (desc->x45_24_ZBUF)
pipeline = &m_texAdditiveZWrite;
else
pipeline = &m_texAdditiveNoZWrite;
} else {
if (desc->x45_24_ZBUF)
pipeline = &m_texZWrite;
else
pipeline = &m_texNoZWrite;
}
} else {
if (desc->x44_31_AALP) {
if (desc->x45_24_ZBUF)
pipeline = &m_noTexAdditiveZWrite;
else
pipeline = &m_noTexAdditiveNoZWrite;
} else {
if (desc->x45_24_ZBUF)
pipeline = &m_noTexZWrite;
else
pipeline = &m_noTexNoZWrite;
}
auto* desc = gen.GetDesc();
switch (GetShaderClass(gen)) {
case EShaderClass::Tex: {
hsh::texture2d tex = desc->x3c_TEXR->GetValueTexture(0)->GetBooTexture();
gen.m_dataBind[0].hsh_tex_noalphawrite_bind(
CParticleSwooshShadersTexPipeline<desc->x44_31_AALP, false, desc->x45_24_ZBUF>(gen.m_vertBuf.get(),
gen.m_uniformBuf.get(), tex));
gen.m_dataBind[1].hsh_tex_alphawrite_bind(
CParticleSwooshShadersTexPipeline<desc->x44_31_AALP, true, desc->x45_24_ZBUF>(gen.m_vertBuf.get(),
gen.m_uniformBuf.get(), tex));
break;
}
case EShaderClass::NoTex: {
gen.m_dataBind[0].hsh_notex_noalphawrite_bind(
CParticleSwooshShadersNoTexPipeline<desc->x44_31_AALP, false, desc->x45_24_ZBUF>(gen.m_vertBuf.get(),
gen.m_uniformBuf.get()));
gen.m_dataBind[1].hsh_notex_alphawrite_bind(
CParticleSwooshShadersNoTexPipeline<desc->x44_31_AALP, true, desc->x45_24_ZBUF>(gen.m_vertBuf.get(),
gen.m_uniformBuf.get()));
break;
}
const CUVElement* const texr = desc->x3c_TEXR.get();
const std::array<boo::ObjToken<boo::ITexture>, 1> textures{
texr ? texr->GetValueTexture(0).GetObj()->GetBooTexture() : nullptr,
};
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms{gen.m_uniformBuf.get()};
for (size_t i = 0; i < gen.m_dataBind.size(); ++i) {
gen.m_dataBind[i] =
ctx.newShaderDataBinding((*pipeline)[i], gen.m_vertBuf.get(), nullptr, nullptr, uniforms.size(),
uniforms.data(), nullptr, texr ? 1 : 0, textures.data(), nullptr, nullptr);
}
}