2017-01-29 07:27:48 +00:00
|
|
|
#include "CTextSupportShader.hpp"
|
|
|
|
#include "GuiSys/CTextRenderBuffer.hpp"
|
|
|
|
#include "TMultiBlendShader.hpp"
|
|
|
|
#include "Graphics/CTexture.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
static const char* TextVS =
|
|
|
|
"struct InstData\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 posIn[4] : POSITION;\n"
|
|
|
|
" float4 uvIn[4] : UV;\n"
|
|
|
|
" float4 fontColorIn : COLOR0;\n"
|
|
|
|
" float4 outlineColorIn : COLOR1;\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" float4 mulColorIn : COLOR2;\n"
|
2017-01-29 07:27:48 +00:00
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"cbuffer TextSupportUniform : register(b0)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4x4 mtx;\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos : SV_Position;\n"
|
|
|
|
" float4 fontColor : COLOR0;\n"
|
|
|
|
" float4 outlineColor : COLOR1;\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" float4 mulColor : COLOR2;\n"
|
2017-01-29 07:27:48 +00:00
|
|
|
" float3 uv : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"VertToFrag main(in InstData inst, in uint vertId : SV_VertexID)\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" vtf.fontColor = color * inst.fontColorIn;\n"
|
|
|
|
" vtf.outlineColor = color * inst.outlineColorIn;\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" vtf.mulColor = inst.mulColorIn;\n"
|
2017-01-29 07:27:48 +00:00
|
|
|
" vtf.uv = inst.uvIn[vertId].xyz;\n"
|
|
|
|
" vtf.pos = mul(mtx, float4(inst.posIn[vertId].xyz, 1.0));\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* TextFS =
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos : SV_Position;\n"
|
|
|
|
" float4 fontColor : COLOR0;\n"
|
|
|
|
" float4 outlineColor : COLOR1;\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" float4 mulColor : COLOR2;\n"
|
2017-01-29 07:27:48 +00:00
|
|
|
" float3 uv : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"Texture2DArray tex : register(t0);\n"
|
|
|
|
"SamplerState samp : register(s0);\n"
|
|
|
|
"\n"
|
|
|
|
"float4 main(in VertToFrag vtf) : SV_Target0\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 texel = tex.Sample(samp, vtf.uv.xyz);\n"
|
2017-01-30 04:16:20 +00:00
|
|
|
" return (vtf.fontColor * texel.r + vtf.outlineColor * texel.g) * vtf.mulColor;\n"
|
2017-01-29 07:27:48 +00:00
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* ImgVS =
|
|
|
|
"struct InstData\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 posIn[4] : POSITION;\n"
|
|
|
|
" float4 uvIn[4] : UV;\n"
|
|
|
|
" float4 colorIn : COLOR;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"cbuffer TextSupportUniform : register(b0)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4x4 mtx;\n"
|
|
|
|
" float4 color;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
" float2 uv : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"VertToFrag main(in InstData inst, in uint vertId : SV_VertexID)\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" vtf.color = color * inst.colorIn;\n"
|
|
|
|
" vtf.uv = inst.uvIn[vertId].xy;\n"
|
|
|
|
" vtf.pos = mul(mtx, float4(inst.posIn[vertId].xyz, 1.0));\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* ImgFS =
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 pos : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
" float2 uv : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"Texture2D tex : register(t0);\n"
|
|
|
|
"SamplerState samp : register(s0);\n"
|
|
|
|
"\n"
|
|
|
|
"float4 main(in VertToFrag vtf) : SV_Target0\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 texel = tex.Sample(samp, vtf.uv);\n"
|
|
|
|
" return vtf.color * texel;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
TMultiBlendShader<CTextSupportShader>::IDataBindingFactory*
|
|
|
|
CTextSupportShader::Initialize(boo::ID3DDataFactory::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 07:27:48 +00:00
|
|
|
};
|
2017-01-30 04:16:20 +00:00
|
|
|
s_TextVtxFmt = ctx.newVertexFormat(11, TextVtxVmt);
|
2017-01-29 07:27:48 +00:00
|
|
|
s_TextAlphaPipeline = ctx.newShaderPipeline(TextVS, TextFS, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
|
|
|
s_TextVtxFmt, boo::BlendFactor::SrcAlpha,
|
2017-01-30 04:16:20 +00:00
|
|
|
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, true, false, false);
|
2017-01-29 07:27:48 +00:00
|
|
|
s_TextAddPipeline = ctx.newShaderPipeline(TextVS, TextFS, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
|
|
|
s_TextVtxFmt, boo::BlendFactor::SrcAlpha,
|
2017-01-30 04:16:20 +00:00
|
|
|
boo::BlendFactor::One, boo::Primitive::TriStrips, true, false, false);
|
2017-01-29 07:27:48 +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, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
|
|
|
s_ImageVtxFmt, boo::BlendFactor::SrcAlpha,
|
2017-01-30 04:16:20 +00:00
|
|
|
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, true, false, false);
|
2017-01-29 07:27:48 +00:00
|
|
|
s_ImageAddPipeline = ctx.newShaderPipeline(ImgVS, ImgFS, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
|
|
|
s_ImageVtxFmt, boo::BlendFactor::SrcAlpha,
|
2017-01-30 04:16:20 +00:00
|
|
|
boo::BlendFactor::One, boo::Primitive::TriStrips, true, false, false);
|
2017-01-29 07:27:48 +00:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|