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

overlay_edit_uv_stretching_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: 9a3036d5940cbb1cdc93709fe0bf9a0658984c11 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#pragma BLENDER_REQUIRE(common_view_lib.glsl)

vec3 weight_to_rgb(float weight)
{
  vec3 r_rgb;
  float blend = ((weight / 2.0) + 0.5);

  if (weight <= 0.25) { /* blue->cyan */
    r_rgb[0] = 0.0;
    r_rgb[1] = blend * weight * 4.0;
    r_rgb[2] = blend;
  }
  else if (weight <= 0.50) { /* cyan->green */
    r_rgb[0] = 0.0;
    r_rgb[1] = blend;
    r_rgb[2] = blend * (1.0 - ((weight - 0.25) * 4.0));
  }
  else if (weight <= 0.75) { /* green->yellow */
    r_rgb[0] = blend * ((weight - 0.50) * 4.0);
    r_rgb[1] = blend;
    r_rgb[2] = 0.0;
  }
  else if (weight <= 1.0) { /* yellow->red */
    r_rgb[0] = blend;
    r_rgb[1] = blend * (1.0 - ((weight - 0.75) * 4.0));
    r_rgb[2] = 0.0;
  }
  else {
    /* exceptional value, unclamped or nan,
     * avoid uninitialized memory use */
    r_rgb[0] = 1.0;
    r_rgb[1] = 0.0;
    r_rgb[2] = 1.0;
  }

  return r_rgb;
}

#define M_PI 3.1415926535897932

vec2 angle_to_v2(float angle)
{
  return vec2(cos(angle), sin(angle));
}

/* 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;
}

float area_ratio_to_stretch(float ratio, float tot_ratio)
{
  ratio *= tot_ratio;
  return (ratio > 1.0f) ? (1.0f / ratio) : ratio;
}

void main()
{
  vec3 world_pos = point_object_to_world(vec3(pos, 0.0));
  gl_Position = point_world_to_ndc(world_pos);

#ifdef STRETCH_ANGLE
  vec2 v1 = angle_to_v2(uv_angles.x * M_PI);
  vec2 v2 = angle_to_v2(uv_angles.y * M_PI);
  float uv_angle = angle_normalized_v2v2(v1, v2) / M_PI;
  float stretch = 1.0 - abs(uv_angle - angle);
  stretch = stretch;
  stretch = 1.0 - stretch * stretch;
#else
  float stretch = 1.0 - area_ratio_to_stretch(ratio, totalAreaRatio);

#endif

  finalColor = vec4(weight_to_rgb(stretch), 1.0);
}