metaforce/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp

89 lines
3.0 KiB
C++
Raw Normal View History

#include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include "Runtime/Graphics/CGraphics.hpp"
2022-01-31 16:06:54 -08:00
//#include <hecl/Pipeline.hpp>
#include <zeus/CVector2f.hpp>
2016-08-19 21:22:13 -07:00
2021-04-10 01:42:06 -07:00
namespace metaforce {
namespace {
struct Vert {
zeus::CVector2f m_pos;
zeus::CVector2f m_uv;
};
2022-01-31 16:06:54 -08:00
//boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
} // Anonymous namespace
2018-10-06 19:59:17 -07:00
2022-01-31 16:06:54 -08:00
void CCameraBlurFilter::Initialize() {
// s_Pipeline = hecl::conv->convert(Shader_CCameraBlurFilter{});
}
2018-10-06 19:59:17 -07:00
2022-01-31 16:06:54 -08:00
void CCameraBlurFilter::Shutdown() {
// s_Pipeline.reset();
}
2018-10-06 19:59:17 -07:00
2018-12-07 21:30:43 -08:00
CCameraBlurFilter::CCameraBlurFilter() {
2022-01-31 16:06:54 -08:00
// CGraphics::CommitResources([this](boo::IGraphicsDataFactory::Context& ctx) {
// m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 32, 4);
// 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 stages{boo::PipelineStage::Vertex};
// const std::array<boo::ObjToken<boo::ITexture>, 1> texs{CGraphics::g_SpareTexture.get()};
// m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
// stages.data(), nullptr, nullptr, texs.size(), texs.data(), nullptr, nullptr);
// return true;
// } BooTrace);
2016-08-19 21:22:13 -07:00
}
2018-12-07 21:30:43 -08:00
void CCameraBlurFilter::draw(float amount, bool clearDepth) {
if (amount <= 0.f) {
2018-12-07 21:30:43 -08:00
return;
}
2019-07-21 01:42:52 -07:00
SCOPED_GRAPHICS_DEBUG_GROUP("CCameraBlurFilter::draw", zeus::skMagenta);
2016-08-20 11:18:44 -07:00
2022-02-27 14:46:15 -08:00
const SClipScreenRect clipRect(CGraphics::g_Viewport);
// CGraphics::ResolveSpareTexture(clipRect, 0, clearDepth);
const float aspect = float(CGraphics::g_CroppedViewport.xc_width) / float(CGraphics::g_CroppedViewport.x10_height);
2016-08-20 11:18:44 -07:00
2022-02-27 14:46:15 -08:00
const float xFac = float(CGraphics::GetCroppedViewportWidth()) / float(CGraphics::GetViewportWidth());
const float yFac = float(CGraphics::GetCroppedViewportHeight()) / float(CGraphics::GetViewportHeight());
const float xBias = float(CGraphics::GetCroppedViewportLeft()) / float(CGraphics::GetViewportWidth());
const float yBias = float(CGraphics::GetCroppedViewportTop()) / float(CGraphics::GetViewportHeight());
2016-08-20 11:18:44 -07:00
const std::array<Vert, 4> verts{{
2018-12-07 21:30:43 -08:00
{{-1.0, -1.0}, {xBias, yBias}},
{{-1.0, 1.0}, {xBias, yBias + yFac}},
{{1.0, -1.0}, {xBias + xFac, yBias}},
{{1.0, 1.0}, {xBias + xFac, yBias + yFac}},
}};
2022-01-31 16:06:54 -08:00
// m_vbo->load(verts.data(), sizeof(verts));
2016-08-20 11:18:44 -07:00
for (size_t i = 0; i < m_uniform.m_uv.size(); ++i) {
auto tmp = static_cast<float>(i);
2018-12-07 21:30:43 -08:00
tmp *= 2.f * M_PIF;
tmp /= 6.f;
2016-08-19 21:22:13 -07:00
2018-12-07 21:30:43 -08:00
float amtX = std::cos(tmp);
amtX *= amount / 448.f / aspect;
2016-08-19 21:22:13 -07:00
2018-12-07 21:30:43 -08:00
float amtY = std::sin(tmp);
amtY *= amount / 448.f;
2016-08-19 21:22:13 -07:00
2018-12-07 21:30:43 -08:00
m_uniform.m_uv[i][0] = amtX * xFac;
m_uniform.m_uv[i][1] = amtY * yFac;
}
m_uniform.m_opacity = std::min(amount / 2.f, 1.f);
2022-01-31 16:06:54 -08:00
// m_uniBuf->load(&m_uniform, sizeof(m_uniform));
2018-12-07 21:30:43 -08:00
2022-01-31 16:06:54 -08:00
// CGraphics::SetShaderDataBinding(m_dataBind);
// CGraphics::DrawArray(0, 4);
2016-08-19 21:22:13 -07:00
}
2018-12-07 21:30:43 -08:00
2021-04-10 01:42:06 -07:00
} // namespace metaforce