3D그래픽2011. 9. 6. 21:22
▶ 평행이동 (Translation)

T(t)=\left ( \begin{array}{cccc} 1 & 0 & 0 & t_{x}\\ 0 & 1 & 0 & t_{y}\\ 0 & 0 & 1 & t_{z}\\ 0 & 0 & 0 & 1\\ \end{array} \right )

→ 평행이동의 역변환

T^{-1}(t)=T(-t)=\left ( \begin{array}{cccc} 1 & 0 & 0 & -t_{x}\\ 0 & 1 & 0 & -t_{y}\\ 0 & 0 & 1 & -t_{z}\\ 0 & 0 & 0 & 1\\ \end{array} \right )



▶ 회전 (Rotation)

R_{x}(\phi)=\left ( \begin{array}{cccc} 1 & 0 & 0 & 0\\ 0 & cos\phi & -sin\phi & 0\\ 0 & sin\phi & cos\phi & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right )
R_{y}(\phi)=\left ( \begin{array}{cccc} cos\phi & 0 & sin\phi & 0\\ 0 & 1 & 0 & 0\\ -sin\phi & 0 & cos\phi & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right )
R_{z}(\phi)=\left ( \begin{array}{cccc} cos\phi & -sin\phi & 0 & 0\\ sin\phi & cos\phi & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right )


→ 모든 3x3 행렬 R에서 대각 원소들의 합 tr(R)은 축과 무관하게 상수값을 가진다.

tr(R)=1+2cos\phi

이 합을 trace라고 부른다.


→ 모든 회전행렬은 직교 행렬이므로

R^{-1}=R^{T}

과 같이, 역행렬은 전치행렬과 같다. 역행렬을 구하는 다른 방법은

R_{i}^{-1}(\phi)=R_{i}(-\phi)

이다.


→ 회전행렬의 판별자는 항상 1개 뿐이다.


→ (예) 특정 점 p를 중심으로 z축을 따라 φ라디안 만큼 물체를 회전시키는 변환 행렬은
(-p) 만큼 평행이동 → z축으로 φ회전 → (p) 만큼 평행이동 시키는 것이다.

X=T(p)R_{z}(\phi)T(-p)



▶ 크기 조정 (Scaling)

S(s)=\left ( \begin{array}{cccc} s_{x} & 0 & 0 & 0\\ 0 & s_{y} & 0 & 0\\ 0 & 0 & s_{z} & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right )

단, s_{x}=s_{y}=s_{z} 인경우 uniform(isotropic)이라 하고, 그렇지 않은경우 non-uniform(anisotropic)이라 한다.

역변환은
S^{-1}(s)=S(\frac{1}{s_{x}}, \frac{1}{s_{y}}, \frac{1}{s_{z}})

특히, uniform이고 동차좌표를 이용하는 경우에는 w 성분을 이용하여 역변환을 표현할 수 있다.

S(s)=\left ( \begin{array}{cccc} s & 0 & 0 & 0\\ 0 & s & 0 & 0\\ 0 & 0 & s & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right )=\left ( \begin{array}{cccc} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & \frac{1}{s}\\ \end{array} \right )

→ 성분들 가운데 하나 또는 세 개가 음수이면 거울 행렬(mirror matrix)이라고도 불리는 반사 행렬(reflection matrix)이 만들어진다. 이렇게 되면 정점들의 감기 순서(winding order)가 반대로 바뀐다.

좌측 상단 3x3 행렬의 판별자의 값이 음수이면 주어진 행렬이 반사 행렬이다.


▶ 변환의 결합

변환의 결합은 순서가 중요하며 다음과 같은 순서로 결합한다.

C=TRS

TRSp=(T(R(Sp)))

'3D그래픽' 카테고리의 다른 글

Phong Shading  (0) 2011.09.10
Bézier, Gouraud, Fresnel 의 발음  (0) 2011.09.08
Goraud shading vs. Phong shading  (0) 2011.09.02
Normal Transform(법선벡터 변환)  (0) 2011.09.02
COLLADA (3D Asset Exchange Schema)  (0) 2011.08.31
Posted by 세월의돌
3D그래픽2011. 9. 2. 15:24
Phong Shading 이란 용어는 그래도 어느정도 들어봤는데, 이와 관련된 내용을 찾다보면 per-pixel lighting 이라던지 per-fragment lighting 이라는 용어가 계속 튀어 나온다. 그래서 내가 뭔가 잘못 알고 있는건가 고민하다가 찾아보기로 결심!

Wikipedia의 내용으로 정리 해 본다.

Gouraud shading, named after Henri Gouraud, is an interpolation method used in computer graphics to produce continuous shading of surfaces represented by polygon meshes. In practice, Gouraud shading is most often used to achieve continuous lighting on triangle surfaces by computing the lighting at the corners of each triangle and linearly interpolating the resulting colours for each pixel covered by the triangle. Gouraud first published the technique in 1971.
  
OpenGL ES 1.x의 fixed pipeline에 구현되어 있는 것으로 알 고 있다. Goraud shading은 vertex에 대해서 연산을 수행하고, 각 pixel(fragment)에 대해서는 단순히 linear interpolation을 하기 때문에, 왼쪽 그림과 같이 polygon의 수가 적은경우 어색할 수 밖에 없다. 다만 1971년에 나온 기술이라니, 그 당시 이러한 연구를 했다는 것 자체가 너무 신기하다.


Phong shading refers to an interpolation technique for surface shading in 3D computer graphics. It is also called Phong interpolationnormal-vector interpolation shadingper-fragment lighting or per-pixel-based lighting. Specifically, it interpolates surface normals across rasterized polygons and computes pixel colors based on the interpolated normals and a reflection model. Phong shading may also refer to the specific combination of Phong interpolation and the Phong reflection model.
결과적으로 Phong shading과 per-pixel lighting 등등은 모두 동일한 용어! : )
normal을 interpolation해서 pixel(또는 fragment)마다 연산을 수행하는 것이 특징. 당연히 더욱 부드럽게 보일 수 있지만 연산량은 Goraud shading에 비해 엄청나게 많아질 수 밖에 없다.



이제 궁금증을 해결 했으니 다시, shader coding의 세계로...

'3D그래픽' 카테고리의 다른 글

Bézier, Gouraud, Fresnel 의 발음  (0) 2011.09.08
Transforms (변환 행렬)  (0) 2011.09.06
Normal Transform(법선벡터 변환)  (0) 2011.09.02
COLLADA (3D Asset Exchange Schema)  (0) 2011.08.31
OpenGL ES 2.0 Q&A by myself  (5) 2011.07.12
Posted by 세월의돌