2019-09-29 00:30:53 +00:00
|
|
|
#include "Runtime/Graphics/Shaders/CWorldShadowShader.hpp"
|
|
|
|
|
2019-09-29 02:22:12 +00:00
|
|
|
#include <array>
|
|
|
|
|
2019-09-29 00:30:53 +00:00
|
|
|
#include "Runtime/Camera/CCameraFilter.hpp"
|
|
|
|
#include "Runtime/Graphics/CGraphics.hpp"
|
|
|
|
|
|
|
|
#include <hecl/Pipeline.hpp>
|
|
|
|
#include <zeus/CVector3f.hpp>
|
2017-10-01 04:26:46 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2017-10-01 04:26:46 +00:00
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
|
|
|
|
static boo::ObjToken<boo::IShaderPipeline> s_ZPipeline;
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CWorldShadowShader::Initialize() {
|
|
|
|
s_Pipeline = hecl::conv->convert(Shader_CWorldShadowShader{});
|
|
|
|
s_ZPipeline = hecl::conv->convert(Shader_CWorldShadowShaderZ{});
|
2018-10-07 02:59:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CWorldShadowShader::Shutdown() {
|
|
|
|
s_Pipeline.reset();
|
|
|
|
s_ZPipeline.reset();
|
2018-10-07 02:59:17 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CWorldShadowShader::CWorldShadowShader(u32 w, u32 h) : m_w(w), m_h(h) {
|
|
|
|
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
|
|
|
|
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 16, 4);
|
|
|
|
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
|
2019-09-29 02:22:12 +00:00
|
|
|
|
|
|
|
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
|
|
|
|
constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
|
|
|
|
m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
|
|
|
|
stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
|
|
|
m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr, bufs.size(), bufs.data(),
|
|
|
|
stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_tex = ctx.newRenderTexture(m_w, m_h, boo::TextureClampMode::ClampToWhite, 1, 0);
|
|
|
|
return true;
|
|
|
|
} BooTrace);
|
2017-10-01 04:26:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CWorldShadowShader::bindRenderTarget() { CGraphics::g_BooMainCommandQueue->setRenderTarget(m_tex); }
|
2017-10-01 04:26:46 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CWorldShadowShader::drawBase(float extent) {
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::drawBase", zeus::skMagenta);
|
|
|
|
|
2019-09-29 02:22:12 +00:00
|
|
|
const std::array<zeus::CVector3f, 4> verts{{
|
|
|
|
{-extent, 0.f, extent},
|
|
|
|
{extent, 0.f, extent},
|
|
|
|
{-extent, 0.f, -extent},
|
|
|
|
{extent, 0.f, -extent},
|
|
|
|
}};
|
|
|
|
m_vbo->load(verts.data(), sizeof(verts));
|
2017-10-01 04:26:46 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
|
2019-02-24 07:15:54 +00:00
|
|
|
m_uniform.m_color = zeus::skWhite;
|
2018-12-08 05:30:43 +00:00
|
|
|
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
2017-10-01 04:26:46 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetShaderDataBinding(m_zDataBind);
|
|
|
|
CGraphics::DrawArray(0, 4);
|
2017-10-01 04:26:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CWorldShadowShader::lightenShadow() {
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::lightenShadow", zeus::skMagenta);
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
m_uniform.m_color = zeus::CColor(1.f, 0.25f);
|
|
|
|
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
2017-10-01 04:26:46 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CGraphics::SetShaderDataBinding(m_dataBind);
|
|
|
|
CGraphics::DrawArray(0, 4);
|
2017-10-01 04:26:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CWorldShadowShader::blendPreviousShadow() {
|
2019-07-21 08:42:52 +00:00
|
|
|
SCOPED_GRAPHICS_DEBUG_GROUP("CWorldShadowShader::blendPreviousShadow", zeus::skMagenta);
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (!m_prevQuad)
|
|
|
|
m_prevQuad.emplace(EFilterType::Blend, m_tex.get());
|
|
|
|
zeus::CRectangle rect(0.f, 1.f, 1.f, -1.f);
|
|
|
|
m_prevQuad->draw({1.f, 0.85f}, 1.f, rect);
|
2017-10-01 04:26:46 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CWorldShadowShader::resolveTexture() {
|
|
|
|
boo::SWindowRect rect = {0, 0, int(m_w), int(m_h)};
|
|
|
|
CGraphics::g_BooMainCommandQueue->resolveBindTexture(m_tex, rect, false, 0, true, false, true);
|
2017-10-01 04:26:46 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|