mirror of https://github.com/AxioDL/metaforce.git
Metal quad shader imps
This commit is contained in:
parent
d234bffe2a
commit
edaa022517
|
@ -14,6 +14,7 @@
|
|||
#include "Runtime/Graphics/CGraphics.hpp"
|
||||
#include "Runtime/Character/CSkinRules.hpp"
|
||||
#include "Graphics/CMetroidModelInstance.hpp"
|
||||
#include "World/CWorldTransManager.hpp"
|
||||
#include <cstdio>
|
||||
|
||||
using YAMLNode = athena::io::YAMLNode;
|
||||
|
@ -27,6 +28,17 @@ URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
|
|||
|
||||
void ViewManager::BuildTestPART(urde::IObjectStore& objStore)
|
||||
{
|
||||
SObjectTag samusCharSet = m_projManager.resourceFactoryMP1().ProjectResourceFactoryBase::TagFromPath(
|
||||
_S("MP1/Shared/ANCS_77289A4A.blend"));
|
||||
SObjectTag platModel = m_projManager.resourceFactoryMP1().ProjectResourceFactoryBase::TagFromPath(
|
||||
_S("MP1/Shared/CMDL_6FA561D0.blend"));
|
||||
SObjectTag bgModel = m_projManager.resourceFactoryMP1().ProjectResourceFactoryBase::TagFromPath(
|
||||
_S("MP1/Shared/CMDL_BC34D54C.blend"));
|
||||
CAnimRes samusAnimRes(samusCharSet.id, -1, zeus::CVector3f::skOne, -1, true);
|
||||
g_GameState->GetWorldTransitionManager()->EnableTransition(samusAnimRes,
|
||||
platModel.id, zeus::CVector3f::skOne,
|
||||
bgModel.id, zeus::CVector3f::skOne, false);
|
||||
|
||||
SObjectTag areaTag = m_projManager.resourceFactoryMP1().ProjectResourceFactoryBase::TagFromPath(
|
||||
_S("MP1/Metroid1/!1IntroLevel1027/00 Exterior Docking Hangar/!area.blend"));
|
||||
auto areaData = m_projManager.resourceFactoryMP1().LoadResourceSync(areaTag);
|
||||
|
@ -79,6 +91,10 @@ void ViewManager::ParticleView::resized(const boo::SWindowRect& root, const boo:
|
|||
void ViewManager::ParticleView::draw(boo::IGraphicsCommandQueue *gfxQ)
|
||||
{
|
||||
gfxQ->clearTarget(false, true);
|
||||
|
||||
g_GameState->GetWorldTransitionManager()->Update(1.f / 60.f);
|
||||
g_GameState->GetWorldTransitionManager()->Draw();
|
||||
|
||||
if (m_vm.m_modelTest.IsLoaded())
|
||||
{
|
||||
CModelFlags flags;
|
||||
|
|
|
@ -0,0 +1,88 @@
|
|||
#include "CColoredQuadFilter.hpp"
|
||||
#include "TMultiBlendShader.hpp"
|
||||
#include "Graphics/CTexture.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
static const char* VS =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct VertData\n"
|
||||
"{\n"
|
||||
" float4 posIn [[ attribute(0) ]];\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct ColoredQuadUniform\n"
|
||||
"{\n"
|
||||
" float4 color;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ColoredQuadUniform& cqu [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" vtf.color = cqu.color;\n"
|
||||
" vtf.position = vec4(v.posIn.xyz, 1.0);\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS =
|
||||
"#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";
|
||||
|
||||
URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CColoredQuadFilter)
|
||||
|
||||
struct CColoredQuadFilterMetalDataBindingFactory : TMultiBlendShader<CColoredQuadFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
boo::IShaderPipeline* pipeline,
|
||||
boo::IVertexFormat* vtxFmt,
|
||||
CColoredQuadFilter& filter)
|
||||
{
|
||||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
return cctx.newShaderDataBinding(pipeline, vtxFmt,
|
||||
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 0, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
TMultiBlendShader<CColoredQuadFilter>::IDataBindingFactory*
|
||||
CColoredQuadFilter::Initialize(boo::MetalDataFactory::Context& ctx,
|
||||
boo::IShaderPipeline*& alphaPipeOut,
|
||||
boo::IShaderPipeline*& additivePipeOut,
|
||||
boo::IShaderPipeline*& colorMultiplyPipeOut,
|
||||
boo::IVertexFormat*& vtxFmtOut)
|
||||
{
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4}
|
||||
};
|
||||
vtxFmtOut = ctx.newVertexFormat(1, VtxVmt);
|
||||
alphaPipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, false, false, false);
|
||||
additivePipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips, false, false, false);
|
||||
colorMultiplyPipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcColor,
|
||||
boo::BlendFactor::DstColor, boo::Primitive::TriStrips, false, false, false);
|
||||
return new CColoredQuadFilterMetalDataBindingFactory;
|
||||
}
|
||||
|
||||
}
|
|
@ -59,14 +59,16 @@ URDE_DECL_SPECIALIZE_SHADER(CSpaceWarpFilter)
|
|||
|
||||
struct CSpaceWarpFilterMetalDataBindingFactory : TShader<CSpaceWarpFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CSpaceWarpFilter& filter)
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
boo::IShaderPipeline* pipeline,
|
||||
boo::IVertexFormat* vtxFmt,
|
||||
CSpaceWarpFilter& filter)
|
||||
{
|
||||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_warpTex};
|
||||
return cctx.newShaderDataBinding(TShader<CSpaceWarpFilter>::m_pipeline,
|
||||
TShader<CSpaceWarpFilter>::m_vtxFmt,
|
||||
return cctx.newShaderDataBinding(pipeline, vtxFmt,
|
||||
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 2, texs);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
#include "CTexturedQuadFilter.hpp"
|
||||
#include "TMultiBlendShader.hpp"
|
||||
#include "Graphics/CTexture.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
static const char* VS =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct VertData\n"
|
||||
"{\n"
|
||||
" float4 posIn [[ attribute(0) ]];\n"
|
||||
" float4 uvIn [[ attribute(1) ]];\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct TexuredQuadUniform\n"
|
||||
"{\n"
|
||||
" float4 color;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float2 uv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant TexuredQuadUniform& tqu [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" vtf.color = tqu.color;\n"
|
||||
" vtf.uv = v.uvIn.xy;\n"
|
||||
" vtf.position = vec4(v.posIn.xyz, 1.0);\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"constexpr sampler samp(address::repeat, 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 ]], texture2d<float> tex [[ texture(0) ]])\n"
|
||||
"{\n"
|
||||
" return vtf.color * tex.sample(samp, vtf.uv);\n"
|
||||
"}\n";
|
||||
|
||||
URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CTexturedQuadFilter)
|
||||
|
||||
struct CTexturedQuadFilterMetalDataBindingFactory : TMultiBlendShader<CTexturedQuadFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
boo::IShaderPipeline* pipeline,
|
||||
boo::IVertexFormat* vtxFmt,
|
||||
CTexturedQuadFilter& filter)
|
||||
{
|
||||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {filter.m_tex->GetBooTexture()};
|
||||
return cctx.newShaderDataBinding(pipeline, vtxFmt,
|
||||
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 1, texs);
|
||||
}
|
||||
};
|
||||
|
||||
TMultiBlendShader<CTexturedQuadFilter>::IDataBindingFactory*
|
||||
CTexturedQuadFilter::Initialize(boo::MetalDataFactory::Context& ctx,
|
||||
boo::IShaderPipeline*& alphaPipeOut,
|
||||
boo::IShaderPipeline*& additivePipeOut,
|
||||
boo::IShaderPipeline*& colorMultiplyPipeOut,
|
||||
boo::IVertexFormat*& vtxFmtOut)
|
||||
{
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
vtxFmtOut = ctx.newVertexFormat(2, VtxVmt);
|
||||
alphaPipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips, false, false, false);
|
||||
additivePipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips, false, false, false);
|
||||
colorMultiplyPipeOut = ctx.newShaderPipeline(VS, FS, vtxFmtOut, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcColor,
|
||||
boo::BlendFactor::DstColor, boo::Primitive::TriStrips, false, false, false);
|
||||
return new CTexturedQuadFilterMetalDataBindingFactory;
|
||||
}
|
||||
|
||||
}
|
|
@ -87,14 +87,16 @@ URDE_DECL_SPECIALIZE_SHADER(CThermalColdFilter)
|
|||
|
||||
struct CThermalColdFilterMetalDataBindingFactory : TShader<CThermalColdFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalColdFilter& filter)
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
boo::IShaderPipeline* pipeline,
|
||||
boo::IVertexFormat* vtxFmt,
|
||||
CThermalColdFilter& filter)
|
||||
{
|
||||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, filter.m_shiftTex};
|
||||
return cctx.newShaderDataBinding(TShader<CThermalColdFilter>::m_pipeline,
|
||||
TShader<CThermalColdFilter>::m_vtxFmt,
|
||||
return cctx.newShaderDataBinding(pipeline, vtxFmt,
|
||||
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 2, texs);
|
||||
}
|
||||
|
|
|
@ -60,14 +60,16 @@ URDE_DECL_SPECIALIZE_SHADER(CThermalHotFilter)
|
|||
|
||||
struct CThermalHotFilterMetalDataBindingFactory : TShader<CThermalHotFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx, CThermalHotFilter& filter)
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
boo::IShaderPipeline* pipeline,
|
||||
boo::IVertexFormat* vtxFmt,
|
||||
CThermalHotFilter& filter)
|
||||
{
|
||||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {CGraphics::g_SpareTexture, g_Renderer->GetThermoPalette()};
|
||||
return cctx.newShaderDataBinding(TShader<CThermalHotFilter>::m_pipeline,
|
||||
TShader<CThermalHotFilter>::m_vtxFmt,
|
||||
return cctx.newShaderDataBinding(pipeline, vtxFmt,
|
||||
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 2, texs);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue