SGStino

AONonRandom

Dec 24th, 2014
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1.     float3 position = Position.Sample(deferredSampler, input.uv).rgb;
  2.     float3 normal = Normal.Sample(deferredSampler, input.uv).rgb;
  3.  
  4.     float depth = distance(position, CameraPosition);
  5.  
  6.     float noise = 0;// rand_1_05(input.uv);
  7.  
  8.     float r = AORadius / SampleRadius;
  9.     float occlusion = 0;
  10.  
  11.     float dAngle = (2 * pi) / SampleDir;
  12.  
  13.     float angle = (2 * pi) * noise;
  14.     float rayLen = r / depth;
  15.  
  16.  
  17.     for (int i = 0; i < SampleDir; i++)
  18.     {
  19.         angle += dAngle;
  20.  
  21.         float2 ray = float2(cos(angle), sin(angle))*rayLen;
  22.  
  23.         for (int j = 0; j < SampleRadius; j++)
  24.         {
  25.             float3 sampleOffset = Position.Sample(deferredSampler, input.uv + ray * j).rgb - position; // vector towards sample
  26.  
  27.             float len = dot(sampleOffset, sampleOffset);
  28.             // dot of the sample vector with the surface normal: how big is the angle.
  29.             // div by len: how far is it? is it still relevant to our sample?
  30.             float sampleAngle = dot(sampleOffset, normal) / len;
  31.             occlusion += saturate(sampleAngle) / SampleDir / SampleRadius;
  32.         }
  33.     }
  34.  
  35.     float final = pow(1 - occlusion, 4);
Advertisement
Add Comment
Please, Sign In to add comment