본문 바로가기
Computer Science/Computer Graphics

Shading

by Gofo 2021. 5. 31.

Normal

Surface Normal

어떤 점에서 표면에 수직인 vector를 surface normal이라 한다.

보통 길이가 1인 unit vector를 사용한다.

 

Diffuse reflection과 specular reflection에서 중요한 역할을 한다.

 

Face Normal

하나의 polygon face에서의 surface normal이다.

 

점의 순서에 따라 normal의 방향이 달라지기 때문에 점의 순서가 중요하다.

반시계 방향으로 점의 순서가 주어질 때의 normal이 앞면(표면의 바깥 방향)을 나타낸다.

 

점의 순서대로 오른쪽 손을 감싸면 그것이 normal의 방향이다.

 


Shading

일반적인 의미로 음영으로 빛에 의해 큰 영향을 받는다.

 

컴퓨터그래픽스에서는 polygon이 차지하는 각 픽셀의 색을 결정하는 과정을 shading이라 한다.

각 픽셀의 색을 어떻게 다르게 할 것인가를 결정하는 과정이다.

  • Flat shading
  • Smooth shading
    • Gouraud shading
    • Phong shading

 

Flat Shading

픽셀별로 계산하는 것이 아니라, polygon 하나에 하나의 face normal을 사용한다.

Polygon 당 물체의 색을 한번만 계산(illumination)한다.

Polygon에 속하는 픽셀의 색을 모두 같게한다.

 

계산이 적기 때문에 빠르지만, curved mesh에서는 각져보이기 때문에 적절하지 않다.

 

Smooth Shading

인접하는 polygon 사이에 color transition을 부드럽게 한다.

 

Face 마다의 face normal을 사용하는 것이 아니라 vertex 마다 vertex normal을 사용한다.

한 점에서의 normal(vertex normal)은 인접한 polygon 들의 face normal의 평균의 unit으로 한다.

각 polygon의 face normal은 cross porduct을 통해서 구할 수 있다.

 

계산량이 많지만, curved shape에 적합하다.

 

대표적으로 두가지 방법이 있다.

  • Gouraud shading
  • Phong shading

 

Gouraud Shading

  1. Vertex 하나 당 하나의 vertex normal을 사용한다.
  2. 각 vertex에서의 색을 계산(illumination) 한다.
  3. polygon 내부는 각 vertex들의 색을 interpolate 해서 채운다.
    • Barycentric interpolation을 이용

 

Interpolate를 하기 때문에 물체의 색상이 부드러워진다.

그러나 specular highlight가 주변에 손상되거나 평균화되기 때문에 이상해진다.

Polygon의 개수를 늘려서 매끄럽게 만들수는 있지만, 계산량이 늘어나는 문제점이 있다.

 

Phong Shading

  1. Vertex 하나 당 하나의 vertex normal을 사용한다.
  2. Vertex normal을 interpolate해서 polygon에서의 각 픽셀별로 색을 계산한다.
    • Barycentric interpolation을 이용

 

interpolate 된 normal이 실제 surface normal에 인접하기 대문에 훨씬 더 자연스러운 highlight를 만들어낸다.

그러나 삼각형이 포함된 픽셀 수 만큼 계산해야 하기 때문에 많은 계산을 필요로 한다.

 

Gouraud Shading vs. Phong Shading

Gouraud shading은 삼각형 하나당 3번만 계산하면 되지만, phong shading은 삼각형이 포함된 픽셀 수 만큼 계산해야 한다.

Gouraud shading보다 계산량이 많아지긴 하지만 훨씬 부드러운 결과를 만들어낸다.

 


참고

본 포스트는 한양대학교 이윤상 교수님의 수업을 정리한 내용입니다.

출처: 한양대학교 이윤상 교수님 컴퓨터그래픽스 강의 강의자료 - https://cgrhyu.github.io/courses/2022-spring-cg.html

 

CGR LAB

Computer Graphics - 2022 Spring Instructor: Yoonsang Lee Teaching Assistant: Chaejun Sohn Undergraduate Mentor: Bokyoung Jang Time / Location: Mon 09:00-11:00 / Online (originally 207 IT.BT Building) - Lab Wed 09:00-11:00 / 508 IT.BT Building - Lecture Cou

cgrhyu.github.io

 

 

 

'Computer Science > Computer Graphics' 카테고리의 다른 글

Affine Transformation Matrix, Transformation의 해석  (0) 2021.05.31
[OpenGL] Lighting, Shading  (0) 2021.05.31
Lighting  (0) 2021.05.31
Mesh, OBJ File  (0) 2021.04.08
Rendering Pipeline, Transformation Pipeline  (0) 2021.04.07

댓글