Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. #version 430
  2. layout(points) in;
  3. layout(triangle_strip, max_vertices = 48) out;
  4.  
  5.  
  6.  
  7. uniform mat4 View;
  8. uniform mat4 Projection;
  9. uniform vec3 eye_position;
  10. uniform float triangle_step;
  11.  
  12. layout(location = 0) out vec2 texture_coord;
  13.  
  14. vec3 vpos = gl_in[0].gl_Position.xyz;
  15. vec3 forward = normalize(eye_position - vpos);
  16. vec3 right = normalize(cross(forward, vec3(0, 1, 0)));
  17. vec3 up = normalize(cross(forward, right));
  18.  
  19. void EmitPoint(vec2 offset)
  20. {
  21. vec3 pos = right * offset.x + up * offset.y + vpos;
  22. gl_Position = Projection * View * vec4(pos, 1.0);
  23. EmitVertex();
  24. }
  25.  
  26. void EmitPoint2(vec3 offset)
  27. {
  28. vec3 pos = vec3(vpos.x + offset.x, vpos.y + offset.y, vpos.z + offset.z);
  29. gl_Position = Projection * View * vec4(pos, 1);
  30. EmitVertex();
  31. }
  32.  
  33. void main()
  34. {
  35. float ds = triangle_step;
  36.  
  37. // Create a quad using triangle strip
  38. //
  39. // 3---------2
  40. // | \ |
  41. // | \ |
  42. // | \ |
  43. // 0---------1
  44. //
  45. // Triangles: (0, 1, 3), (1, 2, 3)
  46. float offset_size = 1.0f;
  47.  
  48. //FATA SPATE
  49. texture_coord = vec2(0.0f);
  50. EmitPoint2(vec3(-ds, -ds, 0));
  51. texture_coord = vec2(offset_size, 0.0f);
  52. EmitPoint2(vec3(ds, -ds, 0));
  53. texture_coord = vec2(0.0f, offset_size);
  54. EmitPoint2(vec3(-ds, ds, 0));
  55. EndPrimitive();
  56. texture_coord = vec2(0.0f);
  57. EmitPoint2(vec3(-ds, -ds, -0.5f));
  58. texture_coord = vec2(0.0f, offset_size);
  59. EmitPoint2(vec3(-ds, ds, -0.5f));
  60. texture_coord = vec2(offset_size, 0.0f);
  61. EmitPoint2(vec3(ds, -ds, -0.5f));
  62. EndPrimitive();
  63.  
  64.  
  65. //3 - 1
  66. texture_coord = vec2(offset_size, offset_size);
  67. EmitPoint2(vec3(-ds, ds, 0));
  68. texture_coord = vec2(0.0f, offset_size);
  69. EmitPoint2(vec3(ds, -ds, 0));
  70. texture_coord = vec2(0.0f, 0.0f);
  71. EmitPoint2(vec3(ds, -ds, -0.5f));
  72. EndPrimitive();
  73. texture_coord = vec2(offset_size, offset_size);
  74. EmitPoint2(vec3(-ds, ds, 0));
  75. texture_coord = vec2(0.0f, 0.0f);
  76. EmitPoint2(vec3(ds, -ds, -0.5f));
  77. texture_coord = vec2(offset_size, 0.0f);
  78. EmitPoint2(vec3(-ds, ds, -0.5f));
  79. EndPrimitive();
  80.  
  81. //3 - 0
  82. texture_coord = vec2(0, offset_size);
  83. EmitPoint2(vec3(-ds, ds, 0));
  84. texture_coord = vec2(0.0f, 0.0f);
  85. EmitPoint2(vec3(-ds, ds, -0.5f));
  86. texture_coord = vec2(offset_size, 0.0f);
  87. EmitPoint2(vec3(-ds, -ds, -0.5f));
  88. EndPrimitive();
  89. texture_coord = vec2(offset_size, offset_size);
  90. EmitPoint2(vec3(-ds, -ds, 0));
  91. texture_coord = vec2(0.0f, offset_size);
  92. EmitPoint2(vec3(-ds, ds, 0.0f));
  93. texture_coord = vec2(offset_size, 0.0f);
  94. EmitPoint2(vec3(-ds, -ds, -0.5f));
  95. EndPrimitive();
  96.  
  97. // 0 - 1
  98. texture_coord = vec2(offset_size, offset_size);
  99. EmitPoint2(vec3(ds, -ds, 0));
  100. texture_coord = vec2(0.0f, offset_size);
  101. EmitPoint2(vec3(-ds, -ds, 0.0f));
  102. texture_coord = vec2(0.0f, 0.0f);
  103. EmitPoint2(vec3(-ds, -ds, -0.5f));
  104. EndPrimitive();
  105. texture_coord = vec2(offset_size, offset_size);
  106. EmitPoint2(vec3(ds, -ds, 0));
  107. texture_coord = vec2(0.0f, 0.0f);
  108. EmitPoint2(vec3(-ds, -ds, -0.5f));
  109. texture_coord = vec2(offset_size, 0.0f);
  110. EmitPoint2(vec3(ds, -ds, -0.5f));
  111. EndPrimitive();
  112.  
  113. // PRIMUL TRIUNGHI
  114.  
  115. //FATA SPATE
  116.  
  117. texture_coord = vec2(offset_size, 0.0f);
  118. EmitPoint2(vec3(ds, -ds, 0));
  119. texture_coord = vec2(offset_size);
  120. EmitPoint2(vec3(ds, ds, 0));
  121. texture_coord = vec2(0.0f, offset_size);
  122. EmitPoint2(vec3(-ds, ds, 0));
  123. EndPrimitive();
  124. texture_coord = vec2(offset_size, 0.0f);
  125. EmitPoint2(vec3(ds, -ds, -0.5f));
  126. texture_coord = vec2(0.0f, offset_size);
  127. EmitPoint2(vec3(-ds, ds, -0.5f));
  128. texture_coord = vec2(offset_size);
  129. EmitPoint2(vec3(ds, ds, -0.5f));
  130. EndPrimitive();
  131.  
  132. //3 - 1
  133. texture_coord = vec2(offset_size, offset_size);
  134. EmitPoint2(vec3(-ds, ds, 0));
  135. texture_coord = vec2(0.0f, 0.0f);
  136. EmitPoint2(vec3(ds, -ds, -0.5f));
  137. texture_coord = vec2(0.0f, offset_size);
  138. EmitPoint2(vec3(ds, -ds, 0));
  139. EndPrimitive();
  140. texture_coord = vec2(offset_size, offset_size);
  141. EmitPoint2(vec3(-ds, ds, 0));
  142. texture_coord = vec2(offset_size, 0.0f);
  143. EmitPoint2(vec3(-ds, ds, -0.5f));
  144. texture_coord = vec2(0.0f, 0.0f);
  145. EmitPoint2(vec3(ds, -ds, -0.5f));
  146. EndPrimitive();
  147.  
  148. //3 - 2
  149. texture_coord = vec2(0.0f, 0.0f);
  150. EmitPoint2(vec3(-ds, ds, 0));
  151. texture_coord = vec2(offset_size, 0.0f);
  152. EmitPoint2(vec3(ds, ds, 0.0f));
  153. texture_coord = vec2(offset_size, offset_size);
  154. EmitPoint2(vec3(ds, ds, -0.5f));
  155. EndPrimitive();
  156. texture_coord = vec2(0.0f, 0.0f);
  157. EmitPoint2(vec3(-ds, ds, 0));
  158. texture_coord = vec2(offset_size, offset_size);
  159. EmitPoint2(vec3(ds, ds, -0.5f));
  160. texture_coord = vec2(0.0f, offset_size);
  161. EmitPoint2(vec3(-ds, ds, -0.5f));
  162. EndPrimitive();
  163.  
  164. //2 - 1
  165. texture_coord = vec2(offset_size, offset_size);
  166. EmitPoint2(vec3(ds, ds, -0.5f));
  167. texture_coord = vec2(0.0f, offset_size);
  168. EmitPoint2(vec3(ds, ds, 0.0f));
  169. texture_coord = vec2(0.0f, 0.0f);
  170. EmitPoint2(vec3(ds, -ds, 0.0f));
  171. EndPrimitive();
  172. texture_coord = vec2(offset_size, offset_size);
  173. EmitPoint2(vec3(ds, ds, -0.5f));
  174. texture_coord = vec2(0.0f, 0.0f);
  175. EmitPoint2(vec3(ds, -ds, 0.0f));
  176. texture_coord = vec2(offset_size, 0.0f);
  177. EmitPoint2(vec3(ds, -ds, -0.5f));
  178. EndPrimitive();
  179.  
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement