Advertisement
Guest User

Untitled

a guest
Jan 12th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.06 KB | None | 0 0
  1. // sending the vertices to gpu:
  2. val a = Vec3(1,0.5f,1)
  3. val b = Vec3(-1,1,-2)
  4. var normal = calcNorm(a,b, cam.pos)
  5. // in shader: (a_position, a_normal, a_color)
  6. vertices.queueVertex(a, -normal, Color.BLUE)
  7. vertices.queueVertex(a, normal, Color.BLUE)
  8. vertices.queueVertex(b, -normal, Color.YELLOW)
  9. vertices.queueVertex(b, normal, Color.YELLOW)
  10.  
  11. ...
  12.  
  13. // calcNorm function:
  14. fun calcNorm(a: Vec3, b: Vec3, camPos: Vec3): Vec3 {
  15. return glm.glm.cross((a-b), (camPos-a)).normalize()
  16. }
  17.  
  18. ...
  19.  
  20. // shader for drawing the line:
  21. attribute vec3 a_position;
  22. attribute vec3 a_normal;
  23. attribute vec3 a_color;
  24.  
  25. uniform mat4 model;
  26. uniform mat4 proj;
  27. uniform mat4 ortho;
  28. uniform mat4 view;
  29. uniform vec3 campos;
  30. varying vec4 v_pos;
  31. varying vec3 v_color;
  32.  
  33. float linewidth = 0.04;
  34. void main() {
  35.     vec4 pos = view * model * vec4((a_position), 1.0);
  36.     float dist = length(vec4(campos, 0.0) - (model * vec4((a_position), 0.0)));
  37.     vec4 delta = vec4((a_normal * (linewidth*dist)), 0.0);
  38.     gl_Position = proj * (pos + delta);
  39.     v_color = a_color;
  40.     v_pos = pos;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement