2016-02-18 20:53:17 +00:00
|
|
|
#include "CLineRendererShaders.hpp"
|
2016-07-24 06:05:12 +00:00
|
|
|
#include "Graphics/CLineRenderer.hpp"
|
2016-02-18 20:53:17 +00:00
|
|
|
|
2016-03-04 23:04:53 +00:00
|
|
|
namespace urde
|
2016-02-18 20:53:17 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
static const char* VS_HLSL_TEX =
|
|
|
|
"struct VertData\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 posIn : POSITION;\n"
|
|
|
|
" float4 colorIn : COLOR;\n"
|
|
|
|
" float4 uvIn : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"cbuffer LineUniform : register(b0)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 moduColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
" float2 uv : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"VertToFrag main(in VertData v)\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" vtf.color = v.colorIn * moduColor;\n"
|
|
|
|
" vtf.uv = v.uvIn.xy;\n"
|
|
|
|
" vtf.position = v.posIn;\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* FS_HLSL_TEX =
|
|
|
|
"SamplerState samp : register(s0);\n"
|
|
|
|
"Texture2D tex0 : register(t0);\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
" float2 uv : UV;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"float4 main(in VertToFrag vtf) : SV_Target0\n"
|
|
|
|
"{\n"
|
|
|
|
" return vtf.color * tex0.Sample(samp, vtf.uv);\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* VS_HLSL_NOTEX =
|
|
|
|
"struct VertData\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 posIn : POSITION;\n"
|
|
|
|
" float4 colorIn : COLOR;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"cbuffer LineUniform : register(b0)\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 moduColor;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"VertToFrag main(in VertData v)\n"
|
|
|
|
"{\n"
|
|
|
|
" VertToFrag vtf;\n"
|
|
|
|
" vtf.color = v.colorIn * moduColor;\n"
|
|
|
|
" vtf.position = v.posIn;\n"
|
|
|
|
" return vtf;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
static const char* FS_HLSL_NOTEX =
|
|
|
|
"struct VertToFrag\n"
|
|
|
|
"{\n"
|
|
|
|
" float4 position : SV_Position;\n"
|
|
|
|
" float4 color : COLOR;\n"
|
|
|
|
"};\n"
|
|
|
|
"\n"
|
|
|
|
"float4 main(in VertToFrag vtf) : SV_Target0\n"
|
|
|
|
"{\n"
|
|
|
|
" return vtf.color;\n"
|
|
|
|
"}\n";
|
|
|
|
|
|
|
|
struct HLSLLineDataBindingFactory : CLineRendererShaders::IDataBindingFactory
|
|
|
|
{
|
2016-03-30 20:44:19 +00:00
|
|
|
void BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CLineRenderer& renderer,
|
|
|
|
boo::IShaderPipeline* pipeline, boo::ITexture* texture)
|
2016-02-18 20:53:17 +00:00
|
|
|
{
|
|
|
|
int texCount = 0;
|
|
|
|
boo::ITexture* textures[1];
|
|
|
|
|
|
|
|
if (texture)
|
|
|
|
{
|
|
|
|
textures[0] = texture;
|
|
|
|
texCount = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
boo::IGraphicsBuffer* uniforms[] = {renderer.m_uniformBuf};
|
|
|
|
|
2016-03-30 20:44:19 +00:00
|
|
|
renderer.m_shaderBind = ctx.newShaderDataBinding(pipeline, nullptr, renderer.m_vertBuf,
|
2016-04-04 19:34:54 +00:00
|
|
|
nullptr, nullptr, 1, uniforms, nullptr,
|
2016-03-30 20:44:19 +00:00
|
|
|
texCount, textures);
|
2016-02-18 20:53:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-30 20:44:19 +00:00
|
|
|
CLineRendererShaders::IDataBindingFactory* CLineRendererShaders::Initialize(boo::ID3DDataFactory::Context& ctx)
|
2016-02-18 20:53:17 +00:00
|
|
|
{
|
|
|
|
static const boo::VertexElementDescriptor VtxFmtTex[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
|
|
|
};
|
2016-03-30 20:44:19 +00:00
|
|
|
m_texVtxFmt = ctx.newVertexFormat(3, VtxFmtTex);
|
2016-02-18 20:53:17 +00:00
|
|
|
|
|
|
|
static const boo::VertexElementDescriptor VtxFmtNoTex[] =
|
|
|
|
{
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
|
|
|
{nullptr, nullptr, boo::VertexSemantic::Color}
|
|
|
|
};
|
2016-03-30 20:44:19 +00:00
|
|
|
m_noTexVtxFmt = ctx.newVertexFormat(2, VtxFmtNoTex);
|
2016-02-18 20:53:17 +00:00
|
|
|
|
2017-03-05 23:03:23 +00:00
|
|
|
m_texAlpha = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr,
|
|
|
|
nullptr, m_texVtxFmt,
|
2016-02-18 20:53:17 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-10 20:52:53 +00:00
|
|
|
boo::Primitive::TriStrips,false, true, boo::CullMode::None);
|
2017-03-05 23:03:23 +00:00
|
|
|
m_texAdditive = ctx.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, nullptr, nullptr,
|
|
|
|
nullptr, m_texVtxFmt,
|
2016-02-18 20:53:17 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
2017-03-10 20:52:53 +00:00
|
|
|
boo::Primitive::TriStrips,false, false, boo::CullMode::None);
|
2017-03-05 23:03:23 +00:00
|
|
|
m_noTexAlpha = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr,
|
|
|
|
nullptr, m_noTexVtxFmt,
|
2016-02-18 20:53:17 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
2017-03-10 20:52:53 +00:00
|
|
|
boo::Primitive::TriStrips, false, true, boo::CullMode::None);
|
2017-03-05 23:03:23 +00:00
|
|
|
m_noTexAdditive = ctx.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, nullptr, nullptr,
|
|
|
|
nullptr, m_noTexVtxFmt,
|
2016-02-18 20:53:17 +00:00
|
|
|
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
2017-03-10 20:52:53 +00:00
|
|
|
boo::Primitive::TriStrips, false, false, boo::CullMode::None);
|
2016-02-18 20:53:17 +00:00
|
|
|
|
|
|
|
return new struct HLSLLineDataBindingFactory;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|