1 | /* |
---|

2 | * Used by Canvas3D to render nodes. |
---|

3 | */ |
---|

4 | |
---|

5 | attribute vec3 position; |
---|

6 | attribute vec3 offset; |
---|

7 | attribute vec3 color; |
---|

8 | attribute vec2 selected_marked; |
---|

9 | |
---|

10 | const float MODE_NORMAL = 0.; |
---|

11 | const float MODE_SELECTED = 1.; |
---|

12 | const float MODE_MARKED = 2.; |
---|

13 | |
---|

14 | uniform float mode; |
---|

15 | uniform mat4 projection, model, view; |
---|

16 | uniform vec3 translation, scale; |
---|

17 | |
---|

18 | varying vec4 var_color; |
---|

19 | |
---|

20 | void main() |
---|

21 | { |
---|

22 | vec3 offset_rotated = offset.xyz; |
---|

23 | offset_rotated *= 0.01; |
---|

24 | |
---|

25 | // Calculate inverse of rotations (in this case, inverse |
---|

26 | // is actually just transpose), so that polygons face |
---|

27 | // camera all the time. |
---|

28 | mat3 invs; |
---|

29 | mat4 modelview = view * model; |
---|

30 | |
---|

31 | invs[0][0] = modelview[0][0]; |
---|

32 | invs[0][1] = modelview[1][0]; |
---|

33 | invs[0][2] = modelview[2][0]; |
---|

34 | |
---|

35 | invs[1][0] = modelview[0][1]; |
---|

36 | invs[1][1] = modelview[1][1]; |
---|

37 | invs[1][2] = modelview[2][1]; |
---|

38 | |
---|

39 | invs[2][0] = modelview[0][2]; |
---|

40 | invs[2][1] = modelview[1][2]; |
---|

41 | invs[2][2] = modelview[2][2]; |
---|

42 | |
---|

43 | offset_rotated = invs * offset_rotated; |
---|

44 | |
---|

45 | vec3 pos = position.xyz; |
---|

46 | pos += translation; |
---|

47 | pos *= scale; |
---|

48 | vec4 off_pos = vec4(pos+offset_rotated, 1.); |
---|

49 | |
---|

50 | // Hide when unwanted |
---|

51 | if (mode == MODE_SELECTED && selected_marked.x == 0.) |
---|

52 | off_pos = vec4(0., 0., 0., 0.); |
---|

53 | |
---|

54 | if (mode == MODE_MARKED && selected_marked.y == 0.) |
---|

55 | off_pos = vec4(0., 0., 0., 0.); |
---|

56 | |
---|

57 | gl_Position = projection * model * view * off_pos; |
---|

58 | var_color = vec4(color, 1.); |
---|

59 | } |
---|