Texture Mapping jagged pixel edges I'm currently writing a software renderer. I managed to implement texture mapping and it works fine. Only issue is, that the edges between the pixels are sometimes jagged in x direction as you can see here:



Could this be caused by a lack of precision? If so, how can I improve it?
What I'm doing is simply stepping along the edges of a triangle and interpolating the UVs for each scanline.

EDIT:
Here's my code for edge stepping and drawing of scanlines. The Edge class has a method step which increments the interpolants for each scanline.

edge.h

Edge(const Vertex&amp; minY, const Vertex&amp; maxY){
    float dy = maxY.position.y - minY.position.y;

    yStart = static_cast&lt;int&gt;(ceil(minY.position.y));
    yEnd = static_cast&lt;int&gt;(ceil(maxY.position.y));

    float prestep = yStart - minY.position.y;

    xStep = (maxY.position.x - minY.position.x) / dy;
    x = minY.position.x + xStep * prestep;

    wStep = (1.0f / maxY.position.w - 1.0f / minY.position.w) / dy;
    w = 1.0f / minY.position.w + wStep * prestep;

    texCoordsStep = (maxY.textureCoordinates / maxY.position.w - minY.textureCoordinates / minY.position.w) / dy;
    texCoords = minY.textureCoordinates / minY.position.w + texCoordsStep * prestep;
}


renderTarget.cpp

void RenderTarget::DrawScanLine(const Edge&amp; left, const Edge&amp; right, int y){
    int xStart = static_cast&lt;int&gt;(ceil(left.GetCurX()));
    int xEnd = static_cast&lt;int&gt;(ceil(right.GetCurX()));
    float dx = static_cast&lt;float&gt;(xEnd - xStart);
    float prestep = xStart - left.GetCurX();

    float w = left.GetCurW();
    float wStep = (right.GetCurW() - w) / dx;

    glm::vec2 texCoordsStep = (right.GetCurTexCoords() - left.GetCurTexCoords()) / dx;
    glm::vec2 texCoords = left.GetCurTexCoords() + texCoordsStep * prestep;

    Uint32* p = pixels + xStart + y * surface-&gt;w;

    for(int x = xStart; x &lt; xEnd; x++){
        float z = 1.0f / w;  //value for perspective correction
        int s = static_cast&lt;int&gt;(texCoords.s * z * texture-&gt;surface-&gt;w) &amp; texture-&gt;surface-&gt;w - 1;
        int t = static_cast&lt;int&gt;(texCoords.t * z * texture-&gt;surface-&gt;h) &amp; texture-&gt;surface-&gt;h - 1;

        *p = texture-&gt;pixels[s + t * texture-&gt;surface-&gt;w];  //copying the texture's pixel to the framebuffer
        p++;
        w += wStep;
        texCoords += texCoordsStep;
        color += colorStep;
    }
}
I strongly suspect that you are simply running out of floating point precision (at least in "U" dimension). With this sort of mathematics, the LSBs will soon become noisy resulting in the jagged appearance when you are (effectively) doing yes/no comparisons against known constants.

May I suggest instead that, rather than doing point sampling of your texture, try doing (at the very least) bilinear filtering which will hide the precision artefacts and also IMHO look better than having little squares.

UPDATE It just occurred to me that one of the possible causes of inaccuracy is that you are doing increments for each pixel X step, e.g. these two

w  += wStep;
texCoords += texCoordsStep;


These will soon cause errors to accumulate. Remove them and replace with multiplies by the X value and I expect things should improve.

UPDATE2 It will also be affected by how far away from the origin of the texture you are when you sample it. If, for example, your source texture is defined over [0..1]x[0..1] and then repeats outside of that range, you might expect sampling  at uv = (1000000.125, 100000.125) to be the same as (0.125,0.125) but, because the precision of FP decreases with increasing magnitude (i.e. the steps between floats also increases), you might end up with something quite different.