Fixed dolphin matricies the ugly way

This commit is contained in:
2026-04-18 00:36:35 -05:00
parent bddc9af3b6
commit 3b94598d2c
3 changed files with 17 additions and 25 deletions
+2 -2
View File
@@ -154,11 +154,11 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
componentid_t boxPos = entityAddComponent(phBoxEnt, COMPONENT_TYPE_POSITION); componentid_t boxPos = entityAddComponent(phBoxEnt, COMPONENT_TYPE_POSITION);
componentid_t boxMesh = entityAddComponent(phBoxEnt, COMPONENT_TYPE_MESH); componentid_t boxMesh = entityAddComponent(phBoxEnt, COMPONENT_TYPE_MESH);
componentid_t boxMat = entityAddComponent(phBoxEnt, COMPONENT_TYPE_MATERIAL); componentid_t boxMat = entityAddComponent(phBoxEnt, COMPONENT_TYPE_MATERIAL);
// phBoxPhys = entityAddComponent(phBoxEnt, COMPONENT_TYPE_PHYSICS); phBoxPhys = entityAddComponent(phBoxEnt, COMPONENT_TYPE_PHYSICS);
entityMeshSetMesh(phBoxEnt, boxMesh, &CUBE_MESH_SIMPLE); entityMeshSetMesh(phBoxEnt, boxMesh, &CUBE_MESH_SIMPLE);
entityMaterialGetShaderMaterial(phBoxEnt, boxMat)->unlit.color = COLOR_RED; entityMaterialGetShaderMaterial(phBoxEnt, boxMat)->unlit.color = COLOR_RED;
entityPositionSetPosition(phBoxEnt, boxPos, (vec3){ 0.0f, 1.0f, 0.0f }); entityPositionSetPosition(phBoxEnt, boxPos, (vec3){ 0.0f, 4.0f, 0.0f });
/* Run the init script. */ /* Run the init script. */
scriptcontext_t ctx; scriptcontext_t ctx;
+11 -18
View File
@@ -43,10 +43,10 @@ errorret_t shaderBindDolphin(shaderdolphin_t *shader) {
GX_LoadProjectionMtx( GX_LoadProjectionMtx(
shader->matrixProjection, shader->dolphinProj,
shader->isProjectionPerspective ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC shader->isProjectionPerspective ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC
); );
GX_LoadPosMtxImm(shader->matrixModelView, GX_PNMTX0); GX_LoadPosMtxImm(shader->dolphinModelView, GX_PNMTX0);
errorOk(); errorOk();
} }
@@ -193,13 +193,13 @@ errorret_t shaderUpdateMVPDolphin() {
// Need to update projection? // Need to update projection?
if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_PROJ) != 0) { if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_PROJ) != 0) {
shaderMat4ToMtx44(SHADER_BOUND->proj, SHADER_BOUND->matrixProjection); shaderMat4ToMtx44(SHADER_BOUND->proj, SHADER_BOUND->dolphinProj);
// Fix projection Z mapping between GLM and GX. // Fix projection Z mapping between GLM and GX.
float A = SHADER_BOUND->matrixProjection[2][2]; float A = SHADER_BOUND->dolphinProj[2][2];
float B = SHADER_BOUND->matrixProjection[2][3]; float B = SHADER_BOUND->dolphinProj[2][3];
SHADER_BOUND->matrixProjection[2][2] = 0.5f * (A + 1.0f); SHADER_BOUND->dolphinProj[2][2] = 0.5f * (A + 1.0f);
SHADER_BOUND->matrixProjection[2][3] = 0.5f * B; SHADER_BOUND->dolphinProj[2][3] = 0.5f * B;
// Is this perspective or ortho originally? Dolphin cares for some reason. // Is this perspective or ortho originally? Dolphin cares for some reason.
const float_t epsilon = 0.0001f; const float_t epsilon = 0.0001f;
@@ -209,7 +209,7 @@ errorret_t shaderUpdateMVPDolphin() {
); );
GX_LoadProjectionMtx( GX_LoadProjectionMtx(
SHADER_BOUND->matrixProjection, SHADER_BOUND->dolphinProj,
SHADER_BOUND->isProjectionPerspective ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC SHADER_BOUND->isProjectionPerspective ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC
); );
} }
@@ -217,25 +217,18 @@ errorret_t shaderUpdateMVPDolphin() {
// Need to update view or model? // Need to update view or model?
bool_t mvDirt = false; bool_t mvDirt = false;
if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_VIEW) != 0) { if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_VIEW) != 0) {
shaderMat4ToMtx(SHADER_BOUND->view, SHADER_BOUND->matrixView);
mvDirt = true; mvDirt = true;
} }
if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_MODEL) != 0) { if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_MODEL) != 0) {
shaderMat4ToMtx(SHADER_BOUND->model, SHADER_BOUND->matrixModel);
mvDirt = true; mvDirt = true;
} }
// Set Model/View Matrix // Set Model/View Matrix
if(mvDirt) { if(mvDirt) {
guMtxIdentity(SHADER_BOUND->matrixModel); glm_mat4_mul(SHADER_BOUND->view, SHADER_BOUND->model, SHADER_BOUND->modelView);
guMtxTransApply(SHADER_BOUND->matrixModel, SHADER_BOUND->matrixModel, 0.0F, 1.0F, 0.0F); shaderMat4ToMtx(SHADER_BOUND->modelView, SHADER_BOUND->dolphinModelView);
guMtxConcat( GX_LoadPosMtxImm(SHADER_BOUND->dolphinModelView, GX_PNMTX0);
SHADER_BOUND->matrixModel,
SHADER_BOUND->matrixView,
SHADER_BOUND->matrixModelView
);
GX_LoadPosMtxImm(SHADER_BOUND->matrixModelView, GX_PNMTX0);
} }
SHADER_BOUND->dirtyMatrix = 0; SHADER_BOUND->dirtyMatrix = 0;
@@ -24,13 +24,12 @@ typedef struct shaderdolphin_s {
mat4 view; mat4 view;
mat4 proj; mat4 proj;
mat4 model; mat4 model;
mat4 modelView;
Mtx dolphinProj;
Mtx dolphinModelView;
bool_t isProjectionPerspective; bool_t isProjectionPerspective;
alignas(32) Mtx44 matrixProjection;
alignas(32) Mtx matrixView;
alignas(32) Mtx matrixModel;
alignas(32) Mtx matrixModelView;
uint_fast8_t dirtyMatrix; uint_fast8_t dirtyMatrix;
} shaderdolphin_t; } shaderdolphin_t;