gaussian_surface.vert 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright (C) 2023, 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 430
  12. uniform mat4 MVP;
  13. uniform float alpha_limit;
  14. uniform int stage;
  15. layout (std430, binding = 0) buffer BoxCenters {
  16. float centers[];
  17. };
  18. layout (std430, binding = 1) buffer Rotations {
  19. vec4 rots[];
  20. };
  21. layout (std430, binding = 2) buffer Scales {
  22. float scales[];
  23. };
  24. layout (std430, binding = 3) buffer Alphas {
  25. float alphas[];
  26. };
  27. layout (std430, binding = 4) buffer Colors {
  28. float colors[];
  29. };
  30. mat3 quatToMat3(vec4 q) {
  31. float qx = q.y;
  32. float qy = q.z;
  33. float qz = q.w;
  34. float qw = q.x;
  35. float qxx = qx * qx;
  36. float qyy = qy * qy;
  37. float qzz = qz * qz;
  38. float qxz = qx * qz;
  39. float qxy = qx * qy;
  40. float qyw = qy * qw;
  41. float qzw = qz * qw;
  42. float qyz = qy * qz;
  43. float qxw = qx * qw;
  44. return mat3(
  45. vec3(1.0 - 2.0 * (qyy + qzz), 2.0 * (qxy - qzw), 2.0 * (qxz + qyw)),
  46. vec3(2.0 * (qxy + qzw), 1.0 - 2.0 * (qxx + qzz), 2.0 * (qyz - qxw)),
  47. vec3(2.0 * (qxz - qyw), 2.0 * (qyz + qxw), 1.0 - 2.0 * (qxx + qyy))
  48. );
  49. }
  50. const vec3 boxVertices[8] = vec3[8](
  51. vec3(-1, -1, -1),
  52. vec3(-1, -1, 1),
  53. vec3(-1, 1, -1),
  54. vec3(-1, 1, 1),
  55. vec3( 1, -1, -1),
  56. vec3( 1, -1, 1),
  57. vec3( 1, 1, -1),
  58. vec3( 1, 1, 1)
  59. );
  60. const int boxIndices[36] = int[36](
  61. 0, 1, 2, 1, 3, 2,
  62. 4, 6, 5, 5, 6, 7,
  63. 0, 2, 4, 4, 2, 6,
  64. 1, 5, 3, 5, 7, 3,
  65. 0, 4, 1, 4, 5, 1,
  66. 2, 3, 6, 3, 7, 6
  67. );
  68. out vec3 worldPos;
  69. out vec3 ellipsoidCenter;
  70. out vec3 ellipsoidScale;
  71. out mat3 ellipsoidRotation;
  72. out vec3 colorVert;
  73. out float alphaVert;
  74. out flat int boxID;
  75. void main() {
  76. boxID = gl_InstanceID;
  77. ellipsoidCenter = vec3(centers[3 * boxID + 0], centers[3 * boxID + 1], centers[3 * boxID + 2]);
  78. float a = alphas[boxID];
  79. alphaVert = a;
  80. ellipsoidScale = vec3(scales[3 * boxID + 0], scales[3 * boxID + 1], scales[3 * boxID + 2]);
  81. ellipsoidScale = 2 * ellipsoidScale;
  82. vec4 q = rots[boxID];
  83. ellipsoidRotation = transpose(quatToMat3(q));
  84. int vertexIndex = boxIndices[gl_VertexID];
  85. worldPos = ellipsoidRotation * (ellipsoidScale * boxVertices[vertexIndex]);
  86. worldPos += ellipsoidCenter;
  87. float r = colors[boxID * 48 + 0] * 0.2 + 0.5;
  88. float g = colors[boxID * 48 + 1] * 0.2 + 0.5;
  89. float b = colors[boxID * 48 + 2] * 0.2 + 0.5;
  90. colorVert = vec3(r, g, b);
  91. if((stage == 0 && a < alpha_limit) || (stage == 1 && a >= alpha_limit))
  92. gl_Position = vec4(0,0,0,0);
  93. else
  94. gl_Position = MVP * vec4(worldPos, 1);
  95. }