Advertisement
Guest User

Untitled

a guest
Jul 12th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Call this function to generate a fake sphere from a point sprite
  2. vec3 point_normal(in vec2 uv)
  3. {
  4.     vec3 n;
  5.     n.xy = uv * 2.0 - 1.0;
  6.  
  7.     float rr = dot(n.xy, n.xy);
  8.     if (rr > 1.0) discard;
  9.     n.z = sqrt(1.0 - rr);
  10.  
  11.     return n;
  12. }
  13.  
  14. // ...
  15. // Then later, use the normal returned by `point_normal` to calculate the new frag depth
  16. // ...
  17.  
  18. float radius = point_sprite_size * 0.5;
  19. vec4 pixel_position = vec4(fs_in.camera_space_position + normal * radius, 1.0);
  20. vec4 clip_space_position = projectionMatrix * pixel_position;
  21. clip_space_position.z /= clip_space_position.w;
  22. gl_FragDepth = clip_space_position.z;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement