diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterHLSL.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp b/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp new file mode 100644 index 000000000..034d7ffb8 --- /dev/null +++ b/Runtime/Graphics/Shaders/CCameraBlurFilterMetal.cpp @@ -0,0 +1,87 @@ +#include "CCameraBlurFilter.hpp" +#include "Graphics/CBooRenderer.hpp" +#include "GameGlobalObjects.hpp" + +namespace urde +{ + +static const char* VS = +"#version 330\n" +BOO_GLSL_BINDING_HEAD +"layout(location=0) in vec4 posIn;\n" +"layout(location=1) in vec4 uvIn;\n" +"\n" +"UBINDING0 uniform ThermalHotUniform\n" +"{\n" +" vec4 colorReg0;\n" +" vec4 colorReg1;\n" +" vec4 colorReg2;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" vec2 sceneUv;\n" +"};\n" +"\n" +"SBINDING(0) out VertToFrag vtf;\n" +"void main()\n" +"{\n" +" vtf.sceneUv = uvIn.xy;\n" +" gl_Position = vec4(posIn.xyz, 1.0);\n" +"}\n"; + +static const char* FS = +"#version 330\n" +BOO_GLSL_BINDING_HEAD +"struct VertToFrag\n" +"{\n" +" vec2 sceneUv;\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" +"}\n"; + +URDE_DECL_SPECIALIZE_SHADER(CCameraBlurFilter) + +struct CCameraBlurFilterMetalDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + boo::IShaderPipeline* pipeline, + boo::IVertexFormat* vtxFmt, + CCameraBlurFilter& filter) + { + boo::MetalDataFactory::Context& cctx = static_cast(ctx); + + boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf}; + boo::ITexture* texs[] = {CGraphics::g_SpareTexture, g_Renderer->GetThermoPalette()}; + return cctx.newShaderDataBinding(pipeline, vtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 2, texs); + } +}; + +TShader::IDataBindingFactory* CCameraBlurFilter::Initialize(boo::MetalDataFactory::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, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::DstAlpha, + boo::BlendFactor::InvDstAlpha, boo::Primitive::TriStrips, false, false, false); + return new CCameraBlurFilterMetalDataBindingFactory; +} + +} diff --git a/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp b/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp index e69de29bb..3cf25f73b 100644 --- a/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp +++ b/Runtime/Graphics/Shaders/CXRayBlurFilterMetal.cpp @@ -0,0 +1,108 @@ +#include "CXRayBlurFilter.hpp" +#include "Graphics/CBooRenderer.hpp" +#include "GameGlobalObjects.hpp" + +namespace urde +{ + +static const char* VS = +"#include \n" +"using namespace metal;\n" +"struct VertData\n" +"{\n" +" float4 posIn [[ attribute(0) ]];\n" +" float4 uvIn [[ attribute(1) ]];\n" +"};\n" +"\n" +"struct XRayBlurUniform\n" +"{\n" +" float4x4 uv0;\n" +" float4x4 uv1;\n" +" float4x4 uv2;\n" +" float4x4 uv3;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" float4 position [[ position ]];\n" +" float2 uv0;\n" +" float2 uv1;\n" +" float2 uv2;\n" +" float2 uv3;\n" +"};\n" +"\n" +"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant XRayBlurUniform& xbu [[ buffer(2) ]])\n" +"{\n" +" VertToFrag vtf;\n" +" vtf.uv0 = (xbu.uv0 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" +" vtf.uv0.y = -vtf.uv0.y;\n" +" vtf.uv1 = (xbu.uv1 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" +" vtf.uv1.y = -vtf.uv1.y;\n" +" vtf.uv2 = (xbu.uv2 * float4(v.uvIn.xy, 0.0, 1.0)).xy;\n" +" vtf.uv2.y = -vtf.uv2.y;\n" +" vtf.uv3 = (xbu.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 = +"#include \n" +"using namespace metal;\n" +"constexpr sampler samp(address::repeat, filter::linear);\n" +"struct VertToFrag\n" +"{\n" +" float4 position [[ position ]];\n" +" float2 uv0;\n" +" float2 uv1;\n" +" float2 uv2;\n" +" float2 uv3;\n" +"};\n" +"\n" +"constant float4 kRGBToYPrime = float4(0.299, 0.587, 0.114, 0.0);\n" +"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" +" texture2d sceneTex [[ texture(0) ]],\n" +" texture2d paletteTex [[ texture(1) ]])\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 CXRayBlurFilterMetalDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, + boo::IShaderPipeline* pipeline, + boo::IVertexFormat* vtxFmt, + CXRayBlurFilter& filter) + { + boo::MetalDataFactory::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::MetalDataFactory::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, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::One, + boo::BlendFactor::Zero, boo::Primitive::TriStrips, false, false, false); + return new CXRayBlurFilterMetalDataBindingFactory; +} + +}