Guest User

Untitled

a guest
Jun 10th, 2010
109
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // vertex shader
  2.  
  3.  
  4. attribute float cameraPosX;
  5. attribute float cameraPosY;
  6. attribute float cameraPosZ;
  7.  
  8. varying float sphIndex;
  9.  
  10. void main()
  11. {
  12.     vec3 cartesian;
  13.     vec3 spherical;
  14.    
  15.     vec3 v = vec3(gl_Vertex);
  16.     vec3 cameraPos;
  17.     cameraPos.x = cameraPosX;
  18.     cameraPos.y = cameraPosY;
  19.     cameraPos.z = cameraPosZ;
  20.    
  21.     gl_Position = ftransform();
  22.    
  23.     vec3 cameraDir = normalize(v - cameraPos);
  24.    
  25.     spherical.x = 1.0;
  26.     spherical.y = acos(cameraDir.z /
  27.                         sqrt(cameraDir.x*cameraDir.x +
  28.                                 cameraDir.y*cameraDir.y +
  29.                                 cameraDir.z*cameraDir.z));
  30.     spherical.y = spherical.y * 180.0 / 3.14159265;
  31.    
  32.     spherical.z = atan(spherical.z, spherical.y);
  33.     spherical.z = spherical.z * 180.0 / 3.14159265;
  34.  
  35.    
  36.     sphIndex = (spherical.y*180.0 + spherical.z) / (180.0*180.0);
  37. }
  38.  
  39.  
  40. // fragment shader
  41.  
  42. attribute float cameraPosX;
  43. attribute float cameraPosY;
  44. attribute float cameraPosZ;
  45.  
  46. varying float sphIndex;
  47.  
  48. void main()
  49. {
  50.     vec3 cartesian;
  51.     vec3 spherical;
  52.    
  53.     vec3 v = vec3(gl_Vertex);
  54.     vec3 cameraPos;
  55.     cameraPos.x = cameraPosX;
  56.     cameraPos.y = cameraPosY;
  57.     cameraPos.z = cameraPosZ;
  58.    
  59.     gl_Position = ftransform();
  60.    
  61.     vec3 cameraDir = normalize(v - cameraPos);
  62.    
  63.     spherical.x = 1.0;
  64.     spherical.y = acos(cameraDir.z /
  65.                         sqrt(cameraDir.x*cameraDir.x +
  66.                                 cameraDir.y*cameraDir.y +
  67.                                 cameraDir.z*cameraDir.z));
  68.     spherical.y = spherical.y * 180.0 / 3.14159265;
  69.    
  70.     spherical.z = atan(spherical.z, spherical.y);
  71.     spherical.z = spherical.z * 180.0 / 3.14159265;
  72.  
  73.    
  74.     sphIndex = (spherical.y*180.0 + spherical.z) / (180.0*180.0);
  75. }
RAW Paste Data