Welcome to mirror list, hosted at ThFree Co, Russian Federation.

grid_vert.glsl « shaders « overlay « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6df4ead9f2aee6c8a9da252dca1b6a400da921d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

/* Infinite grid
 * Clément Foucault */

uniform vec3 planeAxes;
uniform float meshSize;

uniform int gridFlag;

#define PLANE_XY (1 << 4)
#define PLANE_XZ (1 << 5)
#define PLANE_YZ (1 << 6)
#define CLIP_Z_POS (1 << 7)
#define CLIP_Z_NEG (1 << 8)
#define PLANE_IMAGE (1 << 11)
in vec3 pos;

out vec3 local_pos;

void main()
{
  vec3 vert_pos;

  /* Project camera pos to the needed plane */
  if ((gridFlag & PLANE_XY) != 0) {
    vert_pos = vec3(pos.x, pos.y, 0.0);
  }
  else if ((gridFlag & PLANE_XZ) != 0) {
    vert_pos = vec3(pos.x, 0.0, pos.y);
  }
  else if ((gridFlag & PLANE_YZ) != 0) {
    vert_pos = vec3(0.0, pos.x, pos.y);
  }
  else /* PLANE_IMAGE */ {
    vert_pos = vec3(pos.xy * 0.5 + 0.5, 0.0);
  }

  local_pos = vert_pos;

  vec3 real_pos = cameraPos * planeAxes + vert_pos * meshSize;

  /* Used for additional Z axis */
  if ((gridFlag & CLIP_Z_POS) != 0) {
    real_pos.z = clamp(real_pos.z, 0.0, 1e30);
    local_pos.z = clamp(local_pos.z, 0.0, 1.0);
  }
  if ((gridFlag & CLIP_Z_NEG) != 0) {
    real_pos.z = clamp(real_pos.z, -1e30, 0.0);
    local_pos.z = clamp(local_pos.z, -1.0, 0.0);
  }

  gl_Position = ViewProjectionMatrix * vec4(real_pos, 1.0);
}