SlideShare uma empresa Scribd logo
1 de 16
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)
개요
어떻게 하면 그림자 aliasing을 줄일 수
있을까?
 어떻게 하면 shadow map을 잘 만들까 (X)
 shadow map 후처리를 할 수 있는 영역을 어떻게 하면
 잘 찾을 수 있을까 (O)
그림자 경계 영역 :
anti-aliasing을 위해 더 많은 texture fetch와 processing이
필요한 부분
계산이 더 필요한 그림자 경계 영역을 구
하는 두 가지 방법 소개.
이렇게 구한 영역만 anti-aliasing을 줄
이기 위한 복잡한 연산을 한다.
SM 3.0 필요
loop, dynamic flow control 등 제대로 된 flow-control을
  사용할 수 있다.
Shadow map




                              Edge mask map


      edge dilation
           or
depth extent propagation

                           Computation mask map
Computation Masking and Edge
Dilation Using Mipchain Generation
Depth-Extent Propagation for
Computation Masking
graphics hardware에 최적화된 간단한
방법.
edge mask로부터 mipchain을 생성한
다.
shadow mask의 효과적인 근사 확장
 8 pixel로 확장하고 싶다면 miplevel을 3.
edge pixel 과 nonedge pixel 을 구분
할 threshold 필요.
highest-resolution miplevel 의 edge filter 결과 값.


bilinear filtering을 사용
2x2 box filtering을 사용하면 mip level이 올라갈수록 모
  든 방향으로 확장되는게 아니라 한쪽으로 확장되는 경우
  가 발생.
Computation Masking and Edge
Dilation Using Mipchain Generation
 mipchain을 생성하고 확장하려는 edge 픽셀에 맞게
 miplevel을 설정한다.

Depth-Extent Propagation for
Computation Masking
depth extent map
 확장된 edge mask 대신에 light로부터 min, max 거리
 사용.
 edge-filtered shadow map 사용
shadow map 텍스쳐 좌표가 주어 졌을때(확장된 edge 영역),
            z 좌표가 min, max 사이일 때만 복잡한 연산 수행.




edge


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




       edge가 아니므로 min = 1, max = 0 으로 저장
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;
}
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, 0
                tapVals = 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;
    }
use depth extent map
float4 ps_LightPassPDisk12RandRotPCFCondEdgeDepthExtent(
            float3 oTex0 : TEXCOORD0,           // normal in world space
            float4 oTex1 : TEXCOORD1,           // shadow map tex coords
            float3 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
                        }
            }
}
Computation Masking and Edge
Dilation Using Mipchain Generation
 mipchain을 생성하고 확장하려는 edge 픽셀에 맞게
 miplevel을 설정한다.

Depth-Extent Propagation for
Computation Masking
 3x3의 min, max depth값을 기록해 depth extent map
 을 만들고 projection된 shadow map 텍스쳐 z좌표와
 비교해 min, max 범위 안이면 복잡한 연산을 한다.
결론
최대 3배까지 성능 향상.
 edge map, mipmap 을 생성하더라도 부분적으로만 많
 은 tap의 PCF를 거는 게 싸다는 결롞

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

Mais conteúdo relacionado

Mais procurados

Mais procurados (8)

Chuong12
Chuong12Chuong12
Chuong12
 
MUDA
MUDAMUDA
MUDA
 
Dsa 1
Dsa 1Dsa 1
Dsa 1
 
Clear all
Clear allClear all
Clear all
 
Practica 4 errores
Practica 4 erroresPractica 4 errores
Practica 4 errores
 
Excerpt
ExcerptExcerpt
Excerpt
 
Excerpt
ExcerptExcerpt
Excerpt
 
8 khao sat quy dao nghiem
8 khao sat  quy dao nghiem8 khao sat  quy dao nghiem
8 khao sat quy dao nghiem
 

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

  • 1. 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)
  • 2. 개요 어떻게 하면 그림자 aliasing을 줄일 수 있을까? 어떻게 하면 shadow map을 잘 만들까 (X) shadow map 후처리를 할 수 있는 영역을 어떻게 하면 잘 찾을 수 있을까 (O)
  • 3. 그림자 경계 영역 : anti-aliasing을 위해 더 많은 texture fetch와 processing이 필요한 부분
  • 4. 계산이 더 필요한 그림자 경계 영역을 구 하는 두 가지 방법 소개. 이렇게 구한 영역만 anti-aliasing을 줄 이기 위한 복잡한 연산을 한다. SM 3.0 필요 loop, dynamic flow control 등 제대로 된 flow-control을 사용할 수 있다.
  • 5. Shadow map Edge mask map edge dilation or depth extent propagation Computation mask map
  • 6. Computation Masking and Edge Dilation Using Mipchain Generation Depth-Extent Propagation for Computation Masking
  • 7. graphics hardware에 최적화된 간단한 방법. edge mask로부터 mipchain을 생성한 다. shadow mask의 효과적인 근사 확장 8 pixel로 확장하고 싶다면 miplevel을 3.
  • 8. edge pixel 과 nonedge pixel 을 구분 할 threshold 필요. highest-resolution miplevel 의 edge filter 결과 값. bilinear filtering을 사용 2x2 box filtering을 사용하면 mip level이 올라갈수록 모 든 방향으로 확장되는게 아니라 한쪽으로 확장되는 경우 가 발생.
  • 9. Computation Masking and Edge Dilation Using Mipchain Generation mipchain을 생성하고 확장하려는 edge 픽셀에 맞게 miplevel을 설정한다. Depth-Extent Propagation for Computation Masking
  • 10. depth extent map 확장된 edge mask 대신에 light로부터 min, max 거리 사용. edge-filtered shadow map 사용
  • 11. shadow map 텍스쳐 좌표가 주어 졌을때(확장된 edge 영역), z 좌표가 min, max 사이일 때만 복잡한 연산 수행. edge 9 점에서 min, max 값을 뽑아서 저장 edge가 아니므로 min = 1, max = 0 으로 저장
  • 12. 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; }
  • 13. 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, 0 tapVals = 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; }
  • 14. use depth extent map float4 ps_LightPassPDisk12RandRotPCFCondEdgeDepthExtent( float3 oTex0 : TEXCOORD0, // normal in world space float4 oTex1 : TEXCOORD1, // shadow map tex coords float3 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 } } }
  • 15. Computation Masking and Edge Dilation Using Mipchain Generation mipchain을 생성하고 확장하려는 edge 픽셀에 맞게 miplevel을 설정한다. Depth-Extent Propagation for Computation Masking 3x3의 min, max depth값을 기록해 depth extent map 을 만들고 projection된 shadow map 텍스쳐 z좌표와 비교해 min, max 범위 안이면 복잡한 연산을 한다.
  • 16. 결론 최대 3배까지 성능 향상. edge map, mipmap 을 생성하더라도 부분적으로만 많 은 tap의 PCF를 거는 게 싸다는 결롞 Image-processing 연산. standard shadow mapping 알고리즘을 사용. 추가적인 geometry 정보가 필요 없다.