mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-07-15 14:05:52 +00:00
Convert CWorldShadowShader
This commit is contained in:
parent
63f7f225cc
commit
35f33333a5
@ -72,4 +72,5 @@ runtime_add_hsh(Graphics
|
|||||||
Shaders/CScanLinesFilter.cpp
|
Shaders/CScanLinesFilter.cpp
|
||||||
Shaders/CSpaceWarpFilter.cpp
|
Shaders/CSpaceWarpFilter.cpp
|
||||||
Shaders/CXRayBlurFilter.cpp
|
Shaders/CXRayBlurFilter.cpp
|
||||||
|
Shaders/CWorldShadowShader.cpp
|
||||||
)
|
)
|
||||||
|
@ -5,70 +5,74 @@
|
|||||||
#include "Runtime/Camera/CCameraFilter.hpp"
|
#include "Runtime/Camera/CCameraFilter.hpp"
|
||||||
#include "Runtime/Graphics/CGraphics.hpp"
|
#include "Runtime/Graphics/CGraphics.hpp"
|
||||||
|
|
||||||
#include "zeus/CVector3f.hpp"
|
#include "CWorldShadowShader.cpp.hshhead"
|
||||||
|
|
||||||
namespace urde {
|
namespace urde {
|
||||||
|
using namespace hsh::pipeline;
|
||||||
|
|
||||||
|
template <bool Depth>
|
||||||
|
struct CWorldShadowShaderPipeline : pipeline<topology<hsh::TriangleStrip>, BlendAttachment<>, depth_write<Depth>,
|
||||||
|
depth_compare<Depth ? hsh::LEqual : hsh::Always>> {
|
||||||
|
CWorldShadowShaderPipeline(hsh::vertex_buffer<CWorldShadowShader::Vert> vbo,
|
||||||
|
hsh::uniform_buffer<CWorldShadowShader::Uniform> ubo) {
|
||||||
|
this->position = ubo->m_matrix * hsh::float4(vbo->m_pos, 1.f);
|
||||||
|
this->color_out[0] = ubo->m_color;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template struct CWorldShadowShaderPipeline<true>;
|
||||||
|
template struct CWorldShadowShaderPipeline<false>;
|
||||||
|
|
||||||
CWorldShadowShader::CWorldShadowShader(u32 w, u32 h) : m_w(w), m_h(h) {
|
CWorldShadowShader::CWorldShadowShader(u32 w, u32 h) : m_w(w), m_h(h) {
|
||||||
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
|
m_vbo = hsh::create_dynamic_vertex_buffer<Vert>(4);
|
||||||
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 16, 4);
|
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
|
||||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
|
m_tex = hsh::create_render_texture2d({m_w, m_h}, hsh::RGBA8_UNORM, 1, 0);
|
||||||
|
|
||||||
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
|
// FIXME hsh bug: can't bind all constant values
|
||||||
constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
|
bool depth = false;
|
||||||
m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
|
m_dataBind.hsh_bind(CWorldShadowShaderPipeline<depth>(m_vbo.get(), m_uniBuf.get()));
|
||||||
stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
depth = true;
|
||||||
m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
|
m_dataBind.hsh_z_bind(CWorldShadowShaderPipeline<depth>(m_vbo.get(), m_uniBuf.get()));
|
||||||
stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
|
||||||
|
|
||||||
m_tex = ctx.newRenderTexture(m_w, m_h, boo::TextureClampMode::ClampToWhite, 1, 0);
|
|
||||||
return true;
|
|
||||||
} BooTrace);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWorldShadowShader::bindRenderTarget() { CGraphics::g_BooMainCommandQueue->setRenderTarget(m_tex); }
|
void CWorldShadowShader::bindRenderTarget() { m_tex.attach(); }
|
||||||
|
|
||||||
void CWorldShadowShader::drawBase(float extent) {
|
void CWorldShadowShader::drawBase(float extent) {
|
||||||
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::drawBase", zeus::skMagenta);
|
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::drawBase", zeus::skMagenta);
|
||||||
|
|
||||||
const std::array<zeus::CVector3f, 4> verts{{
|
const std::array<Vert, 4> verts{{
|
||||||
{-extent, 0.f, extent},
|
{{-extent, 0.f, extent}},
|
||||||
{extent, 0.f, extent},
|
{{extent, 0.f, extent}},
|
||||||
{-extent, 0.f, -extent},
|
{{-extent, 0.f, -extent}},
|
||||||
{extent, 0.f, -extent},
|
{{extent, 0.f, -extent}},
|
||||||
}};
|
}};
|
||||||
m_vbo->load(verts.data(), sizeof(verts));
|
m_vbo.load(verts);
|
||||||
|
|
||||||
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 = zeus::skWhite;
|
m_uniform.m_color = zeus::skWhite;
|
||||||
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
m_uniBuf.load(m_uniform);
|
||||||
|
|
||||||
CGraphics::SetShaderDataBinding(m_zDataBind);
|
m_zDataBind.draw(0, 4);
|
||||||
CGraphics::DrawArray(0, 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWorldShadowShader::lightenShadow() {
|
void CWorldShadowShader::lightenShadow() {
|
||||||
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::lightenShadow", zeus::skMagenta);
|
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::lightenShadow", zeus::skMagenta);
|
||||||
|
|
||||||
m_uniform.m_color = zeus::CColor(1.f, 0.25f);
|
m_uniform.m_color = zeus::CColor(1.f, 0.25f);
|
||||||
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
m_uniBuf.load(m_uniform);
|
||||||
|
|
||||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
m_dataBind.draw(0, 4);
|
||||||
CGraphics::DrawArray(0, 4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWorldShadowShader::blendPreviousShadow() {
|
void CWorldShadowShader::blendPreviousShadow() {
|
||||||
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::blendPreviousShadow", zeus::skMagenta);
|
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::blendPreviousShadow", zeus::skMagenta);
|
||||||
|
|
||||||
if (!m_prevQuad)
|
if (!m_prevQuad) {
|
||||||
m_prevQuad.emplace(EFilterType::Blend, m_tex.get());
|
m_prevQuad.emplace(EFilterType::Blend, m_tex.get_color(0));
|
||||||
|
}
|
||||||
zeus::CRectangle rect(0.f, 1.f, 1.f, -1.f);
|
zeus::CRectangle rect(0.f, 1.f, 1.f, -1.f);
|
||||||
m_prevQuad->draw({1.f, 0.85f}, 1.f, rect);
|
m_prevQuad->draw({1.f, 0.85f}, 1.f, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CWorldShadowShader::resolveTexture() {
|
void CWorldShadowShader::resolveTexture() { m_tex.resolve_color_binding(0, hsh::rect2d{{}, {m_w, m_h}}, false); }
|
||||||
boo::SWindowRect rect = {0, 0, int(m_w), int(m_h)};
|
|
||||||
CGraphics::g_BooMainCommandQueue->resolveBindTexture(m_tex, rect, false, 0, true, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace urde
|
} // namespace urde
|
||||||
|
@ -11,21 +11,25 @@
|
|||||||
namespace urde {
|
namespace urde {
|
||||||
|
|
||||||
class CWorldShadowShader {
|
class CWorldShadowShader {
|
||||||
hsh::owner<hsh::render_texture2d> m_tex;
|
public:
|
||||||
std::optional<CTexturedQuadFilter> m_prevQuad;
|
|
||||||
u32 m_w, m_h;
|
|
||||||
|
|
||||||
struct Vert {
|
struct Vert {
|
||||||
hsh::float3 m_pos;
|
hsh::float3 m_pos;
|
||||||
};
|
};
|
||||||
struct Uniform {
|
struct Uniform {
|
||||||
zeus::CMatrix4f m_matrix;
|
hsh::float4x4 m_matrix;
|
||||||
zeus::CColor m_color;
|
hsh::float4 m_color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
hsh::owner<hsh::render_texture2d> m_tex;
|
||||||
|
std::optional<CTexturedQuadFilter> m_prevQuad;
|
||||||
|
u32 m_w, m_h;
|
||||||
|
|
||||||
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;
|
hsh::binding m_zDataBind;
|
||||||
|
Uniform m_uniform{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit CWorldShadowShader(u32 w, u32 h);
|
explicit CWorldShadowShader(u32 w, u32 h);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user