daily pastebin goal
51%
SHARE
TWEET

Untitled

a guest May 19th, 2011 328 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Index: softShadow.hlsl
  2. ===================================================================
  3. --- softShadow.hlsl     (revision 47328)
  4. +++ softShadow.hlsl     (working copy)
  5. @@ -35,6 +35,7 @@
  6.  #else
  7.  
  8.  #define NUM_PRE_TAPS 5
  9. +#define NUM_TAPS 5
  10.  
  11.  /// The non-uniform poisson disk used in the
  12.  /// high quality shadow filtering.
  13. @@ -69,18 +70,44 @@
  14.     float2 tap = 0;
  15.     for ( int t = startTap; t < endTap; t++ )
  16.     {
  17. -      tap.x = ( sNonUniformTaps[t].x * sinCos.y - sNonUniformTaps[t].y * sinCos.x ) * filterRadius;
  18. -      tap.y = ( sNonUniformTaps[t].y * sinCos.y + sNonUniformTaps[t].x * sinCos.x ) * filterRadius;
  19. -      float occluder = tex2Dlod( shadowMap, float4( shadowPos + tap, 0, 0 ) ).r;
  20. +      tap.x = ( sNonUniformTaps[t].x * sinCos.y - sNonUniformTaps[t].y * sinCos.x ) * filterRadius * 0.5;
  21. +      tap.y = ( sNonUniformTaps[t].y * sinCos.y + sNonUniformTaps[t].x * sinCos.x ) * filterRadius * 0.5;
  22. +      float depth = tex2Dlod( shadowMap, float4( shadowPos + tap, 0, 0 ) ).r;
  23.  
  24. -      float esm = saturate( exp( esmFactor * ( occluder - distToLight ) ) );
  25. -      shadow += esm / float( endTap - startTap );
  26. +      shadow += saturate( 2.0 - exp( ( distToLight - depth ) * esmFactor ) );
  27.     }
  28.  
  29.     return shadow;
  30.  }
  31.  
  32. +float pcfFilter(sampler2D shadowMap, float2 uv, float filterWidth, float distToLight, int numSamples, float esmFactor)
  33. +{
  34. +       // Compute step size for iterating through the kernel.
  35. +       float stepSize = 2 * filterWidth / numSamples;
  36.  
  37. +       // Compute uv coordinates for upper left corner of the kernel.
  38. +       uv = uv - float2(filterWidth,filterWidth);
  39. +
  40. +       // Iterate through the kernel and add the shadow samples.
  41. +       float shadow = 0;
  42. +       for (int i=0; i<numSamples; i++)
  43. +       {
  44. +           float tx = uv.x + (i*stepSize);
  45. +
  46. +               for (int j=0; j<numSamples; j++)
  47. +               {
  48. +                       // Get depth at this tap.
  49. +                       float depth = tex2Dlod(shadowMap, float4(tx, uv.y + j*stepSize, 0, 0)).r;
  50. +
  51. +                       // We use an ESM filter to hide shadow acne and soften the results.
  52. +                       shadow += saturate( 2.0 - exp( ( distToLight - depth ) * esmFactor ) );
  53. +               }
  54. +       }
  55. +              
  56. +       // Return the average of the samples.
  57. +       return shadow / (numSamples*numSamples);
  58. +}
  59. +
  60.  float softShadow_filter(   sampler2D shadowMap,
  61.                             float2 vpos,
  62.                             float2 shadowPos,
  63. @@ -89,6 +116,9 @@
  64.                             float dotNL,
  65.                             float esmFactor )
  66.  {
  67. +       return pcfFilter( shadowMap, shadowPos, filterRadius, distToLight, 9, esmFactor );
  68. +
  69. +
  70.     #ifndef SOFTSHADOW
  71.  
  72.        // If softshadow is undefined then we skip any complex
  73. @@ -114,11 +144,16 @@
  74.  
  75.        // We live with only the pretap results if we don't
  76.        // have high quality shadow filtering enabled.
  77. -      #ifdef SOFTSHADOW_HIGH_QUALITY
  78. +      #ifndef SOFTSHADOW_HIGH_QUALITY
  79.  
  80. +               shadow /= (float)NUM_PRE_TAPS;
  81. +
  82. +      #else
  83. +
  84.           // Only do the expensive filtering if we're really
  85.           // in a partially shadowed area.
  86. -         if ( shadow * ( 1.0 - shadow ) * max( dotNL, 0 ) > 0.06 )
  87. +                float preshadow = shadow / (float)NUM_PRE_TAPS;
  88. +         if ( preshadow * ( 1.0 - preshadow ) * max( dotNL, 0 ) > 0.06 )
  89.           {
  90.              shadow += softShadow_sampleTaps( shadowMap,
  91.                                               sinCos,
  92. @@ -131,8 +166,10 @@
  93.                                              
  94.              // This averages the taps above with the results
  95.              // of the prediction samples.
  96. -            shadow *= 0.5;                              
  97. +            shadow /= (float)NUM_TAPS;                              
  98.           }
  99. +                else
  100. +                   shadow = preshadow;
  101.  
  102.        #endif // SOFTSHADOW_HIGH_QUALITY
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top