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

softgpu: Round tex coords properly for nearest #8282

Merged
merged 1 commit into from
Dec 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions GPU/Software/Rasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ static inline u8 ClampFogDepth(float fogdepth) {

static inline void GetTexelCoordinates(int level, float s, float t, int& out_u, int& out_v)
{
int width = 1 << (gstate.texsize[level] & 0xf);
int height = 1 << ((gstate.texsize[level]>>8) & 0xf);
int width = gstate.getTextureWidth(level);
int height = gstate.getTextureHeight(level);

int u = (int)(s * width);
int v = (int)(t * height);
int u = (int)(s * width + 0.375f);
int v = (int)(t * height + 0.375f);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this is wrong. In fact, I think we are half a pixel off for bilinear (i.e. a 0,0 -> 1,1 box will apply 50% of texel 1,1 in the center, which is of course wrong.)

-[Unknown]

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's interesting - I hadn't considered the possibility that the offset might need to be different in each of the filtering modes - who knows how they are implemented.

Copy link
Collaborator Author

@unknownbrackets unknownbrackets May 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, AFAICT it's just 0 for nearest (seems to round right at 0.5) and -0.5 for linear (to sample at the centers.) Need to check some throughmode handling still when I have time.

I did try applying a 0.375f / 256.0f offset to correct for rounding issues, which seemed to largely help most everywhere (including Crisis Core.) And with that the Hexyz issue doesn't happen either (probably the same rounding issue.) However, it introduces other issues...

Also tex wrap with negative float uvs was wrong.

-[Unknown]


if (gstate.isTexCoordClampedS()) {
if (u >= width - 1)
Expand All @@ -144,8 +144,8 @@ static inline void GetTexelCoordinates(int level, float s, float t, int& out_u,
static inline void GetTexelCoordinatesQuad(int level, float in_s, float in_t, int u[4], int v[4], int &frac_u, int &frac_v)
{
// 8 bits of fractional UV
int width = 1 << (gstate.texsize[level] & 0xf);
int height = 1 << ((gstate.texsize[level]>>8) & 0xf);
int width = gstate.getTextureWidth(level);
int height = gstate.getTextureHeight(level);

int base_u = in_s * width * 256;
int base_v = in_t * height * 256;
Expand Down Expand Up @@ -190,9 +190,9 @@ static inline void GetTexelCoordinatesQuad(int level, float in_s, float in_t, in

static inline void GetTexelCoordinatesThrough(int level, int s, int t, int& u, int& v)
{
// Not actually sure which clamp/wrap modes should be applied. Let's just wrap for now.
int width = 1 << (gstate.texsize[level] & 0xf);
int height = 1 << ((gstate.texsize[level]>>8) & 0xf);
// TODO: Not actually sure which clamp/wrap modes should be applied. Let's just wrap for now.
int width = gstate.getTextureWidth(level);
int height = gstate.getTextureHeight(level);

// Wrap!
u = ((unsigned int)(s) & (width - 1));
Expand All @@ -202,8 +202,8 @@ static inline void GetTexelCoordinatesThrough(int level, int s, int t, int& u, i
static inline void GetTexelCoordinatesThroughQuad(int level, int s, int t, int *u, int *v)
{
// Not actually sure which clamp/wrap modes should be applied. Let's just wrap for now.
int width = 1 << (gstate.texsize[level] & 0xf);
int height = 1 << ((gstate.texsize[level] >> 8) & 0xf);
int width = gstate.getTextureWidth(level);
int height = gstate.getTextureHeight(level);

// Wrap!
for (int i = 0; i < 4; i++) {
Expand Down