mirror of https://github.com/AxioDL/metaforce.git
CLineRenderer HLSL shaders
This commit is contained in:
parent
5d3cf64a6b
commit
bd0a72a4cb
|
@ -20,7 +20,7 @@ namespace URDE
|
|||
|
||||
void ViewManager::BuildTestPART(pshag::IObjectStore& objStore)
|
||||
{
|
||||
m_partGenDesc = objStore.GetObj({HECL::FOURCC('PART'), 0x1E348530});
|
||||
m_partGenDesc = objStore.GetObj({HECL::FOURCC('PART'), 0x972A5CD2});
|
||||
m_partGen.reset(new pshag::CElementGen(m_partGenDesc,
|
||||
pshag::CElementGen::EModelOrientationType::Normal,
|
||||
pshag::CElementGen::EOptionalSystemFlags::None));
|
||||
|
|
|
@ -154,7 +154,7 @@ void CLineRenderer::Reset()
|
|||
void CLineRenderer::AddVertex(const Zeus::CVector3f& position, const Zeus::CColor& color, float width,
|
||||
const Zeus::CVector2f& uv)
|
||||
{
|
||||
if (!m_shaderBind || m_nextVert >= m_maxVerts)
|
||||
if (m_final || !m_shaderBind || m_nextVert >= m_maxVerts)
|
||||
return;
|
||||
|
||||
float adjWidth = width / 480.f;
|
||||
|
@ -385,15 +385,16 @@ void CLineRenderer::Render(const Zeus::CColor& moduColor)
|
|||
|
||||
SDrawUniform uniformData = {moduColor};
|
||||
m_uniformBuf->load(&uniformData, sizeof(SDrawUniform));
|
||||
CGraphics::SetShaderDataBinding(m_shaderBind);
|
||||
if (m_textured)
|
||||
{
|
||||
m_vertBuf->load(g_StaticLineVertsTex.data(), sizeof(SDrawVertTex) * g_StaticLineVertsTex.size());
|
||||
CGraphics::SetShaderDataBinding(m_shaderBind);
|
||||
CGraphics::DrawArray(boo::Primitive::TriStrips, 0, g_StaticLineVertsTex.size());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vertBuf->load(g_StaticLineVertsNoTex.data(), sizeof(SDrawVertNoTex) * g_StaticLineVertsNoTex.size());
|
||||
CGraphics::SetShaderDataBinding(m_shaderBind);
|
||||
CGraphics::DrawArray(boo::Primitive::TriStrips, 0, g_StaticLineVertsNoTex.size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
#include "CLineRendererShaders.hpp"
|
||||
#include "CLineRenderer.hpp"
|
||||
|
||||
namespace pshag
|
||||
{
|
||||
|
||||
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
|
||||
{
|
||||
void BuildShaderDataBinding(CLineRenderer& renderer, boo::IShaderPipeline* pipeline, boo::ITexture* texture)
|
||||
{
|
||||
int texCount = 0;
|
||||
boo::ITexture* textures[1];
|
||||
|
||||
if (texture)
|
||||
{
|
||||
textures[0] = texture;
|
||||
texCount = 1;
|
||||
}
|
||||
|
||||
boo::IGraphicsBuffer* uniforms[] = {renderer.m_uniformBuf};
|
||||
|
||||
renderer.m_shaderBind = CGraphics::g_BooFactory->newShaderDataBinding(pipeline, nullptr, renderer.m_vertBuf,
|
||||
nullptr, nullptr, 1, uniforms,
|
||||
texCount, textures);
|
||||
}
|
||||
};
|
||||
|
||||
CLineRendererShaders::IDataBindingFactory* CLineRendererShaders::Initialize(boo::ID3DDataFactory& factory)
|
||||
{
|
||||
static const boo::VertexElementDescriptor VtxFmtTex[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Color},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
m_texVtxFmt = factory.newVertexFormat(3, VtxFmtTex);
|
||||
|
||||
static const boo::VertexElementDescriptor VtxFmtNoTex[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::Color}
|
||||
};
|
||||
m_noTexVtxFmt = factory.newVertexFormat(2, VtxFmtNoTex);
|
||||
|
||||
m_texAlpha = factory.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
||||
ComPtr<ID3DBlob>(), m_texVtxFmt,
|
||||
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
||||
false, true, false);
|
||||
m_texAdditive = factory.newShaderPipeline(VS_HLSL_TEX, FS_HLSL_TEX, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
||||
ComPtr<ID3DBlob>(), m_texVtxFmt,
|
||||
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
||||
false, false, false);
|
||||
m_noTexAlpha = factory.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
||||
ComPtr<ID3DBlob>(), m_noTexVtxFmt,
|
||||
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
||||
false, true, false);
|
||||
m_noTexAdditive = factory.newShaderPipeline(VS_HLSL_NOTEX, FS_HLSL_NOTEX, ComPtr<ID3DBlob>(), ComPtr<ID3DBlob>(),
|
||||
ComPtr<ID3DBlob>(), m_noTexVtxFmt,
|
||||
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
||||
false, false, false);
|
||||
|
||||
return new struct HLSLLineDataBindingFactory;
|
||||
}
|
||||
|
||||
}
|
2
hecl
2
hecl
|
@ -1 +1 @@
|
|||
Subproject commit de8d872bfa1f07850389bcbfcec1f1aa957efd69
|
||||
Subproject commit e8ab7ce9b252f02674c88b39a8cdf0a32cc3ba6e
|
Loading…
Reference in New Issue