0
$\begingroup$

I am making a Software renderer, and I noticed that there is a screen shaking like effect happening. shown in the first video:

I tried doing filling without clipping against the small square, and the result is much better, yet, there is some sort of shaking on the edges as shown in the second video

Finally I tried drawing the clipped triangles outline, and the shaking is more apparent as shown in the third video

My initial assumption was the line drawing was not accurate enough, so I tried both DDA and Bresenham line drawing without any success.

Additionally, I tried different triangulation schemes, I noticed that when I increase the number of created triangles (such as when I triangulate a square using the center as a new vertex instead of using one of the corners) the shaking gets worse. That led me to believe to the issue is related to shared edges in the triangles, and indeed in my triangle filling algorithm, I tried to remove the shared edge and got a bit better results (but it introduced different artifacts, some pixels were missing): https://git.sr.ht/~aliabdulkareem/SoftwareRenderer/tree/FixTrianglulation/item/src/drawing.cpp#L450

That did not however remove it entirely (I believe I should remove the shared edges from the triangulation phase as well, not entirely sure how to do that, one idea is when I triangulate the triangles after the first one, I always more pixel in the direction of the two newly formed edges)

Also it does not explain entirely the second video shaking when there was a shared edge in the diagonal of a square, but it was fine, while the square edges were shaking despite not sharing an edge.

I am a bit puzzled as how to debug this as I can at least think of three different reasons:

1- Triangulation is wrong

2- Floating point inaccuracy

3- Aliasing (I heard that in animations, aliasing becomes very clear, not sure if that is the case)

Full source code: https://git.sr.ht/~aliabdulkareem/SoftwareRenderer/tree/FixTrianglulation

$\endgroup$
4
  • $\begingroup$ The shaking does not seem to be permanent. I would first investigate truncation/rounding of the fractional coordinates and the exact way these are computed (possibly with numerical errors that can fluctuate in sign). $\endgroup$
    – user1703
    Commented Jun 27, 2023 at 14:03
  • $\begingroup$ There is obvious aliasing on the lines, but this is not related to the animation. $\endgroup$
    – user1703
    Commented Jun 27, 2023 at 14:05
  • $\begingroup$ Sadly it seems the site that was hosting your video now won't allow access without handing over money :( $\endgroup$
    – Simon F
    Commented Mar 22 at 8:47
  • 1
    $\begingroup$ @SimonF Thanks for letting me know, I will try to find a free posting service (or maybe just upload it here by reducing the size of the file) $\endgroup$
    – Serilena
    Commented Mar 22 at 21:49

1 Answer 1

0
$\begingroup$

I understand that your pipeline looks like this: Transform polygon vertices -> clip polygon -> triangulate -> draw edges of each triangle.

I would start with simple line drawing and disregard the clipping, filling and triangulation for now and see if the shaking still occurs. Then you can try to add the triangulation and the rest, one by one.

There is a couple of things that seem suspicous to me in the third video (see attached image):

  1. The horizontal green line stays still during the animation but shakes up and down. The other green horizontal line and the vertical lines dont shake, but that might be a coincidence. This seems to me like an inaccuracy in the transformation.
  2. The boundary edges of the red polygon dont connect in the vertices in some frames. If the endpoints of both edges are represented by a single point, that means there is an error in the line drawing algorithm.

Aliasing is causing slight trembling of the rotating lines as their slope changes, but not any of the problems mentioned above.

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks for your points, I will go through them and see if I can find issues in them. Regarding the pipeline I actually did implement them like that, starting from line drawing, then triangle drawing then triangle filling, and finally added clipping. I don't recall seeing such shaking, but now I know it is a problem, I might just start again and see if I can track it to an earlier stage in the pipeline. $\endgroup$
    – Serilena
    Commented Jun 25, 2023 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.