2017-10-01 04:26:46 +00:00
|
|
|
#include "CWorldShadowShader.hpp"
|
2018-10-07 02:59:17 +00:00
|
|
|
#include "hecl/Pipeline.hpp"
|
|
|
|
#include "Graphics/CGraphics.hpp"
|
2017-10-01 04:26:46 +00:00
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
2018-10-07 02:59:17 +00:00
|
|
|
static boo::ObjToken<boo::IShaderPipeline> s_Pipeline;
|
|
|
|
static boo::ObjToken<boo::IShaderPipeline> s_ZPipeline;
|
|
|
|
|
|
|
|
void CWorldShadowShader::Initialize()
|
|
|
|
{
|
|
|
|
s_Pipeline = hecl::conv->convert(Shader_CWorldShadowShader{});
|
|
|
|
s_ZPipeline = hecl::conv->convert(Shader_CWorldShadowShaderZ{});
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWorldShadowShader::Shutdown()
|
|
|
|
{
|
|
|
|
s_Pipeline.reset();
|
|
|
|
s_ZPipeline.reset();
|
|
|
|
}
|
|
|
|
|
2017-10-01 04:26:46 +00:00
|
|
|
CWorldShadowShader::CWorldShadowShader(u32 w, u32 h)
|
2017-10-02 01:01:11 +00:00
|
|
|
: m_w(w), m_h(h)
|
2017-10-01 04:26:46 +00:00
|
|
|
{
|
2018-05-25 06:39:38 +00:00
|
|
|
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx)
|
2017-10-02 01:01:11 +00:00
|
|
|
{
|
|
|
|
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, 16, 4);
|
|
|
|
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
|
2018-10-07 02:59:17 +00:00
|
|
|
boo::ObjToken<boo::IGraphicsBuffer> bufs[] = {m_uniBuf.get()};
|
|
|
|
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
|
|
|
m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr,
|
|
|
|
1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
|
|
|
m_zDataBind = ctx.newShaderDataBinding(s_ZPipeline, m_vbo.get(), nullptr, nullptr,
|
|
|
|
1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
2017-10-02 01:01:11 +00:00
|
|
|
m_tex = ctx.newRenderTexture(m_w, m_h, boo::TextureClampMode::ClampToWhite, 1, 0);
|
|
|
|
return true;
|
2018-05-25 06:39:38 +00:00
|
|
|
} BooTrace);
|
2017-10-01 04:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CWorldShadowShader::bindRenderTarget()
|
|
|
|
{
|
|
|
|
CGraphics::g_BooMainCommandQueue->setRenderTarget(m_tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWorldShadowShader::drawBase(float extent)
|
|
|
|
{
|
|
|
|
zeus::CVector3f verts[] = {{-extent, 0.f, extent}, {extent, 0.f, extent},
|
|
|
|
{-extent, 0.f, -extent}, {extent, 0.f, -extent}};
|
|
|
|
m_vbo->load(verts, sizeof(zeus::CVector3f) * 4);
|
|
|
|
|
|
|
|
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
|
|
|
|
m_uniform.m_color = zeus::CColor::skWhite;
|
|
|
|
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
|
|
|
|
|
|
|
CGraphics::SetShaderDataBinding(m_zDataBind);
|
|
|
|
CGraphics::DrawArray(0, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWorldShadowShader::lightenShadow()
|
|
|
|
{
|
|
|
|
m_uniform.m_color = zeus::CColor(1.f, 0.25f);
|
|
|
|
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
|
|
|
|
|
|
|
CGraphics::SetShaderDataBinding(m_dataBind);
|
|
|
|
CGraphics::DrawArray(0, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CWorldShadowShader::blendPreviousShadow()
|
|
|
|
{
|
|
|
|
if (!m_prevQuad)
|
2017-11-05 06:17:12 +00:00
|
|
|
m_prevQuad.emplace(EFilterType::Blend, m_tex.get());
|
2018-01-16 06:42:28 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void CWorldShadowShader::resolveTexture()
|
|
|
|
{
|
2017-10-01 05:32:37 +00:00
|
|
|
boo::SWindowRect rect = {0, 0, int(m_w), int(m_h)};
|
2018-01-15 07:39:25 +00:00
|
|
|
CGraphics::g_BooMainCommandQueue->resolveBindTexture(m_tex, rect, false, 0, true, false, true);
|
2017-10-01 04:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|