컴퓨터공학/Computer Graphics

[3D Viewing Pipeline] Viewport Transformation

Pyxis 2024. 7. 24. 02:00

3D Viewing Pipeline Overview

 

 

이전의 Perspective Projection이 이루어진 뒤, Homogeneous Parameter로 나누어 실제 좌표로 변환했다.

이로써 크기가 2인 Cube상의 좌표로 변환되었다.

이제 마지막 단계인 Viewport Transformation이 남아있다.

[ Trasnformation from the Normalized view volume to 3D screen coordinates ]

크기가 2인 Cube가 화면으로 바뀌어야 하므로, Scaling이 사용된다.

 

변환될 Viewport의 size는 주어져 있다고 가정한다.

Viewport는 전체화면일지, 창화면일지 알 수 없으므로 screen의 해상도로 바로 변환할 수 없다.

변환될 Viewport의 좌표를 나타내는 xv max, xv min, yv max, yv min이 있다고 가정하자.

 

우선 scaling, translation의 x, y factor에 대해서만 생각해보자.

크기가 2인 Normalized view volume(Cube)에서 크기가 (xv max - xv min), (yv max - yv min)인 3D Screen coorindates로 scaling되어야 하므로 scaling factor는 (xv max - xv min) / 2, (yv max - yv min) / 2 이 된다.

 

[ Note : scaling, 2 → (xv max - xv min), (yv max - yv min) | (xv max - xv min) / 2, (yv max - yv min) / 2 ]

 

원점을 중심으로 scaling되고 나서, 원점이 Screen의 중점으로 Translation되어야 하므로 translation factor는

(xv max + xv min) / 2, (yv max - yv min) / 2 이 된다.

 

이제 z factor에 대해서 생각해보자.

Screen Coordinates에서 z는 음수가 없는 depth의 개념으로, *0부터 1까지 범위를 가져야한다.

크기가 2인 Cube에서 크기가 1인 Screen으로 Scaling 되어야 하므로 scaling z factor는 1/2 이다.

[-1, 1]의 범위를 갖는 z가 원점을 중심으로 1/2 scaling된 z 값의 범위는 [-1/2, 1/2] 이므로 +1/2씩 이동이 필요해 translation z factor는 1/2 이다.

The Viewport Transformation from the normalized view volume to 3D screen coordinates

 

Perspective Projection Matrix를 곱해준 뒤, 그 다음 Viewport Transformation Matrix를 곱해준다면 최종적으로 Screen상의 좌표로 옮겨오게 된다.

이 screen에서 원점은 좌측 하단 모서리(lower-left corner)로 정해진다.

그리고 만약 (xv max - xv min), (yv max - yv min)의 비율을 Clipping Window의 aspect ratio와 동일하게 설정한다면 Object의 비율이 유지된다.

 

z 값은 non-linear하지만, vertex들 간의 '상대적인 순서'는 파악할 수 있게 유지되어 있어 나중에 사용되기 위해 depth buffer(z buffer)에 저장된다.

 

 

 

 

[ Reference ]

Computer Graphics with OpenGL 4th edition, Hearn, Baker