Advertisement
Guest User

Untitled

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