diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-08-04 11:52:51 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-08-04 11:55:05 +0300 |
commit | cb67bfdba2e22d0ee967e50afe0912ac80d73e9b (patch) | |
tree | 73062214d0be9135b3b56a863a68d1732523daa5 /source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl | |
parent | 218df9941097bf973485ac343c070bdc6641a539 (diff) |
Viewport normal drawing with constant length
Patch for: T37878
{F10169694}
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D11487
Diffstat (limited to 'source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl')
-rw-r--r-- | source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl b/source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl index 007495f84e0..f649a5cb3ed 100644 --- a/source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl +++ b/source/blender/draw/engines/overlay/shaders/edit_mesh_normal_vert.glsl @@ -1,5 +1,7 @@ uniform float normalSize; +uniform float normalScreenSize; +uniform bool isConstantScreenSizeNormals; uniform sampler2D depthTex; uniform float alpha = 1.0; @@ -49,11 +51,25 @@ void main() } vec3 n = normalize(normal_object_to_world(nor)); - vec3 world_pos = point_object_to_world(pos); if (gl_VertexID == 0) { - world_pos += n * normalSize; + if (isConstantScreenSizeNormals) { + bool is_persp = (ProjectionMatrix[3][3] == 0.0); + if (is_persp) + { + float dist_fac = length(cameraPos - world_pos); + float cos_fac = dot(cameraForward, cameraVec(world_pos)); + world_pos += n * normalScreenSize * dist_fac * cos_fac * pixelFac * sizePixel; + } + else { + float frustrum_fac = mul_project_m4_v3_zfac(n) * sizePixel; + world_pos += n * normalScreenSize * frustrum_fac; + } + } + else { + world_pos += n * normalSize; + } } gl_Position = point_world_to_ndc(world_pos); |