mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 11:47:43 +00:00
Finish CSamusDoll
This commit is contained in:
@@ -865,6 +865,14 @@ void CBooRenderer::DrawStaticGeometry(int modelCount, int mask, int targetMask)
|
||||
DrawSortedGeometry(modelCount, mask, targetMask);
|
||||
}
|
||||
|
||||
void CBooRenderer::DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly)
|
||||
{
|
||||
model.GetInstance().DrawFlat(unsortedOnly ?
|
||||
CBooModel::ESurfaceSelection::UnsortedOnly :
|
||||
CBooModel::ESurfaceSelection::All,
|
||||
flags.m_extendedShader);
|
||||
}
|
||||
|
||||
void CBooRenderer::PostRenderFogs()
|
||||
{
|
||||
for (const auto& warp : x2c4_spaceWarps)
|
||||
@@ -974,6 +982,14 @@ void CBooRenderer::BeginScene()
|
||||
CGraphics::SetViewport(0, 0, g_Viewport.x8_width, g_Viewport.xc_height);
|
||||
CGraphics::SetPerspective(75.f, CGraphics::g_ProjAspect, 1.f, 4096.f);
|
||||
CGraphics::SetModelMatrix(zeus::CTransform::Identity());
|
||||
#if 0
|
||||
if (x310_phazonSuitMaskCountdown != 0)
|
||||
{
|
||||
--x310_phazonSuitMaskCountdown;
|
||||
if (x310_phazonSuitMaskCountdown == 0)
|
||||
x314_phazonSuitMask.reset();
|
||||
}
|
||||
#endif
|
||||
x318_27_currentRGBA6 = x318_26_requestRGBA6;
|
||||
if (!x318_31_persistRGBA6)
|
||||
x318_26_requestRGBA6 = false;
|
||||
@@ -1175,6 +1191,53 @@ void CBooRenderer::SetWorldLightFadeLevel(float level)
|
||||
x2fc_tevReg1Color = zeus::CColor(level, level, level, 1.f);
|
||||
}
|
||||
|
||||
void CBooRenderer::ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, /*const CTexture& maskTex,*/
|
||||
const CTexture& indTex, const zeus::CColor& modColor,
|
||||
float scale, float offX, float offY)
|
||||
{
|
||||
m_phazonSuitFilter.draw(modColor, scale, offX * scale, offY * scale);
|
||||
}
|
||||
|
||||
void CBooRenderer::ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor /*, const CTexture& maskTex*/)
|
||||
{
|
||||
m_phazonSuitFilter.draw(modColor, 0.f, 0.f, 0.f);
|
||||
}
|
||||
|
||||
void CBooRenderer::DoPhazonSuitIndirectAlphaBlur(float blurRadius /*, float f2*/, const TLockedToken<CTexture>& indTex)
|
||||
{
|
||||
m_phazonSuitFilter.drawBlurPasses(blurRadius, indTex.IsLoaded() ? indTex.GetObj() : nullptr);
|
||||
}
|
||||
|
||||
void CBooRenderer::DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod, const TLockedToken<CTexture>& indTex,
|
||||
const zeus::CColor& indirectMod, float blurRadius,
|
||||
float scale, float offX, float offY)
|
||||
{
|
||||
/* Indirect background already in binding 0 */
|
||||
|
||||
/* Resolve alpha channel of just-drawn phazon suit into binding 1 */
|
||||
SClipScreenRect rect;
|
||||
rect.x4_left = g_Viewport.x0_left;
|
||||
rect.x8_top = g_Viewport.x4_top;
|
||||
rect.xc_width = g_Viewport.x8_width;
|
||||
rect.x10_height = g_Viewport.xc_height;
|
||||
CGraphics::ResolveSpareTexture(rect, 1);
|
||||
|
||||
/* Perform blur filter and resolve into binding 2 */
|
||||
DoPhazonSuitIndirectAlphaBlur(blurRadius, indTex);
|
||||
|
||||
/* Draw effect; subtracting binding 1 from binding 2 for the filter 'cutout' */
|
||||
if (indTex && indTex.IsLoaded())
|
||||
ReallyDrawPhazonSuitIndirectEffect(zeus::CColor::skWhite, *indTex, indirectMod, scale, offX, offY);
|
||||
else
|
||||
ReallyDrawPhazonSuitEffect(nonIndirectMod);
|
||||
}
|
||||
|
||||
void CBooRenderer::AllocatePhazonSuitMaskTexture()
|
||||
{
|
||||
x318_26_requestRGBA6 = true;
|
||||
x310_phazonSuitMaskCountdown = 2;
|
||||
}
|
||||
|
||||
void CBooRenderer::FindOverlappingWorldModels(std::vector<u32>& modelBits, const zeus::CAABox& aabb) const
|
||||
{
|
||||
u32 bitmapWords = 0;
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Shaders/CSpaceWarpFilter.hpp"
|
||||
#include "Shaders/CFogVolumePlaneShader.hpp"
|
||||
#include "Shaders/CFogVolumeFilter.hpp"
|
||||
#include "Shaders/CPhazonSuitFilter.hpp"
|
||||
#include "CRandom16.hpp"
|
||||
#include "CPVSVisSet.hpp"
|
||||
#include "zeus/CRectangle.hpp"
|
||||
@@ -149,6 +150,10 @@ class CBooRenderer : public IRenderer
|
||||
|
||||
std::vector<CLight> x300_dynamicLights;
|
||||
|
||||
u32 x310_phazonSuitMaskCountdown = 0;
|
||||
//std::unique_ptr<CTexture> x314_phazonSuitMask;
|
||||
CPhazonSuitFilter m_phazonSuitFilter;
|
||||
|
||||
union
|
||||
{
|
||||
struct
|
||||
@@ -182,6 +187,12 @@ class CBooRenderer : public IRenderer
|
||||
CFogVolumePlaneShader* fvs);
|
||||
void SetupRendererStates() const;
|
||||
|
||||
void ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, /*const CTexture& maskTex,*/
|
||||
const CTexture& indTex, const zeus::CColor& modColor,
|
||||
float scale, float offX, float offY);
|
||||
void ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor /*, const CTexture& maskTex*/);
|
||||
void DoPhazonSuitIndirectAlphaBlur(float blurRadius /*, float f2*/, const TLockedToken<CTexture>& indTex);
|
||||
|
||||
public:
|
||||
CBooRenderer(IObjectStore& store, IFactory& resFac);
|
||||
|
||||
@@ -196,6 +207,7 @@ public:
|
||||
void DrawUnsortedGeometry(int areaIdx, int mask, int targetMask);
|
||||
void DrawSortedGeometry(int areaIdx, int mask, int targetMask);
|
||||
void DrawStaticGeometry(int areaIdx, int mask, int targetMask);
|
||||
void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly);
|
||||
void PostRenderFogs();
|
||||
void AddParticleGen(const CParticleGen&);
|
||||
void AddPlaneObject(const void*, const zeus::CAABox&, const zeus::CPlane&, int);
|
||||
@@ -248,6 +260,10 @@ public:
|
||||
void PrepareDynamicLights(const std::vector<CLight>& lights);
|
||||
void SetWorldLightMultiplyColor(const zeus::CColor& color);
|
||||
void SetWorldLightFadeLevel(float level);
|
||||
void DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod, const TLockedToken<CTexture>& indTex,
|
||||
const zeus::CColor& indirectMod, float blurRadius,
|
||||
float indScale, float indOffX, float indOffY);
|
||||
void AllocatePhazonSuitMaskTexture();
|
||||
|
||||
void ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb,
|
||||
const CModel* model, const CSkinnedModel* sModel);
|
||||
|
||||
@@ -14,7 +14,8 @@ if(WIN32)
|
||||
Shaders/CFogVolumeFilterHLSL.cpp
|
||||
Shaders/CEnergyBarShaderHLSL.cpp
|
||||
Shaders/CRadarPaintShaderHLSL.cpp
|
||||
Shaders/CMapSurfaceShaderHLSL.cpp)
|
||||
Shaders/CMapSurfaceShaderHLSL.cpp
|
||||
Shaders/CPhazonSuitFilterHLSL.cpp)
|
||||
elseif(BOO_HAS_METAL)
|
||||
set(PLAT_SRCS
|
||||
Shaders/CLineRendererShadersMetal.cpp
|
||||
@@ -31,7 +32,8 @@ elseif(BOO_HAS_METAL)
|
||||
Shaders/CFogVolumeFilterMetal.cpp
|
||||
Shaders/CEnergyBarShaderMetal.cpp
|
||||
Shaders/CRadarPaintShaderMetal.cpp
|
||||
Shaders/CMapSurfaceShaderMetal.cpp)
|
||||
Shaders/CMapSurfaceShaderMetal.cpp
|
||||
Shaders/CPhazonSuitFilterMetal.cpp)
|
||||
endif()
|
||||
|
||||
set(GRAPHICS_SOURCES
|
||||
@@ -70,6 +72,7 @@ set(GRAPHICS_SOURCES
|
||||
Shaders/CEnergyBarShader.hpp Shaders/CEnergyBarShader.cpp Shaders/CEnergyBarShaderGLSL.cpp
|
||||
Shaders/CRadarPaintShader.hpp Shaders/CRadarPaintShader.cpp Shaders/CRadarPaintShaderGLSL.cpp
|
||||
Shaders/CMapSurfaceShader.hpp Shaders/CMapSurfaceShader.cpp Shaders/CMapSurfaceShaderGLSL.cpp
|
||||
Shaders/CPhazonSuitFilter.hpp Shaders/CPhazonSuitFilter.cpp Shaders/CPhazonSuitFilterGLSL.cpp
|
||||
${PLAT_SRCS})
|
||||
|
||||
runtime_add_list(Graphics GRAPHICS_SOURCES)
|
||||
|
||||
@@ -23,7 +23,7 @@ class CModel;
|
||||
|
||||
struct CModelFlags
|
||||
{
|
||||
u8 x0_blendMode = 0; /* Blend state 3/5 enable additive */
|
||||
u8 x0_blendMode = 0; /* >6: additive, >4: blend, else opaque */
|
||||
u8 x1_matSetIdx = 0;
|
||||
EExtendedShader m_extendedShader = EExtendedShader::Flat;
|
||||
u16 x2_flags = 0; /* Flags */
|
||||
@@ -36,6 +36,8 @@ struct CModelFlags
|
||||
: x0_blendMode(blendMode), x1_matSetIdx(shadIdx), x2_flags(flags), x4_color(col) {}
|
||||
|
||||
/* Flags
|
||||
0x1: depth equal
|
||||
0x2: depth update
|
||||
0x4: render without texture lock
|
||||
0x8: depth greater
|
||||
0x10: depth non-inclusive
|
||||
@@ -79,6 +81,13 @@ public:
|
||||
void UnlockTextures();
|
||||
};
|
||||
|
||||
enum class ESurfaceSelection
|
||||
{
|
||||
UnsortedOnly,
|
||||
SortedOnly,
|
||||
All
|
||||
};
|
||||
|
||||
private:
|
||||
CBooModel* m_next = nullptr;
|
||||
CBooModel* m_prev = nullptr;
|
||||
@@ -148,6 +157,7 @@ public:
|
||||
|
||||
bool IsOpaque() const {return x3c_firstSortedSurface == nullptr;}
|
||||
void ActivateLights(const std::vector<CLight>& lights);
|
||||
void DisableAllLights();
|
||||
void RemapMaterialData(SShader& shader);
|
||||
bool TryLockTextures() const;
|
||||
void UnlockTextures() const;
|
||||
@@ -165,6 +175,8 @@ public:
|
||||
void Draw(const CModelFlags& flags,
|
||||
const CSkinRules* cskr,
|
||||
const CPoseAsTransforms* pose) const;
|
||||
void DrawFlat(ESurfaceSelection sel, EExtendedShader extendedIdx) const;
|
||||
|
||||
|
||||
const MaterialSet::Material& GetMaterialByIndex(int idx) const
|
||||
{
|
||||
@@ -217,6 +229,7 @@ public:
|
||||
void DrawUnsortedParts(const CModelFlags& flags) const;
|
||||
void Draw(const CModelFlags& flags) const;
|
||||
bool IsLoaded(int shaderIdx) const;
|
||||
void Touch(int shaderIdx) { x28_modelInst->Touch(shaderIdx); }
|
||||
|
||||
const zeus::CAABox& GetAABB() const {return m_aabb;}
|
||||
CBooModel& GetInstance() {return *x28_modelInst;}
|
||||
|
||||
@@ -425,6 +425,19 @@ void CBooModel::ActivateLights(const std::vector<CLight>& lights)
|
||||
}
|
||||
}
|
||||
|
||||
void CBooModel::DisableAllLights()
|
||||
{
|
||||
m_lightingData.ambient = zeus::CColor::skBlack;
|
||||
|
||||
for (size_t curLight = 0 ; curLight<URDE_MAX_LIGHTS ; ++curLight)
|
||||
{
|
||||
CModelShaders::Light& lightOut = m_lightingData.lights[curLight];
|
||||
lightOut.color = zeus::CColor::skClear;
|
||||
lightOut.linAtt[0] = 1.f;
|
||||
lightOut.angAtt[0] = 1.f;
|
||||
}
|
||||
}
|
||||
|
||||
void CBooModel::RemapMaterialData(SShader& shader)
|
||||
{
|
||||
x4_matSet = &shader.m_matSet;
|
||||
@@ -461,6 +474,33 @@ void CBooModel::UnlockTextures() const
|
||||
const_cast<CBooModel*>(this)->x40_24_texturesLoaded = false;
|
||||
}
|
||||
|
||||
void CBooModel::DrawFlat(ESurfaceSelection sel, EExtendedShader extendedIdx) const
|
||||
{
|
||||
const CBooSurface* surf;
|
||||
CModelFlags flags = {};
|
||||
flags.m_extendedShader = extendedIdx;
|
||||
|
||||
if (sel != ESurfaceSelection::SortedOnly)
|
||||
{
|
||||
surf = x38_firstUnsortedSurface;
|
||||
while (surf)
|
||||
{
|
||||
DrawSurface(*surf, flags);
|
||||
surf = surf->m_next;
|
||||
}
|
||||
}
|
||||
|
||||
if (sel != ESurfaceSelection::UnsortedOnly)
|
||||
{
|
||||
surf = x3c_firstSortedSurface;
|
||||
while (surf)
|
||||
{
|
||||
DrawSurface(*surf, flags);
|
||||
surf = surf->m_next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CBooModel::DrawAlphaSurfaces(const CModelFlags& flags) const
|
||||
{
|
||||
const CBooSurface* surf = x3c_firstSortedSurface;
|
||||
|
||||
@@ -21,6 +21,7 @@ class CModel;
|
||||
class CSkinnedModel;
|
||||
class CPVSVisSet;
|
||||
struct CAreaRenderOctTree;
|
||||
class CModelFlags;
|
||||
|
||||
class IRenderer
|
||||
{
|
||||
@@ -51,6 +52,7 @@ public:
|
||||
virtual void DrawUnsortedGeometry(int areaIdx, int mask, int targetMask)=0;
|
||||
virtual void DrawSortedGeometry(int areaIdx, int mask, int targetMask)=0;
|
||||
virtual void DrawStaticGeometry(int areaIdx, int mask, int targetMask)=0;
|
||||
virtual void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly)=0;
|
||||
virtual void PostRenderFogs()=0;
|
||||
virtual void AddParticleGen(const CParticleGen&)=0;
|
||||
virtual void AddPlaneObject(const void*, const zeus::CAABox&, const zeus::CPlane&, int)=0;
|
||||
|
||||
96
Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp
Normal file
96
Runtime/Graphics/Shaders/CPhazonSuitFilter.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "CPhazonSuitFilter.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
void CPhazonSuitFilter::drawBlurPasses(float radius, const CTexture* indTex)
|
||||
{
|
||||
if (!m_dataBind || indTex != m_indTex)
|
||||
{
|
||||
m_indTex = indTex;
|
||||
m_gfxTok = CGraphics::CommitResources(
|
||||
[this](boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
m_uniBufBlurX = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1);
|
||||
m_uniBufBlurY = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f), 1);
|
||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(zeus::CVector4f) * 2, 1);
|
||||
|
||||
struct BlurVert
|
||||
{
|
||||
zeus::CVector3f pos;
|
||||
zeus::CVector2f uv;
|
||||
} blurVerts[4] =
|
||||
{
|
||||
{{-1.f, 1.f, 0.f}, {0.f, 1.f}},
|
||||
{{-1.f, -1.f, 0.f}, {0.f, 0.f}},
|
||||
{{ 1.f, 1.f, 0.f}, {1.f, 1.f}},
|
||||
{{ 1.f, -1.f, 0.f}, {1.f, 0.f}}
|
||||
};
|
||||
m_blurVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, blurVerts, sizeof(BlurVert), 4);
|
||||
|
||||
struct Vert
|
||||
{
|
||||
zeus::CVector3f pos;
|
||||
zeus::CVector2f screenUv;
|
||||
zeus::CVector2f indUv;
|
||||
zeus::CVector2f maskUv;
|
||||
} verts[4] =
|
||||
{
|
||||
{{-1.f, 1.f, 0.f}, {0.01f, 0.99f}, {0.f, 1.f}, {0.f, 1.f}},
|
||||
{{-1.f, -1.f, 0.f}, {0.01f, 0.01f}, {0.f, 1.f}, {0.f, 1.f}},
|
||||
{{ 1.f, 1.f, 0.f}, {0.99f, 0.99f}, {0.f, 1.f}, {0.f, 1.f}},
|
||||
{{ 1.f, -1.f, 0.f}, {0.99f, 0.01f}, {0.f, 1.f}, {0.f, 1.f}}
|
||||
};
|
||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4);
|
||||
|
||||
m_dataBind = TShader<CPhazonSuitFilter>::BuildShaderDataBinding(ctx, *this);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
SClipScreenRect rect;
|
||||
rect.x4_left = g_Viewport.x0_left;
|
||||
rect.x8_top = g_Viewport.x4_top;
|
||||
rect.xc_width = g_Viewport.x8_width;
|
||||
rect.x10_height = g_Viewport.xc_height;
|
||||
|
||||
/* X Pass */
|
||||
zeus::CVector4f blurDir = zeus::CVector4f{2.f * radius / g_Viewport.x8_width, 0.f, 0.f, 0.f};
|
||||
m_uniBufBlurX->load(&blurDir, sizeof(zeus::CVector4f));
|
||||
|
||||
CGraphics::SetShaderDataBinding(m_dataBindBlurX);
|
||||
CGraphics::DrawArray(0, 4);
|
||||
CGraphics::ResolveSpareTexture(rect, 2);
|
||||
|
||||
/* Y Pass */
|
||||
blurDir = zeus::CVector4f{0.f, 2.f * radius / g_Viewport.xc_height, 0.f, 0.f};
|
||||
m_uniBufBlurY->load(&blurDir, sizeof(zeus::CVector4f));
|
||||
|
||||
CGraphics::SetShaderDataBinding(m_dataBindBlurY);
|
||||
CGraphics::DrawArray(0, 4);
|
||||
CGraphics::ResolveSpareTexture(rect, 2);
|
||||
}
|
||||
|
||||
void CPhazonSuitFilter::draw(const zeus::CColor& color,
|
||||
float indScale, float indOffX, float indOffY)
|
||||
{
|
||||
struct Uniform
|
||||
{
|
||||
zeus::CColor color;
|
||||
zeus::CVector4f indScaleOff;
|
||||
} uniform =
|
||||
{
|
||||
color,
|
||||
zeus::CVector4f(indScale, indScale, indOffX, indOffY)
|
||||
};
|
||||
|
||||
m_uniBuf->load(&uniform, sizeof(Uniform));
|
||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
||||
CGraphics::DrawArray(0, 4);
|
||||
}
|
||||
|
||||
void CPhazonSuitFilter::Shutdown() {}
|
||||
|
||||
URDE_SPECIALIZE_SHADER(CPhazonSuitFilter)
|
||||
|
||||
}
|
||||
39
Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp
Normal file
39
Runtime/Graphics/Shaders/CPhazonSuitFilter.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#ifndef __URDE_CPHAZONSUITFILTER_HPP__
|
||||
#define __URDE_CPHAZONSUITFILTER_HPP__
|
||||
|
||||
#include "TShader.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
class CTexture;
|
||||
|
||||
class CPhazonSuitFilter
|
||||
{
|
||||
friend struct CPhazonSuitFilterGLDataBindingFactory;
|
||||
friend struct CPhazonSuitFilterVulkanDataBindingFactory;
|
||||
friend struct CPhazonSuitFilterMetalDataBindingFactory;
|
||||
friend struct CPhazonSuitFilterD3DDataBindingFactory;
|
||||
|
||||
boo::GraphicsDataToken m_gfxTok;
|
||||
boo::IGraphicsBufferD* m_uniBufBlurX;
|
||||
boo::IGraphicsBufferD* m_uniBufBlurY;
|
||||
boo::IGraphicsBufferD* m_uniBuf;
|
||||
boo::IGraphicsBufferS* m_blurVbo;
|
||||
boo::IGraphicsBufferS* m_vbo;
|
||||
const CTexture* m_indTex = nullptr;
|
||||
boo::IShaderDataBinding* m_dataBindBlurX = nullptr;
|
||||
boo::IShaderDataBinding* m_dataBindBlurY = nullptr;
|
||||
boo::IShaderDataBinding* m_dataBind = nullptr;
|
||||
|
||||
public:
|
||||
void drawBlurPasses(float radius, const CTexture* indTex);
|
||||
void draw(const zeus::CColor& color,
|
||||
float indScale, float indOffX, float indOffY);
|
||||
|
||||
using _CLS = CPhazonSuitFilter;
|
||||
#include "TShaderDecl.hpp"
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __URDE_CPHAZONSUITFILTER_HPP__
|
||||
340
Runtime/Graphics/Shaders/CPhazonSuitFilterGLSL.cpp
Normal file
340
Runtime/Graphics/Shaders/CPhazonSuitFilterGLSL.cpp
Normal file
@@ -0,0 +1,340 @@
|
||||
#include "CPhazonSuitFilter.hpp"
|
||||
#include "TShader.hpp"
|
||||
#include "Graphics/CTexture.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
||||
static const char* VS =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"layout(location=0) in vec4 posIn;\n"
|
||||
"layout(location=1) in vec4 screenUvIn;\n"
|
||||
"layout(location=2) in vec4 indUvIn;\n"
|
||||
"layout(location=3) in vec4 maskUvIn;\n"
|
||||
"\n"
|
||||
"UBINDING0 uniform PhazonSuitUniform\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec4 indScaleOff;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec4 indScaleOff;\n"
|
||||
" vec2 screenUv;\n"
|
||||
" vec2 indUv;\n"
|
||||
" vec2 maskUv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) out VertToFrag vtf;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vtf.color = color;\n"
|
||||
" vtf.indScaleOff = indScaleOff;\n"
|
||||
" vtf.screenUv = screenUvIn.xy;\n"
|
||||
" vtf.indUv = indUvIn.xy;\n"
|
||||
" vtf.maskUv = maskUvIn.xy;\n"
|
||||
" gl_Position = vec4(posIn.xyz, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* IndFS =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec4 indScaleOff;\n"
|
||||
" vec2 screenUv;\n"
|
||||
" vec2 indUv;\n"
|
||||
" vec2 maskUv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) in VertToFrag vtf;\n"
|
||||
"layout(location=0) out vec4 colorOut;\n"
|
||||
"TBINDING0 uniform sampler2D screenTex;\n"
|
||||
"TBINDING1 uniform sampler2D indTex;\n"
|
||||
"TBINDING2 uniform sampler2D maskTex;\n"
|
||||
"TBINDING3 uniform sampler2D maskTexBlur;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec2 indUv = (texture(indTex, vtf.indUv).rg - vec2(0.5, 0.5)) * \n"
|
||||
" vtf.indScaleOff.xy + vtf.indScaleOff.zw;\n"
|
||||
" colorOut = vtf.color * texture(screenTex, indUv + vtf.screenUv) * \n"
|
||||
" (texture(maskTexBlur, vtf.maskUv).a - texture(maskTex, vtf.maskUv).a);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec4 indScaleOff;\n"
|
||||
" vec2 screenUv;\n"
|
||||
" vec2 indUv;\n"
|
||||
" vec2 maskUv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) in VertToFrag vtf;\n"
|
||||
"layout(location=0) out vec4 colorOut;\n"
|
||||
"TBINDING0 uniform sampler2D screenTex;\n"
|
||||
"TBINDING1 uniform sampler2D maskTex;\n"
|
||||
"TBINDING2 uniform sampler2D maskTexBlur;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" colorOut = vtf.color * texture(screenTex, vtf.screenUv) * \n"
|
||||
" (texture(maskTexBlur, vtf.maskUv).a - texture(maskTex, vtf.maskUv).a);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* BlurVS =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"layout(location=0) in vec4 posIn;\n"
|
||||
"layout(location=3) in vec4 uvIn;\n"
|
||||
"\n"
|
||||
"UBINDING0 uniform PhazonSuitBlurUniform\n"
|
||||
"{\n"
|
||||
" vec4 blurDir;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec2 uv;\n"
|
||||
" vec2 blurDir;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) out VertToFrag vtf;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vtf.uv = uvIn.xy;\n"
|
||||
" vtf.blurDir = blurDir.xy;\n"
|
||||
" gl_Position = vec4(posIn.xyz, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* BlurFS =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec2 uv;\n"
|
||||
" vec2 blurDir;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) in VertToFrag vtf;\n"
|
||||
"layout(location=0) out vec4 colorOut;\n"
|
||||
"TBINDING0 uniform sampler2D maskTex;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" //this will be our alpha sum\n"
|
||||
" float sum = 0.0;\n"
|
||||
"\n"
|
||||
" //apply blurring, using a 9-tap filter with predefined gaussian weights\n"
|
||||
"\n"
|
||||
" sum += texture(maskTex, vtf.uv - 4.0 * vtf.blurDir).a * 0.0162162162;\n"
|
||||
" sum += texture(maskTex, vtf.uv - 3.0 * vtf.blurDir).a * 0.0540540541;\n"
|
||||
" sum += texture(maskTex, vtf.uv - 2.0 * vtf.blurDir).a * 0.1216216216;\n"
|
||||
" sum += texture(maskTex, vtf.uv - 1.0 * vtf.blurDir).a * 0.1945945946;\n"
|
||||
"\n"
|
||||
" sum += texture(maskTex, vtf.uv).a * 0.2270270270;\n"
|
||||
"\n"
|
||||
" sum += texture(maskTex, vtf.uv - 1.0 * vtf.blurDir).a * 0.1945945946;\n"
|
||||
" sum += texture(maskTex, vtf.uv - 2.0 * vtf.blurDir).a * 0.1216216216;\n"
|
||||
" sum += texture(maskTex, vtf.uv - 3.0 * vtf.blurDir).a * 0.0540540541;\n"
|
||||
" sum += texture(maskTex, vtf.uv - 4.0 * vtf.blurDir).a * 0.0162162162;\n"
|
||||
"\n"
|
||||
" colorOut = vec4(1.0, 1.0, 1.0, sum);\n"
|
||||
"}\n";
|
||||
|
||||
URDE_DECL_SPECIALIZE_SHADER(CPhazonSuitFilter)
|
||||
|
||||
static boo::IVertexFormat* s_VtxFmt = nullptr;
|
||||
static boo::IVertexFormat* s_BlurVtxFmt = nullptr;
|
||||
static boo::IShaderPipeline* s_IndPipeline = nullptr;
|
||||
static boo::IShaderPipeline* s_Pipeline = nullptr;
|
||||
static boo::IShaderPipeline* s_BlurPipeline = nullptr;
|
||||
|
||||
struct CPhazonSuitFilterGLDataBindingFactory : TShader<CPhazonSuitFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
CPhazonSuitFilter& filter)
|
||||
{
|
||||
boo::GLDataFactory::Context& cctx = static_cast<boo::GLDataFactory::Context&>(ctx);
|
||||
|
||||
const boo::VertexElementDescriptor BlurVtxVmt[] =
|
||||
{
|
||||
{filter.m_blurVbo, nullptr, boo::VertexSemantic::Position4},
|
||||
{filter.m_blurVbo, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
boo::IVertexFormat* blurVtxFmt = ctx.newVertexFormat(2, BlurVtxVmt);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBufBlurX};
|
||||
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
||||
boo::ITexture* texs[4];
|
||||
int texBindIdxs[4];
|
||||
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 1;
|
||||
filter.m_dataBindBlurX = cctx.newShaderDataBinding(s_BlurPipeline,
|
||||
blurVtxFmt, filter.m_blurVbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr);
|
||||
|
||||
bufs[0] = filter.m_uniBufBlurY;
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 2;
|
||||
filter.m_dataBindBlurY = cctx.newShaderDataBinding(s_BlurPipeline,
|
||||
blurVtxFmt, filter.m_blurVbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr);
|
||||
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4, 0},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4, 1},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4, 2}
|
||||
};
|
||||
boo::IVertexFormat* vtxFmt = ctx.newVertexFormat(4, VtxVmt);
|
||||
|
||||
bufs[0] = filter.m_uniBuf;
|
||||
size_t texCount;
|
||||
if (filter.m_indTex)
|
||||
{
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 0;
|
||||
texs[1] = filter.m_indTex->GetBooTexture();
|
||||
texBindIdxs[1] = 0;
|
||||
texs[2] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[2] = 1;
|
||||
texs[3] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[3] = 2;
|
||||
texCount = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 0;
|
||||
texs[1] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[1] = 1;
|
||||
texs[2] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[2] = 2;
|
||||
texCount = 3;
|
||||
}
|
||||
|
||||
return cctx.newShaderDataBinding(filter.m_indTex ? s_IndPipeline : s_Pipeline,
|
||||
vtxFmt, filter.m_vbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, texCount, texs, texBindIdxs, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
#if BOO_HAS_VULKAN
|
||||
struct CPhazonSuitFilterVulkanDataBindingFactory : TShader<CPhazonSuitFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
CPhazonSuitFilter& filter)
|
||||
{
|
||||
boo::VulkanDataFactory::Context& cctx = static_cast<boo::VulkanDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBufBlurX};
|
||||
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
||||
boo::ITexture* texs[4];
|
||||
int texBindIdxs[4];
|
||||
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 1;
|
||||
filter.m_dataBindBlurX = cctx.newShaderDataBinding(s_BlurPipeline,
|
||||
s_BlurVtxFmt, filter.m_blurVbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr);
|
||||
|
||||
bufs[0] = filter.m_uniBufBlurY;
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 2;
|
||||
filter.m_dataBindBlurY = cctx.newShaderDataBinding(s_BlurPipeline,
|
||||
s_BlurVtxFmt, filter.m_blurVbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr);
|
||||
|
||||
bufs[0] = filter.m_uniBuf;
|
||||
size_t texCount;
|
||||
if (filter.m_indTex)
|
||||
{
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 0;
|
||||
texs[1] = filter.m_indTex->GetBooTexture();
|
||||
texBindIdxs[1] = 0;
|
||||
texs[2] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[2] = 1;
|
||||
texs[3] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[3] = 2;
|
||||
texCount = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 0;
|
||||
texs[1] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[1] = 1;
|
||||
texs[2] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[2] = 2;
|
||||
texCount = 3;
|
||||
}
|
||||
|
||||
return cctx.newShaderDataBinding(filter.m_indTex ? s_IndPipeline : s_Pipeline,
|
||||
s_VtxFmt, filter.m_vbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, texCount, texs, texBindIdxs, nullptr);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
TShader<CPhazonSuitFilter>::IDataBindingFactory*
|
||||
CPhazonSuitFilter::Initialize(boo::GLDataFactory::Context& ctx)
|
||||
{
|
||||
const char* uniNames[] = {"PhazonSuitUniform"};
|
||||
const char* texNames[] = {"screenTex", "indTex", "maskTex", "maskTexBlur"};
|
||||
s_IndPipeline = ctx.newShaderPipeline(VS, IndFS, 4, texNames, 1, uniNames, boo::BlendFactor::One,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
texNames[1] = "maskTex";
|
||||
texNames[2] = "maskTexBlur";
|
||||
s_Pipeline = ctx.newShaderPipeline(VS, FS, 3, texNames, 1, uniNames, boo::BlendFactor::One,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
uniNames[0] = "PhazonSuitBlurUniform";
|
||||
texNames[0] = "maskTex";
|
||||
s_BlurPipeline = ctx.newShaderPipeline(BlurVS, BlurFS, 1, texNames, 1, uniNames, boo::BlendFactor::One,
|
||||
boo::BlendFactor::Zero, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, false, true, boo::CullMode::None);
|
||||
return new CPhazonSuitFilterGLDataBindingFactory;
|
||||
}
|
||||
|
||||
#if BOO_HAS_VULKAN
|
||||
TShader<CPhazonSuitFilter>::IDataBindingFactory*
|
||||
CPhazonSuitFilter::Initialize(boo::VulkanDataFactory::Context& ctx)
|
||||
{
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 0},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 1},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 2}
|
||||
};
|
||||
s_VtxFmt = ctx.newVertexFormat(4, VtxVmt);
|
||||
const boo::VertexElementDescriptor BlurVtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
s_BlurVtxFmt = ctx.newVertexFormat(2, BlurVtxVmt);
|
||||
s_IndPipeline = ctx.newShaderPipeline(VS, IndFS, s_VtxFmt, boo::BlendFactor::One,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::One,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_BlurPipeline = ctx.newShaderPipeline(BlurVS, BlurFS, s_BlurVtxFmt, boo::BlendFactor::One,
|
||||
boo::BlendFactor::Zero, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, false, true, boo::CullMode::None);
|
||||
return new CPhazonSuitFilterVulkanDataBindingFactory;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
0
Runtime/Graphics/Shaders/CPhazonSuitFilterHLSL.cpp
Normal file
0
Runtime/Graphics/Shaders/CPhazonSuitFilterHLSL.cpp
Normal file
255
Runtime/Graphics/Shaders/CPhazonSuitFilterMetal.cpp
Normal file
255
Runtime/Graphics/Shaders/CPhazonSuitFilterMetal.cpp
Normal file
@@ -0,0 +1,255 @@
|
||||
#include "CPhazonSuitFilter.hpp"
|
||||
#include "TShader.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 screenUvIn [[ attribute(1) ]];\n"
|
||||
" float4 indUvIn [[ attribute(2) ]];\n"
|
||||
" float4 maskUvIn [[ attribute(3) ]];\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct PhazonSuitUniform\n"
|
||||
"{\n"
|
||||
" float4 color;\n"
|
||||
" float4 indScaleOff;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float4 indScaleOff;\n"
|
||||
" float2 screenUv;\n"
|
||||
" float2 indUv;\n"
|
||||
" float2 maskUv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant PhazonSuitUniform& psu [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" vtf.color = psu.color;\n"
|
||||
" vtf.indScaleOff = psu.indScaleOff;\n"
|
||||
" vtf.screenUv = v.screenUvIn.xy;\n"
|
||||
" vtf.indUv = v.indUvIn.xy;\n"
|
||||
" vtf.maskUv = v.maskUvIn.xy;\n"
|
||||
" vtf.position = float4(v.posIn.xyz, 1.0);\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* IndFS =
|
||||
"#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"
|
||||
" float4 indScaleOff;\n"
|
||||
" float2 screenUv;\n"
|
||||
" float2 indUv;\n"
|
||||
" float2 maskUv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||
" texture2d<float> screenTex [[ texture(0) ]],\n"
|
||||
" texture2d<float> indTex [[ texture(1) ]],\n"
|
||||
" texture2d<float> maskTex [[ texture(2) ]],\n"
|
||||
" texture2d<float> maskTexBlur [[ texture(3) ]])\n"
|
||||
"{\n"
|
||||
" float2 indUv = (indTex.sample(samp, vtf.indUv).rg - float2(0.5, 0.5)) * \n"
|
||||
" vtf.indScaleOff.xy + vtf.indScaleOff.zw;\n"
|
||||
" return vtf.color * screenTex.sample(samp, indUv + vtf.screenUv) * \n"
|
||||
" (maskTexBlur.sample(samp, vtf.maskUv).a - maskTex.sample(samp, vtf.maskUv).a);\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 color;\n"
|
||||
" float4 indScaleOff;\n"
|
||||
" float2 screenUv;\n"
|
||||
" float2 indUv;\n"
|
||||
" float2 maskUv;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||
" texture2d<float> screenTex [[ texture(0) ]],\n"
|
||||
" texture2d<float> maskTex [[ texture(1) ]],\n"
|
||||
" texture2d<float> maskTexBlur [[ texture(2) ]])\n"
|
||||
"{\n"
|
||||
" return vtf.color * screenTex.sample(samp, vtf.screenUv) * \n"
|
||||
" (maskTexBlur.sample(samp, vtf.maskUv).a - maskTex.sample(samp, vtf.maskUv).a);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* BlurVS =
|
||||
"#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 PhazonSuitBlurUniform\n"
|
||||
"{\n"
|
||||
" float4 blurDir;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float2 uv;\n"
|
||||
" float2 blurDir;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant PhazonSuitBlurUniform& psu [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" vtf.uv = uvIn.xy;\n"
|
||||
" vtf.blurDir = blurDir.xy;\n"
|
||||
" vtf.position = float4(posIn.xyz, 1.0);\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* BlurFS =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"constexpr sampler samp(address::repeat, filter::linear);\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float2 uv;\n"
|
||||
" float2 blurDir;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||
" texture2d<float> maskTex [[ texture(0) ]])\n"
|
||||
"{\n"
|
||||
" //this will be our alpha sum\n"
|
||||
" float sum = 0.0;\n"
|
||||
"\n"
|
||||
" //apply blurring, using a 9-tap filter with predefined gaussian weights\n"
|
||||
"\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv - 4.0 * vtf.blurDir).a * 0.0162162162;\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv - 3.0 * vtf.blurDir).a * 0.0540540541;\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv - 2.0 * vtf.blurDir).a * 0.1216216216;\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv - 1.0 * vtf.blurDir).a * 0.1945945946;\n"
|
||||
"\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv).a * 0.2270270270;\n"
|
||||
"\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv - 1.0 * vtf.blurDir).a * 0.1945945946;\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv - 2.0 * vtf.blurDir).a * 0.1216216216;\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv - 3.0 * vtf.blurDir).a * 0.0540540541;\n"
|
||||
" sum += maskTex.sample(samp, vtf.uv - 4.0 * vtf.blurDir).a * 0.0162162162;\n"
|
||||
"\n"
|
||||
" return float4(1.0, 1.0, 1.0, sum);\n"
|
||||
"}\n";
|
||||
|
||||
URDE_DECL_SPECIALIZE_SHADER(CPhazonSuitFilter)
|
||||
|
||||
static boo::IVertexFormat* s_VtxFmt = nullptr;
|
||||
static boo::IVertexFormat* s_BlurVtxFmt = nullptr;
|
||||
static boo::IShaderPipeline* s_IndPipeline = nullptr;
|
||||
static boo::IShaderPipeline* s_Pipeline = nullptr;
|
||||
static boo::IShaderPipeline* s_BlurPipeline = nullptr;
|
||||
|
||||
struct CPhazonSuitFilterMetalDataBindingFactory : TShader<CPhazonSuitFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
CPhazonSuitFilter& filter)
|
||||
{
|
||||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBufBlurX};
|
||||
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
||||
boo::ITexture* texs[4];
|
||||
int texBindIdxs[4];
|
||||
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 1;
|
||||
filter.m_dataBindBlurX = cctx.newShaderDataBinding(s_BlurPipeline,
|
||||
s_BlurVtxFmt, filter.m_blurVbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr);
|
||||
|
||||
bufs[0] = filter.m_uniBufBlurY;
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 2;
|
||||
filter.m_dataBindBlurY = cctx.newShaderDataBinding(s_BlurPipeline,
|
||||
s_BlurVtxFmt, filter.m_blurVbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs, texBindIdxs, nullptr);
|
||||
|
||||
bufs[0] = filter.m_uniBuf;
|
||||
size_t texCount;
|
||||
if (filter.m_indTex)
|
||||
{
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 0;
|
||||
texs[1] = filter.m_indTex->GetBooTexture();
|
||||
texBindIdxs[1] = 0;
|
||||
texs[2] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[2] = 1;
|
||||
texs[3] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[3] = 2;
|
||||
texCount = 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
texs[0] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[0] = 0;
|
||||
texs[1] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[1] = 1;
|
||||
texs[2] = CGraphics::g_SpareTexture;
|
||||
texBindIdxs[2] = 2;
|
||||
texCount = 3;
|
||||
}
|
||||
|
||||
return cctx.newShaderDataBinding(filter.m_indTex ? s_IndPipeline : s_Pipeline,
|
||||
s_VtxFmt, filter.m_vbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, texCount, texs, texBindIdxs, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
TShader<CPhazonSuitFilter>::IDataBindingFactory*
|
||||
CPhazonSuitFilter::Initialize(boo::MetalDataFactory::Context& ctx)
|
||||
{
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 0},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 1},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4, 2}
|
||||
};
|
||||
s_VtxFmt = ctx.newVertexFormat(4, VtxVmt);
|
||||
const boo::VertexElementDescriptor BlurVtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
s_BlurVtxFmt = ctx.newVertexFormat(2, BlurVtxVmt);
|
||||
s_IndPipeline = ctx.newShaderPipeline(VS, IndFS, s_VtxFmt,
|
||||
CGraphics::g_ViewportSamples, boo::BlendFactor::One,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_Pipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt,
|
||||
CGraphics::g_ViewportSamples, boo::BlendFactor::One,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_BlurPipeline = ctx.newShaderPipeline(BlurVS, BlurFS, s_BlurVtxFmt,
|
||||
CGraphics::g_ViewportSamples, boo::BlendFactor::One,
|
||||
boo::BlendFactor::Zero, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, false, true, boo::CullMode::None);
|
||||
return new CPhazonSuitFilterMetalDataBindingFactory;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user