mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-10 00:27:43 +00:00
zeus constexpr refactor and thermal visor fixes
This commit is contained in:
@@ -7,7 +7,7 @@ namespace urde {
|
||||
std::unordered_map<uint64_t, CModelShaders::ShaderPipelines> CModelShaders::g_ShaderPipelines;
|
||||
|
||||
void CModelShaders::LightingUniform::ActivateLights(const std::vector<CLight>& lts) {
|
||||
ambient = zeus::CColor::skClear;
|
||||
ambient = zeus::skClear;
|
||||
size_t curLight = 0;
|
||||
|
||||
for (const CLight& light : lts) {
|
||||
@@ -42,9 +42,9 @@ void CModelShaders::LightingUniform::ActivateLights(const std::vector<CLight>& l
|
||||
|
||||
for (; curLight < URDE_MAX_LIGHTS; ++curLight) {
|
||||
CModelShaders::Light& lightOut = lights[curLight];
|
||||
lightOut.pos = zeus::CVector3f::skZero;
|
||||
lightOut.dir = zeus::CVector3f::skDown;
|
||||
lightOut.color = zeus::CColor::skClear;
|
||||
lightOut.pos = zeus::skZero3f;
|
||||
lightOut.dir = zeus::skDown;
|
||||
lightOut.color = zeus::skClear;
|
||||
lightOut.linAtt[0] = 1.f;
|
||||
lightOut.linAtt[1] = 0.f;
|
||||
lightOut.linAtt[2] = 0.f;
|
||||
@@ -144,7 +144,11 @@ static hecl::Backend::ExtensionSlot g_ExtensionSlots[] = {
|
||||
false, true, false, false, true},
|
||||
/* Forced additive shading without culling or Z-write and greater depth test */
|
||||
{1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::SrcAlpha, hecl::Backend::BlendFactor::One,
|
||||
hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true}};
|
||||
hecl::Backend::ZTest::Greater, hecl::Backend::CullMode::None, true, false, true},
|
||||
/* Thermal cold shading */
|
||||
{1, BlockNames, 0, nullptr, hecl::Backend::BlendFactor::Original, hecl::Backend::BlendFactor::Original,
|
||||
hecl::Backend::ZTest::Original, hecl::Backend::CullMode::Original,
|
||||
false, false, true, false, false, false, true}};
|
||||
|
||||
extern const hecl::Backend::Function ExtensionLightingFuncsGLSL[];
|
||||
extern const hecl::Backend::Function ExtensionPostFuncsGLSL[];
|
||||
|
||||
@@ -35,6 +35,7 @@ enum EExtendedShader : uint8_t {
|
||||
DepthGEqualNoZWrite,
|
||||
Disintegrate,
|
||||
ForcedAdditiveNoZWriteDepthGreater,
|
||||
ThermalCold,
|
||||
MAX
|
||||
};
|
||||
|
||||
@@ -45,7 +46,7 @@ public:
|
||||
struct Light {
|
||||
zeus::CVector3f pos;
|
||||
zeus::CVector3f dir;
|
||||
zeus::CColor color = zeus::CColor::skClear;
|
||||
zeus::CColor color = zeus::skClear;
|
||||
float linAtt[4] = {1.f, 0.f, 0.f};
|
||||
float angAtt[4] = {1.f, 0.f, 0.f};
|
||||
};
|
||||
|
||||
@@ -173,7 +173,7 @@ static std::string_view ThermalPostGLSL =
|
||||
"};\n"
|
||||
"vec4 ThermalPostFunc(vec4 colorIn)\n"
|
||||
"{\n"
|
||||
" return vec4(texture(extTex7, vtf.extTcgs[0]).rrr * tmulColor.rgb + taddColor.rgb, tmulColor.a + taddColor.a);\n"
|
||||
" return texture(extTex7, vtf.extTcgs[0]).rrrr * tmulColor + taddColor;\n"
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
@@ -221,6 +221,13 @@ static std::string_view DisintegratePostGLSL = FOG_STRUCT_GLSL
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
static std::string_view ThermalColdPostGLSL =
|
||||
"vec4 ThermalColdPostFunc(vec4 colorIn)\n"
|
||||
"{\n"
|
||||
" return colorIn * vec4(0.75);\n"
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
const hecl::Backend::Function ExtensionLightingFuncsGLSL[] = {
|
||||
{},
|
||||
{LightingGLSL, "LightingFunc"},
|
||||
@@ -244,6 +251,7 @@ const hecl::Backend::Function ExtensionLightingFuncsGLSL[] = {
|
||||
{LightingGLSL, "LightingFunc"},
|
||||
{},
|
||||
{LightingGLSL, "LightingFunc"},
|
||||
{},
|
||||
};
|
||||
|
||||
const hecl::Backend::Function ExtensionPostFuncsGLSL[] = {
|
||||
@@ -269,6 +277,7 @@ const hecl::Backend::Function ExtensionPostFuncsGLSL[] = {
|
||||
{MainPostGLSL, "MainPostFunc"},
|
||||
{DisintegratePostGLSL, "DisintegratePostFunc"},
|
||||
{MainPostGLSL, "MainPostFunc"},
|
||||
{ThermalColdPostGLSL, "ThermalColdPostFunc"},
|
||||
};
|
||||
|
||||
} // namespace urde
|
||||
|
||||
@@ -166,8 +166,7 @@ static std::string_view ThermalPostHLSL =
|
||||
"};\n"
|
||||
"static float4 ThermalPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
||||
"{\n"
|
||||
" return float4(extTex7.Sample(samp, vtf.extTcgs[0]).rrr * tmulColor.rgb + taddColor.rgb, tmulColor.a + "
|
||||
"taddColor.a);\n"
|
||||
" return extTex7.Sample(samp, vtf.extTcgs[0]).rrrr * tmulColor + taddColor;\n"
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
@@ -215,6 +214,13 @@ static std::string_view DisintegratePostHLSL = FOG_STRUCT_HLSL
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
static std::string_view ThermalColdPostHLSL =
|
||||
"static float4 ThermalColdPostFunc(in VertToFrag vtf, float4 colorIn)\n"
|
||||
"{\n"
|
||||
" return colorIn * float4(0.75, 0.75, 0.75, 0.75);\n"
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = {{},
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{},
|
||||
@@ -236,7 +242,8 @@ const hecl::Backend::Function ExtensionLightingFuncsHLSL[] = {{},
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{},
|
||||
{LightingHLSL, "LightingFunc"}};
|
||||
{LightingHLSL, "LightingFunc"},
|
||||
{}};
|
||||
|
||||
const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
|
||||
{},
|
||||
@@ -261,6 +268,7 @@ const hecl::Backend::Function ExtensionPostFuncsHLSL[] = {
|
||||
{MainPostHLSL, "MainPostFunc"},
|
||||
{DisintegratePostHLSL, "DisintegratePostFunc"},
|
||||
{MainPostHLSL, "MainPostFunc"},
|
||||
{ThermalColdPostHLSL, "ThermalColdPostFunc"},
|
||||
};
|
||||
|
||||
} // namespace urde
|
||||
|
||||
@@ -168,9 +168,7 @@ static std::string_view ThermalPostMetal =
|
||||
"static float4 EXTThermalPostFunc(thread VertToFrag& vtf, constant ThermalUniform& lu,\n"
|
||||
" sampler samp, sampler clampSamp, texture2d<float> extTex7, float4 colorIn)\n"
|
||||
"{\n"
|
||||
" //return float4(vtf.extTcgs0.xy, 0.0, 1.0);\n"
|
||||
" return float4(extTex7.sample(samp, vtf.extTcgs0).rrr * lu.tmulColor.rgb + lu.taddColor.rgb,\n"
|
||||
" lu.tmulColor.a + lu.taddColor.a);\n"
|
||||
" return extTex7.sample(samp, vtf.extTcgs0).rrrr * lu.tmulColor + lu.taddColor;\n"
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
@@ -221,6 +219,13 @@ static std::string_view DisintegratePostMetal = FOG_STRUCT_METAL
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
static std::string_view ThermalColdPostMetal =
|
||||
"static float4 ThermalColdPostFunc(thread VertToFrag& vtf, constant LightingUniform& lu, float4 colorIn)\n"
|
||||
"{\n"
|
||||
" return colorIn * float4(0.75, 0.75, 0.75, 0.75);\n"
|
||||
"}\n"
|
||||
"\n"sv;
|
||||
|
||||
const hecl::Backend::Function ExtensionLightingFuncsMetal[] = {{},
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{},
|
||||
@@ -242,7 +247,8 @@ const hecl::Backend::Function ExtensionLightingFuncsMetal[] = {{},
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{},
|
||||
{LightingMetal, "LightingFunc"}};
|
||||
{LightingMetal, "LightingFunc"},
|
||||
{}};
|
||||
|
||||
const hecl::Backend::Function ExtensionPostFuncsMetal[] = {
|
||||
{},
|
||||
@@ -267,6 +273,7 @@ const hecl::Backend::Function ExtensionPostFuncsMetal[] = {
|
||||
{MainPostMetal, "MainPostFunc"},
|
||||
{DisintegratePostMetal, "EXTDisintegratePostFunc"},
|
||||
{MainPostMetal, "MainPostFunc"},
|
||||
{ThermalColdPostMetal, "ThermalColdPostFunc"},
|
||||
};
|
||||
|
||||
} // namespace urde
|
||||
|
||||
@@ -260,7 +260,7 @@ void CTexturedQuadFilter::drawVerts(const zeus::CColor& color, const Vert verts[
|
||||
}
|
||||
|
||||
void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& color, float t) {
|
||||
m_uniform.m_matrix = zeus::CMatrix4f::skIdentityMatrix4f;
|
||||
m_uniform.m_matrix = zeus::CMatrix4f();
|
||||
m_uniform.m_lod = 0.f;
|
||||
m_uniform.m_color = color;
|
||||
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#include "CThermalColdFilter.hpp"
|
||||
#include "Graphics/CGraphics.hpp"
|
||||
#include "Graphics/CBooRenderer.hpp"
|
||||
#include "hecl/Pipeline.hpp"
|
||||
#include "GameGlobalObjects.hpp"
|
||||
|
||||
namespace urde {
|
||||
|
||||
@@ -12,58 +14,34 @@ void CThermalColdFilter::Shutdown() { s_Pipeline.reset(); }
|
||||
|
||||
CThermalColdFilter::CThermalColdFilter() {
|
||||
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
|
||||
m_shiftTex = ctx.newDynamicTexture(8, 4, boo::TextureFormat::RGBA8, boo::TextureClampMode::Repeat);
|
||||
|
||||
struct Vert {
|
||||
zeus::CVector2f m_pos;
|
||||
zeus::CVector2f m_uv;
|
||||
zeus::CVector2f m_uvNoise;
|
||||
} verts[4] = {
|
||||
{{-1.f, -1.f}, {0.f, 0.f}},
|
||||
{{-1.f, 1.f}, {0.f, 1.f}},
|
||||
{{1.f, -1.f}, {1.f, 0.f}},
|
||||
{{1.f, 1.f}, {1.f, 1.f}},
|
||||
{{-1.f, -1.f}, {0.f, 0.f}, {0.f, 0.f}},
|
||||
{{-1.f, 1.f}, {0.f, 1.f}, {0.f, 448.f}},
|
||||
{{1.f, -1.f}, {1.f, 0.f}, {640.f, 0.f}},
|
||||
{{1.f, 1.f}, {1.f, 1.f}, {640.f, 448.f}},
|
||||
};
|
||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 32, 4);
|
||||
m_vbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, verts, 48, 4);
|
||||
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
|
||||
boo::ObjToken<boo::IGraphicsBuffer> bufs[] = {m_uniBuf.get()};
|
||||
boo::PipelineStage stages[] = {boo::PipelineStage::Vertex};
|
||||
boo::ObjToken<boo::ITexture> texs[] = {CGraphics::g_SpareTexture.get(), m_shiftTex.get()};
|
||||
boo::ObjToken<boo::ITexture> texs[] = {CGraphics::g_SpareTexture.get(),
|
||||
g_Renderer->GetRandomStaticEntropyTex()};
|
||||
m_dataBind = ctx.newShaderDataBinding(s_Pipeline, m_vbo.get(), nullptr, nullptr, 1, bufs, stages, nullptr, nullptr,
|
||||
2, texs, nullptr, nullptr);
|
||||
return true;
|
||||
} BooTrace);
|
||||
|
||||
setShift(0);
|
||||
setNoiseOffset(0);
|
||||
setScale(0.f);
|
||||
}
|
||||
|
||||
void CThermalColdFilter::setShift(unsigned shift) {
|
||||
shift = std::min(shift, 31u);
|
||||
for (unsigned y = 0; y < 4; ++y) {
|
||||
unsigned bx = y * 8;
|
||||
for (unsigned x = 0; x < 8; ++x) {
|
||||
unsigned px = bx + x;
|
||||
unsigned spx = px + shift;
|
||||
unsigned ny = spx / 8;
|
||||
if (ny > 3)
|
||||
ny = 3;
|
||||
unsigned nx = spx % 8;
|
||||
m_shiftTexture[y][x][0] = u8(nx * 255 / 7);
|
||||
m_shiftTexture[y][x][1] = u8(ny * 255 / 3);
|
||||
}
|
||||
}
|
||||
m_shiftTex->load(m_shiftTexture[0][0], sizeof(m_shiftTexture));
|
||||
}
|
||||
|
||||
void CThermalColdFilter::draw() {
|
||||
CGraphics::ResolveSpareTexture(CGraphics::g_CroppedViewport);
|
||||
|
||||
m_uniform.m_shiftTexMtx[0][0] = 80.f * (CGraphics::g_ProjAspect / 1.33f);
|
||||
m_uniform.m_shiftTexMtx[1][1] = 120.f;
|
||||
m_uniform.m_shiftTexScale[0] = 1.f / m_uniform.m_shiftTexMtx[0][0];
|
||||
m_uniform.m_shiftTexScale[1] = 1.f / m_uniform.m_shiftTexMtx[1][1];
|
||||
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
||||
|
||||
CGraphics::SetShaderDataBinding(m_dataBind);
|
||||
CGraphics::DrawArray(0, 4);
|
||||
}
|
||||
|
||||
@@ -9,13 +9,10 @@ namespace urde {
|
||||
|
||||
class CThermalColdFilter {
|
||||
struct Uniform {
|
||||
zeus::CMatrix4f m_shiftTexMtx;
|
||||
zeus::CMatrix4f m_indMtx;
|
||||
zeus::CVector2f m_shiftTexScale;
|
||||
zeus::CColor m_colorRegs[3];
|
||||
float m_randOff = 0.f;
|
||||
};
|
||||
u8 m_shiftTexture[4][8][4] = {};
|
||||
boo::ObjToken<boo::ITextureD> m_shiftTex;
|
||||
boo::ObjToken<boo::IGraphicsBufferS> m_vbo;
|
||||
boo::ObjToken<boo::IGraphicsBufferD> m_uniBuf;
|
||||
boo::ObjToken<boo::IShaderDataBinding> m_dataBind;
|
||||
@@ -25,7 +22,7 @@ public:
|
||||
static void Initialize();
|
||||
static void Shutdown();
|
||||
CThermalColdFilter();
|
||||
void setShift(unsigned shift);
|
||||
void setNoiseOffset(unsigned shift) { m_uniform.m_randOff = float(shift); }
|
||||
void setColorA(const zeus::CColor& color) { m_uniform.m_colorRegs[0] = color; }
|
||||
void setColorB(const zeus::CColor& color) { m_uniform.m_colorRegs[1] = color; }
|
||||
void setColorC(const zeus::CColor& color) { m_uniform.m_colorRegs[2] = color; }
|
||||
|
||||
@@ -40,7 +40,7 @@ void CWorldShadowShader::drawBase(float extent) {
|
||||
m_vbo->load(verts, sizeof(zeus::CVector3f) * 4);
|
||||
|
||||
m_uniform.m_matrix = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
|
||||
m_uniform.m_color = zeus::CColor::skWhite;
|
||||
m_uniform.m_color = zeus::skWhite;
|
||||
m_uniBuf->load(&m_uniform, sizeof(m_uniform));
|
||||
|
||||
CGraphics::SetShaderDataBinding(m_zDataBind);
|
||||
|
||||
Reference in New Issue
Block a user