mirror of https://github.com/AxioDL/metaforce.git
CCameraBlurFilter implementation
This commit is contained in:
parent
6d26386780
commit
21fc28bc9b
|
@ -126,7 +126,8 @@ void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
|
|||
flags.m_extendedShaderIdx = 1;
|
||||
m_widescreen.draw(zeus::CColor::skBlack, std::sin(m_theta * 3.f) / 2.f + 0.5f);
|
||||
m_vm.m_modelTest->Draw(flags);
|
||||
m_xrayBlur.draw(25.f);
|
||||
//m_xrayBlur.draw(25.f);
|
||||
m_camBlur.draw((std::sin(m_theta * 3.f) / 2.f + 0.5f) * 3.f);
|
||||
//g_Renderer->DoThermalBlendHot();
|
||||
//m_spaceWarpFilter.setStrength(std::sin(m_theta * 5.f) * 0.5f + 0.5f);
|
||||
//m_spaceWarpFilter.draw(zeus::CVector2f{0.f, 0.f});
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "Runtime/Character/CAssetFactory.hpp"
|
||||
#include "Runtime/Graphics/Shaders/CColoredQuadFilter.hpp"
|
||||
#include "Runtime/Graphics/Shaders/CXRayBlurFilter.hpp"
|
||||
#include "Runtime/Graphics/Shaders/CCameraBlurFilter.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -52,6 +53,7 @@ class ViewManager : public specter::IViewManager
|
|||
CSpaceWarpFilter m_spaceWarpFilter;
|
||||
CWideScreenFilter m_widescreen = { CCameraFilterPass::EFilterType::Blend };
|
||||
CXRayBlurFilter m_xrayBlur;
|
||||
CCameraBlurFilter m_camBlur;
|
||||
CRandom16 m_random;
|
||||
float m_theta = 0.f;
|
||||
public:
|
||||
|
|
|
@ -53,6 +53,26 @@ void CCameraBlurPass::Draw()
|
|||
float uvOffset = uvScale * -0.5f + 0.5f;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0 ; i<7 ; ++i)
|
||||
{
|
||||
float amtX = 0.f;
|
||||
float amtY = 0.f;
|
||||
if (i)
|
||||
{
|
||||
float tmp = i - 1;
|
||||
tmp *= 2.f * M_PIF;
|
||||
tmp /= 6.f;
|
||||
|
||||
amtX = std::cos(tmp);
|
||||
amtX *= x1c_curValue / 640.f;
|
||||
|
||||
amtY = std::sin(tmp);
|
||||
amtY *= x1c_curValue / 448.f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCameraBlurPass::Update(float dt)
|
||||
|
|
|
@ -26,14 +26,34 @@ CCameraBlurFilter::CCameraBlurFilter()
|
|||
});
|
||||
}
|
||||
|
||||
void CCameraBlurFilter::draw()
|
||||
void CCameraBlurFilter::draw(float amount)
|
||||
{
|
||||
if (amount == 0.f)
|
||||
return;
|
||||
|
||||
SClipScreenRect clipRect = {};
|
||||
clipRect.xc_width = CGraphics::g_ViewportResolution.x;
|
||||
clipRect.x10_height = CGraphics::g_ViewportResolution.y;
|
||||
CGraphics::ResolveSpareTexture(clipRect);
|
||||
float aspect = CGraphics::g_ViewportResolution.x / float(CGraphics::g_ViewportResolution.y);
|
||||
|
||||
//m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
||||
for (int i=0 ; i<6 ; ++i)
|
||||
{
|
||||
float tmp = i;
|
||||
tmp *= 2.f * M_PIF;
|
||||
tmp /= 6.f;
|
||||
|
||||
float amtX = std::cos(tmp);
|
||||
amtX *= amount / 448.f * aspect;
|
||||
|
||||
float amtY = std::sin(tmp);
|
||||
amtY *= amount / 448.f;
|
||||
|
||||
m_uniform.m_uv[i][0] = amtX;
|
||||
m_uniform.m_uv[i][1] = amtY;
|
||||
}
|
||||
m_uniform.m_opacity = std::min(amount / 2.f, 1.f);
|
||||
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
||||
|
||||
CGraphics::g_BooMainCommandQueue->setShaderDataBinding(m_dataBind);
|
||||
CGraphics::g_BooMainCommandQueue->draw(0, 4);
|
||||
|
|
|
@ -17,6 +17,8 @@ class CCameraBlurFilter
|
|||
|
||||
struct Uniform
|
||||
{
|
||||
zeus::CVector4f m_uv[6];
|
||||
float m_opacity = 1.f;
|
||||
};
|
||||
boo::GraphicsDataToken m_token;
|
||||
boo::IGraphicsBufferS* m_vbo;
|
||||
|
@ -26,7 +28,7 @@ class CCameraBlurFilter
|
|||
|
||||
public:
|
||||
CCameraBlurFilter();
|
||||
void draw();
|
||||
void draw(float amount);
|
||||
|
||||
using _CLS = CCameraBlurFilter;
|
||||
#include "TShaderDecl.hpp"
|
||||
|
|
|
@ -11,22 +11,40 @@ BOO_GLSL_BINDING_HEAD
|
|||
"layout(location=0) in vec4 posIn;\n"
|
||||
"layout(location=1) in vec4 uvIn;\n"
|
||||
"\n"
|
||||
"UBINDING0 uniform ThermalHotUniform\n"
|
||||
"UBINDING0 uniform CameraBlurUniform\n"
|
||||
"{\n"
|
||||
" vec4 colorReg0;\n"
|
||||
" vec4 colorReg1;\n"
|
||||
" vec4 colorReg2;\n"
|
||||
" vec4 uv0;\n"
|
||||
" vec4 uv1;\n"
|
||||
" vec4 uv2;\n"
|
||||
" vec4 uv3;\n"
|
||||
" vec4 uv4;\n"
|
||||
" vec4 uv5;\n"
|
||||
" float opacity;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec2 sceneUv;\n"
|
||||
" vec2 uvReg;\n"
|
||||
" vec2 uv0;\n"
|
||||
" vec2 uv1;\n"
|
||||
" vec2 uv2;\n"
|
||||
" vec2 uv3;\n"
|
||||
" vec2 uv4;\n"
|
||||
" vec2 uv5;\n"
|
||||
" float opacity;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) out VertToFrag vtf;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vtf.sceneUv = uvIn.xy;\n"
|
||||
" vtf.uvReg = uvIn.xy;\n"
|
||||
" vtf.uv0 = uv0.xy + uvIn.xy;\n"
|
||||
" vtf.uv1 = uv1.xy + uvIn.xy;\n"
|
||||
" vtf.uv2 = uv2.xy + uvIn.xy;\n"
|
||||
" vtf.uv3 = uv3.xy + uvIn.xy;\n"
|
||||
" vtf.uv4 = uv4.xy + uvIn.xy;\n"
|
||||
" vtf.uv5 = uv5.xy + uvIn.xy;\n"
|
||||
" vtf.opacity = opacity;\n"
|
||||
" gl_Position = vec4(posIn.xyz, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
|
@ -35,19 +53,29 @@ static const char* FS =
|
|||
BOO_GLSL_BINDING_HEAD
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec2 sceneUv;\n"
|
||||
" vec2 uvReg;\n"
|
||||
" vec2 uv0;\n"
|
||||
" vec2 uv1;\n"
|
||||
" vec2 uv2;\n"
|
||||
" vec2 uv3;\n"
|
||||
" vec2 uv4;\n"
|
||||
" vec2 uv5;\n"
|
||||
" float opacity;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) in VertToFrag vtf;\n"
|
||||
"layout(location=0) out vec4 colorOut;\n"
|
||||
"TBINDING0 uniform sampler2D sceneTex;\n"
|
||||
"TBINDING1 uniform sampler2D paletteTex;\n"
|
||||
"const vec4 kRGBToYPrime = vec4(0.299, 0.587, 0.114, 0.0);\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" float sceneSample = dot(texture(sceneTex, vtf.sceneUv), kRGBToYPrime);\n"
|
||||
" vec4 colorSample = texture(paletteTex, vec2(sceneSample / 17.0, 0.5));\n"
|
||||
" colorOut = colorSample * sceneSample;\n"
|
||||
" vec4 colorSample = texture(sceneTex, vtf.uvReg) * 0.14285715;\n"
|
||||
" colorSample += texture(sceneTex, vtf.uv0) * 0.14285715;\n"
|
||||
" colorSample += texture(sceneTex, vtf.uv1) * 0.14285715;\n"
|
||||
" colorSample += texture(sceneTex, vtf.uv2) * 0.14285715;\n"
|
||||
" colorSample += texture(sceneTex, vtf.uv3) * 0.14285715;\n"
|
||||
" colorSample += texture(sceneTex, vtf.uv4) * 0.14285715;\n"
|
||||
" colorSample += texture(sceneTex, vtf.uv5) * 0.14285715;\n"
|
||||
" colorOut = vec4(colorSample.rgb, vtf.opacity);\n"
|
||||
"}\n";
|
||||
|
||||
URDE_DECL_SPECIALIZE_SHADER(CCameraBlurFilter)
|
||||
|
@ -68,10 +96,10 @@ struct CCameraBlurFilterGLDataBindingFactory : TShader<CCameraBlurFilter>::IData
|
|||
};
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
||||
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, g_Renderer->GetThermoPalette()};
|
||||
boo::ITexture* texs[] = {CGraphics::g_SpareTexture};
|
||||
return cctx.newShaderDataBinding(pipeline,
|
||||
ctx.newVertexFormat(2, VtxVmt), filter.m_vbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 2, texs);
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -86,10 +114,10 @@ struct CCameraBlurFilterVulkanDataBindingFactory : TShader<CCameraBlurFilter>::I
|
|||
boo::VulkanDataFactory::Context& cctx = static_cast<boo::VulkanDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, g_Renderer->GetThermoPalette()};
|
||||
boo::ITexture* texs[] = {CGraphics::g_SpareTexture};
|
||||
return cctx.newShaderDataBinding(pipeline, vtxFmt,
|
||||
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 2, texs);
|
||||
nullptr, nullptr, nullptr, 1, texs);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
@ -97,10 +125,10 @@ struct CCameraBlurFilterVulkanDataBindingFactory : TShader<CCameraBlurFilter>::I
|
|||
TShader<CCameraBlurFilter>::IDataBindingFactory* CCameraBlurFilter::Initialize(boo::GLDataFactory::Context& ctx,
|
||||
boo::IShaderPipeline*& pipeOut)
|
||||
{
|
||||
const char* texNames[] = {"sceneTex", "paletteTex"};
|
||||
const char* uniNames[] = {"ThermalHotUniform"};
|
||||
pipeOut = ctx.newShaderPipeline(VS, FS, 2, texNames, 1, uniNames, boo::BlendFactor::DstAlpha,
|
||||
boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, false, false, false);
|
||||
const char* texNames[] = {"sceneTex"};
|
||||
const char* uniNames[] = {"CameraBlurUniform"};
|
||||
pipeOut = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, false, false, false);
|
||||
return new CCameraBlurFilterGLDataBindingFactory;
|
||||
}
|
||||
|
||||
|
@ -115,8 +143,8 @@ TShader<CCameraBlurFilter>::IDataBindingFactory* CCameraBlurFilter::Initialize(b
|
|||
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
vtxFmtOut = ctx.newVertexFormat(2, VtxVmt);
|
||||
pipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, boo::BlendFactor::DstAlpha,
|
||||
boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, false, false, false);
|
||||
pipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, false, false, false);
|
||||
return new CCameraBlurFilterVulkanDataBindingFactory;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef __URDE_CCAMERABLURFILTER_HPP__
|
||||
#define __URDE_CCAMERABLURFILTER_HPP__
|
||||
#ifndef __URDE_CXRAYBLURFILTER_HPP__
|
||||
#define __URDE_CXRAYBLURFILTER_HPP__
|
||||
|
||||
#include "TShader.hpp"
|
||||
#include "zeus/CMatrix4f.hpp"
|
||||
|
@ -39,4 +39,4 @@ public:
|
|||
|
||||
}
|
||||
|
||||
#endif // __URDE_CCAMERABLURFILTER_HPP__
|
||||
#endif // __URDE_CXRAYBLURFILTER_HPP__
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "Graphics/Shaders/CSpaceWarpFilter.hpp"
|
||||
#include "Graphics/Shaders/CColoredQuadFilter.hpp"
|
||||
#include "Graphics/Shaders/CTexturedQuadFilter.hpp"
|
||||
#include "Graphics/Shaders/CCameraBlurFilter.hpp"
|
||||
#include "Graphics/Shaders/CXRayBlurFilter.hpp"
|
||||
|
||||
namespace urde
|
||||
|
@ -12,6 +13,7 @@ namespace urde
|
|||
URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
|
||||
URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter)
|
||||
URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
|
||||
URDE_DECL_SPECIALIZE_SHADER(CCameraBlurFilter)
|
||||
URDE_DECL_SPECIALIZE_SHADER(CXRayBlurFilter)
|
||||
URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter)
|
||||
URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter)
|
||||
|
@ -37,6 +39,7 @@ CMain::BooSetter::BooSetter(boo::IGraphicsDataFactory* factory,
|
|||
TShader<CThermalColdFilter>::Initialize();
|
||||
TShader<CThermalHotFilter>::Initialize();
|
||||
TShader<CSpaceWarpFilter>::Initialize();
|
||||
TShader<CCameraBlurFilter>::Initialize();
|
||||
TShader<CXRayBlurFilter>::Initialize();
|
||||
TMultiBlendShader<CColoredQuadFilter>::Initialize();
|
||||
TMultiBlendShader<CTexturedQuadFilter>::Initialize();
|
||||
|
@ -88,6 +91,7 @@ void CMain::Shutdown()
|
|||
TShader<CThermalColdFilter>::Shutdown();
|
||||
TShader<CThermalHotFilter>::Shutdown();
|
||||
TShader<CSpaceWarpFilter>::Shutdown();
|
||||
TShader<CCameraBlurFilter>::Shutdown();
|
||||
TShader<CXRayBlurFilter>::Shutdown();
|
||||
TMultiBlendShader<CColoredQuadFilter>::Shutdown();
|
||||
TMultiBlendShader<CTexturedQuadFilter>::Shutdown();
|
||||
|
|
Loading…
Reference in New Issue