mirror of https://github.com/AxioDL/metaforce.git
Implement CRandomStatic and CScanLines shaders (still need HLSL)
This commit is contained in:
parent
ca69a54faf
commit
6c56cf4c26
|
@ -156,8 +156,10 @@ void CCameraFilterPassPoly::SetFilter(EFilterType type, EFilterShape shape,
|
|||
m_filter = std::make_unique<CCameraFilterPass<CWideScreenFilter>>();
|
||||
break;
|
||||
case EFilterShape::ScanLinesEven:
|
||||
m_filter = std::make_unique<CCameraFilterPass<CScanLinesFilterEven>>();
|
||||
break;
|
||||
case EFilterShape::ScanLinesOdd:
|
||||
m_filter = std::make_unique<CCameraFilterPass<CScanLinesFilter>>();
|
||||
m_filter = std::make_unique<CCameraFilterPass<CScanLinesFilterOdd>>();
|
||||
break;
|
||||
case EFilterShape::RandomStatic:
|
||||
m_filter = std::make_unique<CCameraFilterPass<CRandomStaticFilter>>();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#include "boo/System.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "CBooRenderer.hpp"
|
||||
#include "CTexture.hpp"
|
||||
#include "CModel.hpp"
|
||||
#include "Particle/CParticleGen.hpp"
|
||||
#include "Particle/CGenDescription.hpp"
|
||||
|
@ -611,6 +610,44 @@ void CBooRenderer::GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx
|
|||
SPHERE_RAMP_RES * SPHERE_RAMP_RES);
|
||||
}
|
||||
|
||||
void CBooRenderer::GenerateScanLinesVBO(boo::IGraphicsDataFactory::Context& ctx)
|
||||
{
|
||||
std::vector<zeus::CVector3f> verts;
|
||||
verts.reserve(670);
|
||||
|
||||
for (int i=0 ; i<112 ; ++i)
|
||||
{
|
||||
if (i != 0)
|
||||
verts.push_back(verts.back());
|
||||
verts.push_back(zeus::CVector3f(-1.f, 0.f, (i * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f));
|
||||
verts.push_back(zeus::CVector3f(-1.f, 0.f, (i * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f));
|
||||
verts.push_back(zeus::CVector3f( 1.f, 0.f, (i * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f));
|
||||
verts.push_back(zeus::CVector3f( 1.f, 0.f, (i * (4.f / 448.f) - (1.f / 448.f)) * 2.f - 1.f));
|
||||
if (i != 111)
|
||||
verts.push_back(verts.back());
|
||||
}
|
||||
|
||||
m_scanLinesEvenVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(),
|
||||
sizeof(zeus::CVector3f), verts.size());
|
||||
|
||||
verts.clear();
|
||||
|
||||
for (int i=0 ; i<112 ; ++i)
|
||||
{
|
||||
if (i != 0)
|
||||
verts.push_back(verts.back());
|
||||
verts.push_back(zeus::CVector3f(-1.f, 0.f, (i * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f));
|
||||
verts.push_back(zeus::CVector3f(-1.f, 0.f, (i * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f));
|
||||
verts.push_back(zeus::CVector3f( 1.f, 0.f, (i * (4.f / 448.f) + (3.f / 448.f)) * 2.f - 1.f));
|
||||
verts.push_back(zeus::CVector3f( 1.f, 0.f, (i * (4.f / 448.f) + (1.f / 448.f)) * 2.f - 1.f));
|
||||
if (i != 111)
|
||||
verts.push_back(verts.back());
|
||||
}
|
||||
|
||||
m_scanLinesOddVBO = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts.data(),
|
||||
sizeof(zeus::CVector3f), verts.size());
|
||||
}
|
||||
|
||||
void CBooRenderer::LoadThermoPalette()
|
||||
{
|
||||
m_thermoPaletteTex = xc_store.GetObj("TXTR_ThermoPalette");
|
||||
|
@ -633,11 +670,14 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
|
|||
g_Renderer = this;
|
||||
xee_24_ = true;
|
||||
|
||||
m_staticEntropy = store.GetObj("RandomStaticEntropy");
|
||||
|
||||
m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
||||
{
|
||||
GenerateFogVolumeRampTex(ctx);
|
||||
GenerateSphereRampTex(ctx);
|
||||
m_ballShadowId = ctx.newRenderTexture(m_ballShadowIdW, m_ballShadowIdH, true, false);
|
||||
GenerateScanLinesVBO(ctx);
|
||||
return true;
|
||||
});
|
||||
LoadThermoPalette();
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "Shaders/CFogVolumePlaneShader.hpp"
|
||||
#include "Shaders/CFogVolumeFilter.hpp"
|
||||
#include "Shaders/CPhazonSuitFilter.hpp"
|
||||
#include "CTexture.hpp"
|
||||
#include "CRandom16.hpp"
|
||||
#include "CPVSVisSet.hpp"
|
||||
#include "zeus/CRectangle.hpp"
|
||||
|
@ -93,6 +94,7 @@ class CBooRenderer : public IRenderer
|
|||
|
||||
IFactory& x8_factory;
|
||||
IObjectStore& xc_store;
|
||||
TLockedToken<CTexture> m_staticEntropy;
|
||||
boo::GraphicsDataToken m_gfxToken;
|
||||
// CFont x10_fnt;
|
||||
u32 x18_ = 0;
|
||||
|
@ -125,6 +127,8 @@ class CBooRenderer : public IRenderer
|
|||
TLockedToken<CTexture> m_ballFadeTex;
|
||||
boo::ITexture* m_ballFade = nullptr;
|
||||
boo::ITextureR* m_ballShadowId = nullptr;
|
||||
boo::IGraphicsBufferS* m_scanLinesEvenVBO = nullptr;
|
||||
boo::IGraphicsBufferS* m_scanLinesOddVBO = nullptr;
|
||||
int m_ballShadowIdW = 64;
|
||||
int m_ballShadowIdH = 64;
|
||||
|
||||
|
@ -172,6 +176,7 @@ class CBooRenderer : public IRenderer
|
|||
|
||||
void GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx);
|
||||
void GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx);
|
||||
void GenerateScanLinesVBO(boo::IGraphicsDataFactory::Context& ctx);
|
||||
void LoadThermoPalette();
|
||||
void LoadBallFade();
|
||||
|
||||
|
@ -270,6 +275,9 @@ public:
|
|||
|
||||
boo::ITexture* GetThermoPalette() {return x288_thermoPalette;}
|
||||
boo::ITextureS* GetFogRampTex() {return x1b8_fogVolumeRamp;}
|
||||
boo::ITexture* GetRandomStaticEntropyTex() const {return m_staticEntropy->GetBooTexture();}
|
||||
boo::IGraphicsBuffer* GetScanLinesEvenVBO() const {return m_scanLinesEvenVBO;}
|
||||
boo::IGraphicsBuffer* GetScanLinesOddVBO() const {return m_scanLinesOddVBO;}
|
||||
|
||||
void BindMainDrawTarget() {CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture);}
|
||||
void BindReflectionDrawTarget() {CGraphics::g_BooMainCommandQueue->setRenderTarget(x14c_reflectionTex);}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "CRandomStaticFilter.hpp"
|
||||
#include "Graphics/CBooRenderer.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "CSimplePool.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -13,14 +14,15 @@ CRandomStaticFilter::CRandomStaticFilter(EFilterType type, bool cookieCutter)
|
|||
struct Vert
|
||||
{
|
||||
zeus::CVector2f m_pos;
|
||||
zeus::CVector2f m_uv;
|
||||
} verts[4] =
|
||||
{
|
||||
{{0.0, 0.0}},
|
||||
{{0.0, 1.0}},
|
||||
{{1.0, 0.0}},
|
||||
{{1.0, 1.0}},
|
||||
{{-1.0, -1.0}, {0.0, 0.0}},
|
||||
{{-1.0, 1.0}, {0.0, 448.0}},
|
||||
{{ 1.0, -1.0}, {640.0, 0.0}},
|
||||
{{ 1.0, 1.0}, {640.0, 448.0}},
|
||||
};
|
||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 16, 4);
|
||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, sizeof(Vert), 4);
|
||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
|
||||
m_dataBind = TMultiBlendShader<CRandomStaticFilter>::BuildShaderDataBinding(ctx, type, *this);
|
||||
return true;
|
||||
|
@ -29,7 +31,14 @@ CRandomStaticFilter::CRandomStaticFilter(EFilterType type, bool cookieCutter)
|
|||
|
||||
void CRandomStaticFilter::draw(const zeus::CColor& color, float t)
|
||||
{
|
||||
std::pair<zeus::CVector2f, zeus::CVector2f> rect = g_Renderer->SetViewportOrtho(true, 0.f, 1.f);
|
||||
m_uniform.color = color;
|
||||
m_uniform.randOff = ROUND_UP_32(rand() * 32767 / RAND_MAX);
|
||||
m_uniform.discardThres = 1.f - t;
|
||||
|
||||
m_uniBuf->load(&m_uniform, sizeof(Uniform));
|
||||
|
||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
||||
CGraphics::DrawArray(0, 4);
|
||||
}
|
||||
|
||||
void CRandomStaticFilter::Shutdown() {}
|
||||
|
|
|
@ -19,8 +19,9 @@ class CRandomStaticFilter
|
|||
|
||||
struct Uniform
|
||||
{
|
||||
zeus::CMatrix4f m_matrix;
|
||||
zeus::CColor m_color;
|
||||
zeus::CColor color;
|
||||
float randOff;
|
||||
float discardThres;
|
||||
};
|
||||
boo::GraphicsDataToken m_token;
|
||||
boo::IGraphicsBufferS* m_vbo;
|
||||
|
@ -43,8 +44,8 @@ public:
|
|||
class CCookieCutterDepthRandomStaticFilter : public CRandomStaticFilter
|
||||
{
|
||||
public:
|
||||
CCookieCutterDepthRandomStaticFilter(EFilterType type) :
|
||||
CRandomStaticFilter(type, true) {}
|
||||
CCookieCutterDepthRandomStaticFilter(EFilterType type)
|
||||
: CRandomStaticFilter(type, true) {}
|
||||
CCookieCutterDepthRandomStaticFilter(EFilterType type, const TLockedToken<CTexture>&)
|
||||
: CCookieCutterDepthRandomStaticFilter(type) {}
|
||||
};
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "CRandomStaticFilter.hpp"
|
||||
#include "TMultiBlendShader.hpp"
|
||||
#include "Graphics/CBooRenderer.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -8,23 +10,31 @@ static const char* VS =
|
|||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"layout(location=0) in vec4 posIn;\n"
|
||||
"layout(location=1) in vec4 uvIn;\n"
|
||||
"\n"
|
||||
"UBINDING0 uniform ColoredQuadUniform\n"
|
||||
"UBINDING0 uniform RandomStaticUniform\n"
|
||||
"{\n"
|
||||
" mat4 xf;\n"
|
||||
" vec4 color;\n"
|
||||
" float randOff;\n"
|
||||
" float discardThres;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec2 uv;\n"
|
||||
" float randOff;\n"
|
||||
" float discardThres;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"SBINDING(0) out VertToFrag vtf;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vtf.color = color;\n"
|
||||
" gl_Position = xf * vec4(posIn.xyz, 1.0);\n"
|
||||
" vtf.uv = uvIn.xy;\n"
|
||||
" vtf.randOff = randOff;\n"
|
||||
" vtf.discardThres = discardThres;\n"
|
||||
" gl_Position = vec4(posIn.xyz, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS =
|
||||
|
@ -33,13 +43,65 @@ BOO_GLSL_BINDING_HEAD
|
|||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec2 uv;\n"
|
||||
" float randOff;\n"
|
||||
" float discardThres;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vec2i Lookup8BPP(in vec2 uv, in float randOff)\n"
|
||||
"{\n"
|
||||
" float bx;\n"
|
||||
" float rx = modf(uv.x / 8.0, bx) * 8.0;\n"
|
||||
" float by;\n"
|
||||
" float ry = modf(uv.y / 4.0, by) * 4.0;\n"
|
||||
" float bidx = by * 80.0 + bx;\n"
|
||||
" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n"
|
||||
" float y;\n"
|
||||
" float x = modf(addr / 1024.0, y) * 1024.0;\n"
|
||||
" return vec2i(x, y);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"SBINDING(0) in VertToFrag vtf;\n"
|
||||
"layout(location=0) out vec4 colorOut;\n"
|
||||
"TBINDING0 uniform sampler2D tex;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" colorOut = vtf.color;\n"
|
||||
" colorOut = texelFetch(tex, Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color;\n"
|
||||
" colorOut.a = vtf.color.a;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FSCookieCutter =
|
||||
"#version 330\n"
|
||||
BOO_GLSL_BINDING_HEAD
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" vec4 color;\n"
|
||||
" vec2 uv;\n"
|
||||
" float randOff;\n"
|
||||
" float discardThres;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vec2i Lookup8BPP(in vec2 uv, in float randOff)\n"
|
||||
"{\n"
|
||||
" float bx;\n"
|
||||
" float rx = modf(uv.x / 8.0, bx) * 8.0;\n"
|
||||
" float by;\n"
|
||||
" float ry = modf(uv.y / 4.0, by) * 4.0;\n"
|
||||
" float bidx = by * 80.0 + bx;\n"
|
||||
" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n"
|
||||
" float y;\n"
|
||||
" float x = modf(addr / 1024.0, y) * 1024.0;\n"
|
||||
" return vec2i(x, y);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"SBINDING(0) in VertToFrag vtf;\n"
|
||||
"layout(location=0) out vec4 colorOut;\n"
|
||||
"TBINDING0 uniform sampler2D tex;\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" colorOut = texelFetch(tex, Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color;\n"
|
||||
" if (colorOut.a < vtf.discardThres)\n"
|
||||
" discard;\n"
|
||||
"}\n";
|
||||
|
||||
URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CRandomStaticFilter)
|
||||
|
@ -75,18 +137,20 @@ struct CRandomStaticFilterGLDataBindingFactory : TMultiBlendShader<CRandomStatic
|
|||
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4}
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4},
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
||||
boo::ITexture* texs[] = {g_Renderer->GetRandomStaticEntropyTex()};
|
||||
return cctx.newShaderDataBinding(filter.m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type),
|
||||
ctx.newVertexFormat(1, VtxVmt), filter.m_vbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
||||
ctx.newVertexFormat(2, VtxVmt), filter.m_vbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 1, texs, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
#if BOO_HAS_VULKAN
|
||||
struct CRandomStaticFilterVulkanDataBindingFactory : TMultiBlendShader<CScanLinesFilter>::IDataBindingFactory
|
||||
struct CRandomStaticFilterVulkanDataBindingFactory : TMultiBlendShader<CRandomStaticFilter>::IDataBindingFactory
|
||||
{
|
||||
boo::IShaderDataBinding* BuildShaderDataBinding(boo::IGraphicsDataFactory::Context& ctx,
|
||||
EFilterType type,
|
||||
|
@ -95,9 +159,10 @@ struct CRandomStaticFilterVulkanDataBindingFactory : TMultiBlendShader<CScanLine
|
|||
boo::VulkanDataFactory::Context& cctx = static_cast<boo::VulkanDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {g_Renderer->GetRandomStaticEntropyTex()};
|
||||
return cctx.newShaderDataBinding(filter.m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type),
|
||||
s_VtxFmt, filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
||||
nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
@ -105,16 +170,20 @@ struct CRandomStaticFilterVulkanDataBindingFactory : TMultiBlendShader<CScanLine
|
|||
TMultiBlendShader<CRandomStaticFilter>::IDataBindingFactory*
|
||||
CRandomStaticFilter::Initialize(boo::GLDataFactory::Context& ctx)
|
||||
{
|
||||
const char* uniNames[] = {"ColoredQuadUniform"};
|
||||
s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha,
|
||||
const char* texNames[] = {"tex"};
|
||||
const char* uniNames[] = {"RandomStaticUniform"};
|
||||
s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_AddPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha,
|
||||
s_AddPipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_MultPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcColor,
|
||||
s_MultPipeline = ctx.newShaderPipeline(VS, FS, 1, texNames, 1, uniNames, boo::BlendFactor::SrcColor,
|
||||
boo::BlendFactor::DstColor, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_CookieCutterPipeline = ctx.newShaderPipeline(VS, FSCookieCutter, 1, texNames, 1, uniNames, boo::BlendFactor::SrcColor,
|
||||
boo::BlendFactor::DstColor, boo::Primitive::TriStrips,
|
||||
boo::ZTest::LEqual, true, false, false, boo::CullMode::None);
|
||||
return new CRandomStaticFilterGLDataBindingFactory;
|
||||
}
|
||||
|
||||
|
@ -124,9 +193,10 @@ CRandomStaticFilter::Initialize(boo::VulkanDataFactory::Context& ctx)
|
|||
{
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4}
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
s_VtxFmt = ctx.newVertexFormat(1, VtxVmt);
|
||||
s_VtxFmt = ctx.newVertexFormat(2, VtxVmt);
|
||||
s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
|
@ -136,6 +206,9 @@ CRandomStaticFilter::Initialize(boo::VulkanDataFactory::Context& ctx)
|
|||
s_MultPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, boo::BlendFactor::SrcColor,
|
||||
boo::BlendFactor::DstColor, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_CookieCutterPipeline = ctx.newShaderPipeline(VS, FSCookieCutter, s_VtxFmt, boo::BlendFactor::SrcColor,
|
||||
boo::BlendFactor::DstColor, boo::Primitive::TriStrips,
|
||||
boo::ZTest::LEqual, true, false, false, boo::CullMode::None);
|
||||
return new CRandomStaticFilterVulkanDataBindingFactory;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "CRandomStaticFilter.hpp"
|
||||
#include "TMultiBlendShader.hpp"
|
||||
#include "Graphics/CBooRenderer.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -10,25 +12,34 @@ static const char* VS =
|
|||
"struct VertData\n"
|
||||
"{\n"
|
||||
" float4 posIn [[ attribute(0) ]];\n"
|
||||
" float2 uvIn [[ attribute(1) ]];\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct ColoredQuadUniform\n"
|
||||
"struct RandomStaticUniform\n"
|
||||
"{\n"
|
||||
" float4x4 xf;\n"
|
||||
" float4 color;\n"
|
||||
" float randOff;\n"
|
||||
" float discardThres;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 pos [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float2 uv;\n"
|
||||
" float randOff;\n"
|
||||
" float discardThres;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ColoredQuadUniform& cqu [[ buffer(2) ]])\n"
|
||||
"vertex VertToFrag vmain(VertData v [[ stage_in ]],\n"
|
||||
" constant RandomStaticUniform& su [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" vtf.color = cqu.color;\n"
|
||||
" vtf.position = cqu.xf * float4(v.posIn.xyz, 1.0);\n"
|
||||
" vtf.color = su.color;\n"
|
||||
" vtf.uv = v.uvIn.xy;\n"
|
||||
" vtf.randOff = su.randOff;\n"
|
||||
" vtf.discardThres = su.discardThres;\n"
|
||||
" vtf.pos = float4(v.posIn.xyz, 1.0);\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
|
@ -37,13 +48,66 @@ static const char* FS =
|
|||
"using namespace metal;\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 position [[ position ]];\n"
|
||||
" float4 pos [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float2 uv;\n"
|
||||
" float randOff;\n"
|
||||
" float discardThres;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]])\n"
|
||||
"static uint2 Lookup8BPP(float2 uv, float randOff)\n"
|
||||
"{\n"
|
||||
" return vtf.color;\n"
|
||||
" float bx;\n"
|
||||
" float rx = modf(uv.x / 8.0, bx) * 8.0;\n"
|
||||
" float by;\n"
|
||||
" float ry = modf(uv.y / 4.0, by) * 4.0;\n"
|
||||
" float bidx = by * 80.0 + bx;\n"
|
||||
" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n"
|
||||
" float y;\n"
|
||||
" float x = modf(addr / 1024.0, y) * 1024.0;\n"
|
||||
" return uint2(x, y);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||
" texture2d<float> tex [[ texture(0) ]])\n"
|
||||
"{\n"
|
||||
" float4 colorOut = tex.read(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color;\n"
|
||||
" colorOut.a = vtf.color.a;\n"
|
||||
" return colorOut;\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FSCookieCutter =
|
||||
"#include <metal_stdlib>\n"
|
||||
"using namespace metal;\n"
|
||||
"struct VertToFrag\n"
|
||||
"{\n"
|
||||
" float4 pos [[ position ]];\n"
|
||||
" float4 color;\n"
|
||||
" float2 uv;\n"
|
||||
" float randOff;\n"
|
||||
" float discardThres;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"static uint2 Lookup8BPP(float2 uv, float randOff)\n"
|
||||
"{\n"
|
||||
" float bx;\n"
|
||||
" float rx = modf(uv.x / 8.0, bx) * 8.0;\n"
|
||||
" float by;\n"
|
||||
" float ry = modf(uv.y / 4.0, by) * 4.0;\n"
|
||||
" float bidx = by * 80.0 + bx;\n"
|
||||
" float addr = bidx * 32.0 + ry * 8.0 + rx + randOff;\n"
|
||||
" float y;\n"
|
||||
" float x = modf(addr / 1024.0, y) * 1024.0;\n"
|
||||
" return uint2(x, y);\n"
|
||||
"}\n"
|
||||
"\n"
|
||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n"
|
||||
" texture2d<float> tex [[ texture(0) ]])\n"
|
||||
"{\n"
|
||||
" float4 colorOut = tex.read(Lookup8BPP(vtf.uv, vtf.randOff)) * vtf.color;\n"
|
||||
" if (colorOut.a < vtf.discardThres)\n"
|
||||
" discard_fragment();\n"
|
||||
" return colorOut;\n"
|
||||
"}\n";
|
||||
|
||||
URDE_DECL_SPECIALIZE_MULTI_BLEND_SHADER(CRandomStaticFilter)
|
||||
|
@ -78,9 +142,10 @@ struct CRandomStaticFilterMetalDataBindingFactory : TMultiBlendShader<CRandomSta
|
|||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::ITexture* texs[] = {g_Renderer->GetRandomStaticEntropyTex()};
|
||||
return cctx.newShaderDataBinding(filter.m_cookieCutter ? s_CookieCutterPipeline : SelectPipeline(type),
|
||||
s_VtxFmt, filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
||||
nullptr, nullptr, nullptr, 1, texs, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -89,18 +154,26 @@ CRandomStaticFilter::Initialize(boo::MetalDataFactory::Context& ctx)
|
|||
{
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4}
|
||||
{nullptr, nullptr, boo::VertexSemantic::Position4},
|
||||
{nullptr, nullptr, boo::VertexSemantic::UV4}
|
||||
};
|
||||
s_VtxFmt = ctx.newVertexFormat(1, VtxVmt);
|
||||
s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha,
|
||||
s_VtxFmt = ctx.newVertexFormat(2, VtxVmt);
|
||||
s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, true, boo::CullMode::None);
|
||||
s_AddPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcAlpha,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_AddPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::One, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, true, boo::CullMode::None);
|
||||
s_MultPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples, boo::BlendFactor::SrcColor,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_MultPipeline = ctx.newShaderPipeline(VS, FS, s_VtxFmt, CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcColor,
|
||||
boo::BlendFactor::DstColor, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, true, boo::CullMode::None);
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
s_CookieCutterPipeline = ctx.newShaderPipeline(VS, FSCookieCutter, s_VtxFmt, CGraphics::g_ViewportSamples,
|
||||
boo::BlendFactor::SrcColor,
|
||||
boo::BlendFactor::DstColor, boo::Primitive::TriStrips,
|
||||
boo::ZTest::LEqual, true, false, false, boo::CullMode::None);
|
||||
return new CRandomStaticFilterMetalDataBindingFactory;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,30 +3,24 @@
|
|||
namespace urde
|
||||
{
|
||||
|
||||
CScanLinesFilter::CScanLinesFilter(EFilterType type)
|
||||
CScanLinesFilter::CScanLinesFilter(EFilterType type, bool even)
|
||||
: m_even(even)
|
||||
{
|
||||
m_token = CGraphics::g_BooFactory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
||||
{
|
||||
struct Vert
|
||||
{
|
||||
zeus::CVector2f m_pos;
|
||||
} verts[4] =
|
||||
{
|
||||
{{0.0, 0.0}},
|
||||
{{0.0, 1.0}},
|
||||
{{1.0, 0.0}},
|
||||
{{1.0, 1.0}},
|
||||
};
|
||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 16, 4);
|
||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
|
||||
m_dataBind = TMultiBlendShader<CScanLinesFilter>::BuildShaderDataBinding(ctx, type, *this);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
void CScanLinesFilter::DrawFilter(EFilterShape shape, const zeus::CColor& color, float t)
|
||||
void CScanLinesFilter::draw(const zeus::CColor& color)
|
||||
{
|
||||
m_uniform.color = color;
|
||||
m_uniBuf->load(&m_uniform, sizeof(Uniform));
|
||||
|
||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
||||
CGraphics::DrawArray(0, 670);
|
||||
}
|
||||
|
||||
void CScanLinesFilter::Shutdown() {}
|
||||
|
|
|
@ -19,25 +19,41 @@ class CScanLinesFilter
|
|||
|
||||
struct Uniform
|
||||
{
|
||||
zeus::CMatrix4f m_matrix;
|
||||
zeus::CColor m_color;
|
||||
zeus::CColor color;
|
||||
};
|
||||
boo::GraphicsDataToken m_token;
|
||||
boo::IGraphicsBufferS* m_vbo;
|
||||
boo::IGraphicsBufferD* m_uniBuf;
|
||||
boo::IShaderDataBinding* m_dataBind = nullptr;
|
||||
Uniform m_uniform;
|
||||
bool m_even;
|
||||
|
||||
public:
|
||||
CScanLinesFilter(EFilterType type);
|
||||
CScanLinesFilter(EFilterType type, const TLockedToken<CTexture>&)
|
||||
: CScanLinesFilter(type) {}
|
||||
void DrawFilter(EFilterShape shape, const zeus::CColor& color, float t);
|
||||
CScanLinesFilter(EFilterType type, bool even);
|
||||
void draw(const zeus::CColor& color);
|
||||
void DrawFilter(EFilterShape, const zeus::CColor& color, float) { draw(color); }
|
||||
|
||||
using _CLS = CScanLinesFilter;
|
||||
#include "TMultiBlendShaderDecl.hpp"
|
||||
};
|
||||
|
||||
class CScanLinesFilterEven : public CScanLinesFilter
|
||||
{
|
||||
public:
|
||||
CScanLinesFilterEven(EFilterType type)
|
||||
: CScanLinesFilter(type, true) {}
|
||||
CScanLinesFilterEven(EFilterType type, const TLockedToken<CTexture>&)
|
||||
: CScanLinesFilterEven(type) {}
|
||||
};
|
||||
|
||||
class CScanLinesFilterOdd : public CScanLinesFilter
|
||||
{
|
||||
public:
|
||||
CScanLinesFilterOdd(EFilterType type)
|
||||
: CScanLinesFilter(type, false) {}
|
||||
CScanLinesFilterOdd(EFilterType type, const TLockedToken<CTexture>&)
|
||||
: CScanLinesFilterOdd(type) {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // __URDE_CSCANLINESFILTER_HPP__
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "CScanLinesFilter.hpp"
|
||||
#include "TMultiBlendShader.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "Graphics/CBooRenderer.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -9,9 +11,8 @@ static const char* VS =
|
|||
BOO_GLSL_BINDING_HEAD
|
||||
"layout(location=0) in vec4 posIn;\n"
|
||||
"\n"
|
||||
"UBINDING0 uniform ColoredQuadUniform\n"
|
||||
"UBINDING0 uniform ScanLinesUniform\n"
|
||||
"{\n"
|
||||
" mat4 xf;\n"
|
||||
" vec4 color;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
|
@ -24,7 +25,7 @@ BOO_GLSL_BINDING_HEAD
|
|||
"void main()\n"
|
||||
"{\n"
|
||||
" vtf.color = color;\n"
|
||||
" gl_Position = xf * vec4(posIn.xyz, 1.0);\n"
|
||||
" gl_Position = vec4(posIn.xyz, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char* FS =
|
||||
|
@ -72,14 +73,16 @@ struct CScanLinesFilterGLDataBindingFactory : TMultiBlendShader<CScanLinesFilter
|
|||
{
|
||||
boo::GLDataFactory::Context& cctx = static_cast<boo::GLDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* vbo = filter.m_even ?
|
||||
g_Renderer->GetScanLinesEvenVBO() : g_Renderer->GetScanLinesOddVBO();
|
||||
const boo::VertexElementDescriptor VtxVmt[] =
|
||||
{
|
||||
{filter.m_vbo, nullptr, boo::VertexSemantic::Position4}
|
||||
{vbo, nullptr, boo::VertexSemantic::Position4}
|
||||
};
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
||||
return cctx.newShaderDataBinding(SelectPipeline(type),
|
||||
ctx.newVertexFormat(1, VtxVmt), filter.m_vbo, nullptr, nullptr,
|
||||
ctx.newVertexFormat(1, VtxVmt), vbo, nullptr, nullptr,
|
||||
1, bufs, stages, nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
|
@ -93,9 +96,11 @@ struct CScanLinesFilterVulkanDataBindingFactory : TMultiBlendShader<CScanLinesFi
|
|||
{
|
||||
boo::VulkanDataFactory::Context& cctx = static_cast<boo::VulkanDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* vbo = filter.m_even ?
|
||||
g_Renderer->GetScanLinesEvenVBO() : g_Renderer->GetScanLinesOddVBO();
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
return cctx.newShaderDataBinding(SelectPipeline(type), s_VtxFmt,
|
||||
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
|
@ -104,7 +109,7 @@ struct CScanLinesFilterVulkanDataBindingFactory : TMultiBlendShader<CScanLinesFi
|
|||
TMultiBlendShader<CScanLinesFilter>::IDataBindingFactory*
|
||||
CScanLinesFilter::Initialize(boo::GLDataFactory::Context& ctx)
|
||||
{
|
||||
const char* uniNames[] = {"ColoredQuadUniform"};
|
||||
const char* uniNames[] = {"ScanLinesUniform"};
|
||||
s_AlphaPipeline = ctx.newShaderPipeline(VS, FS, 0, nullptr, 1, uniNames, boo::BlendFactor::SrcAlpha,
|
||||
boo::BlendFactor::InvSrcAlpha, boo::Primitive::TriStrips,
|
||||
boo::ZTest::None, false, true, false, boo::CullMode::None);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "CScanLinesFilter.hpp"
|
||||
#include "TMultiBlendShader.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
#include "Graphics/CBooRenderer.hpp"
|
||||
|
||||
namespace urde
|
||||
{
|
||||
|
@ -12,9 +14,8 @@ static const char* VS =
|
|||
" float4 posIn [[ attribute(0) ]];\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct ColoredQuadUniform\n"
|
||||
"struct ScanLinesUniform\n"
|
||||
"{\n"
|
||||
" float4x4 xf;\n"
|
||||
" float4 color;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
|
@ -24,11 +25,11 @@ static const char* VS =
|
|||
" float4 color;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ColoredQuadUniform& cqu [[ buffer(2) ]])\n"
|
||||
"vertex VertToFrag vmain(VertData v [[ stage_in ]], constant ScanLinesUniform& cqu [[ buffer(2) ]])\n"
|
||||
"{\n"
|
||||
" VertToFrag vtf;\n"
|
||||
" vtf.color = cqu.color;\n"
|
||||
" vtf.position = cqu.xf * float4(v.posIn.xyz, 1.0);\n"
|
||||
" vtf.position = float4(v.posIn.xyz, 1.0);\n"
|
||||
" return vtf;\n"
|
||||
"}\n";
|
||||
|
||||
|
@ -76,9 +77,11 @@ struct CScanLinesFilterMetalDataBindingFactory : TMultiBlendShader<CScanLinesFil
|
|||
{
|
||||
boo::MetalDataFactory::Context& cctx = static_cast<boo::MetalDataFactory::Context&>(ctx);
|
||||
|
||||
boo::IGraphicsBuffer* vbo = filter.m_even ?
|
||||
g_Renderer->GetScanLinesEvenVBO() : g_Renderer->GetScanLinesOddVBO();
|
||||
boo::IGraphicsBuffer* bufs[] = {filter.m_uniBuf};
|
||||
return cctx.newShaderDataBinding(SelectPipeline(type), s_VtxFmt,
|
||||
filter.m_vbo, nullptr, nullptr, 1, bufs,
|
||||
vbo, nullptr, nullptr, 1, bufs,
|
||||
nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -109,7 +109,7 @@ void CPauseScreenBlur::Draw(const CStateManager&) const
|
|||
const_cast<CTexturedQuadFilter&>(m_quarterFilter).DrawFilter(EFilterShape::FullscreenQuarters, filterColor, t);
|
||||
zeus::CColor scanLinesColor =
|
||||
zeus::CColor::lerp(zeus::CColor::skWhite, zeus::CColor(0.75f, 1.f), t);
|
||||
const_cast<CScanLinesFilter&>(m_linesFilter).DrawFilter(EFilterShape::ScanLinesEven, scanLinesColor, t);
|
||||
const_cast<CScanLinesFilterEven&>(m_linesFilter).draw(scanLinesColor);
|
||||
}
|
||||
|
||||
if (x50_24_blurring /*&& x1c_camBlur.x2d_noPersistentCopy*/)
|
||||
|
|
|
@ -32,7 +32,7 @@ class CPauseScreenBlur
|
|||
float x18_blurAmt = 0.f;
|
||||
CCameraBlurPass x1c_camBlur;
|
||||
CTexturedQuadFilter m_quarterFilter = { EFilterType::Multiply, x4_mapLightQuarter };
|
||||
CScanLinesFilter m_linesFilter = { EFilterType::Multiply };
|
||||
CScanLinesFilterEven m_linesFilter = { EFilterType::Multiply };
|
||||
|
||||
union
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue