From 6d2638678085cb46db2c965d10480d143e3ab45d Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 19 Aug 2016 19:33:06 -1000 Subject: [PATCH] HLSL XRayBlurFilter --- Runtime/CStateManager.cpp | 1 + .../Shaders/CColoredQuadFilterHLSL.cpp | 3 +- .../Shaders/CColoredQuadFilterMetal.cpp | 3 +- .../Graphics/Shaders/CXRayBlurFilterHLSL.cpp | 105 ++++++++++++++++++ 4 files changed, 110 insertions(+), 2 deletions(-) diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 8140955e9..014b36f39 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -239,6 +239,7 @@ void CStateManager::UpdateThermalVisor() bool CStateManager::RenderLast(TUniqueId) { + return false; } void CStateManager::AddDrawableActor(const CActor& actor, const zeus::CVector3f& vec, diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilterHLSL.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilterHLSL.cpp index e188b4f42..2aa191e19 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilterHLSL.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilterHLSL.cpp @@ -13,6 +13,7 @@ static const char* VS = "\n" "cbuffer ColoredQuadUniform : register(b0)\n" "{\n" +" float4x4 xf;\n" " float4 color;\n" "};\n" "\n" @@ -26,7 +27,7 @@ static const char* VS = "{\n" " VertToFrag vtf;\n" " vtf.color = color;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" +" vtf.position = mul(xf, float4(v.posIn.xyz, 1.0));\n" " return vtf;\n" "}\n"; diff --git a/Runtime/Graphics/Shaders/CColoredQuadFilterMetal.cpp b/Runtime/Graphics/Shaders/CColoredQuadFilterMetal.cpp index 4c0171609..493081172 100644 --- a/Runtime/Graphics/Shaders/CColoredQuadFilterMetal.cpp +++ b/Runtime/Graphics/Shaders/CColoredQuadFilterMetal.cpp @@ -15,6 +15,7 @@ static const char* VS = "\n" "struct ColoredQuadUniform\n" "{\n" +" float4x4 xf;\n" " float4 color;\n" "};\n" "\n" @@ -28,7 +29,7 @@ static const char* VS = "{\n" " VertToFrag vtf;\n" " vtf.color = cqu.color;\n" -" vtf.position = float4(v.posIn.xyz, 1.0);\n" +" vtf.position = cqu.xf * float4(v.posIn.xyz, 1.0);\n" " return vtf;\n" "}\n"; diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp index e69de29bb..129d8c3b2 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilterHLSL.cpp @@ -0,0 +1,105 @@ +#include "CXRayBlurFilter.hpp" +#include "Graphics/CBooRenderer.hpp" +#include "GameGlobalObjects.hpp" + +namespace urde +{ + +static const char* VS = +"struct VertData\n" +"{\n" +" float4 posIn : POSITION;\n" +" float4 uvIn : UV;\n" +"};\n" +"\n" +"cbuffer XRayBlurUniform : register(b0)\n" +"{\n" +" float4x4 uv0;\n" +" float4x4 uv1;\n" +" float4x4 uv2;\n" +" float4x4 uv3;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" float4 position : SV_Position;\n" +" float2 uv0 : UV0;\n" +" float2 uv1 : UV1;\n" +" float2 uv2 : UV2;\n" +" float2 uv3 : UV3;\n" +"};\n" +"\n" +"VertToFrag main(in VertData v)\n" +"{\n" +" VertToFrag vtf;\n" +" vtf.uv0 = mul(uv0, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" +" vtf.uv0.y = -vtf.uv0.y;\n" +" vtf.uv1 = mul(uv1, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" +" vtf.uv1.y = -vtf.uv1.y;\n" +" vtf.uv2 = mul(uv2, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" +" vtf.uv2.y = -vtf.uv2.y;\n" +" vtf.uv3 = mul(uv3, float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" +" vtf.uv3.y = -vtf.uv3.y;\n" +" vtf.position = float4(v.posIn.xyz, 1.0);\n" +" return vtf;\n" +"}\n"; + +static const char* FS = +"Texture2D sceneTex : register(t0);\n" +"Texture2D paletteTex : register(t1);\n" +"SamplerState samp : register(s0);\n" +"struct VertToFrag\n" +"{\n" +" float4 position : SV_Position;\n" +" float2 uv0 : UV0;\n" +" float2 uv1 : UV1;\n" +" float2 uv2 : UV2;\n" +" float2 uv3 : UV3;\n" +"};\n" +"\n" +"static const float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0);\n" +"float4 main(in VertToFrag vtf) : SV_Target0\n" +"{\n" +" float4 colorSample = paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv0), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.25;\n" +" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv1), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.25;\n" +" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv2), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.25;\n" +" colorSample += paletteTex.Sample(samp, float2(dot(sceneTex.Sample(samp, vtf.uv3), kRGBToYPrime) * 0.98 + 0.01, 0.5)) * 0.25;\n" +" return colorSample;\n" +"}\n"; + +URDE_DECL_SPECIALIZE_SHADER(CXRayBlurFilter) + +struct CXRayBlurFilterD3DDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + boo::IShaderPipeline* pipeline, + boo::IVertexFormat* vtxFmt, + CXRayBlurFilter& filter) + { + boo::ID3DDataFactory::Context& cctx = static_cast(ctx); + + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_booTex}; + return cctx.newShaderDataBinding(pipeline, vtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 2, texs); + } +}; + +TShader::IDataBindingFactory* CXRayBlurFilter::Initialize(boo::ID3DDataFactory::Context& ctx, + boo::IShaderPipeline*& pipeOut, + boo::IVertexFormat*& vtxFmtOut) +{ + const boo::VertexElementDescriptor VtxVmt[] = + { + {nullptr, nullptr, boo::VertexSemantic::Position4}, + {nullptr, nullptr, boo::VertexSemantic::UV4} + }; + vtxFmtOut = ctx.newVertexFormat(2, VtxVmt); + pipeOut = ctx.newShaderPipeline(VS, FS, ComPtr(), ComPtr(), ComPtr(), + vtxFmtOut, boo::BlendFactor::One, + boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false); + return new CXRayBlurFilterD3DDataBindingFactory; +} + +}