View Single Post
Old 02 March 2015, 11:58   #29
Mrs Beanbag
Glastonbridge Software
Mrs Beanbag's Avatar
Join Date: Jan 2012
Location: Edinburgh/Scotland
Posts: 2,202
Originally Posted by mc6809e View Post
Oh, I just meant that since the CPU is usually busy with other calculations of all sorts while the blitter is less taxed, adding a cross product calculation for a surface normal plus dot product to see its relation to a ray from the camera just adds more calculation to an already burdened CPU. It might be worth it just to give the blitter more work even if the blitter would take more time, assuming it runs concurrently with the CPU. It would depend on how much internal operation the CPU was performing (plenty for multiplies and divides).
well first off, it occurred to me overnight, if you are not doing hidden surface removal, you can take your number of DMA cycles and double it! Well my intuition tells me a few multiplies would still be worth it.

We need to calculate a predicate based on a vector triple product of the triangle vertices (assuming we are working with triangles, but any face visibility can be calculated from any co-planar triangle).

P = (Ay.Bz - Az.By).Cx + (Az.Bx - Ax.Bz).Cy + (Ax.By - Ay.Bx).Cz [1]

= Ay.Bz.Cx - Az.By.Cx + Az.Bx.Cy - Ax.Bz.Cy + (Ax.By - Ay.Bx).Cz [2]

= (Bx.Cy - By.Cx).Az + (Ay.Cx - Ax.Cy).Bz + (Ax.By - Ay.Bx).Cz [3]

= {(Bx.Cy - By.Cx)/(Bz.Cz) + (Ay.Cx - Ax.Cy)/(Az.Cz) + (Ax.By - Ay.Bx)/(Az.Bz)}.(Az.Bz.Cz) [4]

but we already did Ax/Az, Ay/Az &c because these are just the screen co-ordinates of the points! so let ax = Ax/Az... and we don't care about multiplying by (Az.Bz.Cz) at all because we only want the sign of the result, not the magnitude! So assuming all of these are positive (but we can just use XOR otherwise)...

p = - + - + - ay.bx [5]

= (ax-cx)(by-cy) - (ay-cy)(bx-cx) [6]

Sign(P) = Sign(p) xor Sign(Az) xor Sign(Bz) xor Sign(Cz) [7]

This is only two multiplications and it is good as long as none of the Z co-ordinates are zero (in which case we can't really compute the screen co-ordinates - but it simplifies [3] for us).

My intuition tells me something else, but that's not proof of course. I want to say that any object for which surface normals work should also work using Z-sorting. I have no proof though so I'll have to think about it more.
How do you Z-sort a planar object anyway? Sorting points is easy, but which point do you use? The centre of mass?

Consider the following shape:

The sides of the polygon are "walls" from the perspective of the viewer at the bottom. Sorted by their centre point, we can see that faces 4 and 5 get incorrectly drawn over the top of face 3.

Last edited by Mrs Beanbag; 02 March 2015 at 12:25.
Mrs Beanbag is offline  
Page generated in 0.05612 seconds with 9 queries