• Create Account

Banner advertising on our site currently available from just \$5!

# Triangle rasterization

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

### #1sheep19  Members   -  Reputation: 415

Like
0Likes
Like

Posted 20 October 2012 - 07:49 PM

I just learned about triangle rasterization in graphics class, but there are still some details that I don't understand.

Let's say I have this triangle:

I want to decide which pixels are going to be drawn.

So firstly I calculate the (inverse)slops of the lines:
dx/dy(01) = (P0.x - P1.x) / (P0.y - P1.y) = (1 - 4) / (4 - 1) = -3 / 3 = -1
dx/dy(12) = (P1.x - P2.x) / (P1.y - P2.y) = (4 - 4) / (1 - 3) = 0
dx/dy(02) = ... = -3

Let's rename them to stepA(dx/dy01) stepB (dx/dy12), stepC(dx/dy02) just to be easier to type.

--------
So we start at the bottom vertex.
xLeft = 4
xRight = 4
y = 1

Pixels in the range [xLeft, xRight) are drawn.
So pixel (3,1) is not going to be draw according to this, but it should be! How am I going to test for this?

--------------
Now, we are going up one pixel
y = 2
xLeft += stepA => xLeft += -1 => xLeft = 3
xRight += stepB => xRight += 0 => xRight = 4
pixel (3, 2) is drawn (seems correct)
-----------------

y = 3
xLeft = 2
xRight = 1 (because now we are adding stepC)

xRight is smaller than xLeft!!?? Why has this heppened? What am I supposed to do here?

That's the way the "algorithm" was presented in the class, but there are these (the above) questions/doubts that I have.
Maybe I should be in the middle of pixels (y varies between 1.5, 2.5, etc)?
Or maybe I get results this bad because I have a small screen? (5x5) Maybe these would be unnotisable in a larger grid?

### #2ginkgo  Members   -  Reputation: 294

Like
0Likes
Like

Posted 21 October 2012 - 07:44 AM