This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 30th, 2013  |  syntax: C  |  size: 0.73 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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;
clone this paste RAW Paste Data