longlat.gp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2020, Inria
  3. * GRAPHDECO research group, https://team.inria.fr/graphdeco
  4. * All rights reserved.
  5. *
  6. * This software is free for non-commercial, research and evaluation use
  7. * under the terms of the LICENSE.md file.
  8. *
  9. * For inquiries contact sibr@inria.fr and/or George.Drettakis@inria.fr
  10. */
  11. #version 450
  12. layout(triangles) in;
  13. layout(triangle_strip, max_vertices=6) out;
  14. layout(location = 1) in vec3 colors_tes[];
  15. layout(location = 2) in vec2 coordsTex_tes[];
  16. layout(location = 3) in vec3 normals_tes[];
  17. uniform vec3 pos;
  18. const float PI = 3.1415926535897932384626433832795;
  19. layout(location = 0) out vec4 position;
  20. layout(location = 1) out vec3 colors_gs;
  21. layout(location = 2) out vec2 coordsTex_gs;
  22. layout(location = 3) out vec3 normals_gs;
  23. void main()
  24. {
  25. int i,j;
  26. vec3 toPoint[3];
  27. vec3 d[3];
  28. float lat[3];
  29. float longt[3];
  30. for(i=0; i<3; i++)
  31. {
  32. toPoint[i] = gl_in[i].gl_Position.xyz-pos;
  33. d[i] = normalize(toPoint[i]);
  34. lat[i] = d[i].z;
  35. longt[i] = atan(d[i].y,d[i].x);
  36. if(longt[i]<0)
  37. longt[i] += 2.0f*PI;
  38. }
  39. if((abs(longt[1]-longt[2])<PI && abs(longt[0]-longt[2])<PI && abs(longt[1]-longt[0])<PI)){
  40. float fact=100.0f;
  41. for(i=0; i<3; i++)
  42. {
  43. gl_Position = vec4(longt[i]/PI-1.0,-lat[i],length(toPoint[i])/fact,1.0f);
  44. position=gl_Position;
  45. colors_gs = colors_tes[i];
  46. coordsTex_gs = coordsTex_tes[i];
  47. normals_gs = normals_tes[i];
  48. EmitVertex();
  49. }
  50. EndPrimitive();
  51. }
  52. else{
  53. for(i=0; i<3; i++){
  54. if(abs(longt[i]-longt[(i+1)%3])>PI && abs(longt[i]-longt[(i+2)%3])>PI){
  55. float longt_0[3]=longt;
  56. float longt_1[3]=longt;
  57. if(longt[i]>PI){
  58. longt_0[i]=longt[i]-2.0f*PI;
  59. longt_1[(i+1)%3]=longt[(i+1)%3]+2.0f*PI;
  60. longt_1[(i+2)%3]=longt[(i+2)%3]+2.0f*PI;
  61. }
  62. else{
  63. longt_0[i]=longt[i]+2.0f*PI;
  64. longt_1[(i+1)%3]=longt[(i+1)%3]-2.0f*PI;
  65. longt_1[(i+2)%3]=longt[(i+2)%3]-2.0f*PI;
  66. }
  67. for(j=0; j<3; j++)
  68. {
  69. gl_Position = vec4(longt_0[j]/PI-1.0,-lat[j],length(toPoint[j])/100.0f,1.0f);
  70. position=gl_Position;
  71. colors_gs = colors_tes[i];
  72. coordsTex_gs = coordsTex_tes[i];
  73. normals_gs = normals_tes[i];
  74. EmitVertex();
  75. }
  76. EndPrimitive();
  77. for(j=0; j<3; j++)
  78. {
  79. gl_Position = vec4(longt_1[j]/PI-1.0,-lat[j],length(toPoint[j])/100.0f,1.0f);
  80. position=gl_Position;
  81. colors_gs = colors_tes[i];
  82. coordsTex_gs = coordsTex_tes[i];
  83. normals_gs = normals_tes[i];
  84. EmitVertex();
  85. }
  86. EndPrimitive();
  87. break;
  88. }
  89. }
  90. }
  91. }