Fix an insane number of things with hsh refactoring

This commit is contained in:
Luke Street 2020-10-07 20:03:07 -04:00
parent 3c9816af12
commit 036e769210
41 changed files with 255 additions and 198 deletions

View File

@ -269,7 +269,7 @@ void CNESEmulator::InitializeEmulator() {
};
m_vbo = hsh::create_vertex_buffer<TexUVVert>(verts);
m_uniBuf = hsh::create_dynamic_uniform_buffer<ViewBlock>();
m_shadBind = CNESShader::BuildShaderDataBinding(m_vbo.get(), m_uniBuf.get(), m_texture.get());
CNESShader::BuildShaderDataBinding(m_shadBind, m_vbo.get(), m_uniBuf.get(), m_texture.get());
// double useFreq = 223740;
double useFreq = apuGetFrequency();
@ -753,12 +753,11 @@ void CNESEmulator::Draw(const zeus::CColor& mulColor, bool filtering) {
float widthFac = NESAspect / g_Viewport.aspect;
Uniform uniform = {zeus::CMatrix4f{}, mulColor};
uniform.m_matrix[0][0] = widthFac;
m_uniBuf->load(&uniform, sizeof(Uniform));
ViewBlock uniform = {zeus::CMatrix4f{}, mulColor};
uniform.m_mv[0][0] = widthFac;
m_uniBuf.load(uniform);
CGraphics::SetShaderDataBinding(m_shadBind);
CGraphics::DrawArray(0, 4);
m_shadBind.draw(0, 4);
}
void CNESEmulator::LoadPassword(const u8* state) {

View File

@ -8,7 +8,7 @@
#include "Runtime/Graphics/CTexture.hpp"
namespace urde {
std::array<CMappableObject::Vert, 8> CMappableObject::skDoorVerts{};
std::array<CMapSurfaceShader::Vert, 8> CMappableObject::skDoorVerts{};
constexpr std::array<u32, 24> DoorIndices{
6, 4, 2, 0, 3, 1, 7, 5, 1, 0, 5, 4, 7, 6, 3, 2, 3, 2, 1, 0, 5, 4, 7, 6,
@ -118,10 +118,10 @@ void CMappableObject::Draw(int curArea, const CMapWorldInfo& mwInfo, float alpha
CLineRenderer& line = ds.m_outline;
const u32* baseIdx = &DoorIndices[s * 4];
line.Reset();
line.AddVertex(skDoorVerts[baseIdx[0]].m_pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[1]].m_pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[3]].m_pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[2]].m_pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[0]].pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[1]].pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[3]].pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[2]].pos, colors.second, 1.f);
line.Render();
}
} else {
@ -188,10 +188,10 @@ void CMappableObject::DrawDoorSurface(int curArea, const CMapWorldInfo& mwInfo,
CLineRenderer& line = ds.m_outline;
const u32* baseIdx = &DoorIndices[surfIdx * 4];
line.Reset();
line.AddVertex(skDoorVerts[baseIdx[0]].m_pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[1]].m_pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[3]].m_pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[2]].m_pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[0]].pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[1]].pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[3]].pos, colors.second, 1.f);
line.AddVertex(skDoorVerts[baseIdx[2]].pos, colors.second, 1.f);
line.Render();
}
@ -236,7 +236,7 @@ bool CMappableObject::IsVisibleToAutoMapper(bool worldVis, const CMapWorldInfo&
}
}
hsh::owner<hsh::vertex_buffer<CMappableObject::Vert>> CMappableObject::g_doorVbo;
hsh::owner<hsh::vertex_buffer<CMapSurfaceShader::Vert>> CMappableObject::g_doorVbo;
hsh::owner<hsh::index_buffer<u32>> CMappableObject::g_doorIbo;
void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) {
@ -245,14 +245,14 @@ void CMappableObject::ReadAutoMapperTweaks(const ITweakAutoMapper& tweaks) {
// Wrap door verts around -Z to build surface
auto& doorVerts = skDoorVerts;
doorVerts[0].assign(-centerF[2], -centerF[1], 0.f);
doorVerts[1].assign(-centerF[2], -centerF[1], 2.f * centerF[0]);
doorVerts[2].assign(-centerF[2], centerF[1], 0.f);
doorVerts[3].assign(-centerF[2], centerF[1], 2.f * centerF[0]);
doorVerts[4].assign(.2f * -centerF[2], -centerF[1], 0.f);
doorVerts[5].assign(.2f * -centerF[2], -centerF[1], 2.f * centerF[0]);
doorVerts[6].assign(.2f * -centerF[2], centerF[1], 0.f);
doorVerts[7].assign(.2f * -centerF[2], centerF[1], 2.f * centerF[0]);
doorVerts[0] = {-centerF[2], -centerF[1], 0.f};
doorVerts[1] = {-centerF[2], -centerF[1], 2.f * centerF[0]};
doorVerts[2] = {-centerF[2], centerF[1], 0.f};
doorVerts[3] = {-centerF[2], centerF[1], 2.f * centerF[0]};
doorVerts[4] = {.2f * -centerF[2], -centerF[1], 0.f};
doorVerts[5] = {.2f * -centerF[2], -centerF[1], 2.f * centerF[0]};
doorVerts[6] = {.2f * -centerF[2], centerF[1], 0.f};
doorVerts[7] = {.2f * -centerF[2], centerF[1], 2.f * centerF[0]};
g_doorVbo = hsh::create_vertex_buffer(skDoorVerts);
g_doorIbo = hsh::create_index_buffer(DoorIndices);

View File

@ -19,13 +19,7 @@ class CStateManager;
class CMappableObject {
public:
struct Vert {
hsh::float3 m_pos;
void assign(float x, float y, float z) {
m_pos = hsh::float3(x, y, z);
}
};
static hsh::owner<hsh::vertex_buffer<Vert>> g_doorVbo;
static hsh::owner<hsh::vertex_buffer<CMapSurfaceShader::Vert>> g_doorVbo;
static hsh::owner<hsh::index_buffer<u32>> g_doorIbo;
enum class EMappableObjectType {
@ -59,7 +53,7 @@ public:
enum class EVisMode { Always, MapStationOrVisit, Visit, Never, MapStationOrVisit2 };
private:
static std::array<CMappableObject::Vert, 8> skDoorVerts;
static std::array<CMapSurfaceShader::Vert, 8> skDoorVerts;
EMappableObjectType x0_type;
EVisMode x4_visibilityMode;

View File

@ -139,22 +139,13 @@ set(RUNTIME_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
set(RUNTIME_LIBRARIES RetroDataSpec AssetNameMapNull NESEmulator
libjpeg-turbo jbus kabufuda discord-rpc logvisor)
if(MSVC)
# WTF MS???? LINK.EXE is unable to address static libraries larger than 4GB.
# This is a hack to split this large library in two.
add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A})
add_runtime_common_library(RuntimeCommonB ${RUNTIME_SOURCES_B})
target_include_directories(RuntimeCommonB PUBLIC ${RUNTIME_INCLUDES})
target_link_libraries(RuntimeCommonB PUBLIC ${RUNTIME_LIBRARIES})
target_link_libraries(RuntimeCommon PUBLIC RuntimeCommonB)
target_hsh(RuntimeCommon)
target_hsh(RuntimeCommonB)
else()
add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A} ${RUNTIME_SOURCES_B})
target_include_directories(RuntimeCommon PUBLIC ${RUNTIME_INCLUDES})
target_link_libraries(RuntimeCommon PUBLIC ${RUNTIME_LIBRARIES})
target_hsh(RuntimeCommon)
endif()
add_runtime_common_library(RuntimeCommon ${RUNTIME_SOURCES_A})
add_runtime_common_library(RuntimeCommonB ${RUNTIME_SOURCES_B})
target_include_directories(RuntimeCommonB PUBLIC ${RUNTIME_INCLUDES})
target_link_libraries(RuntimeCommonB PUBLIC ${RUNTIME_LIBRARIES})
target_link_libraries(RuntimeCommon PUBLIC RuntimeCommonB)
target_hsh(RuntimeCommon)
target_hsh(RuntimeCommonB)
add_executable(urde CMain.hpp CMain.cpp)
target_link_libraries(urde PUBLIC RuntimeCommon)

View File

@ -668,7 +668,7 @@ void CStateManager::ResetViewAfterDraw(const SViewport& backupViewport,
cam->GetFarClipDistance());
}
void CStateManager::'DrawWorld() {
void CStateManager::DrawWorld() {
SCOPED_GRAPHICS_DEBUG_GROUP("CStateManager::DrawWorld", zeus::skBlue);
const CTimeProvider timeProvider(xf14_curTimeMod900);
const SViewport backupViewport = g_Viewport;

View File

@ -693,8 +693,8 @@ CBooRenderer::CBooRenderer(IObjectStore& store, IFactory& resFac)
GenerateFogVolumeRampTex();
GenerateSphereRampTex();
m_ballShadowId = hsh::create_render_texture2d({skBallShadowIdSize, skBallShadowIdSize}, hsh::RGBA8_UNORM, 1, 0);
x14c_reflectionTex = hsh::create_render_texture2d({256, 256}, hsh::RGBA8_UNORM, 1, 0);
m_ballShadowId = hsh::create_render_texture2d({skBallShadowIdSize, skBallShadowIdSize}, 1, 0);
x14c_reflectionTex = hsh::create_render_texture2d({256, 256}, 1, 0);
GenerateScanLinesVBO();
LoadThermoPalette();

View File

@ -308,7 +308,7 @@ public:
void BindReflectionDrawTarget() { x14c_reflectionTex.attach(); }
void BindBallShadowIdTarget() { m_ballShadowId.attach(); }
void ResolveBallShadowIdTarget() {
m_ballShadowId.resolve_color_binding(0, hsh::rect2d({0, 0}, {m_ballShadowIdW, m_ballShadowIdH}), false);
m_ballShadowId.resolve_color_binding(0, hsh::rect2d({0, 0}, {skBallShadowIdSize, skBallShadowIdSize}), false);
}
void FindOverlappingWorldModels(std::vector<u32>& modelBits, const zeus::CAABox& aabb) const;

View File

@ -22,6 +22,7 @@ ERglCullMode gx_CullMode;
std::array<zeus::CColor, 2> gx_AmbientColors;
/// End GX state
hsh::owner<hsh::render_texture2d> CGraphics::g_SpareTexture;
CGraphics::CProjectionState CGraphics::g_Proj;
CGraphics::CFogState CGraphics::g_Fog;
std::array<zeus::CColor, 3> CGraphics::g_ColorRegs{};
@ -176,11 +177,6 @@ void CGraphics::SetModelMatrix(const zeus::CTransform& xf) {
SetViewMatrix();
}
constexpr zeus::CMatrix4f PlusOneZ(1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 1.f, 0.f, 0.f, 0.f, 1.f);
constexpr zeus::CMatrix4f VulkanCorrect(1.f, 0.f, 0.f, 0.f, 0.f, -1.f, 0.f, 0.f, 0.f, 0.f, 0.5f, 0.5f + FLT_EPSILON,
0.f, 0.f, 0.f, 1.f);
zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect, float znear, float zfar,
bool forRenderer) {
CProjectionState st;
@ -199,14 +195,8 @@ zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect,
float fpn = st.x18_far + st.x14_near;
float fmn = st.x18_far - st.x14_near;
if (!forRenderer) {
return zeus::CMatrix4f(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f);
}
zeus::CMatrix4f mat2(2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f);
return VulkanCorrect * mat2;
return zeus::CMatrix4f{2.f * st.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * st.x14_near / tmb, tpb / tmb, 0.f,
0.f, 0.f, -fpn / fmn, -2.f * st.x18_far * st.x14_near / fmn, 0.f, 0.f, -1.f, 0.f};
}
zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) {
@ -218,16 +208,9 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) {
float fpn = g_Proj.x18_far + g_Proj.x14_near;
float fmn = g_Proj.x18_far - g_Proj.x14_near;
if (!forRenderer) {
return zeus::CMatrix4f(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb,
tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f,
0.f, -1.f, 0.f);
}
zeus::CMatrix4f mat2(2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb,
tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f,
0.f, -1.f, 0.f);
return VulkanCorrect * mat2;
return zeus::CMatrix4f{2.f * g_Proj.x14_near / rml, 0.f, rpl / rml, 0.f, 0.f, 2.f * g_Proj.x14_near / tmb,
tpb / tmb, 0.f, 0.f, 0.f, -fpn / fmn, -2.f * g_Proj.x18_far * g_Proj.x14_near / fmn, 0.f,
0.f, -1.f, 0.f};
} else {
float rml = g_Proj.x8_right - g_Proj.x4_left;
float rpl = g_Proj.x8_right + g_Proj.x4_left;
@ -236,14 +219,8 @@ zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix(bool forRenderer) {
float fpn = g_Proj.x18_far + g_Proj.x14_near;
float fmn = g_Proj.x18_far - g_Proj.x14_near;
if (!forRenderer) {
return zeus::CMatrix4f(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn,
-fpn / fmn, 0.f, 0.f, 0.f, 1.f);
}
zeus::CMatrix4f mat2(2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn,
-fpn / fmn, 0.f, 0.f, 0.f, 1.f);
return VulkanCorrect * mat2;
return zeus::CMatrix4f{2.f / rml, 0.f, 0.f, -rpl / rml, 0.f, 2.f / tmb, 0.f, -tpb / tmb, 0.f, 0.f, -2.f / fmn,
-fpn / fmn, 0.f, 0.f, 0.f, 1.f};
}
}

View File

@ -457,6 +457,7 @@ using BlendAttachmentExt =
hsh::ColorComponentFlags(
hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue |
(Alpha != AlphaMode::NoAlpha ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>;
template <AlphaMode Alpha = AlphaMode::NoAlpha>
using AdditiveAttachmentExt =
hsh::pipeline::color_attachment<hsh::SrcAlpha, hsh::One, hsh::Add, AlphaSrc<Alpha, hsh::SrcAlpha>::Factor,
@ -464,6 +465,7 @@ using AdditiveAttachmentExt =
hsh::ColorComponentFlags(
hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue |
(Alpha != AlphaMode::NoAlpha ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>;
template <AlphaMode Alpha = AlphaMode::NoAlpha>
using MultiplyAttachmentExt =
hsh::pipeline::color_attachment<hsh::Zero, hsh::SrcColor, hsh::Add, AlphaSrc<Alpha, hsh::Zero>::Factor,
@ -471,6 +473,7 @@ using MultiplyAttachmentExt =
hsh::ColorComponentFlags(
hsh::CC_Red | hsh::CC_Green | hsh::CC_Blue |
(Alpha != AlphaMode::NoAlpha ? hsh::CC_Alpha : hsh::ColorComponentFlags()))>;
template <AlphaMode Alpha = AlphaMode::NoAlpha>
using SubtractAttachmentExt = hsh::pipeline::color_attachment<
hsh::SrcAlpha, hsh::One, hsh::ReverseSubtract, AlphaSrc<Alpha, hsh::SrcAlpha>::Factor,

View File

@ -176,7 +176,7 @@ private:
ModelInstance m_ballShadowInstance;
hsh::vertex_buffer_typeless m_staticVbo;
hsh::index_buffer<u32> m_staticIbo;
hsh::index_buffer_typeless m_staticIbo;
hsh::texture2d m_lastDrawnShadowMap;
hsh::texture2d m_lastDrawnOneTexture;
@ -203,7 +203,7 @@ public:
~CBooModel();
CBooModel(TToken<CModel>& token, CModel* parent, std::vector<CBooSurface>* surfaces, SShader& shader,
hsh::vertex_buffer_typeless vbo,
hsh::index_buffer<u32> ibo,
hsh::index_buffer_typeless ibo,
const zeus::CAABox& aabb, u8 renderMask, int numInsts);
static void MakeTexturesFromMats(const MaterialSet& matSet,
@ -307,9 +307,9 @@ public:
zeus::CVector3f GetPoolVertex(size_t idx) const;
size_t GetPoolNormalOffset(size_t idx) const;
zeus::CVector3f GetPoolNormal(size_t idx) const;
void ApplyVerticesCPU(hsh::owner<hsh::vertex_buffer_typeless>& vertBuf,
void ApplyVerticesCPU(hsh::dynamic_owner<hsh::vertex_buffer_typeless>& vertBuf,
const std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn) const;
void RestoreVerticesCPU(hsh::owner<hsh::vertex_buffer_typeless>& vertBuf) const;
void RestoreVerticesCPU(hsh::dynamic_owner<hsh::vertex_buffer_typeless>& vertBuf) const;
void _WarmupShaders();
static void WarmupShaders(const SObjectTag& cmdlTag);

View File

@ -11,7 +11,6 @@
#include <array>
#include <boo/graphicsdev/Metal.hpp>
#include <hecl/CVarManager.hpp>
#include <hecl/HMDLMeta.hpp>
#include <hecl/Runtime.hpp>
@ -124,26 +123,19 @@ void CBooModel::EnsureViewDepStateCached(const CBooModel& model, const CBooSurfa
mtxsOut[1][3][0] = -surfPos.dot(v2) * f1 + 0.5f;
mtxsOut[1][2][1] = f2;
mtxsOut[1][3][1] = -modelToPlayerLocal.z() * f2;
switch (CGraphics::g_BooPlatform) {
case boo::IGraphicsDataFactory::Platform::OpenGL:
mtxsOut[1] = ReflectPostGL * mtxsOut[1];
break;
default:
break;
}
}
}
boo::ObjToken<boo::ITexture> CBooModel::g_shadowMap;
hsh::texture2d CBooModel::g_shadowMap;
zeus::CTransform CBooModel::g_shadowTexXf;
boo::ObjToken<boo::ITexture> CBooModel::g_disintegrateTexture;
boo::ObjToken<boo::ITextureCubeR> CBooModel::g_reflectionCube;
hsh::texture2d CBooModel::g_disintegrateTexture;
hsh::texturecube CBooModel::g_reflectionCube;
void CBooModel::EnableShadowMaps(hsh::texture2d map, const zeus::CTransform& texXf) {
g_shadowMap = map;
g_shadowTexXf = texXf;
}
void CBooModel::DisableShadowMaps() { g_shadowMap = nullptr; }
void CBooModel::DisableShadowMaps() { g_shadowMap.reset(); }
CBooModel::~CBooModel() {
if (m_prev)
@ -155,13 +147,14 @@ CBooModel::~CBooModel() {
}
CBooModel::CBooModel(TToken<CModel>& token, CModel* parent, std::vector<CBooSurface>* surfaces, SShader& shader,
hsh::vertex_buffer_typeless vbo, hsh::index_buffer<u32> ibo, const zeus::CAABox& aabb,
hsh::vertex_buffer_typeless vbo, hsh::index_buffer_typeless ibo, const zeus::CAABox& aabb,
u8 renderMask, int numInsts)
: m_modelTok(token)
, m_model(parent)
, x0_surfaces(surfaces)
, x4_matSet(&shader.m_matSet)
, m_geomLayout(&*shader.m_geomLayout)
, m_vtxFmt(m_model->GetHMDLMeta())
, m_matSetIdx(shader.m_matSetIdx)
, x1c_textures(shader.x0_textures)
, x20_aabb(aabb)
@ -302,11 +295,11 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
/* Build geometry uniform buffer if shared not available */
hsh::uniform_buffer_typeless geomUniformBuf;
if (sharedLayoutBuf >= 0) {
geomUniformBuf = m_geomLayout->GetSharedBuffer(sharedLayoutBuf);
geomUniformBuf = m_geomLayout->GetSharedBuffer(sharedLayoutBuf).get();
} else {
auto CreateUBO = [&]<uint32_t NSkinSlots>() {
newInst.m_geomUniformBuffer = hsh::create_dynamic_uniform_buffer<CModelShaders::VertUniform<NSkinSlots>>();
geomUniformBuf = newInst.m_geomUniformBuffer;
geomUniformBuf = newInst.m_geomUniformBuffer.get();
};
switch (m_vtxFmt.NSkinSlots) {
#define VERT_UNIFORM(nskins) \
@ -376,7 +369,7 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
for (const CBooSurface& surf : *x0_surfaces) {
const MaterialSet::Material& mat = x4_matSet->materials.at(surf.m_data.matIdx);
std::array<boo::ObjToken<boo::ITexture>, 12> texs{
std::array<hsh::texture_typeless, 12> texs{
g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(),
g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->m_clearTexture.get(),
g_Renderer->m_whiteTexture.get(), g_Renderer->m_clearTexture.get(), g_Renderer->x220_sphereRamp.get(),
@ -386,12 +379,13 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
for (const auto& ch : mat.chunks) {
if (const auto* const pass = ch.get_if<MaterialSet::Material::PASS>()) {
auto search = x1c_textures.find(pass->texId.toUint32());
boo::ObjToken<boo::ITexture> btex;
if (search != x1c_textures.cend() && (btex = search->second.GetObj()->GetBooTexture())){
texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex;}
} else if (const auto* const pass = ch.get_if<MaterialSet::Material::CLR>()) {
boo::ObjToken<boo::ITexture> btex = g_Renderer->GetColorTexture(zeus::CColor(pass->color));
texs[MaterialSet::Material::TexMapIdx(pass->type)] = btex;
hsh::texture2d tex;
if (search != x1c_textures.cend() && (tex = search->second.GetObj()->GetBooTexture())) {
texs[MaterialSet::Material::TexMapIdx(pass->type)] = tex;
}
} else if (const auto* const clr = ch.get_if<MaterialSet::Material::CLR>()) {
hsh::texture2d tex = g_Renderer->GetColorTexture(clr->color);
texs[MaterialSet::Material::TexMapIdx(clr->type)] = tex;
}
}
}
@ -412,8 +406,9 @@ CBooModel::ModelInstance* CBooModel::PushNewModelInstance(int sharedLayoutBuf) {
bool useReflection = mat.flags.samusReflection() || mat.flags.samusReflectionSurfaceEye();
if (useReflection) {
if (g_Renderer->x14c_reflectionTex)
texs[11] = g_Renderer->x14c_reflectionTex.get();
if (g_Renderer->x14c_reflectionTex.Owner.IsValid()) {
// texs[11] = g_Renderer->x14c_reflectionTex.get_color(0);
}
thisOffs[3] = curReflect;
curReflect += 256;
} else {
@ -1181,8 +1176,8 @@ static const u8* MemoryFromPartData(const u8*& dataCur, const u32*& secSizeCur)
std::unique_ptr<CBooModel> CModel::MakeNewInstance(int shaderIdx, int subInsts, bool lockParent) {
if (shaderIdx >= x18_matSets.size())
shaderIdx = 0;
auto ret = std::make_unique<CBooModel>(m_selfToken, this, &x8_surfaces, x18_matSets[shaderIdx], m_staticVbo, m_ibo,
m_aabb, (m_flags & 0x2) != 0, subInsts);
auto ret = std::make_unique<CBooModel>(m_selfToken, this, &x8_surfaces, x18_matSets[shaderIdx], m_staticVbo.get(),
m_ibo.get(), m_aabb, (m_flags & 0x2) != 0, subInsts);
if (lockParent)
ret->LockParent();
return ret;
@ -1228,26 +1223,67 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 /* dataLen */, IObjectStore* stor
matSet.BuildShaders(m_hmdlMeta);
}
CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) {
/* Index buffer is always static */
if (m_hmdlMeta.indexCount)
m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, m_hmdlMeta.indexCount);
/* Index buffer is always static */
if (m_hmdlMeta.indexCount)
m_ibo =
hsh::create_index_buffer(hsh::detail::ArrayProxy{reinterpret_cast<const u32*>(iboData), m_hmdlMeta.indexCount});
if (!m_hmdlMeta.bankCount) {
/* Non-skinned models use static vertex buffers shared with CBooModel instances */
if (m_hmdlMeta.vertCount)
m_staticVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, m_hmdlMeta.vertStride, m_hmdlMeta.vertCount);
} else {
/* Skinned models use per-instance dynamic buffers for vertex manipulation effects */
size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount;
if (vboSz) {
m_dynamicVertexData.reset(new uint8_t[vboSz]);
memmove(m_dynamicVertexData.get(), vboData, vboSz);
if (!m_hmdlMeta.bankCount) {
/* Non-skinned models use static vertex buffers shared with CBooModel instances */
if (m_hmdlMeta.vertCount) {
auto CreateVBO = [this, vboData]<uint32_t NUVs, uint32_t NWeights>() {
using VertData = CModelShaders::VertData<0, NUVs, NWeights>;
assert(sizeof(VertData) != m_hmdlMeta.vertStride && "Vert data stride mismatch");
m_staticVbo = hsh::create_vertex_buffer(
hsh::detail::ArrayProxy{reinterpret_cast<const VertData*>(vboData), m_hmdlMeta.vertCount});
};
#define VERT_DATA(uvs) \
switch (m_hmdlMeta.weightCount) { \
case 0: \
CreateVBO.operator()<uvs, 0>(); \
break; \
case 1: \
CreateVBO.operator()<uvs, 1>(); \
break; \
case 2: \
CreateVBO.operator()<uvs, 2>(); \
break; \
case 3: \
CreateVBO.operator()<uvs, 3>(); \
break; \
case 4: \
CreateVBO.operator()<uvs, 4>(); \
break; \
default: \
assert(false && "Unhandled weight count"); \
break; \
} \
break;
switch (m_hmdlMeta.uvCount) {
case 0:
VERT_DATA(0)
case 1:
VERT_DATA(1)
case 2:
VERT_DATA(2)
case 3:
VERT_DATA(3)
case 4:
VERT_DATA(4)
#undef VERT_DATA
default:
assert(false && "Unhandled UV count");
break;
}
}
return true;
} BooTrace);
} else {
/* Skinned models use per-instance dynamic buffers for vertex manipulation effects */
size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount;
if (vboSz) {
m_dynamicVertexData.reset(new uint8_t[vboSz]);
memmove(m_dynamicVertexData.get(), vboData, vboSz);
}
}
const u32 surfCount = hecl::SBig(*reinterpret_cast<const u32*>(surfInfo));
x8_surfaces.reserve(surfCount);
@ -1315,9 +1351,9 @@ zeus::CVector3f CModel::GetPoolNormal(size_t idx) const {
return {floats};
}
void CModel::ApplyVerticesCPU(hsh::owner<hsh::vertex_buffer_typeless>& vertBuf,
void CModel::ApplyVerticesCPU(hsh::dynamic_owner<hsh::vertex_buffer_typeless>& vertBuf,
const std::vector<std::pair<zeus::CVector3f, zeus::CVector3f>>& vn) const {
u8* data = reinterpret_cast<u8*>(vertBuf->map(m_hmdlMeta.vertStride * m_hmdlMeta.vertCount));
u8* data = reinterpret_cast<u8*>(vertBuf.map()); // m_hmdlMeta.vertStride * m_hmdlMeta.vertCount
for (u32 i = 0; i < std::min(u32(vn.size()), m_hmdlMeta.vertCount); ++i) {
const std::pair<zeus::CVector3f, zeus::CVector3f>& avn = vn[i];
float* floats = reinterpret_cast<float*>(data + GetPoolVertexOffset(i));
@ -1328,14 +1364,14 @@ void CModel::ApplyVerticesCPU(hsh::owner<hsh::vertex_buffer_typeless>& vertBuf,
floats[4] = avn.second.y();
floats[5] = avn.second.z();
}
vertBuf->unmap();
vertBuf.unmap();
}
void CModel::RestoreVerticesCPU(hsh::owner<hsh::vertex_buffer_typeless>& vertBuf) const {
void CModel::RestoreVerticesCPU(hsh::dynamic_owner<hsh::vertex_buffer_typeless>& vertBuf) const {
size_t size = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount;
u8* data = reinterpret_cast<u8*>(vertBuf->map(size));
u8* data = reinterpret_cast<u8*>(vertBuf.map()); // size
memcpy(data, m_dynamicVertexData.get(), size);
vertBuf->unmap();
vertBuf.unmap();
}
void CModel::_WarmupShaders() {

View File

@ -76,7 +76,7 @@ public:
hsh::texture_typeless GetBooTexture() const { return m_booTex.get(); }
hsh::texture_typeless GetPaletteTexture() const { return m_paletteTex.get(); }
std::unique_ptr<u8[]> BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut, std::unique_ptr<u8[]>& paletteOut) const;
hsh::texture_typeless GetFontTexture(EFontType tp);
hsh::texture2d_array GetFontTexture(EFontType tp);
const CTextureInfo* GetTextureInfo() const { return m_textureInfo; }
};

View File

@ -204,8 +204,8 @@ void CTexture::BuildIA8FromGCN(CInputStream& in) {
});
}
static std::vector<RGBA8> DecodePalette(int numEntries, CInputStream& in) {
std::vector<RGBA8> ret;
static std::vector<CTexture::RGBA8> DecodePalette(int numEntries, CInputStream& in) {
std::vector<CTexture::RGBA8> ret;
ret.reserve(numEntries);
enum class EPaletteType { IA8, RGB565, RGB5A3 };
@ -544,8 +544,8 @@ void CTexture::BuildC8Font(const void* data, EFontType ftype) {
h /= 2;
}
m_booTex = hsh::create_texture2d_array({x4_w, x6_h}, layerCount, hsh::R8_UNORM, x8_mips, [&](void* data, std::size_t size) {
std::memcpy(data, texels, size);
m_booTex = hsh::create_texture2d_array({x4_w, x6_h}, layerCount, hsh::RGBA8_UNORM, x8_mips, [&](void* data, std::size_t size) {
std::memcpy(data, buf.get(), size);
});
}
@ -609,9 +609,9 @@ CTexture::CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex, const CTex
case ETexelFormat::RGBA8:
BuildRGBA8FromGCN(r);
break;
case ETexelFormat::CMPR:
BuildDXT1FromGCN(r);
break;
// case ETexelFormat::CMPR:
// BuildDXT1FromGCN(r);
// break;
case ETexelFormat::RGBA8PC:
BuildRGBA8(owned.get() + 12, length - 12);
break;
@ -719,7 +719,7 @@ std::unique_ptr<u8[]> CTexture::BuildMemoryCardTex(u32& sizeOut, ETexelFormat& f
return ret;
}
hsh::texture_typeless CTexture::GetFontTexture(EFontType tp) {
hsh::texture2d_array CTexture::GetFontTexture(EFontType tp) {
if (m_ftype != tp && x0_fmt == ETexelFormat::C8PC) {
m_ftype = tp;
BuildC8Font(m_otex.get() + 12, m_ftype);

View File

@ -9,18 +9,16 @@
namespace urde {
using namespace hsh::pipeline;
template <ERglCullMode CullMode, ERglEnum Compare, bool DepthWrite, ERglBlendMode Mode, ERglBlendFactor SrcFac,
ERglBlendFactor DstFac, ERglLogicOp Op, bool AlphaWrite>
struct CAABoxShaderPipeline
: pipeline<topology<hsh::TriangleStrip>, ERglBlendModeAttachment<Mode, SrcFac, DstFac, Op, AlphaWrite>,
ERglCullModeAttachment<CullMode>, ERglDepthCompareAttachment<Compare>, depth_write<DepthWrite>> {
struct CAABoxShaderPipeline : pipeline<topology<hsh::TriangleStrip>,
ERglBlendModeAttachment<ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha,
ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear, false>,
ERglCullModeAttachment<ERglCullMode::None>,
ERglDepthCompareAttachment<ERglEnum::LEqual>, depth_write<true>> {
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<ERglCullMode::None, ERglEnum::LEqual, true, ERglBlendMode::Blend,
ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha, ERglLogicOp::Clear, true>;
constexpr size_t VertexCount = 34;
@ -53,8 +51,7 @@ CAABoxShader::CAABoxShader(const zeus::CAABox& aabb) {
m_vbo = hsh::create_vertex_buffer(verts);
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
m_dataBind.hsh_bind(CAABoxShaderPipeline<gx_CullMode, gx_DepthTest, gx_DepthWrite, gx_BlendMode, gx_BlendSrcFac,
gx_BlendDstFac, gx_BlendOp, gx_AlphaWrite>(m_vbo.get(), m_uniBuf.get()));
m_dataBind.hsh_bind(CAABoxShaderPipeline(m_vbo.get(), m_uniBuf.get()));
}
void CAABoxShader::draw(const zeus::CColor& color) {

View File

@ -14,10 +14,13 @@ template <EFilterType Type>
struct CColoredQuadFilterPipeline : FilterPipeline<Type> {
CColoredQuadFilterPipeline(hsh::vertex_buffer<CColoredQuadFilter::Vert> vbo,
hsh::uniform_buffer<CColoredQuadFilter::Uniform> uniBuf) {
this->position = hsh::float4(vbo->m_pos, 1.f);
this->position = uniBuf->m_matrix * hsh::float4(vbo->m_pos, 1.f);
this->color_out[0] = uniBuf->m_color;
}
};
template struct CColoredQuadFilterPipeline<EFilterType::Add>;
template struct CColoredQuadFilterPipeline<EFilterType::Blend>;
template struct CColoredQuadFilterPipeline<EFilterType::Multiply>;
CColoredQuadFilter::CColoredQuadFilter(EFilterType type) {
constexpr std::array<Vert, 4> verts{{
@ -36,6 +39,7 @@ CColoredQuadFilter::CColoredQuadFilter(EFilterType type) {
void CColoredQuadFilter::draw(const zeus::CColor& color, const zeus::CRectangle& rect) {
SCOPED_GRAPHICS_DEBUG_GROUP("CColoredQuadFilter::draw", zeus::skMagenta);
m_uniform.m_matrix = zeus::CMatrix4f{};
m_uniform.m_matrix[0][0] = rect.size.x() * 2.f;
m_uniform.m_matrix[1][1] = rect.size.y() * 2.f;
m_uniform.m_matrix[3][0] = rect.position.x() * 2.f - 1.f;

View File

@ -1,5 +1,7 @@
#pragma once
#include "hsh/hsh.h"
#include "zeus/CColor.hpp"
#include "zeus/CMatrix4f.hpp"

View File

@ -15,8 +15,8 @@ struct CDecalShaderTexPipeline
std::conditional_t<Additive, std::conditional_t<RedToAlpha, MultiplyAttachment<>, AdditiveAttachment<>>,
BlendAttachment<>>,
depth_compare<hsh::LEqual>, depth_write<false>> {
CDecalShaderTexPipeline(hsh::vertex_buffer<SParticleInstanceTex> vbo, hsh::uniform_buffer<SParticleUniforms> uniBuf,
hsh::texture2d tex) {
CDecalShaderTexPipeline(hsh::vertex_buffer<SParticleInstanceTex> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<SParticleUniforms> uniBuf, hsh::texture2d tex) {
this->position = uniBuf->mvp * vbo->pos[this->vertex_id];
this->color_out[0] = vbo->color * uniBuf->moduColor * tex.sample<float>(vbo->uvs[this->vertex_id]);
if constexpr (RedToAlpha) {
@ -31,7 +31,7 @@ template struct CDecalShaderTexPipeline<false, false>;
template <bool Additive>
struct CDecalShaderNoTexPipeline : pipeline<std::conditional_t<Additive, AdditiveAttachment<>, BlendAttachment<>>,
depth_compare<hsh::LEqual>, depth_write<!Additive>> {
CDecalShaderNoTexPipeline(hsh::vertex_buffer<SParticleInstanceNoTex> vbo,
CDecalShaderNoTexPipeline(hsh::vertex_buffer<SParticleInstanceNoTex> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<SParticleUniforms> uniBuf) {
this->position = uniBuf->mvp * vbo->pos[this->vertex_id];
this->color_out[0] = vbo->color * uniBuf->moduColor;

View File

@ -33,7 +33,7 @@ using BlendModeAttachment = typename BlendModeAttachmentExt<Mode, AlphaWrite>::t
template <BlendMode Mode, bool AlphaWrite, bool ZTest, bool ZWrite, bool RedToAlpha>
struct CElementGenShadersTexPipeline : pipeline<topology<hsh::TriangleStrip>, BlendModeAttachment<Mode, AlphaWrite>,
depth_compare<ZTest ? hsh::LEqual : hsh::Always>, depth_write<ZWrite>> {
CElementGenShadersTexPipeline(hsh::vertex_buffer<SParticleInstanceTex> vbo,
CElementGenShadersTexPipeline(hsh::vertex_buffer<SParticleInstanceTex> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<SParticleUniforms> uniBuf, hsh::texture2d tex) {
this->position = uniBuf->mvp * vbo->pos[this->vertex_id];
this->color_out[0] = vbo->color * uniBuf->moduColor * tex.sample<float>(vbo->uvs[this->vertex_id]);
@ -42,15 +42,14 @@ struct CElementGenShadersTexPipeline : pipeline<topology<hsh::TriangleStrip>, Bl
}
}
};
template struct CElementGenShadersTexPipeline<BlendMode::Regular, true, true, true, false>;
template struct CElementGenShadersTexPipeline<BlendMode::Additive, true, true, true, true>;
template struct CElementGenShadersTexPipeline<BlendMode::Subtract, true, true, true, true>;
template struct CElementGenShadersTexPipeline<BlendMode::Additive, false, true, false, false>;
template struct CElementGenShadersTexPipeline<BlendMode::Regular, false, true, false, false>;
template <BlendMode Mode, bool AlphaWrite, bool ZTest, bool ZWrite, bool ColoredIndirect>
struct CElementGenShadersIndTexPipeline
: pipeline<topology<hsh::TriangleStrip>, BlendModeAttachment<Mode, AlphaWrite>,
depth_compare<ZTest ? hsh::LEqual : hsh::Always>, depth_write<ZWrite>> {
CElementGenShadersIndTexPipeline(hsh::vertex_buffer<SParticleInstanceIndTex> vbo,
CElementGenShadersIndTexPipeline(hsh::vertex_buffer<SParticleInstanceIndTex> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<SParticleUniforms> uniBuf, hsh::texture2d texrTex,
hsh::texture2d tindTex, hsh::render_texture2d sceneTex) {
this->position = uniBuf->mvp * vbo->pos[this->vertex_id];
@ -65,22 +64,19 @@ struct CElementGenShadersIndTexPipeline
}
}
};
template struct CElementGenShadersIndTexPipeline<BlendMode::Regular, true, true, true, true>;
template struct CElementGenShadersIndTexPipeline<BlendMode::Additive, true, true, true, false>;
template struct CElementGenShadersIndTexPipeline<BlendMode::Regular, false, true, false, false>;
template <BlendMode Mode, bool AlphaWrite, bool ZTest, bool ZWrite>
struct CElementGenShadersNoTexPipeline
: pipeline<topology<hsh::TriangleStrip>, BlendModeAttachment<Mode, AlphaWrite>,
depth_compare<ZTest ? hsh::LEqual : hsh::Always>, depth_write<ZWrite>> {
CElementGenShadersNoTexPipeline(hsh::vertex_buffer<SParticleInstanceNoTex> vbo,
CElementGenShadersNoTexPipeline(hsh::vertex_buffer<SParticleInstanceNoTex> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<SParticleUniforms> uniBuf) {
this->position = uniBuf->mvp * vbo->pos[this->vertex_id];
this->color_out[0] = vbo->color * uniBuf->moduColor;
}
};
template struct CElementGenShadersNoTexPipeline<BlendMode::Regular, true, true, true>;
template struct CElementGenShadersNoTexPipeline<BlendMode::Additive, true, true, true>;
template struct CElementGenShadersNoTexPipeline<BlendMode::Subtract, true, true, true>;
template struct CElementGenShadersNoTexPipeline<BlendMode::Regular, false, true, false>;
CElementGenShaders::EShaderClass CElementGenShaders::GetShaderClass(CElementGen& gen) {
const auto* desc = gen.x1c_genDesc.GetObj();

View File

@ -61,19 +61,19 @@ void CEnergyBarShader::draw(const zeus::CColor& color0, const std::vector<Vertex
if (!verts0.empty()) {
m_uniform.m_color = color0;
m_uniBuf[0].load(m_uniform);
m_dataBind[0].draw_indexed(0, verts0.size());
m_dataBind[0].draw(0, verts0.size());
vertIter += verts0.size();
}
if (!verts1.empty()) {
m_uniform.m_color = color1;
m_uniBuf[1].load(m_uniform);
m_dataBind[1].draw_indexed(vertIter, verts1.size());
m_dataBind[1].draw(vertIter, verts1.size());
vertIter += verts1.size();
}
if (!verts2.empty()) {
m_uniform.m_color = color2;
m_uniBuf[2].load(m_uniform);
m_dataBind[2].draw_indexed(vertIter, verts2.size());
m_dataBind[2].draw(vertIter, verts2.size());
}
}

View File

@ -8,6 +8,8 @@
#include "zeus/CVector2f.hpp"
#include "zeus/CVector3f.hpp"
#include "hsh/hsh.h"
namespace urde {
class CTexture;

View File

@ -12,7 +12,7 @@ struct CEnvFxShadersPipeline
// FIXME replace MultiplyAttachment with ERglBlendFactor One:One equivalent
: pipeline<topology<hsh::TriangleStrip>, std::conditional_t<Blend, BlendAttachment<false>, MultiplyAttachment<false>>,
depth_compare<hsh::LEqual>, depth_write<false>> {
CEnvFxShadersPipeline(hsh::vertex_buffer<CEnvFxShaders::Instance> vbo,
CEnvFxShadersPipeline(hsh::vertex_buffer<CEnvFxShaders::Instance> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<CEnvFxShaders::Uniform> envFxUniBuf,
hsh::uniform_buffer<CGraphics::CFogState> fogUniBuf, hsh::texture2d texFlake,
hsh::texture2d texEnv) {

View File

@ -35,7 +35,7 @@ template <bool Additive, bool AlphaWrite, hsh::Compare ZComp>
struct CLineRendererNoTexPipeline
: pipeline<std::conditional_t<Additive, AdditiveAttachment<AlphaWrite>, BlendAttachment<AlphaWrite>>,
depth_compare<ZComp>> {
CLineRendererNoTexPipeline(hsh::vertex_buffer<CLineRenderer::SDrawVertTex> vbo,
CLineRendererNoTexPipeline(hsh::vertex_buffer<CLineRenderer::SDrawVertNoTex> vbo,
hsh::uniform_buffer<CLineRenderer::SDrawUniform> uniBuf HSH_VAR_STAGE(fragment)) {
this->position = vbo->pos;
hsh::float4 colorIn = vbo->color * uniBuf->moduColor;
@ -46,6 +46,7 @@ struct CLineRendererNoTexPipeline
template struct CLineRendererNoTexPipeline<false, false, hsh::Always>;
template struct CLineRendererNoTexPipeline<false, false, hsh::LEqual>;
template struct CLineRendererNoTexPipeline<false, false, hsh::Greater>;
template struct CLineRendererNoTexPipeline<false, false, hsh::GEqual>;
template struct CLineRendererNoTexPipeline<false, true, hsh::Always>;
template struct CLineRendererNoTexPipeline<false, true, hsh::LEqual>;
template struct CLineRendererNoTexPipeline<false, true, hsh::Greater>;

View File

@ -23,8 +23,7 @@ CMapSurfaceShader::CMapSurfaceShader(hsh::vertex_buffer<Vert> vbo, hsh::index_bu
void CMapSurfaceShader::draw(const zeus::CColor& color, u32 start, u32 count) {
SCOPED_GRAPHICS_DEBUG_GROUP("CMapSurfaceShader::draw", zeus::skMagenta);
Uniform uniform = {CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), color};
m_uniBuf.load(uniform);
m_uniBuf.load({CGraphics::GetPerspectiveProjectionMatrix(true) * CGraphics::g_GXModelView.toMatrix4f(), color});
m_dataBind.draw_indexed(start, count);
}

View File

@ -5,6 +5,8 @@
#include "zeus/CColor.hpp"
#include "zeus/CMatrix4f.hpp"
#include "hsh/hsh.h"
namespace urde {
class CMapSurfaceShader {

View File

@ -9,7 +9,7 @@ namespace urde {
using namespace hsh::pipeline;
struct CRadarPaintShaderPipeline : pipeline<topology<hsh::TriangleStrip>, AdditiveAttachment<>, depth_write<false>> {
CRadarPaintShaderPipeline(hsh::vertex_buffer<CRadarPaintShader::Instance> vbo,
CRadarPaintShaderPipeline(hsh::vertex_buffer<CRadarPaintShader::Instance> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<CRadarPaintShader::Uniform> ubo, hsh::texture2d tex) {
this->position = ubo->xf * hsh::float4(vbo->pos[this->vertex_id], 1.f);
this->color_out[0] = vbo->color * tex.sample<float>(vbo->uv[this->vertex_id]);

View File

@ -2,6 +2,8 @@
#include "Runtime/CToken.hpp"
#include "hsh/hsh.h"
#include "zeus/CColor.hpp"
namespace urde {

View File

@ -4,6 +4,8 @@
#include "Runtime/GCNTypes.hpp"
#include "hsh/hsh.h"
#include "zeus/CVector3f.hpp"
namespace urde {

View File

@ -33,7 +33,7 @@ using DrawFlagsAttachment = typename DrawFlagsAttachmentExt<Flags>::type;
template <CGuiWidget::EGuiModelDrawFlags Flags>
struct CTextSupportShaderCharacterPipeline
: pipeline<topology<hsh::TriangleStrip>, DrawFlagsAttachment<Flags>, depth_write<false>, depth_compare<hsh::LEqual>> {
CTextSupportShaderCharacterPipeline(hsh::vertex_buffer<CTextSupportShader::CharacterInstance> vbo,
CTextSupportShaderCharacterPipeline(hsh::vertex_buffer<CTextSupportShader::CharacterInstance> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<CTextSupportShader::Uniform> ubo, hsh::texture2d_array tex) {
this->position = ubo->m_mvp * hsh::float4(vbo->m_pos[this->vertex_id], 1.f);
hsh::float4 fontColor = ubo->m_uniformColor * vbo->m_fontColor;
@ -49,7 +49,7 @@ template struct CTextSupportShaderCharacterPipeline<CGuiWidget::EGuiModelDrawFla
template <CGuiWidget::EGuiModelDrawFlags Flags>
struct CTextSupportShaderImagePipeline
: pipeline<topology<hsh::TriangleStrip>, DrawFlagsAttachment<Flags>, depth_write<false>, depth_compare<hsh::LEqual>> {
CTextSupportShaderImagePipeline(hsh::vertex_buffer<CTextSupportShader::ImageInstance> vbo,
CTextSupportShaderImagePipeline(hsh::vertex_buffer<CTextSupportShader::ImageInstance> vbo HSH_VAR_INSTANCE,
hsh::uniform_buffer<CTextSupportShader::Uniform> ubo, hsh::texture2d tex) {
this->position = ubo->m_mvp * hsh::float4(vbo->m_pos[this->vertex_id], 1.f);
// FIXME hsh bug: sampler appears to be completely ignored

View File

@ -12,25 +12,51 @@ namespace urde {
template <EFilterType Type, bool TexAlpha>
struct CTexturedQuadFilterPipeline : FilterPipeline<Type> {
CTexturedQuadFilterPipeline(hsh::vertex_buffer<CTexturedQuadFilter::Vert> vbo,
hsh::uniform_buffer<CTexturedQuadFilter::Uniform> uniBuf, hsh::texture2d tex) {
this->position = hsh::float4(vbo->m_pos, 1.f);
hsh::uniform_buffer<CTexturedQuadFilter::Uniform> uniBuf,
hsh::texture2d tex) {
this->position = uniBuf->m_matrix * hsh::float4(vbo->m_pos, 1.f);
if constexpr (TexAlpha) {
this->color_out[0] = uniBuf->m_color * tex.sample_bias<float>(vbo->m_uv, uniBuf->m_lod, {});
this->color_out[0] = uniBuf->m_color * tex.sample_bias<float>(vbo->m_uv, uniBuf->m_lod);
} else {
this->color_out[0] =
uniBuf->m_color * hsh::float4(tex.sample_bias<float>(vbo->m_uv, uniBuf->m_lod, {}).xyz(), 1.f);
uniBuf->m_color * hsh::float4(tex.sample_bias<float>(vbo->m_uv, uniBuf->m_lod).xyz(), 1.f);
}
}
};
template struct CTexturedQuadFilterPipeline<EFilterType::Blend, false>;
template struct CTexturedQuadFilterPipeline<EFilterType::Add, true>;
template struct CTexturedQuadFilterPipeline<EFilterType::Multiply, false>;
template <typename Tex>
CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, Tex tex, ZTest ztest)
template <EFilterType Type, bool TexAlpha>
struct CTexturedQuadFilterRenderTexPipeline : FilterPipeline<Type> {
CTexturedQuadFilterRenderTexPipeline(hsh::vertex_buffer<CTexturedQuadFilter::Vert> vbo,
hsh::uniform_buffer<CTexturedQuadFilter::Uniform> uniBuf,
hsh::render_texture2d tex) {
this->position = uniBuf->m_matrix * hsh::float4(vbo->m_pos, 1.f);
if constexpr (TexAlpha) {
this->color_out[0] = uniBuf->m_color * tex.sample_bias<float>(vbo->m_uv, uniBuf->m_lod);
} else {
this->color_out[0] =
uniBuf->m_color * hsh::float4(tex.sample_bias<float>(vbo->m_uv, uniBuf->m_lod).xyz(), 1.f);
}
}
};
template struct CTexturedQuadFilterRenderTexPipeline<EFilterType::Blend, false>;
CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, hsh::texture2d tex, ZTest ztest)
: m_zTest(ztest) {
m_vbo = hsh::create_dynamic_vertex_buffer<Vert>(16);
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
m_dataBind.hsh_bind(CTexturedQuadFilterPipeline<type, false>(m_vbo.get(), m_uniBuf.get(), tex));
}
CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, hsh::render_texture2d tex, ZTest ztest)
: m_zTest(ztest) {
m_vbo = hsh::create_dynamic_vertex_buffer<Vert>(16);
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
m_dataBind.hsh_rend_bind(CTexturedQuadFilterRenderTexPipeline<type, false>(m_vbo.get(), m_uniBuf.get(), tex));
}
CTexturedQuadFilter::CTexturedQuadFilter(EFilterType type, TLockedToken<CTexture> tex, ZTest ztest)
: CTexturedQuadFilter(type, (tex ? tex->GetBooTexture() : hsh::texture2d{}), ztest) {
m_tex = tex;
@ -49,8 +75,10 @@ void CTexturedQuadFilter::draw(const zeus::CColor& color, float uvScale, const z
m_uniform.m_matrix[0][0] = rect.size.x() * 2.f;
m_uniform.m_matrix[1][1] = rect.size.y() * 2.f;
m_uniform.m_matrix[2][2] = 1.f;
m_uniform.m_matrix[3][0] = rect.position.x() * 2.f - 1.f;
m_uniform.m_matrix[3][1] = rect.position.y() * 2.f - 1.f;
m_uniform.m_matrix[3][3] = 1.f;
m_uniform.m_color = color;
m_uniBuf.load(m_uniform);
@ -140,13 +168,18 @@ void CTexturedQuadFilter::DrawFilter(EFilterShape shape, const zeus::CColor& col
}
}
template <typename Tex>
CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, Tex tex) {
CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, hsh::texture2d tex) {
m_vbo = hsh::create_dynamic_vertex_buffer<Vert>(16);
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
m_dataBind.hsh_bind_alpha(CTexturedQuadFilterPipeline<type, true>(m_vbo.get(), m_uniBuf.get(), tex));
}
CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, hsh::render_texture2d tex) {
m_vbo = hsh::create_dynamic_vertex_buffer<Vert>(16);
m_uniBuf = hsh::create_dynamic_uniform_buffer<Uniform>();
m_dataBind.hsh_render_bind_alpha(CTexturedQuadFilterRenderTexPipeline<type, true>(m_vbo.get(), m_uniBuf.get(), tex));
}
CTexturedQuadFilterAlpha::CTexturedQuadFilterAlpha(EFilterType type, TLockedToken<CTexture> tex)
: CTexturedQuadFilterAlpha(type, (tex ? tex->GetBooTexture() : hsh::texture2d{})) {
m_tex = tex;

View File

@ -2,6 +2,8 @@
#include "Runtime/CToken.hpp"
#include "hsh/hsh.h"
#include "zeus/CColor.hpp"
#include "zeus/CMatrix4f.hpp"
#include "zeus/CRectangle.hpp"
@ -32,7 +34,7 @@ protected:
hsh::dynamic_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{};
ZTest m_zTest;
CTexturedQuadFilter() = default;
@ -40,8 +42,8 @@ protected:
public:
static constexpr zeus::CRectangle DefaultRect{0.f, 0.f, 1.f, 1.f};
explicit CTexturedQuadFilter(EFilterType type, TLockedToken<CTexture> tex, ZTest zTest = ZTest::None);
template <typename Tex>
explicit CTexturedQuadFilter(EFilterType type, Tex tex, ZTest zTest = ZTest::None);
explicit CTexturedQuadFilter(EFilterType type, hsh::texture2d tex, ZTest zTest = ZTest::None);
explicit CTexturedQuadFilter(EFilterType type, hsh::render_texture2d tex, ZTest zTest = ZTest::None);
CTexturedQuadFilter(const CTexturedQuadFilter&) = delete;
CTexturedQuadFilter& operator=(const CTexturedQuadFilter&) = delete;
CTexturedQuadFilter(CTexturedQuadFilter&&) = default;
@ -56,8 +58,8 @@ public:
class CTexturedQuadFilterAlpha : public CTexturedQuadFilter {
public:
explicit CTexturedQuadFilterAlpha(EFilterType type, TLockedToken<CTexture> tex);
template <typename Tex>
explicit CTexturedQuadFilterAlpha(EFilterType type, Tex tex);
explicit CTexturedQuadFilterAlpha(EFilterType type, hsh::texture2d tex);
explicit CTexturedQuadFilterAlpha(EFilterType type, hsh::render_texture2d tex);
};
} // namespace urde

View File

@ -2,6 +2,8 @@
#include <array>
#include "hsh/hsh.h"
#include "zeus/CColor.hpp"
#include "zeus/CMatrix4f.hpp"

View File

@ -5,11 +5,13 @@
#include "Runtime/CToken.hpp"
#include "zeus/CMatrix4f.hpp"
#include "hsh/hsh.h"
namespace urde {
class CTexture;
class CXRayBlurFilter {
friend struct CXRayBlurFilterPipeline;
public:
struct Vert {
hsh::float2 m_pos;
hsh::float2 m_uv;
@ -17,6 +19,8 @@ class CXRayBlurFilter {
struct Uniform {
std::array<hsh::float4x4, 8> m_uv;
};
private:
TLockedToken<CTexture> m_paletteTex;
hsh::owner<hsh::vertex_buffer<Vert>> m_vbo;
hsh::dynamic_owner<hsh::uniform_buffer<Uniform>> m_uniBuf;

View File

@ -8,6 +8,9 @@
#include "Runtime/IOStreams.hpp"
#include "Runtime/GuiSys/CGuiObject.hpp"
// FIXME move extent/rect/etc to builtin_types
#include "hsh/hsh.h"
#include "zeus/CColor.hpp"
#include "zeus/CTransform.hpp"
#include "zeus/CVector3f.hpp"

View File

@ -148,7 +148,7 @@ public:
const char16_t* str, int len) const;
const CGlyph* GetGlyph(char16_t chr) const { return InternalGetGlyph(chr); }
void GetSize(const CDrawStringOptions& opts, int& width, int& height, const char16_t* str, int len) const;
hsh::texture2d GetTexture() {
hsh::texture2d_array GetTexture() {
return x80_texture->GetFontTexture(x2c_mode);
}

View File

@ -57,7 +57,9 @@ void CTextRenderBuffer::CommitResources() {
m_uniBuf2 = hsh::create_dynamic_uniform_buffer<CTextSupportShader::Uniform>();
}
for (BooFontCharacters& chs : m_fontCharacters) {
CTextSupportShader::BuildCharacterShaderBinding(*this, chs, m_drawFlags);
if (!chs.m_charData.empty()) {
CTextSupportShader::BuildCharacterShaderBinding(*this, chs, m_drawFlags);
}
}
for (BooImage& img : m_images) {
CTextSupportShader::BuildImageShaderBinding(*this, img, m_drawFlags);

View File

@ -9,6 +9,8 @@
#include "Runtime/GuiSys/CFontImageDef.hpp"
#include "Runtime/GuiSys/CGuiWidget.hpp"
#include "hsh/hsh.h"
#include "zeus/CColor.hpp"
#include "zeus/CMatrix4f.hpp"
#include "zeus/CVector2f.hpp"

View File

@ -209,7 +209,6 @@ void CGameArchitectureSupport::specialKeyUp(boo2::Keycode key, boo2::KeyModifier
CMain::CMain(IFactory* resFactory, CSimplePool* resStore, hsh::surface surface)
: x128_globalObjects(std::make_unique<CGameGlobalObjects>(resFactory, resStore)) {
CGraphics::InitializeBoo(surface);
xe4_gameplayResult = EGameplayResult::Playing;
g_Main = this;
}

View File

@ -74,6 +74,7 @@ CParticleSwoosh::CParticleSwoosh(const TToken<CSwooshDescription>& desc, int len
m_cachedVerts.reserve(maxVerts);
m_vertBuf = hsh::create_dynamic_vertex_buffer<CParticleSwooshShaders::Vert>(maxVerts);
m_uniformBuf = hsh::create_dynamic_uniform_buffer<CParticleSwooshShaders::Uniform>();
CParticleSwooshShaders::BuildShaderDataBinding(*this);
}
}
}

View File

@ -628,7 +628,7 @@ void CActorModelParticles::LightDudeOnFire(CActor& act) {
const CTexture* CActorModelParticles::GetAshyTexture(const CActor& act) {
auto iter = FindSystem(act.GetUniqueId());
if (iter != x0_items.cend() && iter->xdc_ashy && iter->xdc_ashy.IsLoaded()) {
iter->xdc_ashy->GetBooTexture()->setClampMode(boo::TextureClampMode::ClampToEdge);
//iter->xdc_ashy->GetBooTexture()->setClampMode(boo::TextureClampMode::ClampToEdge);
return iter->xdc_ashy.GetObj();
}
return nullptr;

View File

@ -4,6 +4,8 @@
#include "Runtime/rstl.hpp"
#include "Runtime/World/CRippleManager.hpp"
#include "hsh/hsh.h"
namespace urde {
class CStateManager;

View File

@ -290,7 +290,7 @@ void CWorldTransManager::DrawEnabled() {
DrawFirstPass(&lights);
SClipScreenRect rect(g_Viewport);
CGraphics::ResolveSpareTexture(rect);
CGraphics::g_BooMainCommandQueue->clearTarget(true, true);
hsh::clear_attachments();
DrawSecondPass(&lights);
m_dissolve.drawCropped(zeus::CColor{1.f, 1.f, 1.f, 1.f - t}, 1.f);
}