Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perspective division before Viewport transformation #97

Open
Buzzefall opened this issue Mar 14, 2022 · 1 comment
Open

Perspective division before Viewport transformation #97

Buzzefall opened this issue Mar 14, 2022 · 1 comment

Comments

@Buzzefall
Copy link

Buzzefall commented Mar 14, 2022

I wonder why the main-branch implementation of triangle(...) rasterization works like that:

  1. pts[i] = Viewport * verts_clip[i]; ( where verts_clip[i] = Projection * verts[i])
  2. 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?

@XiaofanLinUS
Copy link

According to my calculation, everything works as expected.
IMG_0327

In case you need to examine it, I included my full study note on this one.
Note 97.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants