diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-01-10 19:59:11 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-01-11 18:00:23 +0300 |
commit | 621a6d4a5de872a94f81d239ff627d24afecc56b (patch) | |
tree | e5b563f388f9a7f635b8255549c33b49d1ce83ff /source/blender/gpu/shaders | |
parent | 5f3fdee53a3e2716013147029e6da9e90e2c8ba8 (diff) |
UVEdit: Add back uv angle stretch aspect correction
This is now done in shader so that the batches are shared across ImageUV
areas.
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r-- | source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl index 4588e41573b..c575e06ed3b 100644 --- a/source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl +++ b/source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl @@ -1,8 +1,16 @@ uniform mat4 ModelViewProjectionMatrix; +uniform vec2 aspect; in vec2 pos; + +#ifndef STRETCH_ANGLE in float stretch; +#else + +in vec4 uv_adj; +in float angle; +#endif noperspective out vec4 finalColor; @@ -42,8 +50,30 @@ vec3 weight_to_rgb(float weight) return r_rgb; } +#define M_PI 3.1415926535897932 + +/* Adapted from BLI_math_vector.h */ +float angle_normalized_v2v2(vec2 v1, vec2 v2) +{ + v1 = normalize(v1 * aspect); + v2 = normalize(v2 * aspect); + /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */ + bool q = (dot(v1, v2) >= 0.0); + vec2 v = (q) ? (v1 - v2) : (v1 + v2); + float a = 2.0 * asin(length(v) / 2.0); + return (q) ? a : M_PI - a; +} + void main() { gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); + +#ifdef STRETCH_ANGLE + float uv_angle = angle_normalized_v2v2(uv_adj.xy, uv_adj.zw) / M_PI; + float stretch = 1.0 - abs(uv_angle - angle); + stretch = stretch; + stretch = 1.0 - stretch * stretch; +#endif + finalColor = vec4(weight_to_rgb(stretch), 1.0); } |