16
ShaderX 5 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping ohyecloudy(http://dodoubt.tistory.com) shader study(http://cafe.naver.com/shader.cafe)

[ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

Shad

erX5

Edge Masking and Per-Texel Depth Extent PropagationFor Computation CullingDuring Shadow Mapping

ohyecloudy(http://dodoubt.tistory.com)shader study(http://cafe.naver.com/shader.cafe)

Page 2: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

개 요

어떻게 하면 그림자 aliasing 을 줄일 수 있을까 ?

어떻게 하면 shadow map 을 잘 만들까 (X)shadow map 후처리를 할 수 있는 영역을 어떻게 하면 잘 찾을 수 있을까 (O)

Page 3: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

그림자 경계 영역 : anti-aliasing 을 위해 더 많은 texture fetch 와 pro-cessing 이 필요한 부분

Page 4: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

계산이 더 필요한 그림자 경계 영역을 구하는 두 가지 방법 소개 .이렇게 구한 영역만 anti-aliasing 을 줄이기 위한 복잡한 연산을 한다 .SM 3.0 필요loop, dynamic flow control 등 제대로 된 flow-con-

trol 을 사용할 수 있다 .

Page 5: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

Shadow map

Edge mask map

Computation mask map

edge dilationor

depth extent propagation

Page 6: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

Computation Masking and Edge Dilation Using Mipchain Genera-tionDepth-Extent Propagation for Computation Masking

Page 7: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

graphics hardware 에 최적화된 간단한 방법 .edge mask 로부터 mipchain 을 생성한다 .shadow mask 의 효과적인 근사 확장

8 pixel 로 확장하고 싶다면 miplevel 을 3.

Page 8: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

edge pixel 과 nonedge pixel 을 구분할 threshold 필요 .highest-resolution miplevel 의 edge filter 결과 값 .

bilinear filtering 을 사용2x2 box filtering 을 사용하면 mip level 이

올라갈수록 모든 방향으로 확장되는게 아니라 한쪽으로 확장되는 경우가 발생 .

Page 9: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

Computation Masking and Edge Dilation Using Mipchain Genera-tion

mipchain 을 생성하고 확장하려는 edge 픽셀에 맞게 miplevel 을 설정한다 .

Depth-Extent Propagation for Computation Masking

Page 10: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

depth extent map확장된 edge mask 대신에 light 로부터 min, max 거리 사용 .edge-filtered shadow map 사용

Page 11: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

edge

edge 가 아니므로 min = 1, max = 0 으로 저장

shadow map 텍스쳐 좌표가 주어 졌을때 ( 확장된 edge 영역 ),z 좌표가 min, max 사이일 때만 복잡한 연산 수행 .

9 점에서 min, max 값을 뽑아서 저장

Page 12: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

float4 ps_EdgeMapRGMinMax( float2 oTex : TEXCOORD0 ) : COLOR0{

float4 neighborOffsets[4] = {{ 1.0, 0.0, 0, 0 },{-1.0, 0.0, 0, 0 },{ 0.0, 1.0, 0, 0 },{ 0.0,-1.0, 0, 0 }

};float centerTapDepth = tex2D( ShadowSampler, oTex ).r;for( int i=0; i< 4; i++ ){

currTapDepth = tex2D( ShadowSampler, oTex+(g_vFullTexelOffset*neighborOffsets[i]) ).r;depthDiff = abs( centerTapDepth - currTapDepth );

if( depthDiff > g_fMinEdgeDelta ){

furthestTapDepth = max( currTapDepth, centerTapDepth );furthestTepDepthMin = min( furthestTepDepthMin, furthestTapDepth );furthestTepDepthMax = max( furthestTepDepthMax, furthestTapDepth );

}}

outColor.r = furthestTapDepthMin;outColor.g = furthestTapDepthMax;

return outColor;}

Page 13: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

Mipchain

min, max 때문에 filtering 으로 생성 (X).PS 를 만들어서 생성한다 .

float4 ps_MipLevel3x3MinMaxRG(float4 oTex0 : TEXCOORD0,float4 oFullTexelOffset : TEXCOORD1 ) : COLOR0

{float4 tapOffset = oFullTexelOffset;

outCol.rg = tex2Dlod( ShadowMipPointSampler, oTex0 ).rg;

// 1, 1, 0, 0tapVals = tex2Dlod( ShadowMipPointSampler, oTex0 +

( tapOffset * float4(1, 1, 0, 0) ) ).rg;outCol.r = min( outCol.r, tapVals.r );outCol.g = max( outCol.g, tapVals.g );

// 0, 1, 0, 0// 1, 0, 0, 0// -1, 1, 0, 0// -1, 0, 0, 0// 1, -1, 0, 0// 0, -1, 0, 0// -1, -1, 0, 0

return outCol;}

Page 14: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

float4 ps_LightPassPDisk12RandRotPCFCondEdgeDepthExtent(float3 oTex0 : TEXCOORD0, // normal in world spacefloat4 oTex1 : TEXCOORD1, // shadow map tex coordsfloat3 oTex2 : TEXCOORD2,float2 vPos : VPOS ) // world space light vector (not normalized

: COLOR0{

projCoords.xyz = oTex1 / oTex1.w;projCoords.w = 0;lightVal = ComputeLighting(oTex1, dist, oTex2, oTex0 );if( dot(lightVal, float3(1, 1, 1) ) == 0 ){

return 0;}else{

projCoords.w = g_fEdgeMaskMipLevel - 1; // going up 1 miplevel

edgeValMinMax = tex2Dlod( EdgeMipPointSampler, projCoords ).rg;if( (edgeValMinMax.r > projCoords.z ) || (edgeValMinMax.g < projCoords.z ) ){

// simple shadow map test}else{

// complex processing. ex) PCF 12taps}

}}

use depth extent map

Page 15: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

Computation Masking and Edge Dilation Using Mipchain Genera-tion

mipchain 을 생성하고 확장하려는 edge 픽셀에 맞게 miplevel 을 설정한다 .

Depth-Extent Propagation for Computation Masking

3x3 의 min, max depth 값을 기록해 depth ex-tent map 을 만들고 projection 된 shadow map 텍스쳐 z 좌표와 비교해 min, max 범위 안이면 복잡한 연산을 한다 .

Page 16: [ShaderX5] 4.4 Edge Masking and Per-Texel Depth Extent Propagation For Computation Culling During Shadow Mapping

결론

최대 3 배까지 성능 향상 .edge map, mipmap 을 생성하더라도 부분적으로만 많은 tap 의 PCF 를 거는 게 싸다는 결론

Image-processing 연산 .standard shadow mapping 알고리즘을 사용 .추가적인 geometry 정보가 필요 없다 .