컴퓨터그래픽스

[23-1 컴퓨터 그래픽스 정리] Clipping, Rasterization

begong 2023. 7. 13. 21:59
반응형
본 글은 국민대학교 김준호 교수님의 "컴퓨터 그래픽스" 강의자료 정리 목적으로 만들었습니다.
글 자료의 모든 권한은 김준호 교수님께 있습니다.

Clipping

Clipping

To eliminate objects that lie outside of viewing volume

  • Performed in several places in the pipeline
  • Accept/Reject(or cull)
  • Supported by H/W or S/W

Screenshot 2023-04-23 at 12 03 40 PMScreenshot 2023-04-23 at 12 03 22 PM

화면(범위) 안에 들어오지 않는것을 전부 잘라냄

하드웨어적으로 동작함.

Bounding Boxes and Volumes

Rather than doing clipping on a complex polygon, we can use ans axis-aligned bounding box or extent

  • usually, usedin the game-engine하드웨어적으로 잘해주더라도 결국 소프트웨어적으로 어느정도 계산하고 넘겨야함
  • pci express가 한정적이고, 너무많은 데이터를 보내면 랜더링이 너무 오래걸림 (할 작업이 많음)

Bounding Boxes and Volumes

Determine accept/reject based only on bounding box

Screenshot 2023-04-23 at 12 07 49 PM

bounding box를 설정하고 화면과 안겹치면 데이터를 아얘 안보냄

겹치거나 걸치면 보냄

Rasterization

Rasterization

Rasterization (Scan conversion)

  • The process of converting a primitive into a set of pixels
  • It computes
    • Fragment location
      • Which pixels that are inside primitive specified by a set of vertices
    • per-fragment attributes
      • Attributes, such as color and texture coordinates are determined by interpolating values at vertices

Line Rasterization

DDA algorithm

  • With a given line equation, compute y by increasing x by Δx

선의 기울기를 결정해서 픽셀을 색칠

Screenshot 2023-04-23 at 12 18 19 PM

기울기가 1이 넘어가면 픽셀이 띄엄띄엄 표시되는 단점이 있음

그래서 오른쪽처럼 기울기를 역수를 취해서 계산을 하기도 함

Polygon Rasterization

Bilinear interpolation

  • First, colors on the line is interpolated
  • second, colors on each scan line interpolated

Here, several attributes are interpolated over the fragments in a triangle

Screenshot 2023-04-23 at 12 21 53 PM

vertex에 준 모든것은 이 형식으로 interpolation을 할수 있다.

data는 vertex에만 위치하기 때문에 Pixel에 값을 줄 수 없음

보간법을 이용해 c4,C5위치의 색을 구하고 C4,c5의 값으로 빨간색 선 상의 색을 구할 수 있음

Hidden Surface Removal

Hidden surface Removal

Screenshot 2023-04-23 at 12 51 16 PM

앞쪽 물체에 가려진 뒤쪽 물체의 일부는 그려지지 않는다.

보여질지 안보여질지 모르기 때문에 일단 계산을 해야한다.

Hidden surface Removal - z-buffer Algorithm

z-buffer (or depth-buffer) algorithm

  • It uses a buffer called z- or depth-buffer to store the depth of the closest object at each pixel found so far
  • As we render each polygon, compare the depth of each pixel to depth in z-buffer
  • If less, place shade of pixel in color buffer and update z-buffer

Screenshot 2023-04-23 at 12 52 32 PM

화면 크기만한 버퍼를 만듦

카메라에 가장 가까운 fragment 만 Pixel로 바꾸자

we have an additional buffer whose size is identical to the color buffer

Each pixel in the depth buffer keeps a depth-value, which is the sitance to the point on the nearest object from the synthetic camera

Screenshot 2023-04-23 at 12 55 35 PM

컬러버퍼와 다른 depth버퍼를 만들어서 거리를 저장

거리가 작을 경우만 남겨둠

Advantages

  • the programmer do not need to care about the rendering order of objects in a scene
    • 그리는 순서에 상관없이 동일한 결과가 나온다
    • 코드를 짤때 순서가 중요하지 않다. 어쩌피 realtime으로 계산해야한다.
  • z-buffer algorithm can combine shading and hidden surface removal through scan line algorithm
    • 물체끼리 뚫는 경우에도 잘 적용 된다.

Hidden Surface Removal - Painter's Algorithm

A kind of s/w approach

Render polygons a back to front order so that polygons behind others are simply painted over

  • we need to perform a sorting algorithm
    • 뒤에있는것 부터 그려져서 앞에껄 그리면서 뒤덮게 된다.Requires ordering of polygons first
  • O(nlogn) caculation for ordering
  • Not every polygon is either in front or behind all other polygons
    • 사선의 경우 상당히 모호함.

단점

  • Sorting하는대에 시간이 넘 오래걸림
    • 카메라의 위치가 바뀔때마다 sorting을 해야한다
  • 만약에 sorting을 한번만해도 된다면?
    • 그래도 뒤에서부터 그리기 때문에 계속 색을 계산하고, 덮고 쓰고 해야함.
    • 앞에서 부터 하면 굳이 색 계산을 안해도 될때가 있기 때문에 비효율적
  • 선후 관계를 측정할 수 없는 cyclic overlap, penetration의 경우에는 정렬 불가능

장점

  • For using alpha blending, we have to render polygons a back to front order
    • z-buffer알고리즘에서 할 수 없는 투명, 반투명을 표현할 수 있다.
    • 하지만 상당히 복잡하고 느려진다.
    • 따라서 물체마다 적절하게 자료구조를 사용해야 한다.

Hidden-Surface Removal - Back-face Removal

Back-face removal (culling) algorithm

  • Face is visible if 90>= θ >= -90
  • recall that you always send the vertices in a polygon in the order of CCW.
    • 간단하게 50퍼정도 사라진다.

보여지는 곳만 계산하고 안보여지는것은 계산하지 않겠다

  • Ex ) 물체의 뒷쪽면만약 내가 바라보는 관점에서 polygon의 좌표가 반시계방향이라면? => polygon이 나의 시선에 인식되는상태내가 보지 못하는 것은 계산을 하지 않는다.
  • 하드웨어 작업을 안한다? => rasterizer 계산을 안해도 된다.
  • 반대라면? => 나에게 안보이는 쪽을 Polygon이 바라보고있다.
반응형