[Computer Graphics] Shadow Mapping

2023. 10. 10. 18:28Run/Computer Graphics

 

 

- Shadow helps depth perception.

- Shadow depends on the light and geometry.

 

- This area is in shadow due to occlusion from the object.

- 이 영역 밖은 seen by camera & seen by light

- 이 영역 안은 seen by camera & not seen by light

- Occlusion: point seen by camera but not seen by light

 

 

Two Step algorithm to create shadows:

Step 1) Determine d1 by making shadow map.

Step 2) Compute d2 during shading and compare d2 to d1.

→ 2개의 distance를 계산하고, 두 값을 비교하여 같으면 어둡게 칠하고, 다르면 원래 색상 그대로 둔다.

 

Step 1

- Light이 위치한 position에 fake camera를 생성한다.

- 이 camera는 light이 바라보는 장면과 같은 장면을 보게된다.

- 이를 'flashlight in the eye' rendering이라고 한다.

   (∵ Camera and light coincide. Light mimics camera flash.)

 

실제 카메라에는 flashlight가 카메라 중앙이 아닌 위쪽에 위치해 있다.

중앙에 있다면 물체에 그림자가 지지 않아야 한다. 그렇지만 실제로 카메라로 촬영을 하면 물체 뒤에 그림자가 생긴다.

 

Shadow Map

- Scene depths rendered from viewpoint of light

- Contains depth to each pixel instead of colors

- Shadow Map은 우리가 보고자 하는 것이 아니다. 우리는 실제로 카메라가 보는 모습을 보고자 한다.

- 이를 위해 Framebuffer Objects(FBO)를 사용한다.

 

- Color buffer: access the depth values stored here as the shadow map.

 

- Send uniforms for pretend camera at light and send attributes.

- `drawElements()` renders the scene from the viewpoint of the light, and stores the rendered depth values into `shadowMapTexture`, which contains d1.

Step 2

- In view shader, `gl_Position` gets vertex position seen from camera, and renders point to screen.

- `fVertexPositionToLight` is used to obtain d2 for each point rendered to screen.

- Transform `fVertexPositionToLight` to lie betweeon 0~1, this gets stored in `shadowMapCoordinates`.

- d2 is z value of `shadowMapCoordinates`.

- x and y values serve as texture coordinates into shadow map. Use theses to access shadowMap for d1.

- Render pixel as in shadow if d2 > d1.

 

Two Step algorithm improvements

- d2 > d1 가 너무 strict하다.

 

- d2 == d1 을 적용하면 위와 같은 문제가 발생한다.

- We can soften the comparison to allow for d2 being slightly greater than d1 in striated region(줄무늬 영역).

 

d2 > d1 에서 d2 - d1 > 0.06 으로 변경한 모습이다.

또한, 일반적으로 그림자가 완전히 검은색은 아니므로 visibility를 0.4로 설정했다.

개선된 모습에서 그림자가 sharp한 것을 볼 수 있는데, 이는 일반적인 그림자의 형태가 아니다. (especially indoor lighting)

 

Smooth Shadows

- Happen because light sources are never truly points.

 

- Umbra: 본그림자 → completely dark shadow / Penumbra: 반그림자 → partial shadow

- Smooth shadow를 생성하기 위해서 OpenGL에서는 sample2Dshadow를 사용한다.

  (samples neighboring regions of the shadow map)

- OpenGL ES(WebGL)에는 이러한 기능이 없다.

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

[Computer Graphics] Curves & Surfaces  (1) 2023.10.10
[Computer Graphics] Reflection Mapping  (1) 2023.10.10
[Computer Graphics] Texture Mapping  (0) 2023.10.10
[Computer Graphics] Lighting  (1) 2023.10.10
[Computer Graphics] Viewing  (1) 2023.10.10