-
Notifications
You must be signed in to change notification settings - Fork 46
[COLL] Barycentric Test function decompiled #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a7ff99f
first function in coll decompiled
mateusfavarin 9b19cec
better macro
mateusfavarin 48f98bc
COLL_BarycentricTest decompiled
mateusfavarin bf94982
Merge branch 'main' into coll_decomp
mateusfavarin 8b825af
dont generate code if profiler guard isn't active
mateusfavarin 79c5295
fix gamma calculation
mateusfavarin ad008f9
flush cache after modifying instructions
mateusfavarin 70b6106
add in naughty dog bug...
mateusfavarin b25bbfc
address PR review
mateusfavarin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,45 @@ | ||
| #pragma once | ||
|
|
||
| #include <ctr/macros.h> | ||
| #include <ctr/math.h> | ||
| #include <ctr/lev.h> | ||
|
|
||
| void COLL_ProjectPointToEdge(SVec3* out, const SVec3* v1, const SVec3* v2, const SVec3* point); | ||
| typedef enum Axis | ||
| { | ||
| AXIS_Z = 1, | ||
| AXIS_X = 2, | ||
| AXIS_Y = 3, | ||
| } Axis; | ||
|
|
||
| typedef enum BarycentricTest | ||
| { | ||
| BARYCENTRIC_TEST_INVALID = -1, | ||
| BARYCENTRIC_TEST_SNAP_V1 = 0, | ||
| BARYCENTRIC_TEST_EDGE_V1_V2 = 1, | ||
| BARYCENTRIC_TEST_SNAP_V2 = 2, | ||
| BARYCENTRIC_TEST_EDGE_V2_V3 = 3, | ||
| BARYCENTRIC_TEST_SNAP_V3 = 4, | ||
| BARYCENTRIC_TEST_EDGE_V1_V3 = 5, | ||
| BARYCENTRIC_TEST_INSIDE_TRIANGLE = 6, | ||
| } BarycentricTest; | ||
|
|
||
| typedef struct CollVertex | ||
| { | ||
| SVec3 pos; | ||
| u16 normalDominantAxis; | ||
| Vertex* levVertex; | ||
| SVec3 triNormal; | ||
| u16 planeDist; | ||
| } CollVertex; | ||
|
|
||
| typedef struct TestVertex | ||
| { | ||
| SVec3 pos; | ||
| u16 normalDominantAxis; | ||
| SVec3 triNormal; | ||
| u16 planeDist; | ||
| SVec3 interpolationPoint; | ||
| } TestVertex; | ||
|
|
||
| void COLL_ProjectPointToEdge(SVec3* out, const SVec3* v1, const SVec3* v2, const SVec3* point); | ||
| s32 COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #pragma once | ||
|
|
||
| #include <ctr/macros.h> | ||
| #include <ctr/math.h> | ||
|
|
||
| typedef union Color | ||
| { | ||
| struct | ||
| { | ||
| u8 r; | ||
| u8 g; | ||
| u8 b; | ||
| u8 a; | ||
| }; | ||
| u32 color; | ||
| } Color; | ||
|
|
||
| typedef struct Vertex | ||
| { | ||
| SVec3 pos; | ||
| u16 flags; | ||
| Color colorHi; | ||
| Color colorLo; | ||
| } Vertex; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,4 +46,6 @@ typedef int8_t s8; | |
| #define OFFSETOF(TYPE, ELEMENT) ((unsigned int)&(((TYPE *)0)->ELEMENT)) | ||
|
|
||
| #define nullptr ((void *) 0) | ||
| #define force_inline static inline __attribute__((always_inline)) | ||
| #define force_inline static inline __attribute__((always_inline)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is static necessary? |
||
|
|
||
| //#define FIX_CTR_BUGS | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #pragma once | ||
|
|
||
| #define REWRITE_PROFILER | ||
| void LoadProfilerPatches(); | ||
| //#define REWRITE_PROFILER | ||
|
|
||
| void LoadProfilerPatches(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,4 +36,119 @@ void COLL_ProjectPointToEdge(SVec3* out, const SVec3* v1, const SVec3* v2, const | |
| out->y = coords.y; | ||
| out->z = coords.z; | ||
| TEST_COLL_ProjectPointToEdge(v1, v2, point, out); | ||
| } | ||
|
|
||
| /* Address: 0x8001f928 */ | ||
| static s32 _COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3) | ||
| { | ||
| Vec2 deltaT; | ||
| Vec2 deltaTri[2]; | ||
| const SVec3* edgeV2; | ||
| const SVec3* edgeV3; | ||
| u32 firstAxis, secondAxis; | ||
|
|
||
| if (t->normalDominantAxis == AXIS_X) | ||
| { | ||
| firstAxis = 1; // y | ||
| secondAxis = 2; // z | ||
| } | ||
| else if (t->normalDominantAxis == AXIS_Y) | ||
| { | ||
| firstAxis = 2; // z | ||
| secondAxis = 0; // x | ||
| } | ||
| else | ||
| { | ||
| firstAxis = 0; // x | ||
| secondAxis = 1; // y | ||
| } | ||
|
|
||
| deltaTri[0].x = v2->pos.v[firstAxis] - v1->pos.v[firstAxis]; | ||
| deltaTri[0].y = v3->pos.v[firstAxis] - v1->pos.v[firstAxis]; | ||
| deltaT.x = t->interpolationPoint.v[firstAxis] - v1->pos.v[firstAxis]; | ||
| edgeV2 = &v2->pos; | ||
| edgeV3 = &v3->pos; | ||
| if (abs(deltaTri[0].x) < abs(deltaTri[0].y)) | ||
| { | ||
| edgeV2 = &v3->pos; | ||
| edgeV3 = &v2->pos; | ||
| s32 temp = deltaTri[0].x; | ||
| deltaTri[0].x = deltaTri[0].y; | ||
| deltaTri[0].y = temp; | ||
| } | ||
| deltaTri[1].x = edgeV2->v[secondAxis] - v1->pos.v[secondAxis]; | ||
| deltaTri[1].y = edgeV3->v[secondAxis] - v1->pos.v[secondAxis]; | ||
| deltaT.y = t->interpolationPoint.v[secondAxis] - v1->pos.v[secondAxis]; | ||
|
|
||
| s32 beta = FP(-1); | ||
| s32 gamma = FP(-1); | ||
| if (deltaTri[0].x != 0) | ||
| { | ||
| s32 dem = ((deltaTri[1].y * deltaTri[0].x) - (deltaTri[0].y * deltaTri[1].x)) >> 6; | ||
| if (dem != 0) | ||
| { | ||
| beta = (((deltaT.y * deltaTri[0].x) - (deltaT.x * deltaTri[1].x)) << 6) / dem; | ||
| gamma = ((deltaT.x * FP_ONE) - (beta * deltaTri[0].y)) / deltaTri[0].x; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if ((deltaTri[0].y != 0) && (deltaTri[1].x != 0)) | ||
| { | ||
| beta = FP_DIV(deltaT.y, deltaTri[0].y); | ||
| gamma = ((deltaT.y * FP_ONE) - (beta * deltaTri[1].y)) / deltaTri[1].x; | ||
| } | ||
| } | ||
|
|
||
| /* Naughty Dog bug: their hand written assembly code | ||
| forgets to check beta == -1, creating false collisions */ | ||
| #ifdef FIX_CTR_BUGS | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. big appreciate |
||
| if ((beta == FP(-1)) || (gamma == FP(-1))) { return BARYCENTRIC_TEST_INVALID; } | ||
| #else | ||
| if (gamma == FP(-1)) { return BARYCENTRIC_TEST_INVALID; } | ||
| #endif | ||
|
|
||
| s32 alpha = beta + gamma + FP(-1); | ||
| if (gamma < 0) | ||
| { | ||
| if (beta < 0) | ||
| { | ||
| t->pos = v1->pos; | ||
| return BARYCENTRIC_TEST_SNAP_V1; | ||
| } | ||
| if (alpha < 0) | ||
| { | ||
| COLL_ProjectPointToEdge(&t->pos, &v1->pos, edgeV3, &t->interpolationPoint); | ||
| return BARYCENTRIC_TEST_EDGE_V1_V3; | ||
| } | ||
| t->pos = *edgeV3; | ||
| return BARYCENTRIC_TEST_SNAP_V3; | ||
| } | ||
| if (beta < 0) | ||
| { | ||
| if (alpha < 0) | ||
| { | ||
| COLL_ProjectPointToEdge(&t->pos, &v1->pos, edgeV2, &t->interpolationPoint); | ||
| return BARYCENTRIC_TEST_EDGE_V1_V2; | ||
| } | ||
| t->pos = *edgeV2; | ||
| return BARYCENTRIC_TEST_SNAP_V2; | ||
| } | ||
| if (alpha > 0) | ||
| { | ||
| COLL_ProjectPointToEdge(&t->pos, edgeV2, edgeV3, &t->interpolationPoint); | ||
| return BARYCENTRIC_TEST_EDGE_V2_V3; | ||
| } | ||
| t->pos = t->interpolationPoint; | ||
| return BARYCENTRIC_TEST_INSIDE_TRIANGLE; | ||
| } | ||
|
|
||
| s32 COLL_BarycentricTest(TestVertex* t, const CollVertex* v1, const CollVertex* v2, const CollVertex* v3) | ||
| { | ||
| #ifdef TEST_COLL_IMPL | ||
| TestVertex input = *t; | ||
| #endif | ||
| const s32 ret = _COLL_BarycentricTest(t, v1, v2, v3); | ||
| TEST_COLL_BarycentricTest(&input, v1, v2, v3, &t->pos, ret); | ||
| return ret; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
??? why not just uint8_t?