[그래픽스] Fragment Shader - Texturing

YEOM JINSEOP·2023년 11월 21일
0

Computer Graphics

목록 보기
9/14
  • Rasterizer가 출력하는 fragment별 attribute는 대체로 normal과 texture coordinate을 포함한다.
    framgnet shader는 이들을 이용해 fragment의 색상을 계산한다.

  • fragment shader가 만드는 최종 영상의 품질을 결정하는 핵심 알고리즘은 lightingtexturing으로 구분된다.


Texturing

  • texture는 texel들의 배열이다. (texel은 pixel과 동일한 개념)

  • 이 배열이 색상 정보를 저장하고 있다면, 이를 image texture라고 부른다.

  • polygon mesh의 각 vertex마다 texture coordinate을 할당해야 한다.

  • 2차원 texture coordinate은 보통 (s,t)(s, t) 혹은 (u,v)(u, v)로 표현하는데,
    각 좌표는 원칙적으로 [0, 1] 범위 안에 정규화 돼있다.


Texture coordinate Interpolation

  • Scan conversion 알고리즘을 이용한다.
    먼저 변을 따라 texture coordinate을 interpolation하고,
    이후 scan line을 따라 texture coordinate을 interpolation한다.


Texture Mapping

  • 해상도가 rx×ryr_x \times r_y인 texutre가 주어졌을 때, 정규화된 texture coordinate (s,t)(s, t)는 아래와 같이 실제 texture space로 매핑된다.
    이를 가리켜, texture coordinate (s,t)(s,t)가 texture space (s,t)(s',t')로 projection된다고 표현한다.
    s=s×rxt=t×rys' = s \times r_x \\ t' = t \times r_y

Surface parameterization

  • polygon mesh의 각 vertex에 texture coordinate (s,t)(s, t)를 할당하는 작업을 말한다.
  • 이 작업을 위해서는 3차원 mesh를 2차원 평면에 펼쳐야 한다.
    이렇게 펼쳐진 2차원 직사각형 mesh를 [0, 1]의 범위를 갖는 stst parameter space에 매핑하면,
    각 vertex에 (s,t)(s,t) texture coordinate이 할당된다.

  • 이는 vertex array에 기록되어, vertex shader에게 전달된다.

  • 참고로, 복잡한 polygon mesh는 여러 개의 patch로 나눠져 각각 parameterization된다.
    parameterization이 완료된 2차원 patch 포토샵 등을 이용해 이미지를 그린다,
    이 이미지를 chart라고 부르며, 여러 chart를 하나의 커다란 texture에 모은 것을 atlas라고 부른다.


Texture Wrapping

  • (a) texture
    (b) [0, 1] 범위를 벗어난 texture coordinate
    (c) 경계 고정 모드(clamp-to-edge) : [0,1] 범위 밖의 texture coordinate를 [0, 1] 범위의 경계로 고정
    (d) 반복 모드(repeat): [0, 1] 범위 밖의 texture coordinate을 그 소수점 이하만 이용 (ex. 1.1 -> 0.1)
    (e) 반사 반복 모드(mirrored repeat): 1 - 반복모드 값
    (f) 반복 모드 + 반사 반복 모드

Texture Filtering

  • fragment의 texture 좌표 (s,t)(s, t)는 texture space의 (s,t)(s', t')으로 투영된다.
    그러면, (s,t)(s', t') 주변의 texel을 고려해서 해당 fragment의 color를 결정해야 하는데,
    이를 texture filtering이라고 부른다.

texture 확대

  1. nearest point sampling
  • (s,t)(s', t')와 가장 가까운 texel 사용
  1. bilinear interpolation
  • (s,t)(s', t') 주위를 둘러싸는 네 개의 texel을 bilinear interpolation하여,
    해당 pixel의 texture color를 결정.
  • 보다 부드러운 texturing 결과.

texture 축소

  • aliasing: high-frequency 신호를 낮은 frequency로 샘플링할 때에 발생하는 오류.
    pixel에 비해 texel이 너무 많아서 texturing에 참여하지 못하는 texel이 발생하기 때문에 나타남.
    ex) 모든 pixel이 검은색 texel에 둘러싸이게 되면, texturing 결과가 검은색으로 나타남.

  • 따라서 anti-aliasing 기술이 필요함.
    해결 방법은 texture를 작게 만들어서 texel 수를 pixel 수에 맞추면 된다.

Mipmapping

  • 원본 texture의 resolution을 downampling한다.
    이때 원본 및 downsampling된 texture들은 (l+1)(l+1)개의 레벨을 갖는 texture pyramid로 묶일 수 있다.
    이 pyramid를 mipmap이라 부른다.

Mipmap Filtering

  • texture space에 projection된 pixel은 (s,t)(s', t')에 놓인 '점'이 아니라
    (s,t)(s', t')를 중심으로 일정한 '영역'을 차지하게 된다.
    이 영역을 pixel footprint라고 부른다.

  • 0번 level texture 오른쪽 아래 구석 예시처럼 pixel footprint는 2×22 \times 2 texel 영역을 차지한다.
    (연두색:pixel, 노란색: texel)
    texel이 pixel보다 너무 많다.

  • level을 올라가면서 (점점 texel 개수가 적어지겠지)
    pixel과 texel의 개수가 같은 레벨을 선택한다.

  • nearest sampling 혹은 bilinear samping을 통해 filtering 된다.

vertex shader and fragment shader

0개의 댓글

관련 채용 정보