mirror of https://github.com/AxioDL/metaforce.git
Implement Metal CLineRenderer shaders
This commit is contained in:
parent
8cd46293c2
commit
5a0fb04e03
|
@ -10,6 +10,9 @@ boo::IShaderPipeline* CLineRendererShaders::m_texAdditive = nullptr;
|
|||
boo::IShaderPipeline* CLineRendererShaders::m_noTexAlpha = nullptr;
|
||||
boo::IShaderPipeline* CLineRendererShaders::m_noTexAdditive = nullptr;
|
||||
|
||||
boo::IVertexFormat* CLineRendererShaders::m_texVtxFmt = nullptr;
|
||||
boo::IVertexFormat* CLineRendererShaders::m_noTexVtxFmt = nullptr;
|
||||
|
||||
std::unique_ptr<CLineRendererShaders::IDataBindingFactory> CLineRendererShaders::m_bindFactory;
|
||||
boo::GraphicsDataToken CLineRendererShaders::m_gfxToken;
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@ private:
|
|||
static boo::IShaderPipeline* m_noTexAlpha;
|
||||
static boo::IShaderPipeline* m_noTexAdditive;
|
||||
|
||||
static boo::IVertexFormat* m_texVtxFmt;
|
||||
static boo::IVertexFormat* m_noTexVtxFmt;
|
||||
|
||||
static std::unique_ptr<IDataBindingFactory> m_bindFactory;
|
||||
static boo::GraphicsDataToken m_gfxToken;
|
||||
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
#include "CLineRendererShaders.hpp"
|
||||
#include "CLineRenderer.hpp"
|
||||
|
||||
namespace pshag
|
||||
{
|
||||
|
||||
static const char* VS_METAL_TEX =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct VertData\n"
|
||||
"{\n"
|
||||
" float4 posIn;\n"
|
||||
" float4 colorIn;\n"
|
||||
" float4 uvIn;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct LineUniform\n"
|
||||
"{\n"
|
||||
" float4 moduColor;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float2 uv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]],\n"
|
||||
" uint vertId [[ vertex_id ]],\n"
|
||||
" constant LineUniform& line [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" constant VertData& v = va[vertId];\n"
|
||||
" vtf.color = v.colorIn * line.moduColor;\n"
|
||||
" vtf.uv = v.uvIn.xy;\n"
|
||||
" vtf.position = v.posIn;\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS_METAL_TEX =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float2 uv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||
" texture2d<float> tex0 [[ texture(0) ]])\n"
|
||||
"{\n"
|
||||
" return vtf.color * tex0.sample(samp, vtf.uv);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* VS_METAL_NOTEX =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct VertData\n"
|
||||
"{\n"
|
||||
" float4 posIn;\n"
|
||||
" float4 colorIn;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct LineUniform\n"
|
||||
"{\n"
|
||||
" float4 moduColor;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(constant VertData* va [[ buffer(0) ]],\n"
|
||||
" uint vertId [[ vertex_id ]],\n"
|
||||
" constant LineUniform& line [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" constant VertData& v = va[vertId];\n"
|
||||
" vtf.color = v.colorIn * line.moduColor;\n"
|
||||
" vtf.position = v.posIn;\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS_METAL_NOTEX =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n"
|
||||
"{\n"
|
||||
" return vtf.color;\n"
|
||||
"}\n";
|
||||
|
||||
struct MetalLineDataBindingFactory : 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::MetalDataFactory& 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_METAL_TEX, FS_METAL_TEX, m_texVtxFmt,
|
||||
CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
||||
false, true, false);
|
||||
m_texAdditive = factory.newShaderPipeline(VS_METAL_TEX, FS_METAL_TEX, m_texVtxFmt,
|
||||
CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
||||
false, false, false);
|
||||
m_noTexAlpha = factory.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, m_noTexVtxFmt,
|
||||
CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcAlpha, boo::BlendFactor::InvSrcAlpha,
|
||||
false, true, false);
|
||||
m_noTexAdditive = factory.newShaderPipeline(VS_METAL_NOTEX, FS_METAL_NOTEX, m_noTexVtxFmt,
|
||||
CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcAlpha, boo::BlendFactor::One,
|
||||
false, false, false);
|
||||
|
||||
return new struct MetalLineDataBindingFactory;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,7 +1,14 @@
|
|||
if(WIN32)
|
||||
set(PLAT_SRCS CLineRendererShadersHLSL.cpp)
|
||||
elseif(APPLE)
|
||||
set(PLAT_SRCS CLineRendererShadersMetal.cpp)
|
||||
endif()
|
||||
|
||||
add_library(RuntimeCommonGraphics
|
||||
IRenderer.hpp
|
||||
CBooRenderer.hpp CBooRenderer.cpp
|
||||
CLineRenderer.hpp CLineRenderer.cpp
|
||||
CLineRendererShaders.hpp CLineRendererShadersGLSL.cpp
|
||||
CMetroidModelInstance.hpp
|
||||
CLight.hpp)
|
||||
CLight.hpp
|
||||
${PLAT_SRCS})
|
||||
|
|
Loading…
Reference in New Issue