Advertisement
Guest User

Untitled

a guest
Dec 21st, 2014
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. float w = width / 2.f;
  2. float h = height / 2.f;
  3.  
  4. // Right vertices with outwards normals
  5. X Y NorX NorY
  6. vertices.emplace_back(w, -h, 1.f, 0.f);
  7. vertices.emplace_back(w, h, 1.f, 0.f);
  8.  
  9. // Bottom vertices with outwards normals
  10. vertices.emplace_back( w, h, 0.f, 1.f);
  11. vertices.emplace_back(-w, h, 0.f, 1.f);
  12.  
  13. // Left vertices with outwards normals
  14. vertices.emplace_back(-w, h, -1.f, 0.f);
  15. vertices.emplace_back(-w, -h, -1.f, 0.f);
  16.  
  17. // Top vertices with outwards normals
  18. vertices.emplace_back(-w, -h, 0.f, -1.f);
  19. vertices.emplace_back( w, -h, 0.f, -1.f);
  20.  
  21. // Right vertices with inwards normals
  22. vertices.emplace_back(w, -h, -1.f, 0.f);
  23. vertices.emplace_back(w, h, -1.f, 0.f);
  24.  
  25. // ** SNIP **
  26. // Here's the rest of "inverted normal" vertices
  27. // ** SNIP
  28.  
  29. // Indices that make the triangles
  30. // Right
  31. indices.emplace_back(0);
  32. indices.emplace_back(1);
  33. indices.emplace_back(8);
  34. indices.emplace_back(8);
  35. indices.emplace_back(1);
  36. indices.emplace_back(9);
  37.  
  38. // Down
  39. indices.emplace_back(2);
  40. indices.emplace_back(3);
  41. indices.emplace_back(10);
  42. indices.emplace_back(10);
  43. indices.emplace_back(3);
  44. indices.emplace_back(11);
  45.  
  46. // ** SNIP ** And here's the rest of the indices ** SNIP **
  47.  
  48. // Vertex attributes
  49. layout(location = 0) in vec3 in_position;
  50. layout(location = 3) in vec3 in_normal; // Y is always 0
  51.  
  52. // Uniforms
  53. uniform mat4 u_world;
  54. uniform mat4 u_view;
  55. uniform mat4 u_projection;
  56. uniform vec2 u_lightPosition;
  57.  
  58. void main() {
  59. // Get the world position of the vertex
  60. vec4 vPos = u_world * vec4(in_position, 1.0);
  61.  
  62. // Flatten to XZ-plane
  63. vec2 xzPos = vec2(vPos.x, vPos.z);
  64.  
  65. // Get the direction from the vertex to the light
  66. vec2 dir = normalize(xzPos - u_lightPosition);
  67.  
  68. // If the normals point outwards, extrude them
  69. if(dot(dir, vec2(in_nor.x, in_nor.z)) < 0) {
  70. vPos.x += dir.x * 10000;
  71. vPos.z += dir.y * 10000;
  72. }
  73.  
  74. // Apply the position
  75. gl_Position = u_projection * u_view * vPos;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement