Perspective division before Viewport transformation
Buzzefall opened this issue · 1 comments
I wonder why the main-branch implementation of triangle(...)
rasterization works like that:
pts[i] = Viewport * verts_clip[i];
( where verts_clip[i] = Projection * verts[i])
pts2[i] = pts[i] / pts[i].w
And it seems to produce adequate result.
I thought we should first project objects (with perspective division), then scale achieving [-1, 1]x[-1, 1]
rectangle in plane Oxy
and shift coordinates to make then positive as [0, wid]x[0, hei]
. This way distant objects should shrink and vanish to the center of a screen.
But if we first make Viewport
scale and shift, and then make perspective division, [-1, 1]x[-1, 1]
rectangle should become [0, wid/(1+rz)]x[0, hei/(1+rz)]
for corresponding z values. Then distant objects should shrink and vanish to the point (0, 0)
on a screen.
Is it just fine-tuning of object positions for tutorial purpose and there is a mistake in code?
Of I miss something simple?
According to my calculation, everything works as expected.
In case you need to examine it, I included my full study note on this one.
Note 97.pdf