2023. 10. 10. 18:26ㆍRun/Computer Graphics
- Light source emits light rays in many directions in 3D.
- Lighting에 필요한 것: light sources, material properties of the objects, reflectance coefficients
Types of Light Sources
1. Ambient Light
- Uniform light present everywhere.
- 3 values: Iar(ambient red), Iag(ambient green), lab(ambient blue)
ex) Iar = 150, Iag = 150, Iab = 20
2. Point Light
- Brightness falls off as square of distance.
- p0을 정의해줘야 한다.
3. Spotlight
- Rays are emitted over a narrow angle.
- Intensity falls away with angle.
- Intensity is proportional to cosine of angle.
- 종종 cos𝜃이 유의미한 차이를 만들어내지 못하기 때문에 cos^e𝜃 를 사용한다.
- Source location p0, direction(unit vector) of maximum intensity u을 정의해줘야 한다.
- Brightness는 red, green, blue value를 가진 vector이다.
4. Directional Light
- Light source: sun, stars, venus, ...
- The point of origin is at infinity → direction i만 정의해주면 된다.
[요약]
Ambient Light | Specify intensity Ia |
Point Light | Specify point p0, intensity at point p0 I(p0) |
Spotlight | Specify point p0, intensity at point p0 I(p0), angle 𝜃 max |
Directional Light | Specify direction i, intensity along direction I(i) |
Phong Reflection
1. Ambient Reflection: 빛의 방향과 관계없이 반사되는 reflection
- Iar, Iag, Iab : ambient terms in the incident light
- Kar, Kag, Kab : ambient reflectance coefficients
- Rar, Rag, Rab : ambient terms in the reflected light
2. Diffuse Reflection: 빛이 모든 방향으로 균일하게 반사되는 reflection (빛의 방향과 관계 O)
- Idr, Idg, Idb : diffuse terms in the incident light
- Kdr, Kdg, Kdb : diffuse reflectance coefficents
- Rdr, Rdg, Rdb : diffuse terms in the reflected light
- n(normal): unit vector perpendicular to surface
- cos𝜃 을 계산하기 위해 unit vector i와 normal n을 사용한다.
- cos𝜃 값이 0 이하인 경우를 위해 그냥 cos𝜃 대신 max(cos𝜃, 0)을 사용한다.
3. Specular Reflection: 빛의 일부가 한 방향으로 크게 반사되는 reflection
- Lot of reflection in specific direction & very little reflection anywhere else.
- Surface가 완벽한 거울이면 reflection은 정확히 한 방향으로만 진행된다.
- Diffuse reflection과 달리, viewer의 위치에 따라 달라진다.
- r: i mirrored around n ( = 2 ( i * n) n - i )
- Isr, Isg, Isb : diffuse terms in the incident light
- Ksr, Ksg, Ksb : specular reflectance coefficients
- Rsr, Rsg, Rsb : diffuse terms in the reflected light
- ɑ: shininess (값이 클수록 한 곳에 집중된다.)
[요약]
- The total reflected intensity is the sum of all components.
- 여러 종류의 light sources를 적용하려면 각 값을 또 더해주면 된다.
(ex. Rr = Rar1 + Rar2 + Rdr1 + Rdr2 + Rsr1 + Rsr2)
Normals
- 위에서 보았듯, Diffuse Reflection을 위해서는 Face Normal이 필요하다.
- WebGL에서 face는 삼각형 형태이다.
- n = v1 * v2 = (p1 - p0) * (p2 - p0)
- Face Normal을 구하고 나면, 각 face의 light input을 계산할 수 있다.
- 다만 문제는, Flat Shading이기 때문에 실제 빛 반사처럼 부드럽게 표현되지 않는다는 것이다.
- Interpolated Shading을 사용하면 훨씬 더 자연스럽다. (Reflection is specified per vertex)
- Vertex Normal (normal at each vertex) 을 사용한다.
- 특정 vertex를 포함한 모든 Face Normal을 계산하고, 이를 평균낸다.
- 이때 Vertex Normal이 unit vector가 아니기 때문에 normalize를 진행해야 한다.
Two Types of Interpolated Shading
1. Gouraud Shading: Interpolates Colors
- Normals are same for all pixels in a face → pointy appearance
- Compute Color in VS & Interpolate Color from VS to FS
- Does lighting calculations per vertex
2. Phong Shading: Interpolates Normals (Phong reflection이랑 다른 것!)
- Each pixel in a face gets a different normal → color appears smoother
- Interpolate Normal from VS to FS & Compute Color in FS
- Does lighting calculations per fragment → Slower (∵ fragment 수 > vertex 수)
'Run > Computer Graphics' 카테고리의 다른 글
[Computer Graphics] Shadow Mapping (0) | 2023.10.10 |
---|---|
[Computer Graphics] Texture Mapping (0) | 2023.10.10 |
[Computer Graphics] Viewing (1) | 2023.10.10 |
[Computer Grpahics] WebGL Variables (0) | 2023.10.10 |
[Computer Graphics] WebGL 다각형 그리기 (0) | 2023.10.10 |