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