Fixed dolphin matricies the ugly way
This commit is contained in:
@@ -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 boxMesh = entityAddComponent(phBoxEnt, COMPONENT_TYPE_MESH);
|
||||
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);
|
||||
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. */
|
||||
scriptcontext_t ctx;
|
||||
|
||||
@@ -43,10 +43,10 @@ errorret_t shaderBindDolphin(shaderdolphin_t *shader) {
|
||||
|
||||
|
||||
GX_LoadProjectionMtx(
|
||||
shader->matrixProjection,
|
||||
shader->dolphinProj,
|
||||
shader->isProjectionPerspective ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC
|
||||
);
|
||||
GX_LoadPosMtxImm(shader->matrixModelView, GX_PNMTX0);
|
||||
GX_LoadPosMtxImm(shader->dolphinModelView, GX_PNMTX0);
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -193,13 +193,13 @@ errorret_t shaderUpdateMVPDolphin() {
|
||||
|
||||
// Need to update projection?
|
||||
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.
|
||||
float A = SHADER_BOUND->matrixProjection[2][2];
|
||||
float B = SHADER_BOUND->matrixProjection[2][3];
|
||||
SHADER_BOUND->matrixProjection[2][2] = 0.5f * (A + 1.0f);
|
||||
SHADER_BOUND->matrixProjection[2][3] = 0.5f * B;
|
||||
float A = SHADER_BOUND->dolphinProj[2][2];
|
||||
float B = SHADER_BOUND->dolphinProj[2][3];
|
||||
SHADER_BOUND->dolphinProj[2][2] = 0.5f * (A + 1.0f);
|
||||
SHADER_BOUND->dolphinProj[2][3] = 0.5f * B;
|
||||
|
||||
// Is this perspective or ortho originally? Dolphin cares for some reason.
|
||||
const float_t epsilon = 0.0001f;
|
||||
@@ -209,7 +209,7 @@ errorret_t shaderUpdateMVPDolphin() {
|
||||
);
|
||||
|
||||
GX_LoadProjectionMtx(
|
||||
SHADER_BOUND->matrixProjection,
|
||||
SHADER_BOUND->dolphinProj,
|
||||
SHADER_BOUND->isProjectionPerspective ? GX_PERSPECTIVE : GX_ORTHOGRAPHIC
|
||||
);
|
||||
}
|
||||
@@ -217,25 +217,18 @@ errorret_t shaderUpdateMVPDolphin() {
|
||||
// Need to update view or model?
|
||||
bool_t mvDirt = false;
|
||||
if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_VIEW) != 0) {
|
||||
shaderMat4ToMtx(SHADER_BOUND->view, SHADER_BOUND->matrixView);
|
||||
mvDirt = true;
|
||||
}
|
||||
|
||||
if((SHADER_BOUND->dirtyMatrix & SHADER_DOLPHIN_DIRTY_MODEL) != 0) {
|
||||
shaderMat4ToMtx(SHADER_BOUND->model, SHADER_BOUND->matrixModel);
|
||||
mvDirt = true;
|
||||
}
|
||||
|
||||
// Set Model/View Matrix
|
||||
if(mvDirt) {
|
||||
guMtxIdentity(SHADER_BOUND->matrixModel);
|
||||
guMtxTransApply(SHADER_BOUND->matrixModel, SHADER_BOUND->matrixModel, 0.0F, 1.0F, 0.0F);
|
||||
guMtxConcat(
|
||||
SHADER_BOUND->matrixModel,
|
||||
SHADER_BOUND->matrixView,
|
||||
SHADER_BOUND->matrixModelView
|
||||
);
|
||||
GX_LoadPosMtxImm(SHADER_BOUND->matrixModelView, GX_PNMTX0);
|
||||
glm_mat4_mul(SHADER_BOUND->view, SHADER_BOUND->model, SHADER_BOUND->modelView);
|
||||
shaderMat4ToMtx(SHADER_BOUND->modelView, SHADER_BOUND->dolphinModelView);
|
||||
GX_LoadPosMtxImm(SHADER_BOUND->dolphinModelView, GX_PNMTX0);
|
||||
}
|
||||
|
||||
SHADER_BOUND->dirtyMatrix = 0;
|
||||
|
||||
@@ -24,13 +24,12 @@ typedef struct shaderdolphin_s {
|
||||
mat4 view;
|
||||
mat4 proj;
|
||||
mat4 model;
|
||||
mat4 modelView;
|
||||
|
||||
Mtx dolphinProj;
|
||||
Mtx dolphinModelView;
|
||||
|
||||
bool_t isProjectionPerspective;
|
||||
alignas(32) Mtx44 matrixProjection;
|
||||
alignas(32) Mtx matrixView;
|
||||
alignas(32) Mtx matrixModel;
|
||||
alignas(32) Mtx matrixModelView;
|
||||
|
||||
uint_fast8_t dirtyMatrix;
|
||||
} shaderdolphin_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user