GRP2 Rasterizer texturing issue

Programming topics can be found here.
Post Reply
User avatar
121344
Posts: 15
Joined: Sun Sep 29, 2013 4:05 pm

GRP2 Rasterizer texturing issue

Post by 121344 » Tue Mar 18, 2014 4:22 pm

Hey everyone, I'm currently working on my GRP2 retake.

This is the issue that I'm having:

Image

As you can see, the black lines from my UV texture aren't straight. I think this happens because of the following code:

Code: Select all

const float ySpanRcp = 1.0f / (fy2 - fy1);
				
const float dx = (fx2 - fx1) * ySpanRcp;
const float2 duv = (uv2 - uv1) * ySpanRcp;
const float dw = (fw2 - fw1) * ySpanRcp;
This code is executed once for every edge of the triangle. When an edge is almost horizontal, (fy2 - fy1) gets close to zero. My guess is that the interpolated uv coordinates become inaccurate because of this. One half of the triangle is textured differently from the other half. How do I fix this?
Marco Jonkers
2GA-2PR

bikker
Posts: 67
Joined: Fri Sep 27, 2013 12:40 pm

Re: GRP2 Rasterizer texturing issue

Post by bikker » Thu Mar 20, 2014 5:41 pm

Hm, it looks a bit more complex than just a horizontal edge problem. Does it work on a cube?

User avatar
121344
Posts: 15
Joined: Sun Sep 29, 2013 4:05 pm

Re: GRP2 Rasterizer texturing issue

Post by 121344 » Sat Mar 22, 2014 7:34 pm

Ahh, I found the problem. I forgot to add depth to my sub-pixel correction:

Code: Select all

// Sub-pixel correction
float correction = (float) iy1 - fy1;
fx1 += correction * dx;
fw1 += correction * dw; // <--
uv1 += correction * duv;
Marco Jonkers
2GA-2PR

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest