SHARE
TWEET

1.5.00/shadow.h

a guest Apr 18th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef SHADOW_H
  2. #define SHADOW_H
  3.  
  4. #include "common.h"
  5.  
  6. //uniform   sampler s_smap  : register(ps,s0);  // 2D/cube shadowmap
  7. //Texture2D<float>  s_smap;     // 2D/cube shadowmap
  8. //  Used for RGBA texture too ?!
  9. Texture2D   s_smap : register(ps,t0);       // 2D/cube shadowmap
  10. SamplerComparisonState      smp_smap;   //  Special comare sampler
  11. sampler     smp_jitter;
  12.  
  13. #define KERNEL  .6f
  14.  
  15. //////////////////////////////////////////////////////////////////////////////////////////
  16. // hardware + PCF
  17. //////////////////////////////////////////////////////////////////////////////////////////
  18. half sample_hw_pcf (float4 tc,float4 shift)
  19. {
  20.     static const float  ts = KERNEL / float(SMAP_size);
  21.  
  22. //  return tex2Dproj( s_smap, tc + tc.w * shift * ts ).x;
  23.    
  24.     tc.xyz  /= tc.w;
  25.     tc.xy   += shift.xy * ts;
  26.  
  27.     return s_smap.SampleCmpLevelZero( smp_smap, tc.xy, tc.z).x;
  28. }
  29.  
  30. half shadow_hw( float4 tc )
  31. {
  32.     half    s0      = sample_hw_pcf( tc, float4( -1, -1, 0, 0) );
  33.     half    s1      = sample_hw_pcf( tc, float4( +1, -1, 0, 0) );
  34.     half    s2      = sample_hw_pcf( tc, float4( -1, +1, 0, 0) );
  35.     half    s3      = sample_hw_pcf( tc, float4( +1, +1, 0, 0) );
  36.  
  37.     return  (s0+s1+s2+s3)/4.h;
  38. }
  39. //////////////////////////////////////////////////////////////////////////////////////////
  40. //  D24X8+PCF
  41. //////////////////////////////////////////////////////////////////////////////////////////
  42. half shadow( float4 tc )
  43. {
  44.     return shadow_hw( tc );
  45. }
  46.  
  47. //////////////////////////////////////////////////////////////////////////////////////////
  48. // testbed
  49.  
  50. //uniform sampler2D jitter0;
  51. //uniform sampler2D jitter1;
  52. Texture2D   jitter0;
  53. Texture2D   jitter1;
  54. //uniform sampler2D jitter2;
  55. //uniform sampler2D jitter3;
  56. //uniform half4         jitterS;
  57.  
  58. Texture2D   jitterMipped;
  59.  
  60. half4   test        (float4 tc, half2 offset)
  61. {
  62.  
  63. //  float4  tcx = float4 (tc.xy + tc.w*offset, tc.zw);
  64. //  return  tex2Dproj (s_smap,tcx);
  65.  
  66.     tc.xyz  /= tc.w;
  67.     tc.xy   += offset;
  68.     return s_smap.SampleCmpLevelZero( smp_smap, tc.xy, tc.z).x;
  69. }
  70.  
  71. half    shadowtest  (float4 tc, float4 tcJ)             // jittered sampling
  72. {
  73.     half4   r;
  74.  
  75.     const   float   scale   = (2.7f/float(SMAP_size));
  76.  
  77. //  half4   J0  = tex2Dproj (jitter0,tcJ)*scale;
  78. //  half4   J1  = tex2Dproj (jitter1,tcJ)*scale;
  79.     tcJ.xy      /=  tcJ.w;
  80.     half4   J0  = jitter0.Sample( smp_jitter, tcJ )*scale;
  81.     half4   J1  = jitter1.Sample( smp_jitter, tcJ )*scale;
  82.  
  83.         r.x     = test  (tc,J0.xy).x;
  84.         r.y     = test  (tc,J0.wz).y;
  85.         r.z     = test  (tc,J1.xy).z;
  86.         r.w     = test  (tc,J1.wz).x;
  87.  
  88.     return  dot(r,1.h/4.h);
  89. }
  90.  
  91. half    shadowtest_sun  (float4 tc, float2 tcJ)         // jittered sampling
  92. {
  93.     half4   r;
  94.  
  95. //  const   float   scale   = (2.0f/float(SMAP_size));
  96.     const   float   scale   = (0.7f/float(SMAP_size));
  97. //  half4   J0  = tex2D (jitter0,tcJ)*scale;
  98. //  half4   J1  = tex2D (jitter1,tcJ)*scale;
  99.     half4   J0  = jitter0.Sample( smp_jitter, tcJ )*scale;
  100.     half4   J1  = jitter1.Sample( smp_jitter, tcJ )*scale;
  101.  
  102.         r.x     = test  (tc,J0.xy).x;
  103.         r.y     = test  (tc,J0.wz).y;
  104.         r.z     = test  (tc,J1.xy).z;
  105.         r.w     = test  (tc,J1.wz).x;
  106.  
  107.     return  dot(r,1.h/4.h);
  108. }
  109.  
  110. half    shadow_rain     (float4 tc, float2 tcJ)         // jittered sampling
  111. {
  112.     half4   r;
  113.  
  114.     const   float   scale   = (4.0f/float(SMAP_size));
  115. //  half4   J0  = jitter0.Sample( smp_jitter, tcJ )*scale;
  116. //  half4   J1  = jitter1.Sample( smp_jitter, tcJ )*scale;
  117.     half4   J0  = jitter0.Sample( smp_linear, tcJ )*scale;
  118.     half4   J1  = jitter1.Sample( smp_linear, tcJ )*scale;
  119.  
  120.     r.x     = test  (tc,J0.xy).x;
  121.     r.y     = test  (tc,J0.wz).y;
  122.     r.z     = test  (tc,J1.xy).z;
  123.     r.w     = test  (tc,J1.wz).x;
  124.  
  125. //  half4   J0  = jitterMipped.Sample( smp_base, tcJ )*scale;
  126.  
  127. //  r.x     = test  (tc,J0.xy).x;
  128. //  r.y     = test  (tc,J0.wz).y;
  129. //  r.z     = test  (tc,J0.yz).z;
  130. //  r.w     = test  (tc,J0.xw).x;
  131.  
  132.     return  dot(r,1.h/4.h);
  133. }
  134.  
  135. //////////////////////////////////////////////////////////////////////////////////////////
  136. #ifdef  USE_SUNMASK
  137. float3x4 m_sunmask; // ortho-projection
  138. half sunmask( float4 P )
  139. {
  140.     float2      tc  = mul( m_sunmask, P );      //
  141. //  return      tex2D( s_lmap, tc ).w;          // A8
  142.     return      s_lmap.Sample( smp_linear, tc ).w;  // A8  
  143. }
  144. #else
  145. half sunmask( float4 P ) { return 1.h; }        //
  146. #endif
  147. //////////////////////////////////////////////////////////////////////////////////////////
  148. uniform float4x4    m_shadow;
  149.  
  150. #endif
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