2017-01-29 03:58:16 +00:00
|
|
|
#include "CTextSupportShader.hpp"
|
|
|
|
#include "GuiSys/CTextRenderBuffer.hpp"
|
|
|
|
#include "TMultiBlendShader.hpp"
|
|
|
|
#include "Graphics/CTexture.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
static const char* TextVS =
|
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct InstData\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 posIn[4];\n"
|
|
|
|
" float4 uvIn[4];\n"
|
|
|
|
" float4 fontColorIn;\n"
|
|
|
|
" float4 outlineColorIn;\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" float4 mulColorIn;\n"
|
2017-01-29 03:58:16 +00:00
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct TextSupportUniform\n"
|
|
|
|
"{\n"
|
|
|
|
" float4x4 mtx;\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos [[ position ]];\n"
|
|
|
|
" float4 fontColor;\n"
|
|
|
|
" float4 outlineColor;\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" float4 mulColor;\n"
|
2017-01-29 03:58:16 +00:00
|
|
|
" float3 uv;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"vertex VertToFrag vmain(constant InstData* instArr [[ buffer(1) ]],\n"
|
|
|
|
" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n"
|
|
|
|
" constant TextSupportUniform& uData [[ buffer(2) ]])\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" constant InstData& inst = instArr[instId];\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" vtf.fontColor = inst.fontColorIn * uData.color;\n"
|
|
|
|
" vtf.outlineColor = inst.outlineColorIn * uData.color;\n"
|
|
|
|
" vtf.mulColor = inst.mulColorIn;\n"
|
2017-01-29 03:58:16 +00:00
|
|
|
" vtf.uv = inst.uvIn[vertId].xyz;\n"
|
|
|
|
" vtf.pos = uData.mtx * float4(inst.posIn[vertId].xyz, 1.0);\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* TextFS =
|
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos [[ position ]];\n"
|
|
|
|
" float4 fontColor;\n"
|
|
|
|
" float4 outlineColor;\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" float4 mulColor;\n"
|
2017-01-29 03:58:16 +00:00
|
|
|
" float3 uv;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
2018-01-07 05:19:49 +00:00
|
|
|
" sampler clampSamp [[ sampler(2) ]],\n"
|
2017-01-29 03:58:16 +00:00
|
|
|
" texture2d_array<float> tex [[ texture(0) ]])\n"
|
|
|
|
"{\n"
|
2018-01-07 05:19:49 +00:00
|
|
|
" float4 texel = tex.sample(clampSamp, vtf.uv.xy, vtf.uv.z);\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" return (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor;\n"
|
2017-01-29 03:58:16 +00:00
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* ImgVS =
|
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct InstData\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 posIn[4];\n"
|
|
|
|
" float4 uvIn[4];\n"
|
|
|
|
" float4 colorIn;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct TextSupportUniform\n"
|
|
|
|
"{\n"
|
|
|
|
" float4x4 mtx;\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos [[ position ]];\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
" float2 uv;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"vertex VertToFrag vmain(constant InstData* instArr [[ buffer(1) ]],\n"
|
|
|
|
" uint vertId [[ vertex_id ]], uint instId [[ instance_id ]],\n"
|
|
|
|
" constant TextSupportUniform& uData [[ buffer(2) ]])\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" constant InstData& inst = instArr[instId];\n"
|
|
|
|
" vtf.color = uData.color * inst.colorIn;\n"
|
|
|
|
" vtf.uv = inst.uvIn[vertId].xy;\n"
|
|
|
|
" vtf.pos = uData.mtx * float4(inst.posIn[vertId].xyz, 1.0);\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* ImgFS =
|
|
|
|
"#include <metal_stdlib>\n"
|
|
|
|
"using namespace metal;\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos [[ position ]];\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
" float2 uv;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
2018-01-07 05:19:49 +00:00
|
|
|
" sampler clampSamp [[ sampler(2) ]],\n"
|
2017-01-29 03:58:16 +00:00
|
|
|
" texture2d<float> tex [[ texture(0) ]])\n"
|
|
|
|
"{\n"
|
2018-01-07 05:19:49 +00:00
|
|
|
" float4 texel = tex.sample(clampSamp, vtf.uv);\n"
|
2017-01-29 03:58:16 +00:00
|
|
|
" return vtf.color * texel;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
TMultiBlendShader<CTextSupportShader>::IDataBindingFactory*
|
|
|
|
CTextSupportShader::Initialize(boo::MetalDataFactory::Context& ctx)
|
|
|
|
{
|
|
|
|
boo::VertexElementDescriptor TextVtxVmt[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 1},
|
2017-01-30 04:16:20 +00:00
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 2},
|
2017-01-29 03:58:16 +00:00
|
|
|
};
|
2017-01-30 04:16:20 +00:00
|
|
|
s_TextVtxFmt = ctx.newVertexFormat(11, TextVtxVmt);
|
2018-01-07 05:19:49 +00:00
|
|
|
s_TextAlphaPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, s_TextVtxFmt,
|
2017-03-14 07:03:58 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
2017-12-20 06:06:54 +00:00
|
|
|
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
|
2018-01-07 05:19:49 +00:00
|
|
|
s_TextAddPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, s_TextVtxFmt,
|
2017-03-14 07:03:58 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::Primitive::TriStrips,
|
2017-12-20 06:06:54 +00:00
|
|
|
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
|
2018-01-07 05:19:49 +00:00
|
|
|
s_TextAddOverdrawPipeline = ctx.newShaderPipeline(TextVS, TextFS, nullptr, nullptr, s_TextVtxFmt,
|
2017-12-20 06:06:54 +00:00
|
|
|
boo::BlendFactor::One, boo::BlendFactor::One, boo::Primitive::TriStrips,
|
|
|
|
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
|
2017-01-29 03:58:16 +00:00
|
|
|
|
|
|
|
boo::VertexElementDescriptor ImageVtxVmt[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 0},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 1},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 2},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4 | boo::VertexSemantic::Instanced, 3},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 0},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 1},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 2},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4 | boo::VertexSemantic::Instanced, 3},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color | boo::VertexSemantic::Instanced, 0},
|
|
|
|
};
|
|
|
|
s_ImageVtxFmt = ctx.newVertexFormat(9, ImageVtxVmt);
|
2018-01-07 05:19:49 +00:00
|
|
|
s_ImageAlphaPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, s_ImageVtxFmt,
|
2017-03-14 07:03:58 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
2017-12-20 06:06:54 +00:00
|
|
|
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
|
2018-01-07 05:19:49 +00:00
|
|
|
s_ImageAddPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, s_ImageVtxFmt,
|
2017-03-14 07:03:58 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One, boo::Primitive::TriStrips,
|
2017-12-20 06:06:54 +00:00
|
|
|
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
|
2018-01-07 05:19:49 +00:00
|
|
|
s_ImageAddOverdrawPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, nullptr, nullptr, s_ImageVtxFmt,
|
2017-12-20 06:06:54 +00:00
|
|
|
boo::BlendFactor::One, boo::BlendFactor::One, boo::Primitive::TriStrips,
|
|
|
|
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
|
2017-01-29 03:58:16 +00:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-05 06:17:12 +00:00
|
|
|
template <>
|
|
|
|
void CTextSupportShader::Shutdown<boo::MetalDataFactory>()
|
|
|
|
{
|
|
|
|
s_TextVtxFmt.reset();
|
|
|
|
s_TextAlphaPipeline.reset();
|
|
|
|
s_TextAddPipeline.reset();
|
2017-12-20 06:06:54 +00:00
|
|
|
s_TextAddOverdrawPipeline.reset();
|
2017-11-05 06:17:12 +00:00
|
|
|
s_ImageVtxFmt.reset();
|
|
|
|
s_ImageAlphaPipeline.reset();
|
|
|
|
s_ImageAddPipeline.reset();
|
2017-12-20 06:06:54 +00:00
|
|
|
s_ImageAddOverdrawPipeline.reset();
|
2017-11-05 06:17:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 03:58:16 +00:00
|
|
|
}
|