2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-05 17:15:52 +00:00

CAABoxShader: Convert to hsh pipeline

This commit is contained in:
Luke Street 2020-09-29 00:58:21 -04:00
parent f4f840cb17
commit fc9e18fe46
6 changed files with 58 additions and 57 deletions

View File

@ -1,55 +1,57 @@
#include "Runtime/Graphics/Shaders/CAABoxShader.hpp"
#include <array>
#include "Runtime/Graphics/CGraphics.hpp"
#include <hecl/Pipeline.hpp>
#include <zeus/CAABox.hpp>
#include "Runtime/Graphics/CGraphics.hpp"
#include "CAABoxShader.cpp.hshhead"
namespace urde {
using namespace hsh::pipeline;
CAABoxShader::CAABoxShader(bool zOnly) {
CGraphics::CommitResources([this, zOnly](boo::IGraphicsDataFactory::Context& ctx) {
m_vbo = ctx.newDynamicBuffer(boo::BufferUse::Vertex, sizeof(zeus::CVector3f), 34);
m_uniBuf = ctx.newDynamicBuffer(boo::BufferUse::Uniform, sizeof(Uniform), 1);
const std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> bufs{m_uniBuf.get()};
constexpr std::array<boo::PipelineStage, 1> stages{boo::PipelineStage::Vertex};
m_dataBind =
ctx.newShaderDataBinding(zOnly ? s_zOnlyPipeline : s_Pipeline, m_vbo.get(), nullptr, nullptr, bufs.size(),
bufs.data(), stages.data(), nullptr, nullptr, 0, nullptr, nullptr, nullptr);
return true;
} BooTrace);
}
template <bool zOnly>
struct CAABoxShaderPipeline
: pipeline<topology<hsh::TriangleStrip>, std::conditional_t<zOnly, NoColorAttachment<>, BlendAttachment<>>,
depth_compare<hsh::LEqual>, depth_write<true>, cull_mode<hsh::CullNone>> {
CAABoxShaderPipeline(hsh::vertex_buffer<CAABoxShader::Vert> vbo, hsh::uniform_buffer<CAABoxShader::Uniform> uniBuf) {
this->position = uniBuf->m_xf * hsh::float4(vbo->m_pos, 1.f);
this->color_out[0] = uniBuf->m_color;
}
};
template struct CAABoxShaderPipeline<true>;
template struct CAABoxShaderPipeline<false>;
void CAABoxShader::setAABB(const zeus::CAABox& aabb) {
const std::array<zeus::CVector3f, 34> vboData{{
{aabb.max.x(), aabb.max.y(), aabb.min.z()}, {aabb.max.x(), aabb.min.y(), aabb.min.z()},
{aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.min.y(), aabb.max.z()},
{aabb.max.x(), aabb.min.y(), aabb.max.z()},
CAABoxShader::CAABoxShader(const zeus::CAABox& aabb, bool zOnly) {
const std::array<Vert, 34> verts{{
{{aabb.max.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.max.x(), aabb.min.y(), aabb.min.z()}},
{{aabb.max.x(), aabb.max.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.min.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.min.y(), aabb.max.z()}},
{aabb.min.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()},
{aabb.max.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()},
{aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.max.y(), aabb.max.z()},
{{aabb.min.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.min.z()}},
{{aabb.max.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.max.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.max.y(), aabb.max.z()}},
{aabb.min.x(), aabb.max.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()},
{aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()},
{aabb.min.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()},
{{aabb.min.x(), aabb.max.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.min.z()}},
{{aabb.min.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
{{aabb.min.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.max.z()}},
{aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.min.z()},
{aabb.max.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()},
{aabb.max.x(), aabb.min.y(), aabb.max.z()}, {aabb.max.x(), aabb.min.y(), aabb.max.z()},
{{aabb.min.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.min.z()}},
{{aabb.max.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.min.y(), aabb.max.z()}},
{aabb.min.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.min.y(), aabb.max.z()},
{aabb.max.x(), aabb.min.y(), aabb.max.z()}, {aabb.min.x(), aabb.max.y(), aabb.max.z()},
{aabb.max.x(), aabb.max.y(), aabb.max.z()}, {aabb.max.x(), aabb.max.y(), aabb.max.z()},
{{aabb.min.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.min.y(), aabb.max.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.max.z()}},
{{aabb.max.x(), aabb.max.y(), aabb.max.z()}}, {{aabb.max.x(), aabb.max.y(), aabb.max.z()}},
{aabb.min.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.min.y(), aabb.min.z()},
{aabb.max.x(), aabb.min.y(), aabb.min.z()}, {aabb.min.x(), aabb.max.y(), aabb.min.z()},
{aabb.max.x(), aabb.max.y(), aabb.min.z()},
{{aabb.min.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.min.y(), aabb.min.z()}},
{{aabb.max.x(), aabb.min.y(), aabb.min.z()}}, {{aabb.min.x(), aabb.max.y(), aabb.min.z()}},
{{aabb.max.x(), aabb.max.y(), aabb.min.z()}},
}};
m_vbo->load(vboData.data(), sizeof(vboData));
m_vbo = hsh::create_vertex_buffer(verts);
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
m_dataBind.hsh_bind(CAABoxShaderPipeline<zOnly>(m_vbo.get(), m_uniBuf.get()));
}
void CAABoxShader::draw(const zeus::CColor& color) {
@ -57,10 +59,9 @@ void CAABoxShader::draw(const zeus::CColor& color) {
m_uniform.m_xf = CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f();
m_uniform.m_color = color;
m_uniBuf->load(&m_uniform, sizeof(Uniform));
m_uniBuf.load(m_uniform);
CGraphics::SetShaderDataBinding(m_dataBind);
CGraphics::DrawArray(0, 34);
m_dataBind.draw(0, 34);
}
} // namespace urde

View File

@ -1,15 +1,15 @@
#pragma once
#include "zeus/CColor.hpp"
#include "zeus/CMatrix4f.hpp"
#include "hsh/hsh.h"
namespace zeus {
class CColor;
class CAABox;
}
} // namespace zeus
namespace urde {
class CAABoxShader {
public:
struct Vert {
hsh::float3 m_pos;
};
@ -17,14 +17,15 @@ class CAABoxShader {
hsh::float4x4 m_xf;
hsh::float4 m_color;
};
private:
hsh::owner<hsh::vertex_buffer<Vert>> m_vbo;
hsh::dynamic_owner<hsh::uniform_buffer<Uniform>> m_uniBuf;
hsh::binding m_dataBind;
Uniform m_uniform;
Uniform m_uniform{};
public:
explicit CAABoxShader(bool zOnly = false);
void setAABB(const zeus::CAABox& aabb);
CAABoxShader(const zeus::CAABox& aabb, bool zOnly = false);
void draw(const zeus::CColor& color);
};

View File

@ -17,11 +17,11 @@ CPhazonBeam::CPhazonBeam(CAssetId characterId, EWeaponType type, TUniqueId playe
, x238_aaBoxScale(zeus::CVector3f(-0.14664599f, 0.f, -0.14909725f) * scale.y(),
zeus::CVector3f(0.14664599f, 0.64619601f, 0.14909725f) * scale.y())
, x250_aaBoxTranslate(zeus::CVector3f(-0.0625f, 0.f, -0.09375f) * scale.y(),
zeus::CVector3f(0.0625f, -0.25f, 0.09375f) * scale.y()) {
zeus::CVector3f(0.0625f, -0.25f, 0.09375f) * scale.y())
, m_aaboxShaderScale(x238_aaBoxScale, true)
, m_aaboxShaderTranslate(x250_aaBoxTranslate, true) {
x21c_phazonVeins = g_SimplePool->GetObj("PhazonVeins");
x228_phazon2nd1 = g_SimplePool->GetObj("Phazon2nd_1");
m_aaboxShaderScale.setAABB(x238_aaBoxScale);
m_aaboxShaderTranslate.setAABB(x250_aaBoxTranslate);
}
void CPhazonBeam::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& mgr) {

View File

@ -22,8 +22,8 @@ class CPhazonBeam final : public CGunWeapon {
bool x274_26_veinsAlphaActive : 1 = false;
bool x274_27_phazonVeinsIdx : 1 = false;
float x278_fireTime = 1.f / 3.f;
CAABoxShader m_aaboxShaderScale{true};
CAABoxShader m_aaboxShaderTranslate{true};
CAABoxShader m_aaboxShaderScale;
CAABoxShader m_aaboxShaderTranslate;
void ReInitVariables();
void DrawClipScaleCube();
void DrawClipTranslateCube();

View File

@ -131,7 +131,8 @@ CPlayerGun::CPlayerGun(TUniqueId playerId)
, x678_morph(g_tweakPlayerGun->GetGunTransformTime(), g_tweakPlayerGun->GetHoloHoldTime())
, x6c8_hologramClipCube(zeus::CVector3f(-0.29329199f, 0.f, -0.2481945f),
zeus::CVector3f(0.29329199f, 1.292392f, 0.2481945f))
, x6e0_rightHandModel(CAnimRes(g_tweakGunRes->xc_rightHand, 0, zeus::CVector3f(3.f), 0, true)) {
, x6e0_rightHandModel(CAnimRes(g_tweakGunRes->xc_rightHand, 0, zeus::CVector3f(3.f), 0, true))
, m_aaboxShader(x6c8_hologramClipCube, true) {
x354_bombFuseTime = g_tweakPlayerGun->GetBombFuseTime();
x358_bombDropDelayTime = g_tweakPlayerGun->GetBombDropDelayTime();
x668_aimVerticalSpeed = g_tweakPlayerGun->GetAimVerticalSpeed();
@ -175,8 +176,6 @@ CPlayerGun::CPlayerGun(TUniqueId playerId)
x550_camBob.SetPlayerVelocity(zeus::skZero3f);
x550_camBob.SetBobMagnitude(0.f);
x550_camBob.SetBobTimeScale(0.f);
m_aaboxShader.setAABB(x6c8_hologramClipCube);
}
void CPlayerGun::InitBeamData() {

View File

@ -258,7 +258,7 @@ private:
CTexturedQuadFilter m_screenQuad{EFilterType::Blend, CGraphics::g_SpareTexture.get_color(0),
CTexturedQuadFilter::ZTest::GEqualZWrite};
CAABoxShader m_aaboxShader{true};
CAABoxShader m_aaboxShader;
void InitBeamData();
void InitBombData();