Skip to content

Commit

Permalink
Add support for important material buffer flags
Browse files Browse the repository at this point in the history
This flag will most likely be crucial when porting particle materials as they use different buffers.
  • Loading branch information
Mauler125 committed Dec 4, 2024
1 parent caf27c3 commit adf5f03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/assets/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ void MaterialAsset_t::FromJSON(const rapidjson::Value& mapEntry)
this->materialTypeStr = JSON_GetValueRequired<const char*>(mapEntry, "shaderType");
this->materialType = Material_ShaderTypeFromString(this->materialTypeStr);

// this only seems to be in apex? heavily affects how the buffers are setup
// and which one is selected at Pak_LoadMaterialAsset(). Func sub_1403B4680
// also checks if this flag is '4' and materialType is 'PTCS'. The material
// "particle/smoke/smoke_charge02_close" (PTCU) for instance, has this set
// to 4, and 4 uses a different global buffer if this (flag & 253) != 0
if (this->assetVersion == 15)
this->uberBufferFlags = (uint8_t)JSON_GetNumberRequired<int>(mapEntry, "uberBufferFlags");

// material max dimensions
this->width = (short)JSON_GetNumberRequired<int>(mapEntry, "width"); // Set material width.
this->height = (short)JSON_GetNumberRequired<int>(mapEntry, "height"); // Set material height.
Expand Down
7 changes: 5 additions & 2 deletions src/public/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ struct __declspec(align(16)) MaterialAssetHeader_v15_t

uint16_t numAnimationFrames; // used in CMaterialGlue::GetNumAnimationFrames (0x1403B4250), which is called from GetSpriteInfo @ 0x1402561FC
MaterialShaderType_e materialType;
uint8_t bytef3; // used for unksections loading in UpdateMaterialAsset
uint8_t uberBufferFlags; // used for setting up buffers in Pak_UpdateMaterialAsset for the CMaterialGlue instance.

char pad_00F4[0x4];

Expand Down Expand Up @@ -553,8 +553,10 @@ struct MaterialAsset_t

MaterialDXState_v15_t dxStates[MAT_DX_STATE_COUNT]; // seems to be used for setting up some D3D states?

std::string materialTypeStr;
MaterialShaderType_e materialType;
uint8_t uberBufferFlags;

std::string materialTypeStr;

std::string name;
std::string surface;
Expand Down Expand Up @@ -641,6 +643,7 @@ struct MaterialAsset_t
matl->flags2 = this->flags2;

matl->materialType = this->materialType;
matl->uberBufferFlags = this->uberBufferFlags;

matl->textureAnimation = this->textureAnimation;
matl->numAnimationFrames = this->numAnimationFrames;
Expand Down

0 comments on commit adf5f03

Please sign in to comment.