SHARE
TWEET

Untitled

a guest Dec 21st, 2014 135 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //PARTICLE DEPTH VERTEX SHADER
  2. #version 400
  3.  
  4. in vec3 vertexPos;
  5.  
  6. uniform mat4 projection;
  7. uniform mat4 mView;
  8. uniform vec2 screenSize;
  9. uniform vec3 lightPos;
  10.  
  11. out vec3 pos;
  12. out float radius;
  13.  
  14. void main() {
  15.         vec4 viewPos = mView * vec4(vertexPos, 1.0);
  16.     float dist = length(viewPos);    
  17.     gl_Position = projection * viewPos;
  18.     //gl_PointSize = 6 * screenSize.y / (8.0 * gl_Position.z);
  19.     gl_PointSize = 1.0 * (200.0 / dist);
  20.    
  21.     pos = viewPos.xyz;
  22.     radius = gl_PointSize;
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29. //PARTICLE DEPTH FRAGMENT SHADER
  30. #version 400
  31.  
  32. in vec3 pos;
  33. in float radius;
  34.  
  35. uniform mat4 mView;
  36. uniform mat4 projection;
  37. uniform vec2 screenSize;
  38. uniform vec3 lightPos;
  39.  
  40. out float depth;
  41.  
  42. float linearizeDepth(float depth) {
  43.         float n = 0.01f;
  44.         float f = 100f;
  45.        
  46.         return (2.0 * n) / (f + n - depth * (f - n));
  47. }
  48.  
  49. void main() {
  50.         //calculate normal
  51.         vec3 normal;
  52.         normal.xy = gl_PointCoord * 2.0 - 1.0;
  53.         float r2 = dot(normal.xy, normal.xy);
  54.        
  55.         if (r2 > 1.0) {
  56.                 discard;
  57.         }
  58.        
  59.         normal.z = sqrt(1.0 - r2);
  60.  
  61.         //calculate depth
  62.         vec4 pixelPos = vec4(pos + normal * radius, 1.0);
  63.         vec4 clipSpacePos = projection * pixelPos;
  64.        
  65.         depth = clipSpacePos.z / clipSpacePos.w * 0.5f + 0.5f;
  66.         depth = linearizeDepth(depth);
  67. }
  68.  
  69.  
  70.  
  71.  
  72. //OUTPUT VERTEX SHADER
  73. #version 400
  74.  
  75. in vec2 vertexPos;
  76.  
  77. out vec2 pos;
  78.  
  79. void main() {
  80.         pos = 0.5f * vertexPos + 0.5f;
  81.         gl_Position = vec4(vertexPos, 0.0f, 1.0f);
  82. }
  83.  
  84. //OUTPUT FRAGMENT SHADER
  85. #version 400
  86.  
  87. in vec2 coord;
  88.  
  89. uniform sampler2D depthMap;
  90. uniform vec2 screenSize;
  91. uniform mat4 projection;
  92.  
  93. out vec4 color;
  94.  
  95. float linearizeDepth(float depth) {
  96.         float n = 0.01f;
  97.         float f = 100f;
  98.        
  99.         return (2.0 * n) / (f + n - depth * (f - n));
  100. }
  101.  
  102. void main() {
  103.         float curDepth = texture2D(depthMap, coord).x;
  104.         //curDepth = linearizeDepth(curDepth);
  105.         color = vec4(curDepth);
  106. }
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