SHARE
TWEET

Untitled

a guest Dec 10th, 2014 171 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330
  2.  
  3. uniform mat4 projectionMatrix;
  4. uniform float sphereRadius;
  5.  
  6. in vec3 fPosition;
  7.  
  8. void main()
  9. {
  10.     vec3 Normal;
  11.     // Get the coordinates of the fragment
  12.     Normal.xy = gl_PointCoord * 2.0 - vec2(1.0);
  13.     // Is the fragment inside the unit circle?
  14.     float r2 = dot(Normal.xy,Normal.xy);
  15.     if(r2 > 1.0) discard;
  16.     // Compute the depth on a unit sphere
  17.     Normal.z = -sqrt(1.0 - r2);
  18.  
  19.     // View-space depth
  20.     vec4 fPos = vec4(fPosition - sphereRadius*Normal, 1.0);
  21.     vec4 clipPos = projectionMatrix * fPos;
  22.     gl_FragDepth = clipPos.z / clipPos.w;
  23.  
  24.     //far * near / (far * -ndc.z + far + near * ndc.z)
  25. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top