metaforce/Runtime/Graphics/Shaders/CTextSupportShaderGLSL.cpp

219 lines
9.2 KiB
C++
Raw Normal View History

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 =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"layout(location=0) in vec4 posIn[4];\n"
"layout(location=4) in vec4 uvIn[4];\n"
"layout(location=8) in vec4 fontColorIn;\n"
"layout(location=9) in vec4 outlineColorIn;\n"
2017-01-30 04:16:20 +00:00
"layout(location=10) in vec4 mulColorIn;\n"
2017-01-29 03:58:16 +00:00
"\n"
"UBINDING0 uniform TextSupportUniform\n"
"{\n"
" mat4 mtx;\n"
" vec4 color;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" vec4 fontColor;\n"
" vec4 outlineColor;\n"
2017-01-30 04:16:20 +00:00
" vec4 mulColor;\n"
2017-01-29 03:58:16 +00:00
" vec3 uv;\n"
"};\n"
"\n"
"SBINDING(0) out VertToFrag vtf;\n"
"void main()\n"
"{\n"
2017-11-15 04:12:13 +00:00
" vec3 pos = posIn[gl_VertexID].xyz;\n"
" vtf.uv = uvIn[gl_VertexID].xyz;\n"
2017-01-29 03:58:16 +00:00
" vtf.fontColor = color * fontColorIn;\n"
" vtf.outlineColor = color * outlineColorIn;\n"
2017-01-30 04:16:20 +00:00
" vtf.mulColor = mulColorIn;\n"
2017-11-15 04:12:13 +00:00
" gl_Position = mtx * vec4(pos, 1.0);\n"
2017-01-29 03:58:16 +00:00
"}\n";
static const char* TextFS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"struct VertToFrag\n"
"{\n"
" vec4 fontColor;\n"
" vec4 outlineColor;\n"
2017-01-30 04:16:20 +00:00
" vec4 mulColor;\n"
2017-01-29 03:58:16 +00:00
" vec3 uv;\n"
"};\n"
"\n"
"SBINDING(0) in VertToFrag vtf;\n"
"layout(location=0) out vec4 colorOut;\n"
"TBINDING0 uniform sampler2DArray tex;\n"
"void main()\n"
"{\n"
" vec4 texel = texture(tex, vtf.uv);\n"
2017-01-30 04:16:20 +00:00
" colorOut = (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor;\n"
2017-01-29 03:58:16 +00:00
"}\n";
static const char* ImgVS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"layout(location=0) in vec3 posIn[4];\n"
"layout(location=4) in vec2 uvIn[4];\n"
"layout(location=8) in vec4 colorIn;\n"
"\n"
"UBINDING0 uniform TextSupportUniform\n"
"{\n"
" mat4 mtx;\n"
" vec4 color;\n"
"};\n"
"\n"
"struct VertToFrag\n"
"{\n"
" vec4 color;\n"
" vec2 uv;\n"
"};\n"
"\n"
"SBINDING(0) out VertToFrag vtf;\n"
"void main()\n"
"{\n"
2017-11-16 23:49:25 +00:00
" vec3 pos = posIn[gl_VertexID].xyz;\n"
2017-01-29 03:58:16 +00:00
" vtf.uv = uvIn[gl_VertexID];\n"
2017-11-16 23:49:25 +00:00
" vtf.color = color * colorIn;\n"
" gl_Position = mtx * vec4(pos, 1.0);\n"
2017-01-29 03:58:16 +00:00
"}\n";
static const char* ImgFS =
"#version 330\n"
BOO_GLSL_BINDING_HEAD
"struct VertToFrag\n"
"{\n"
" vec4 color;\n"
" vec2 uv;\n"
"};\n"
"\n"
"SBINDING(0) in VertToFrag vtf;\n"
"layout(location=0) out vec4 colorOut;\n"
"TBINDING0 uniform sampler2D tex;\n"
"void main()\n"
"{\n"
" vec4 texel = texture(tex, vtf.uv);\n"
" colorOut = vtf.color * texel;\n"
"}\n";
TMultiBlendShader<CTextSupportShader>::IDataBindingFactory*
CTextSupportShader::Initialize(boo::GLDataFactory::Context& ctx)
{
const char* texNames[] = {"tex"};
const char* uniNames[] = {"TextSupportUniform"};
s_TextAlphaPipeline = ctx.newShaderPipeline(TextVS, TextFS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha,
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
2017-01-29 03:58:16 +00:00
s_TextAddPipeline = ctx.newShaderPipeline(TextVS, TextFS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha,
boo::BlendFactor::One, boo::Primitive::TriStrips,
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
s_TextAddOverdrawPipeline = ctx.newShaderPipeline(TextVS, TextFS, 1, texNames, 1, uniNames, 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
s_ImageAlphaPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha,
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
2017-01-29 03:58:16 +00:00
s_ImageAddPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha,
boo::BlendFactor::One, boo::Primitive::TriStrips,
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
s_ImageAddOverdrawPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, 1, texNames, 1, uniNames, 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;
}
template <>
void CTextSupportShader::Shutdown<boo::GLDataFactory>()
{
s_TextAlphaPipeline.reset();
s_TextAddPipeline.reset();
s_TextAddOverdrawPipeline.reset();
s_ImageAlphaPipeline.reset();
s_ImageAddPipeline.reset();
s_ImageAddOverdrawPipeline.reset();
}
2017-01-29 03:58:16 +00:00
#if BOO_HAS_VULKAN
TMultiBlendShader<CTextSupportShader>::IDataBindingFactory*
CTextSupportShader::Initialize(boo::VulkanDataFactory::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);
2017-01-29 03:58:16 +00:00
s_TextAlphaPipeline = ctx.newShaderPipeline(TextVS, TextFS, s_TextVtxFmt, boo::BlendFactor::SrcAlpha,
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
2017-01-29 03:58:16 +00:00
s_TextAddPipeline = ctx.newShaderPipeline(TextVS, TextFS, s_TextVtxFmt, boo::BlendFactor::SrcAlpha,
boo::BlendFactor::One, boo::Primitive::TriStrips,
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
s_TextAddOverdrawPipeline = ctx.newShaderPipeline(TextVS, TextFS, s_TextVtxFmt, 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);
s_ImageAlphaPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, s_ImageVtxFmt, boo::BlendFactor::SrcAlpha,
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
2017-01-29 03:58:16 +00:00
s_ImageAddPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, s_ImageVtxFmt, boo::BlendFactor::SrcAlpha,
boo::BlendFactor::One, boo::Primitive::TriStrips,
boo::ZTest::LEqual, false, true, false, boo::CullMode::None);
s_ImageAddOverdrawPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, s_ImageVtxFmt, 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-06 06:58:04 +00:00
template <>
void CTextSupportShader::Shutdown<boo::VulkanDataFactory>()
{
s_TextVtxFmt.reset();
s_TextAlphaPipeline.reset();
s_TextAddPipeline.reset();
s_TextAddOverdrawPipeline.reset();
2017-11-06 06:58:04 +00:00
s_ImageVtxFmt.reset();
s_ImageAlphaPipeline.reset();
s_ImageAddPipeline.reset();
s_ImageAddOverdrawPipeline.reset();
2017-11-06 06:58:04 +00:00
}
2017-01-29 03:58:16 +00:00
#endif
}