SHARE
TWEET

Untitled

a guest Apr 30th, 2013 58 Never
  1. float chebyshevUpperBound()
  2. {
  3.         vec2 moments = texture2D(ShadowMap,ShadowCoordPostW.xy).rg;
  4.        
  5.         // Surface is fully lit. as the current fragment is before the light occluder
  6.         if (ShadowCoordPostW.z <= moments.x)
  7.                 return 1.0 ;
  8.  
  9.         // The fragment is either in shadow or penumbra. We now use chebyshev's upperBound to check
  10.         // How likely this pixel is to be lit (p_max)
  11.         float variance = moments.y - (moments.x*moments.x);
  12.         variance = max(variance,0.1);
  13.  
  14.         float d = ShadowCoordPostW.z - moments.x;
  15.         float p_max = (variance / (variance + d*d));
  16.        
  17.         return max(p_max, 0.4);
  18. }
  19.  
  20. //Color computation in main()
  21. shadow = chebyshevUpperBound();
  22. fragColor = ((ambient_color + diffuse_color * diffuse_value))*texel;
  23. fragColor.rgb *= shadow;
RAW Paste Data
Top