From 21fc28bc9b7970bba009abfc2b5880774c9d7112 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 20 Aug 2016 08:18:44 -1000 Subject: [PATCH] CCameraBlurFilter implementation --- Editor/ViewManager.cpp | 3 +- Editor/ViewManager.hpp | 2 + Runtime/Camera/CCameraFilter.cpp | 20 ++++++ .../Graphics/Shaders/CCameraBlurFilter.cpp | 24 ++++++- .../Graphics/Shaders/CCameraBlurFilter.hpp | 4 +- .../Shaders/CCameraBlurFilterGLSL.cpp | 72 +++++++++++++------ Runtime/Graphics/Shaders/CXRayBlurFilter.hpp | 6 +- Runtime/MP1/MP1.cpp | 4 ++ 8 files changed, 106 insertions(+), 29 deletions(-) diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index f498072ce..5a546c5cd 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -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}); diff --git a/Editor/ViewManager.hpp b/Editor/ViewManager.hpp index 83afffe4f..d86e6c4ff 100644 --- a/Editor/ViewManager.hpp +++ b/Editor/ViewManager.hpp @@ -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: diff --git a/Runtime/Camera/CCameraFilter.cpp b/Runtime/Camera/CCameraFilter.cpp index f0d171965..b4a562115 100644 --- a/Runtime/Camera/CCameraFilter.cpp +++ b/Runtime/Camera/CCameraFilter.cpp @@ -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) diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp index 74e1d0c80..60cd647ab 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.cpp @@ -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); diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp index c4447f01e..3c62d4ef3 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilter.hpp @@ -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" diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp index 57b0d3d43..a632444a7 100644 --- a/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp +++ b/Runtime/Graphics/Shaders/CCameraBlurFilterGLSL.cpp @@ -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::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::I boo::VulkanDataFactory::Context& cctx = static_cast(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::I TShader::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::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 diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp index d51f86a3e..cc0727c69 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilter.hpp @@ -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__ diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 207bb2dcb..0e55ea27b 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -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::Initialize(); TShader::Initialize(); TShader::Initialize(); + TShader::Initialize(); TShader::Initialize(); TMultiBlendShader::Initialize(); TMultiBlendShader::Initialize(); @@ -88,6 +91,7 @@ void CMain::Shutdown() TShader::Shutdown(); TShader::Shutdown(); TShader::Shutdown(); + TShader::Shutdown(); TShader::Shutdown(); TMultiBlendShader::Shutdown(); TMultiBlendShader::Shutdown();