diff --git a/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp b/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp index 1a52dffc6..c49436513 100644 --- a/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp +++ b/Runtime/Graphics/Shaders/CThermalColdFilterMetal.cpp @@ -46,6 +46,7 @@ static const char* VS = " vtf.colorReg1 = tcu.colorReg1;\n" " vtf.colorReg2 = tcu.colorReg2;\n" " vtf.sceneUv = v.uvIn.xy;\n" +" vtf.sceneUv.y = -vtf.sceneUv.y;\n" " vtf.shiftUv = (float3x3(tcu.shiftMtx[0].xyz, tcu.shiftMtx[1].xyz, tcu.shiftMtx[2].xyz) * v.uvIn.xyz).xy;\n" " vtf.shiftScale = tcu.shiftScale.xy;\n" " vtf.position = float4(v.posIn.xyz, 1.0);\n" diff --git a/Runtime/Graphics/Shaders/CThermalHotFilterMetal.cpp b/Runtime/Graphics/Shaders/CThermalHotFilterMetal.cpp index e69de29bb..eb23cdfbc 100644 --- a/Runtime/Graphics/Shaders/CThermalHotFilterMetal.cpp +++ b/Runtime/Graphics/Shaders/CThermalHotFilterMetal.cpp @@ -0,0 +1,92 @@ +#include "CThermalHotFilter.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 ThermalHotUniform\n" +"{\n" +" float4 colorReg0;\n" +" float4 colorReg1;\n" +" float4 colorReg2;\n" +"};\n" +"\n" +"struct VertToFrag\n" +"{\n" +" float4 position [[ position ]];\n" +" float2 sceneUv;\n" +"};\n" +"\n" +"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ThermalHotUniform& thu [[ buffer(2) ]])\n" +"{\n" +" VertToFrag vtf;\n" +" vtf.sceneUv = v.uvIn.xy;\n" +" vtf.sceneUv.y = -vtf.sceneUv.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 sceneUv;\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" +" float sceneSample = dot(sceneTex.sample(samp, vtf.sceneUv), kRGBToYPrime);\n" +" float4 colorSample = paletteTex.sample(samp, float2(sceneSample / 17.0, 0.5));\n" +" return colorSample * sceneSample;\n" +"}\n"; + +URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter) + +struct CThermalHotFilterMetalDataBindingFactory : TShader::IDataBindingFactory +{ + boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalHotFilter& 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(TShader::m_pipeline, + TShader::m_vtxFmt, + filter.m_vbo, nullptr, nullptr, 1, bufs, + nullptr, nullptr, nullptr, 2, texs); + } +}; + +TShader::IDataBindingFactory* CThermalHotFilter::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 CThermalHotFilterMetalDataBindingFactory; +} + +} diff --git a/hecl b/hecl index ecddcbf1a..d0339be1d 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit ecddcbf1a46cf5a1d7b610de97a10718cebcd75e +Subproject commit d0339be1d573b89abdd8d3f53816c61afea7af80