This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/draw/modes/shaders/object_grid_vert.glsl
Germano Cavalcante 4bf37bafc2 View3D Grid: fix imperial grid drawing
This is a step to finish the D4325 and fix the T61286.
Currently the grid is highlighted in steps of 10 out of 10, which is wrong for the imperial units as seen in `buImperialLenDef`.
The idea of the code is to pass the steps of the grid already dimensioned as a uniform.

Another important thing to note is that subdivisions now only affect the grid without unity.
This matches the 2.7x Blender versions.

No performance loss (almost no gain too).

Reviewers: fclem

Subscribers: zlsa, rl.amorato

Differential Revision: https://developer.blender.org/D4379
2019-08-19 12:05:57 -03:00

53 lines
1.1 KiB
GLSL

/* Infinite grid
* Clément Foucault */
uniform vec3 planeAxes;
uniform float meshSize;
uniform int gridFlag;
#define cameraPos (ViewMatrixInverse[3].xyz)
#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)
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 {
vert_pos = vec3(0.0, pos.x, pos.y);
}
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);
}