Date post: | 27-Jun-2015 |
Category: |
Technology |
Upload: | - |
View: | 1,644 times |
Download: | 0 times |
Sh
ad
erX
5
4.2 Multisampling Extension for Gradient Shadow Maps
ohyecloudyhttp://ohyecloudy.com
shader study http://cafe.naver.com/shader.cafe
2010.5.24
Overview of Gradient Shadow Maps
Multisampling and PCF
Merging the Algorithms
Optimizing Texture Look-ups
Conclusion
• Slope-scale depth bias
– gradient를 depth bias에 사용
• Fuzzy depth comparison
– 1 or 0이 아니라 0~1 값을 쓴다.
• Linearly filtered depth values
– point 샘플링이 아니라 보간 해서 사용.
• 예) bilinear filter
float lightVisibility_GSM(float3 lightCoord)
{
// get the magnitude of the gradient, by either method
float gradient = length(getGradientVector(lightCoord));
// get the difference between stored and interpolated depth
// (depthMap should have LINEAR filtering enabled)
float diff = tex2D(depthMap, lightCoord.xy).x – lightCoord.z;
// replace the less-than operator with a smooth function
// for diff >= 0 the result is 1
return saturate(diff/gradient + 1);
}
Overview of Gradient Shadow Maps
Multisampling and PCF Merging the Algorithms
Optimizing Texture Look-ups
Conclusion
float lightVisibility_PCF(float3 ligthCoord)
{
float result = 0;
for (int i = 0; i < n; ++i)
{
float3 offCoord = lightCoord + offset[i];
result +=
lightCoord.z <
tex2D(depthMap, offCoord.xy).x;
}
return result / n;
}
Overview of Gradient Shadow Maps
Multisampling and PCF
Merging the Algorithms Optimizing Texture Look-ups
Conclusion
float lightVisibility_PCF_with_GSM(float3 lightCoord)
{
float result = 0;
for (int i = 0; i < n; ++i)
{
result +=
lightVisibility_GSM(lightCoord + offset[i]);
}
return result / n;
}
incident light
surface
shadow volume
PCF area
incident light
surface
shadow volume
PCF area
float lightVisibility_GSM_modified(float3 lightCoord, float2 offset) { // get the gradient, by either method float2 gradientVector = getGradientVector(lightCoord); float gradient = length(gradientVector); // calculate an offset coordinate // the z coord is moved along with the local gradient // (this is equivalent to having a local plane equation) float3 offCoord = float3( lightCoord.xy + offset, lightCoord.z + dot(offset, gradientVector)); // the rest is straightforward float diff = offCoord.z – tex2D(depthMap, offCoord.xy).x; return saturate(diff/gradient + 1); }
Overview of Gradient Shadow Maps
Multisampling and PCF
Merging the Algorithms
Optimizing Texture Look-ups Conclusion
• depth map에 scalar depth 저장했을 때
– gradient vector : texture loockup 3번
• 추가로 depth sampling 한번, PCF에서 4번
• 전체 PCF 영역에서 평균 gradient를 근사
–최소 제곱 근사값least squares approximation을 찾기 위한 선형회귀linear regression
ii
ii
i
i
yz
xz
yyx
yxx
yz
xz 1
2
2
ii
T
ii pzppz 1
2
2
i
ii
i
ii
y
yz
x
xz
yz
xz
공(共)분산 행렬 covariance matrix
yx 제거
float lightVisibility_unrolled_circluar8(float3 lightCoord)
{
const float displace = .5 / depthMapResolution;
const float displaceLong = 1.41421 * displace;
float depths[8] = {
tex2D(depthMap, lightCoord.xy + float2(-displaceLong,0)).x,
tex2D(depthMap, lightCoord.xy + float2(displaceLong,0)).x,
tex2D(depthMap, lightCoord.xy + float2(0,-displaceLong)).x,
tex2D(depthMap, lightCoord.xy + float2(0,displaceLong)).x,
tex2D(depthMap, lightCoord.xy + float2(-displaceLong,-displaceLong)).x,
tex2D(depthMap, lightCoord.xy + float2(displaceLong,-displaceLong)).x,
tex2D(depthMap, lightCoord.xy + float2(-displaceLong, displaceLong)).x,
tex2D(depthMap, lightCoord.xy + float2(displaceLong, displaceLong)).x };
const float inverseCovariance = 1. / (1 + 1+ 2);
float2 gradientVector = float2(
depths[1] * 1.41421 + depths[5] + depths[7]
-depths[0] * 1.41421 – depths[4] – depths[6],
depths[3] * 1.41421 + depths[6] + depths[7]
-depths[2] * 1.41421 – depths[4] – depths[5] ) *
inverseCovariance;
// continue with summation over PCF samples
// using the average gradient
}
8 PCF samples
Overview of Gradient Shadow Maps
Multisampling and PCF
Merging the Algorithms
Optimizing Texture Look-ups
Conclusion
• ShaderX4에서 봤던 Acne 제거 기술 복습
– Slope-scale depth bias,
– Fuzzy depth comparison,
– Linearly filtered depth values
• 추가로 부드러운 그림자 가장자리(edge)를 만들기 위한 기술
– PCF
–샘플링 회수를 줄이기 위한 근사