Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/shaders/gpu_shader_2D_edituvs_stretch_vert.glsl
| uniform mat4 ModelViewProjectionMatrix; | uniform mat4 ModelViewProjectionMatrix; | ||||
| uniform vec2 aspect; | uniform vec2 aspect; | ||||
| in vec2 pos; | in vec2 pos; | ||||
| #ifndef STRETCH_ANGLE | #ifdef STRETCH_ANGLE | ||||
| in float stretch; | |||||
| #else | |||||
| in vec2 uv_angles; | in vec2 uv_angles; | ||||
| in float angle; | in float angle; | ||||
| #else | |||||
| in float ratio; | |||||
| uniform float totalAreaRatio; | |||||
| uniform float totalAreaRatioInv; | |||||
| #endif | #endif | ||||
| noperspective out vec4 finalColor; | noperspective out vec4 finalColor; | ||||
| vec3 weight_to_rgb(float weight) | vec3 weight_to_rgb(float weight) | ||||
| { | { | ||||
| vec3 r_rgb; | vec3 r_rgb; | ||||
| float blend = ((weight / 2.0) + 0.5); | float blend = ((weight / 2.0) + 0.5); | ||||
| ▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | float angle_normalized_v2v2(vec2 v1, vec2 v2) | ||||
| v2 = normalize(v2 * aspect); | v2 = normalize(v2 * aspect); | ||||
| /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */ | /* this is the same as acos(dot_v3v3(v1, v2)), but more accurate */ | ||||
| bool q = (dot(v1, v2) >= 0.0); | bool q = (dot(v1, v2) >= 0.0); | ||||
| vec2 v = (q) ? (v1 - v2) : (v1 + v2); | vec2 v = (q) ? (v1 - v2) : (v1 + v2); | ||||
| float a = 2.0 * asin(length(v) / 2.0); | float a = 2.0 * asin(length(v) / 2.0); | ||||
| return (q) ? a : M_PI - a; | return (q) ? a : M_PI - a; | ||||
| } | } | ||||
| float area_ratio_to_stretch(float ratio, float tot_ratio, float inv_tot_ratio) | |||||
| { | |||||
| ratio *= (ratio > 0.0f) ? tot_ratio : -inv_tot_ratio; | |||||
| return (ratio > 1.0f) ? (1.0f / ratio) : ratio; | |||||
| } | |||||
| void main() | void main() | ||||
| { | { | ||||
| gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); | gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0); | ||||
| #ifdef STRETCH_ANGLE | #ifdef STRETCH_ANGLE | ||||
| vec2 v1 = angle_to_v2(uv_angles.x * M_PI); | vec2 v1 = angle_to_v2(uv_angles.x * M_PI); | ||||
| vec2 v2 = angle_to_v2(uv_angles.y * M_PI); | vec2 v2 = angle_to_v2(uv_angles.y * M_PI); | ||||
| float uv_angle = angle_normalized_v2v2(v1, v2) / M_PI; | float uv_angle = angle_normalized_v2v2(v1, v2) / M_PI; | ||||
| float stretch = 1.0 - abs(uv_angle - angle); | float stretch = 1.0 - abs(uv_angle - angle); | ||||
| stretch = stretch; | stretch = stretch; | ||||
| stretch = 1.0 - stretch * stretch; | stretch = 1.0 - stretch * stretch; | ||||
| #else | |||||
| float stretch = 1.0 - area_ratio_to_stretch(ratio, totalAreaRatio, -totalAreaRatioInv); | |||||
| #endif | #endif | ||||
| finalColor = vec4(weight_to_rgb(stretch), 1.0); | finalColor = vec4(weight_to_rgb(stretch), 1.0); | ||||
| } | } | ||||