Instanced model rendering supported

This commit is contained in:
theclub654 2024-01-01 00:17:35 -05:00
parent c61b858377
commit 45a623d31d
25 changed files with 3690 additions and 187 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ Sly1/x64/
x64/ x64/
Sly1/jb_intro.brx Sly1/jb_intro.brx
Sly1/uw_bonus_drivewheels_final.brx Sly1/uw_bonus_drivewheels_final.brx
Sly1/uw_exterior_boat.brx
Sly1/uw_bonus_library.brx Sly1/uw_bonus_library.brx
Sly1/uw_bonus_security.brx Sly1/uw_bonus_security.brx
Sly1/uw_boss_blimp.brx Sly1/uw_boss_blimp.brx

View File

@ -34,7 +34,7 @@ void RemoveAloHierarchy(ALO *palo)
s_pdliFirst = &plo; s_pdliFirst = &plo;
plo.m_ppv = (void**)plo.m_pdl; plo.m_ppv = (void**)plo.m_pdl;
// Loading object header from RIPG object // Loading object header from object
LO *LocalObject = (LO*)palo; LO *LocalObject = (LO*)palo;
while (true) while (true)
@ -131,6 +131,7 @@ void LoadAloFromBrx(ALO* palo, CBinaryInputStream* pbis)
{ {
palo->xf.mat = pbis->ReadMatrix(); palo->xf.mat = pbis->ReadMatrix();
palo->xf.pos = pbis->ReadVector(); palo->xf.pos = pbis->ReadVector();
pbis->U8Read(); pbis->U8Read();
pbis->U8Read(); pbis->U8Read();
pbis->U8Read(); pbis->U8Read();
@ -140,7 +141,7 @@ void LoadAloFromBrx(ALO* palo, CBinaryInputStream* pbis)
palo->sRadiusRenderSelf = pbis->F32Read(); palo->sRadiusRenderSelf = pbis->F32Read();
palo->sRadiusRenderAll = pbis->F32Read(); palo->sRadiusRenderAll = pbis->F32Read();
LoadOptionFromBrx(palo, pbis); LoadOptionFromBrx(palo, pbis);
LoadGlobsetFromBrx(&palo->globset, pbis, palo); LoadGlobsetFromBrx(&palo->globset ,pbis, palo);
LoadAloAloxFromBrx(pbis); LoadAloAloxFromBrx(pbis);
palo->cposec = pbis->U8Read(); palo->cposec = pbis->U8Read();
@ -258,7 +259,7 @@ void RenderAloAsBone(ALO* palo, CM* pcm, RO* pro)
void DrawAlo(ALO* palo) void DrawAlo(ALO* palo)
{ {
DrawGlob(&palo->globset); DrawGlob(&palo->globset, palo->xf.mat, palo->xf.pos);
} }
void DeleteModel(ALO *palo) void DeleteModel(ALO *palo)

View File

@ -68,32 +68,34 @@ float CBinaryInputStream::F32Read()
glm::vec3 CBinaryInputStream::ReadVector() glm::vec3 CBinaryInputStream::ReadVector()
{ {
return glm::vec3(F32Read(), F32Read(), F32Read()); glm::vec3 temp{};
} file.read(reinterpret_cast<char*> (&temp), sizeof(glm::vec3));
return temp;
glm::vec2 CBinaryInputStream::ReadVector2()
{
return glm::vec2(F32Read(), F32Read());
} }
glm::vec4 CBinaryInputStream::ReadVector4() glm::vec4 CBinaryInputStream::ReadVector4()
{ {
return glm::vec4 (F32Read(), F32Read(), F32Read(), F32Read()); glm::vec4 temp{};
file.read(reinterpret_cast<char*> (&temp), sizeof(glm::vec4));
return temp;
} }
glm::mat3 CBinaryInputStream::ReadMatrix() glm::mat3 CBinaryInputStream::ReadMatrix()
{ {
return glm::mat3 (ReadVector(), ReadVector(), ReadVector()); glm::mat3 temp{};
} file.read(reinterpret_cast<char*> (&temp), sizeof(glm::mat3));
return temp;
glm::mat4x4 CBinaryInputStream::ReadMatrix4x4()
{
return glm::mat4x2(ReadVector(), ReadVector(), ReadVector(), ReadVector());
} }
glm::mat4 CBinaryInputStream::ReadMatrix4() glm::mat4 CBinaryInputStream::ReadMatrix4()
{ {
return glm::mat4(ReadVector4(), ReadVector4(), ReadVector4(), ReadVector4()); glm::mat4 temp{};
file.read(reinterpret_cast<char*> (&temp[0]), sizeof(glm::vec3));
file.read(reinterpret_cast<char*> (&temp[1]), sizeof(glm::vec3));
file.read(reinterpret_cast<char*> (&temp[2]), sizeof(glm::vec3));
file.read(reinterpret_cast<char*> (&temp[3]), sizeof(glm::vec3));
temp[3][3] = 1.0;
return temp;
} }
void CBinaryInputStream::ReadGeom(GEOM *pgeom) void CBinaryInputStream::ReadGeom(GEOM *pgeom)
@ -142,9 +144,9 @@ void CBinaryInputStream::ReadGeom(GEOM *pgeom)
void CBinaryInputStream::ReadBspc() void CBinaryInputStream::ReadBspc()
{ {
U16Read(); U16Read();
uint16_t unk0 = U16Read(); uint16_t cbsp = U16Read();
for (int i = 0; i < unk0; i++) for (int i = 0; i < cbsp; i++)
{ {
U16Read(); U16Read();
U16Read(); U16Read();

View File

@ -34,16 +34,13 @@ class CBinaryInputStream
float F32Read(); float F32Read();
// Reads vector from file // Reads vector from file
glm::vec3 ReadVector(); glm::vec3 ReadVector();
// Reads vector 2 from file
glm::vec2 ReadVector2();
// Reads vector 4 from file // Reads vector 4 from file
glm::vec4 ReadVector4(); glm::vec4 ReadVector4();
// Reads matrix from file // Reads matrix from file
glm::mat3 ReadMatrix(); glm::mat3 ReadMatrix();
// Reads matrix4x4 from file
glm::mat4x4 ReadMatrix4x4();
// Reads matrix 4 from file // Reads matrix 4 from file
glm::mat4 ReadMatrix4(); glm::mat4 ReadMatrix4();
// Reads Collision data from file
void ReadGeom(GEOM *pgeom); void ReadGeom(GEOM *pgeom);
void ReadBspc(); void ReadBspc();
void ReadVbsp(); // GOTTA COME BACK TO THIS void ReadVbsp(); // GOTTA COME BACK TO THIS

View File

@ -13,7 +13,7 @@ LO* PloNew(CID cid, SW* psw, ALO* paloParent, OID oid, int isplice)
VTLO *pvtlo = (VTLO*)g_mpcidpvt[cid]; VTLO *pvtlo = (VTLO*)g_mpcidpvt[cid];
// Returning a address for the newly made object // Returning a address for the newly made object
LO *localObject = (LO*)pvtlo->pfnNewLo(); LO* localObject = (LO*)pvtlo->pfnNewLo();
// Storing vtable with object // Storing vtable with object
localObject->pvtlo = pvtlo; localObject->pvtlo = pvtlo;

View File

@ -8,5 +8,5 @@ uniform mat4 model;
void main() void main()
{ {
gl_Position = proj * view * model * vec4(pos.y, pos.x, pos.z, 1.0); gl_Position = proj * view * model * vec4(pos, 1.0);
} }

View File

@ -27,6 +27,11 @@ void RenderMenuGui(SW* psw)
} }
if (ImGui::MenuItem("Wireframe", "", &fRenderWireFrame))
{
}
ImGui::EndMenu(); ImGui::EndMenu();
} }

View File

@ -11,5 +11,6 @@ void DeleteWorld(SW* psw);
static ImGuiFileDialog instance_a; static ImGuiFileDialog instance_a;
extern inline bool fRenderModels = true; extern inline bool fRenderModels = true;
extern inline bool fRenderCollision = false; extern inline bool fRenderCollision = false;
extern inline bool fRenderWireFrame = false;
void RenderMenuGui(SW* psw); void RenderMenuGui(SW* psw);

View File

@ -7,7 +7,6 @@ void* NewFly()
void InitFly(FLY* pfly) void InitFly(FLY* pfly)
{ {
//std::cout << "FLY Size: " << sizeof(FLY) << "\n";
InitSo(pfly); InitSo(pfly);
AppendDlEntry(&pfly->psw->dlFly, pfly); AppendDlEntry(&pfly->psw->dlFly, pfly);
} }

View File

@ -3,13 +3,13 @@
FREECAMERA::FREECAMERA(glm::vec3 position) FREECAMERA::FREECAMERA(glm::vec3 position)
{ {
cameraPos = position; cameraPos = position;
worldUp = glm::vec3(0.0f, 1.0f, 0.0f); worldUp = glm::vec3(0.0f, 0.0f, 1.0f);
yaw = -90.0; yaw = -90;
pitch = 0.0f; pitch = 0;
speed = 10000.0; speed = 10000.0;
fov = 45.0f; fov = 45.0f;
cameraDirection = glm::vec3(1.0f, 0.0f, 0.0f); cameraDirection = glm::vec3{0.0};
cameraRight = glm::vec3(0.0f, 0.0f, 0.0f);
UpdateCameraVectors(); UpdateCameraVectors();
} }
@ -77,7 +77,8 @@ void FREECAMERA::UpdateViewProjMatrix(int height, int width, GLSHADER shader)
glm::mat4 view{ 1.0 }; glm::mat4 view{ 1.0 };
// Creates a large frustum // Creates a large frustum
proj = glm::perspective(glm::radians(fov), (float)height / (float)width, 100.0f, 1000000.0f); proj = glm::perspective(fov, (float)height / (float)width, 100.0f, 1000000.0f);
// Transform coordinates from world space to camera space // Transform coordinates from world space to camera space
view = glm::lookAt(cameraPos, cameraPos + cameraDirection, cameraUp); view = glm::lookAt(cameraPos, cameraPos + cameraDirection, cameraUp);
@ -100,9 +101,10 @@ void FREECAMERA::SendViewProjShader(glm::mat4 proj, glm::mat4 view, GLSHADER sha
void FREECAMERA::UpdateCameraVectors() void FREECAMERA::UpdateCameraVectors()
{ {
glm::vec3 direction; glm::vec3 direction;
direction.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch)); direction.x = cos(glm::radians(-yaw)) * cos(glm::radians(-pitch));
direction.y = sin(glm::radians(pitch)); direction.z = sin(glm::radians(pitch));
direction.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch)); direction.y = sin(glm::radians(-yaw)) * cos(glm::radians(-pitch));
cameraDirection = glm::normalize(direction); cameraDirection = glm::normalize(direction);
cameraRight = glm::normalize(glm::cross(cameraDirection, worldUp)); cameraRight = glm::normalize(glm::cross(cameraDirection, worldUp));

View File

@ -20,7 +20,7 @@ enum class CAMERADIRECTION
class FREECAMERA class FREECAMERA
{ {
public: public:
glm::vec3 cameraPos; glm::vec3 cameraPos;
glm::vec3 cameraDirection; glm::vec3 cameraDirection;

View File

@ -32,7 +32,6 @@ void GL::InitGL()
glViewport(0, 0, width, height); glViewport(0, 0, width, height);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();

View File

@ -4,7 +4,7 @@ std::vector <SHD> g_ashd;
extern std::vector<ALO*> allSWAloObjs; extern std::vector<ALO*> allSWAloObjs;
extern std::vector<void*> allSwLights; extern std::vector<void*> allSwLights;
void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo) void LoadGlobsetFromBrx(GLOBSET* pglobset ,CBinaryInputStream* pbis, ALO* palo)
{ {
pglobset->cpsaa = 0; pglobset->cpsaa = 0;
@ -38,14 +38,11 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
if ((unk_5 & 1) != 0) if ((unk_5 & 1) != 0)
{ {
pbis->S16Read(); int instanceIndex = pbis->S16Read();
pglobset->aglob[i].pdmat = glm::mat4 pdmat = pbis->ReadMatrix4();
{
pbis->F32Read(), pbis->F32Read(), pbis->F32Read(), 0.0f, if(instanceIndex != 0)
pbis->F32Read(), pbis->F32Read(), pbis->F32Read(), 0.0f, pglobset->aglob[instanceIndex].pdmat.push_back(pdmat);
pbis->F32Read(), pbis->F32Read(), pbis->F32Read(), 0.0f,
pbis->F32Read(), pbis->F32Read(), pbis->F32Read(), 1.0f,
};
} }
if ((unk_5 & 2) != 0) if ((unk_5 & 2) != 0)
@ -77,27 +74,33 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
if ((unk_5 & 0x100) != 0) if ((unk_5 & 0x100) != 0)
{ {
pbis->S16Read(); WRBG wrbg{};
int8_t unk_8 = pbis->S8Read(); WRBG* pwrbg = &wrbg;
if (unk_8 != -1) pwrbg->oid = (OID)pbis->S16Read();
pwrbg->weki.wek = (WEK)pbis->S8Read();
if (pwrbg->weki.wek != -1)
{ {
pbis->F32Read(); pwrbg->weki.sInner = pbis->F32Read();
pbis->F32Read(); pwrbg->weki.uInner = pbis->F32Read();
pbis->F32Read(); pwrbg->weki.sOuter = pbis->F32Read();
pbis->F32Read(); pwrbg->weki.uOuter = pbis->F32Read();
pbis->ReadMatrix4x4(); pwrbg->weki.dmat = pbis->ReadMatrix4();
} }
pbis->U8Read(); pwrbg->cmat = pbis->U8Read();
pbis->U8Read(); pwrbg->fDpos = pbis->U8Read();
pbis->U8Read(); pwrbg->fDuv = pbis->U8Read();
pglobset->aglob[i].pwrbg = pwrbg;
pwrbg->pwrbgNextGlobset = pglobset->pwrbgFirst;
pglobset->pwrbgFirst = pwrbg;
} }
pglobset->aglob[i].posCenter = pbis->ReadVector(); pglobset->aglob[i].posCenter = pbis->ReadVector();
pglobset->aglob[i].sRadius = pbis->F32Read(); pglobset->aglob[i].sRadius = pbis->F32Read();
pbis->S16Read(); pbis->S16Read();
pbis->U8Read(); pglobset->aglob[i].rtck = (RTCK)pbis->U8Read();
pbis->U8Read(); pbis->U8Read();
pglobset->aglob[i].oid = (OID)pbis->U8Read(); pglobset->aglob[i].oid = (OID)pbis->U8Read();
@ -166,7 +169,7 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
pglobset->aglob[i].asubglob[a].indexes[f].bMisc = pbis->U8Read(); pglobset->aglob[i].asubglob[a].indexes[f].bMisc = pbis->U8Read();
} }
// Loading texture property info from vector // Loading texture property
pglobset->aglob[i].asubglob[a].pshd = &g_ashd[pbis->U16Read()]; pglobset->aglob[i].asubglob[a].pshd = &g_ashd[pbis->U16Read()];
pglobset->aglob[i].asubglob[a].unSelfIllum = pbis->U8Read(); pglobset->aglob[i].asubglob[a].unSelfIllum = pbis->U8Read();
@ -204,6 +207,7 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
} }
BuildSubGlob(pglobset, pglobset->aglob[i].asubglob[a].pshd, pglobset->aglob[i].asubglob[a].vertices, pglobset->aglob[i].asubglob[a].vertexes, pglobset->aglob[i].asubglob[a].normals, pglobset->aglob[i].asubglob[a].vertexColors, pglobset->aglob[i].asubglob[a].texcoords, pglobset->aglob[i].asubglob[a].indexes, pglobset->aglob[i].asubglob[a].indices); BuildSubGlob(pglobset, pglobset->aglob[i].asubglob[a].pshd, pglobset->aglob[i].asubglob[a].vertices, pglobset->aglob[i].asubglob[a].vertexes, pglobset->aglob[i].asubglob[a].normals, pglobset->aglob[i].asubglob[a].vertexColors, pglobset->aglob[i].asubglob[a].texcoords, pglobset->aglob[i].asubglob[a].indexes, pglobset->aglob[i].asubglob[a].indices);
MakeGLBuffers(&pglobset->aglob[i].asubglob[a]);
} }
uint16_t numSubMesh1 = pbis->U16Read(); uint16_t numSubMesh1 = pbis->U16Read();
@ -251,14 +255,10 @@ void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo)
} }
} }
if (pglobset->cglob != 0)
{
MakeGLBuffers(pglobset);
allSWAloObjs.push_back(palo); allSWAloObjs.push_back(palo);
}
} }
void BuildSubGlob(GLOBSET* pglobset, SHD* pshd ,std::vector<VERTICE>& vertices,std::vector<glm::vec3>& vertexes, std::vector<glm::vec3>& normals, std::vector<RGBA>& vertexColors, std::vector<glm::vec2>& texcoords, std::vector<VTXFLG>& indexes, std::vector<uint16_t> &indices) void BuildSubGlob(GLOBSET* pglobset, SHD* pshd, std::vector<VERTICE>& vertices, std::vector <glm::vec3>& vertexes, std::vector <glm::vec3>& normals, std::vector <RGBA>& vertexColors, std::vector <glm::vec2>& texcoords, std::vector <VTXFLG>& indexes, std::vector<uint16_t>& indices)
{ {
for (int i = 0; i < indexes.size(); i++) for (int i = 0; i < indexes.size(); i++)
{ {
@ -266,6 +266,7 @@ void BuildSubGlob(GLOBSET* pglobset, SHD* pshd ,std::vector<VERTICE>& vertices,s
vertice.pos = vertexes[indexes[i].ipos]; vertice.pos = vertexes[indexes[i].ipos];
vertice.normal = normals[indexes[i].inormal]; vertice.normal = normals[indexes[i].inormal];
vertice.color = (RGBA)0;
if (indexes[i].iuv == 0xFF) if (indexes[i].iuv == 0xFF)
vertice.uv = glm::vec2{0.0}; vertice.uv = glm::vec2{0.0};
@ -275,6 +276,9 @@ void BuildSubGlob(GLOBSET* pglobset, SHD* pshd ,std::vector<VERTICE>& vertices,s
vertices.push_back(vertice); vertices.push_back(vertice);
} }
for (int i = 0; i < vertexColors.size(); i++)
vertices[i].color = vertexColors[i];
uint32_t idx = 0; uint32_t idx = 0;
for (int i = 2; i < indexes.size(); i++) for (int i = 2; i < indexes.size(); i++)
{ {
@ -301,24 +305,22 @@ void BuildSubGlob(GLOBSET* pglobset, SHD* pshd ,std::vector<VERTICE>& vertices,s
vertexColors.shrink_to_fit(); vertexColors.shrink_to_fit();
texcoords.clear(); texcoords.clear();
texcoords.shrink_to_fit(); texcoords.shrink_to_fit();
indexes.clear();
indexes.shrink_to_fit();
} }
void MakeGLBuffers(GLOBSET *pglobset) void MakeGLBuffers(SUBGLOB *subglob)
{ {
for (int i = 0; i < pglobset->aglob.size(); i++) glGenVertexArrays(1, &subglob->VAO);
{ glBindVertexArray(subglob->VAO);
for (int a = 0; a < pglobset->aglob[i].asubglob.size(); a++)
{
glGenVertexArrays(1, &pglobset->aglob[i].asubglob[a].VAO);
glBindVertexArray(pglobset->aglob[i].asubglob[a].VAO);
glGenBuffers(1, &pglobset->aglob[i].asubglob[a].VBO); glGenBuffers(1, &subglob->VBO);
glBindBuffer(GL_ARRAY_BUFFER, pglobset->aglob[i].asubglob[a].VBO); glBindBuffer(GL_ARRAY_BUFFER, subglob->VBO);
glBufferData(GL_ARRAY_BUFFER, pglobset->aglob[i].asubglob[a].vertices.size() * sizeof(VERTICE), pglobset->aglob[i].asubglob[a].vertices.data(), GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, subglob->vertices.size() * sizeof(VERTICE), subglob->vertices.data(), GL_STATIC_DRAW);
glGenBuffers(1, &pglobset->aglob[i].asubglob[a].EBO); glGenBuffers(1, &subglob->EBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, pglobset->aglob[i].asubglob[a].EBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, subglob->EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, pglobset->aglob[i].asubglob[a].indices.size() * sizeof(uint16_t), pglobset->aglob[i].asubglob[a].indices.data(), GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, subglob->indices.size() * sizeof(uint16_t), subglob->indices.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)0);
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
@ -326,33 +328,47 @@ void MakeGLBuffers(GLOBSET *pglobset)
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)12); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)12);
glEnableVertexAttribArray(1); glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)24); glVertexAttribPointer(2, 1, GL_UNSIGNED_INT, GL_FALSE, sizeof(VERTICE), (void*)24);
glEnableVertexAttribArray(2); glEnableVertexAttribArray(2);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(VERTICE), (void*)28);
glEnableVertexAttribArray(3);
glBindVertexArray(0); glBindVertexArray(0);
}
}
} }
void DrawGlob(GLOBSET* pglobset) void DrawGlob(GLOBSET* pglobset, glm::mat3 mat, glm::vec3 pos)
{ {
glm::mat4 model = mat;
// Sly 1 uses a Z up axis
model[3][0] = pos[0];
model[3][1] = pos[1];
model[3][2] = pos[2];
model[3][3] = 1.0;
for (int i = 0; i < pglobset->cglob; i++) for (int i = 0; i < pglobset->cglob; i++)
{ {
for (int a = 0; a < pglobset->aglob[i].csubglob; a++) for (int a = 0; a < pglobset->aglob[i].csubglob; a++)
{ {
glm::mat4 model{ 1.0 };
int modelUniformLocation = glGetUniformLocation(glShader.ID, "model"); int modelUniformLocation = glGetUniformLocation(glShader.ID, "model");
glUniformMatrix4fv(modelUniformLocation, 1, GL_FALSE, glm::value_ptr(model)); glUniformMatrix4fv(modelUniformLocation, 1, GL_FALSE, glm::value_ptr(model));
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, pglobset->aglob[i].asubglob[a].pshd->glTexture); glBindTexture(GL_TEXTURE_2D, pglobset->aglob[i].asubglob[a].pshd->glTexture);
glBindVertexArray(pglobset->aglob[i].asubglob[a].VAO); glBindVertexArray(pglobset->aglob[i].asubglob[a].VAO);
glDrawElements(GL_TRIANGLES, pglobset->aglob[i].asubglob[a].indices.size(), GL_UNSIGNED_SHORT, (void*)0); glDrawElements(GL_TRIANGLES, pglobset->aglob[i].asubglob[a].indices.size(), GL_UNSIGNED_SHORT, 0);
glBindVertexArray(0);
// Draws instanced models.
for (int b = 0; b < pglobset->aglob[i].pdmat.size(); b++)
{
glm::mat4 instanceModelMatrix = pglobset->aglob[i].pdmat[b];
int instanceModelUniformLocation = glGetUniformLocation(glShader.ID, "model");
glUniformMatrix4fv(instanceModelUniformLocation, 1, GL_FALSE, glm::value_ptr(instanceModelMatrix));
glDrawElements(GL_TRIANGLES, pglobset->aglob[i].asubglob[a].indices.size(), GL_UNSIGNED_SHORT, 0);
}
} }
} }
} }

View File

@ -3,6 +3,7 @@
out vec4 FragColor; out vec4 FragColor;
in vec3 aNormal; in vec3 aNormal;
in vec4 aColor;
in vec2 aTexcoord; in vec2 aTexcoord;
uniform sampler2D Texture; uniform sampler2D Texture;

View File

@ -11,11 +11,47 @@ enum TWPS
TWPS_ShadowMidtone = 1, TWPS_ShadowMidtone = 1,
TWPS_ShadowMidtoneSaturate = 2 TWPS_ShadowMidtoneSaturate = 2
}; };
enum RTCK
{
RTCK_Nil = -1,
RTCK_None = 0,
RTCK_All = 1,
RTCK_WorldZ = 2,
RTCK_LocalX = 3,
RTCK_LocalY = 4,
RTCK_LocalZ = 5,
RTCK_Max = 6
};
enum WEK
{
WEK_Nil = -1,
WEK_XYZ = 0,
WEK_XY = 1,
WEK_XZ = 2,
WEK_YZ = 3,
WEK_X = 4,
WEK_Y = 5,
WEK_Z = 6,
WEK_Max = 7
};
struct LTFN
{
float ruShadow;
float ruMidtone;
float ruHighlight;
float ruUnused;
float duShadow;
float duMidtone;
float duHighlight;
float duUnused;
};
struct VERTICE struct VERTICE
{ {
glm::vec3 pos; glm::vec3 pos;
glm::vec3 normal; glm::vec3 normal;
RGBA color;
glm::vec2 uv; glm::vec2 uv;
}; };
@ -32,6 +68,30 @@ struct VTXFLG
byte bMisc; byte bMisc;
}; };
struct WEKI
{
WEK wek;
float sInner;
float uInner;
float sOuter;
float uOuter;
glm::mat4 dmat;
};
struct WRBG
{
struct ALO* palo;
struct GLOB* pglob;
OID oid;
struct WR* pwr;
int cmat;
int fDpos;
int fDuv;
WEKI weki;
struct WRBG* pwrbgNextGlobset;
struct WRBG* pwrbgNextWr;
};
struct SUBGLOB // NOT DONE struct SUBGLOB // NOT DONE
{ {
GLuint VAO; GLuint VAO;
@ -40,7 +100,6 @@ struct SUBGLOB // NOT DONE
glm::vec3 posCenter; // Submodel orgin glm::vec3 posCenter; // Submodel orgin
float sRadius; float sRadius;
std::vector <VERTICE> vertices; std::vector <VERTICE> vertices;
std::vector <glm::vec3> vertexes; std::vector <glm::vec3> vertexes;
std::vector <glm::vec3> normals; std::vector <glm::vec3> normals;
@ -48,8 +107,11 @@ struct SUBGLOB // NOT DONE
std::vector <glm::vec2> texcoords; std::vector <glm::vec2> texcoords;
std::vector <VTXFLG> indexes; std::vector <VTXFLG> indexes;
std::vector <uint16_t> indices; std::vector <uint16_t> indices;
uint32_t unSelfIllum; uint32_t unSelfIllum;
struct SHD* pshd; struct SHD* pshd;
struct RSGLD *prsgld;
struct WRBSG *pwrbsg;
int cibnd; int cibnd;
int aibnd[4]; int aibnd[4];
@ -69,19 +131,19 @@ struct GLOB // NOT DONE
int fDynamic; int fDynamic;
int grfglob; int grfglob;
//GLEAM *pgleam //GLEAM *pgleam
//RTCK rtck; RTCK rtck;
struct SAA* psaa; struct SAA* psaa;
float uFog; float uFog;
//FGFN fgfn; //FGFN fgfn;
float rSubglobRadius; float rSubglobRadius;
//WRBG *pwrbg; struct WRBG *pwrbg;
// Number of submodels for model // Number of submodels for model
int csubglob; int csubglob;
std::vector<SUBGLOB> asubglob; std::vector<SUBGLOB> asubglob;
int csubcel; int csubcel;
//SUBCEL *asubcel; //SUBCEL *asubcel;
// Object world space coordinates // Object world space coordinates
glm::mat4 pdmat; std::vector <glm::mat4> pdmat;
//BLOT *pblot; //BLOT *pblot;
OID oid; OID oid;
char* pchzName; char* pchzName;
@ -92,7 +154,7 @@ struct GLOBI // NOT DONE
int grfzon; int grfzon;
//SUBGLOBI *asubglobi; //SUBGLOBI *asubglobi;
int cframeStaticLights; int cframeStaticLights;
//TWPS twps; TWPS twps;
float uAlpha; float uAlpha;
float tUnfade; float tUnfade;
}; // NOT DONE }; // NOT DONE
@ -100,27 +162,27 @@ struct GLOBI // NOT DONE
struct GLOBSET // NOT DONE struct GLOBSET // NOT DONE
{ {
int cbnd; int cbnd;
//BND *abnd; struct BND *abnd;
std::vector <OID> mpibndoid; std::vector <OID> mpibndoid;
// Number of submodeles for a model uint64_t cglob;
int cglob;
std::vector <GLOB> aglob; std::vector <GLOB> aglob;
std::vector <GLOBI> aglobi; std::vector <GLOBI> aglobi;
//LTFN ltfn; LTFN ltfn;
uint32_t grfglobset; uint32_t grfglobset;
RGBA rgbaCel; RGBA rgbaCel;
int cpose; int cpose;
std::vector <float> agPoses; std::vector <float> agPoses;
std::vector <float> agPosesOrig; std::vector <float> agPosesOrig;
//WRBG *pwrbgFirst; struct WRBG *pwrbgFirst;
int cpsaa; int cpsaa;
struct SAA** apsaa; struct SAA** apsaa;
}; // NOT DONE };
// Loads 3D models from binary file // Loads 3D model data from binary file
void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo); // NOT FINISHED void LoadGlobsetFromBrx(GLOBSET* pglobset, CBinaryInputStream* pbis, ALO* palo); // NOT FINISHED
// Converts strips to tri lists
void BuildSubGlob(GLOBSET *pglobset, SHD* pshd, std::vector<VERTICE> &vertices , std::vector <glm::vec3> &vertexes, std::vector <glm::vec3> &normals, std::vector <RGBA> &vertexColors, std::vector <glm::vec2> &texcoords, std::vector <VTXFLG> &indexes, std::vector<uint16_t> &indices); void BuildSubGlob(GLOBSET *pglobset, SHD* pshd, std::vector<VERTICE> &vertices , std::vector <glm::vec3> &vertexes, std::vector <glm::vec3> &normals, std::vector <RGBA> &vertexColors, std::vector <glm::vec2> &texcoords, std::vector <VTXFLG> &indexes, std::vector<uint16_t> &indices);
// Storing 3D models in VRAM // Storing 3D models in VRAM
void MakeGLBuffers(GLOBSET* pglobset); void MakeGLBuffers(SUBGLOB* subglob);
// Draws Model // Draws Model
void DrawGlob(GLOBSET *pglobset); // NOT FINISHED void DrawGlob(GLOBSET* pglobset, glm::mat3 mat, glm::vec3 pos); // NOT FINISHED

View File

@ -2,9 +2,11 @@
layout (location = 0) in vec3 pos; layout (location = 0) in vec3 pos;
layout (location = 1) in vec3 normal; layout (location = 1) in vec3 normal;
layout (location = 2) in vec2 texCoord; layout (location = 2) in vec4 color;
layout (location = 3) in vec2 texcoord;
out vec3 aNormal; out vec3 aNormal;
out vec4 aColor;
out vec2 aTexcoord; out vec2 aTexcoord;
uniform mat4 proj; uniform mat4 proj;
@ -13,7 +15,8 @@ uniform mat4 model;
void main() void main()
{ {
gl_Position = proj * view * model * vec4(pos.y, pos.x, pos.z, 1.0); gl_Position = proj * view * model * vec4(pos, 1.0);
aNormal = normal; aNormal = normal;
aTexcoord = texCoord; aColor = color;
aTexcoord = texcoord;
} }

File diff suppressed because it is too large Load Diff

View File

@ -47,6 +47,11 @@ int main(int cphzArgs, char* aphzArgs[])
g_freecamera.UpdateViewProjMatrix(g_gl.height, g_gl.width, glShader); g_freecamera.UpdateViewProjMatrix(g_gl.height, g_gl.width, glShader);
g_freecamera.UpdateViewProjMatrix(g_gl.height, g_gl.width, glShaderCollision); g_freecamera.UpdateViewProjMatrix(g_gl.height, g_gl.width, glShaderCollision);
if(fRenderWireFrame != 0)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
else
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if(fRenderModels != 0) if(fRenderModels != 0)
DrawSwAll(); DrawSwAll();

View File

@ -13,8 +13,10 @@ void InitProxy(PROXY *pproxy)
void LoadProxyFromBrx(PROXY *pproxy, CBinaryInputStream* pbis) void LoadProxyFromBrx(PROXY *pproxy, CBinaryInputStream* pbis)
{ {
pbis->ReadMatrix(); InitDl(&pproxy->dlProxyRoot, 0x470);
pbis->ReadVector();
pproxy->xf.mat = pbis->ReadMatrix();
pproxy->xf.pos = pbis->ReadVector();
byte numProxyObjs = pbis->U8Read(); byte numProxyObjs = pbis->U8Read();

View File

@ -11,8 +11,6 @@ class PROXY : public ALO
DLE dleProxy; DLE dleProxy;
}; };
static int LoadProxyFromBrxCount = 0;
void* NewProxy(); void* NewProxy();
void InitProxy(PROXY *pproxy); void InitProxy(PROXY *pproxy);
void LoadProxyFromBrx(PROXY *pproxy, CBinaryInputStream *pbis); void LoadProxyFromBrx(PROXY *pproxy, CBinaryInputStream *pbis);

View File

@ -47,13 +47,14 @@ void DrawSwCollisionAll()
{ {
glShaderCollision.Use(); glShaderCollision.Use();
glm::mat4 model{ 1.0 };
int modelUniformLocation = glGetUniformLocation(glShaderCollision.ID, "model");
glUniformMatrix4fv(modelUniformLocation, 1, GL_FALSE, glm::value_ptr(model));
for (int i = 0; i < allcollisionModels.size(); i++) for (int i = 0; i < allcollisionModels.size(); i++)
{ {
int modelUniformLocation = glGetUniformLocation(glShaderCollision.ID, "model");
glUniformMatrix4fv(modelUniformLocation, 1, GL_FALSE, glm::value_ptr(glm::mat4{1.0}));
glBindVertexArray(allcollisionModels[i]->VAO); glBindVertexArray(allcollisionModels[i]->VAO);
glDrawElements(GL_LINES, allcollisionModels[i]->indices.size(), GL_UNSIGNED_SHORT, 0); glDrawElements(GL_LINES, allcollisionModels[i]->indices.size(), GL_UNSIGNED_SHORT, 0);
glBindVertexArray(0);
} }
} }

View File

@ -7,7 +7,7 @@ void* NewSo()
void InitSo(SO* pso) void InitSo(SO* pso)
{ {
InitDl(&pso->dlPhys, 0x440); InitDl(&pso->dlPhys, 0x468);
InitAlo(pso); InitAlo(pso);
InitGeom(&pso->geomLocal); InitGeom(&pso->geomLocal);

View File

@ -51,7 +51,7 @@ public:
glm::vec3 posWorldPrev; glm::vec3 posWorldPrev;
GEOM geomLocal; GEOM geomLocal;
GEOM geomWorld; GEOM geomWorld;
void* plvo; struct LVO* plvo;
float sRadiusSelf; float sRadiusSelf;
float sRadiusAll; float sRadiusAll;
float sRadiusPrune; float sRadiusPrune;
@ -68,11 +68,11 @@ public:
glm::vec3 posMax; glm::vec3 posMax;
char constrForce[32]; char constrForce[32];
char constrTorque[32]; char constrTorque[32];
void* poxa; struct OXA* poxa;
glm::vec3 dpos; glm::vec3 dpos;
glm::vec3 drot; glm::vec3 drot;
void* pxa; struct XA* pxa;
void* pxpInternal; struct XP* pxpInternal;
int grfpvaXpValid; int grfpvaXpValid;
int ipsoRoot; int ipsoRoot;
int ipso; int ipso;
@ -81,7 +81,7 @@ public:
GEOM geomCameraLocal; GEOM geomCameraLocal;
GEOM geomCameraWorld; GEOM geomCameraWorld;
char bspcCamera[12]; char bspcCamera[12];
void* pstso; struct STSO* pstso;
}; };
void* NewSo(); void* NewSo();

View File

@ -17,36 +17,36 @@ void InitSw(SW* psw)
InitDl(&psw->dlChild, 0x38); InitDl(&psw->dlChild, 0x38);
InitDl(&psw->dlMRD, 0xA0); InitDl(&psw->dlMRD, 0xA0);
InitDl(&psw->dlMRDRealClock, 0x1C + 0x54); InitDl(&psw->dlMRDRealClock, 0x1C + 0x54); // GOTTA COME BACK TO THIS
InitDl(&psw->dlBusy, 0x90); InitDl(&psw->dlBusy, 0x90);
InitDl(&psw->dlBusySo, 0x1C + 0x434); InitDl(&psw->dlBusySo, 0x790);
InitDl(&psw->dlRoot, 0x428); InitDl(&psw->dlRoot, 0x458);
InitDl(&psw->dlAsega, 0x1C + 0x34); InitDl(&psw->dlAsega, 0x1C + 0x34); // GOTTA COME BACK TO THIS
InitDl(&psw->dlAsegaRealClock, 0x1C + 0x34); InitDl(&psw->dlAsegaRealClock, 0x1C + 0x34); // GOTTA COME BACK TO THIS
InitDl(&psw->dlAsegaPending, 0x1C + 0x34); InitDl(&psw->dlAsegaPending, 0x1C + 0x34); // GOTTA COME BACK TO THIS
InitDl(&psw->dlSma, 0x10); InitDl(&psw->dlSma, 0x10);
InitDl(&psw->dlAmb, 0x1C + 0x60); InitDl(&psw->dlAmb, 0x1C + 0x60); // GOTTA COME BACK TO THIS
InitDl(&psw->dlExc, 0x1C + 4); InitDl(&psw->dlExc, 0x1C + 4); // GOTTA COME BACK TO THIS
InitDl(&psw->dlLight, 0x538); InitDl(&psw->dlLight, 0x568);
InitDl(&psw->dlShadow, 0x1C + 0xb8); InitDl(&psw->dlShadow, 0x1C + 0xb8); // GOTTA COME BACK TO THIS
InitDl(&psw->dlExplste, 0x1C + 100); InitDl(&psw->dlExplste, 0x1C + 100);// GOTTA COME BACK TO THIS
InitDl(&psw->dlProxy, 0x1C + 0x2ec); InitDl(&psw->dlProxy, 0x470);
InitDl(&psw->dlFly, 0x1C + 0x60c); InitDl(&psw->dlFly, 0xB50);
InitDl(&psw->dlDprize, 0x1C + 900); InitDl(&psw->dlDprize, 0x500);
InitDl(&psw->dlRat, 0x1C + 0x630); InitDl(&psw->dlRat, 0xB90);
InitDl(&psw->dlRathole, 0x1C + 0x90); InitDl(&psw->dlRathole, 0xC8);
InitDl(&psw->dlDartFree, 0x1C + 0x59c); InitDl(&psw->dlDartFree, 0xA70);
InitDl(&psw->dlSpire, 0x1C + 0x50); InitDl(&psw->dlSpire, 0x1C + 0x50); // GOTTA COME BACK TO THIS
InitDl(&psw->dlRail, 0x1C + 0x50); InitDl(&psw->dlRail, 0x1C + 0x50); // GOTTA COME BACK TO THIS
InitDl(&psw->dlLanding, 0x1C + 0x50); InitDl(&psw->dlLanding, 0x1C + 0x50); // GOTTA COME BACK TO THIS
InitDl(&psw->dlBusyLasen, 0x1C + 0xb20); InitDl(&psw->dlBusyLasen, 0x1200);
InitDl(&psw->dlBlipg, 0x1C + 0x640); InitDl(&psw->dlBlipg, 0x1C + 0x640);// GOTTA COME BACK TO THIS
InitDl(&psw->dlBlipgFree, 0x1C + 0x640); InitDl(&psw->dlBlipgFree, 0x1C + 0x640);// GOTTA COME BACK TO THIS
InitDl(&psw->dlFader, 0x1C + 0xc); InitDl(&psw->dlFader, 0x1C + 0xc);// GOTTA COME BACK TO THIS
InitDl(&psw->dlRealClockFader, 0x1C + 0xc); InitDl(&psw->dlRealClockFader, 0x1C + 0xc);// GOTTA COME BACK TO THIS
InitDl(&psw->dlCrfod, 0x1C + 0xb90); InitDl(&psw->dlCrfod, 0x1C + 0xb90);// GOTTA COME BACK TO THIS
InitDl(&psw->dlShape, 0x1C + 0x44); InitDl(&psw->dlShape, 0x80);
InitDl(&psw->dlPathzone, 0x1C + 100); InitDl(&psw->dlPathzone, 0xB8);
} }
void InitSwDlHash(SW* psw) void InitSwDlHash(SW* psw)
@ -57,7 +57,7 @@ void InitSwDlHash(SW* psw)
void LoadSwFromBrx(SW* psw, CBinaryInputStream* pbis) void LoadSwFromBrx(SW* psw, CBinaryInputStream* pbis)
{ {
std::cout << "Loading World\n"; std::cout << "Loading World...\n";
// Setting difficulty for world // Setting difficulty for world
OnDifficultyWorldPreLoad(&g_difficulty); OnDifficultyWorldPreLoad(&g_difficulty);
//StartupSplice(); //StartupSplice();

View File

@ -1,7 +1,6 @@
#pragma once #pragma once
#include "lo.h" #include "lo.h"
// GOTTA COME BACK TO THIS AND CHANGE VTABLE CB
enum WREK enum WREK
{ {
WREK_Nil = -1, WREK_Nil = -1,
@ -19,6 +18,7 @@ struct WRE
}; };
}; };
class WR : public LO class WR : public LO
{ {
public: public: