mirror of https://github.com/AxioDL/metaforce.git
CRandomStaticFilter: Convert to hsh pipeline
This commit is contained in:
parent
32fc69c215
commit
7b3783ddf9
|
@ -68,4 +68,5 @@ runtime_add_hsh(Graphics
|
|||
Shaders/CParticleSwooshShaders.cpp
|
||||
Shaders/CPhazonSuitFilter.cpp
|
||||
Shaders/CRadarPaintShader.cpp
|
||||
Shaders/CRandomStaticFilter.cpp
|
||||
)
|
||||
|
|
|
@ -6,40 +6,78 @@
|
|||
#include "Runtime/Camera/CCameraFilter.hpp"
|
||||
#include "Runtime/Graphics/CBooRenderer.hpp"
|
||||
|
||||
namespace urde {
|
||||
#include "CRandomStaticFilter.cpp.hshhead"
|
||||
|
||||
static boo::ObjToken<boo::IShaderPipeline> SelectPipeline(EFilterType type) {
|
||||
switch (type) {
|
||||
case EFilterType::Blend:
|
||||
return s_AlphaPipeline;
|
||||
case EFilterType::Add:
|
||||
return s_AddPipeline;
|
||||
case EFilterType::Multiply:
|
||||
return s_MultPipeline;
|
||||
default:
|
||||
return {};
|
||||
namespace urde {
|
||||
using namespace hsh::pipeline;
|
||||
|
||||
template <EFilterType Type, bool CookieCutter>
|
||||
struct FilterTypeAttachmentExt {
|
||||
using type = color_attachment<>;
|
||||
};
|
||||
template <bool CookieCutter>
|
||||
struct FilterTypeAttachmentExt<EFilterType::Blend, CookieCutter> {
|
||||
using type = BlendAttachmentExt<CookieCutter ? AlphaMode::AlphaReplace : AlphaMode::NoAlpha>;
|
||||
};
|
||||
template <bool CookieCutter>
|
||||
struct FilterTypeAttachmentExt<EFilterType::Add, CookieCutter> {
|
||||
using type = AdditiveAttachmentExt<CookieCutter ? AlphaMode::AlphaReplace : AlphaMode::NoAlpha>;
|
||||
};
|
||||
template <bool CookieCutter>
|
||||
struct FilterTypeAttachmentExt<EFilterType::Multiply, CookieCutter> {
|
||||
using type = MultiplyAttachmentExt<CookieCutter ? AlphaMode::AlphaReplace : AlphaMode::NoAlpha>;
|
||||
};
|
||||
template <bool CookieCutter>
|
||||
struct FilterTypeAttachmentExt<EFilterType::NoColor, CookieCutter> {
|
||||
using type = NoColorAttachmentExt<CookieCutter ? AlphaMode::AlphaReplace : AlphaMode::NoAlpha>;
|
||||
};
|
||||
template <EFilterType Type, bool CookieCutter>
|
||||
using FilterTypeAttachment = typename FilterTypeAttachmentExt<Type, CookieCutter>::type;
|
||||
|
||||
template <EFilterType Type, bool CookieCutter>
|
||||
struct CRandomStaticFilterPipeline
|
||||
: pipeline<topology<hsh::TriangleStrip>, FilterTypeAttachment<Type, CookieCutter>,
|
||||
depth_compare<CookieCutter ? hsh::LEqual : hsh::Always>, depth_write<CookieCutter>> {
|
||||
CRandomStaticFilterPipeline(hsh::vertex_buffer<CRandomStaticFilter::Vert> vbo,
|
||||
hsh::uniform_buffer<CRandomStaticFilter::Uniform> ubo, hsh::texture2d tex) {
|
||||
this->position = hsh::float4(vbo->m_pos, 0.f, 1.f);
|
||||
hsh::float4 color = tex.read<float>(Lookup8BPP(vbo->m_uv, ubo->randOff)) * ubo->color;
|
||||
if constexpr (CookieCutter) {
|
||||
if (color.w < ubo->discardThres) {
|
||||
hsh::discard();
|
||||
}
|
||||
} else {
|
||||
color.w = ubo->color.w;
|
||||
}
|
||||
this->color_out[0] = color;
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr hsh::uint2 Lookup8BPP(hsh::float2 uv, float randOff) {
|
||||
int bx = int(uv.x) >> 3;
|
||||
int rx = int(uv.x) & 0x7;
|
||||
int by = int(uv.y) >> 2;
|
||||
int ry = int(uv.y) & 0x3;
|
||||
int bidx = by * 128 + bx;
|
||||
int addr = bidx * 32 + ry * 8 + rx + int(randOff);
|
||||
return hsh::uint2(addr & 0x3ff, addr >> 10);
|
||||
}
|
||||
};
|
||||
template struct CRandomStaticFilterPipeline<EFilterType::Blend, false>;
|
||||
template struct CRandomStaticFilterPipeline<EFilterType::Add, false>;
|
||||
template struct CRandomStaticFilterPipeline<EFilterType::Multiply, false>;
|
||||
template struct CRandomStaticFilterPipeline<EFilterType::NoColor, true>;
|
||||
|
||||
CRandomStaticFilter::CRandomStaticFilter(EFilterType type, bool cookieCutter) : m_cookieCutter(cookieCutter) {
|
||||
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
|
||||
const std::array<Vert, 4> verts{{
|
||||
{{-1.f, -1.f}, {0.f, 0.f}},
|
||||
{{-1.f, 1.f}, {0.f, 448.f}},
|
||||
{{1.f, -1.f}, {640.f, 0.f}},
|
||||
{{1.f, 1.f}, {640.f, 448.f}},
|
||||
}};
|
||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(), sizeof(Vert), verts.size());
|
||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 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{g_Renderer->GetRandomStaticEntropyTex()};
|
||||
m_dataBind = ctx.newShaderDataBinding(m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type), m_vbo.get(),
|
||||
nullptr, nullptr, bufs.size(), bufs.data(), stages.data(), nullptr, nullptr,
|
||||
texs.size(), texs.data(), nullptr, nullptr);
|
||||
return true;
|
||||
} BooTrace);
|
||||
constexpr std::array<Vert, 4> verts{{
|
||||
{{-1.f, -1.f}, {0.f, 0.f}},
|
||||
{{-1.f, 1.f}, {0.f, 448.f}},
|
||||
{{1.f, -1.f}, {640.f, 0.f}},
|
||||
{{1.f, 1.f}, {640.f, 448.f}},
|
||||
}};
|
||||
m_vbo = hsh::create_vertex_buffer(verts);
|
||||
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
|
||||
m_dataBind.hsh_bind(CRandomStaticFilterPipeline<type, cookieCutter>(m_vbo.get(), m_uniBuf.get(),
|
||||
g_Renderer->GetRandomStaticEntropyTex()));
|
||||
}
|
||||
|
||||
void CRandomStaticFilter::draw(const zeus::CColor& color, float t) {
|
||||
|
@ -48,11 +86,9 @@ void CRandomStaticFilter::draw(const zeus::CColor& color, float t) {
|
|||
m_uniform.color = color;
|
||||
m_uniform.randOff = ROUND_UP_32(int64_t(rand()) * 32767 / RAND_MAX);
|
||||
m_uniform.discardThres = 1.f - t;
|
||||
m_uniBuf.load(m_uniform);
|
||||
|
||||
m_uniBuf->load(&m_uniform, sizeof(Uniform));
|
||||
|
||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
||||
CGraphics::DrawArray(0, 4);
|
||||
m_dataBind.draw(0, 4);
|
||||
}
|
||||
|
||||
} // namespace urde
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "hsh/hsh.h"
|
||||
|
||||
#include "Runtime/CToken.hpp"
|
||||
|
||||
namespace urde {
|
||||
|
@ -9,6 +11,7 @@ enum class EFilterShape;
|
|||
enum class EFilterType;
|
||||
|
||||
class CRandomStaticFilter {
|
||||
public:
|
||||
struct Uniform {
|
||||
hsh::float4 color;
|
||||
float randOff;
|
||||
|
@ -18,6 +21,8 @@ class CRandomStaticFilter {
|
|||
hsh::float2 m_pos;
|
||||
hsh::float2 m_uv;
|
||||
};
|
||||
|
||||
private:
|
||||
hsh::owner<hsh::vertex_buffer<Vert>> m_vbo;
|
||||
hsh::dynamic_owner<hsh::uniform_buffer<Uniform>> m_uniBuf;
|
||||
hsh::binding m_dataBind;
|
||||
|
|
Loading…
Reference in New Issue