Skip to content
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

Allow using position and normals as tex coordinates #82

Merged
merged 4 commits into from
Nov 23, 2024

Conversation

mardy
Copy link
Collaborator

@mardy mardy commented Nov 16, 2024

Some application (like the Neverball game) specify the same array of positional coordinates to glTexCoordPointer(), and setup an appropriate texture matrix to transform them as needed. But GX only allows submitting up to two components of texture coordinates (s and t), and simply discarding the third component leads to incorrect rendering results.

The solution (which only works in the case the same array pointer is specified both as positional and texture coordinates -- a fully generic solution does not seem to be possible) is to setup the TEV so that texture coordinates are read from the positional array. This requires some refactoring of the array processing code.

Unlike the previous MR, these commits are all related (but can still be reviewed independently).

The registers to be used as texture input coordinates will (in the
following commit) computed when setting up the vertex arrays, so this
operation must happen before setting up the TEV (which uses those
registers).

This small refactoring also reduces some code duplication.
The GX_VA_TEX* formats only allow up to two components in the texture
input coordinates (s and t), but OpenGL applications can provide up to
four, along with a texture matrix to transform them.
While we are not able to support this general case (not easily, at
least!), we can handle the case where the array with the texture input
coordinates is the same passed for the positional or normal attributes,
because in that case we can skip re-uploading these coordinates at all
and can setup the TEV to read texture coordinates from GX_TG_POS or
GX_TG_NRM and transform them with the given matrix.

This works well with Neverball, which passes the same array of positions
as texture coordinates when it needs to apply the ball shadow to the
object lying under the ball.
@mardy mardy force-pushed the reuse-tex-coordinates branch from c548bdc to fc73521 Compare November 23, 2024 11:31
@WinterMute WinterMute merged commit 00e5cc6 into devkitPro:master Nov 23, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants