3. Overview
• CSM 기본 구현에 대핚 내용이 아니다.
• 실무에 적용할 때, 생기는 문제들 해결
방법을 알려주는 글.
4. flickering of shadow quality
storage strategy
non-optimized split selection
correct computation of texture
coordinates
filter across splits
5. • 그림자 품질이 다음 프레임에 급격히 변핚다.
• light, viewer 위치가 변하면 발생.
6.
7. Exact Solution
• split을 감싸는 bounding sphere 사용
– shadow map size가 stable
– scale, offset 문제 해결
8. // step 1 : calculate the light basis
vector3 direction = normalize(WORLD.getColumn3(2));
vector3 side = normalize(WORLD.getColumn3(1));
vector3 up = normalize(WORLD.getColumn3(0));
// update all splits
for (int i = 0; i < numSplits; i++)
{
// Step 2 : Calculate the bounding sphere “bs” of each split
// Step 3 : update the split-specific view matrix
// ‘matrixView[i]’ and projection matrix ‘matrixProjections[i]’
}
9. // step 1 : calculate the light basis
direction, side, up
// update all splits
for (int i = 0; i < numSplits; i++)
{
// Step 2 : Calculate the bounding sphere “bs” of each split
Sphere bs = CalculateBoundingSphere(split[i]);
vector3 center = INVWORLDVIEW * bs.getCenter();
float radius = bs.getRadius();
// adjust the sphere’s center to make sure it is transformed
into the center of the shadow map
float x = ceilf(dot(center,up)*sizeSM/radius)*radius/sizeSM;
float y = ceilf(dot(center,side)*sizeSM/radius)*radius/sizeSM;
center = up*x + side*y + direction * dot(center, direction);
// Step 3 : update the split-specific view matrix
// ‘matrixView[i]’ and projection matrix ‘matrixProjections[i]’
}
10. // step 1 : calculate the light basis
direction, side, up
// update all splits
for (int i = 0; i < numSplits; i++)
{
// Step 2 : Calculate the bounding sphere “bs” of each split
// Step 3 : update the split-specific view matrix
// ‘matrixView[i]’ and projection matrix ‘matrixProjections[i]’
matrixProjections[i]
= MatrixOrthoProjection(
-radius, radius, radius, -radius, near, far);
vector3 origin = center – direction * far;
matrixView[i] = MatrixLookAt(origin, center, up);
}
11.
12. Approximated Solution
• sphere를 사용하니 그림자 텍스쳐 낭비 심함.
– bounding-box 사용.
– scale, offset 직접 계산.
– 구한 scale, offset을 여러 프레임에 걸쳐 부드럽게
보간.
24. 개선된 방법
• Vertex Shader
– split 번호를 판단 X
– 월드 좌표를 PS에 넘겨준다.
• Pixel Shader
– split 번호를 계산
– world texcoord 트랜스폼
– 해당하는 shadow maps에서 depth 샘플링.
• 수학적으로 틀렸으나 빠르고 눈에 띄는 artifacts X