FastUIDraw
fastuidraw_align.vert.glsl.hpp
Go to the documentation of this file.
1 /*!
2  * \file fastuidraw_align.vert.glsl.hpp
3  * \brief file fastuidraw_align.vert.glsl.hpp
4  *
5  * Copyright 2018 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 
20 /*!\addtogroup GLSLVertCode
21  * @{
22  */
23 
24 ///@cond
25 void
26 fastuidraw_align_compute_Q_adjoint_Q(in vec3 pclip_p,
27  out mat2 Q, out mat2 adjQ)
28 {
29  vec3 clip;
30  clip = vec3(fastuidraw_viewport_pixels, 1.0) * pclip_p;
31 
32  vec2 c0, c1;
33  c0.x = clip.z * fastuidraw_item_matrix[0].x - clip.x * fastuidraw_item_matrix[0].z;
34  c0.y = clip.z * fastuidraw_item_matrix[0].y - clip.y * fastuidraw_item_matrix[0].z;
35  c1.x = clip.z * fastuidraw_item_matrix[1].x - clip.x * fastuidraw_item_matrix[1].z;
36  c1.y = clip.z * fastuidraw_item_matrix[1].y - clip.y * fastuidraw_item_matrix[1].z;
37 
38  Q = mat2(c0, c1);
39  adjQ = mat2( Q[1][1], -Q[0][1], -Q[1][0], Q[0][0]);
40 }
41 ///@endcond
42 
43 /*!
44  * Given a normal vector in local coordinate and a position
45  * in -clip- coordinates, return the vector N in local coordinates
46  * so that N transformed to screen coordiantes is perpindicular
47  * to the vector T transformed to screen coordinate where T
48  * is the vector perpindicular to the input normal vector.
49  * The magnitude of N is not necessarily the same as the magnitude
50  * of the input vector n, only the nature of its direction is
51  * guarnateed.
52  * \param clip_p position in CLIP coordinates
53  * \param n normal vector in LOCAL coordinates
54  */
55 vec2
57 {
58  mat2 Q, adjQ;
59 
60  fastuidraw_align_compute_Q_adjoint_Q(clip_p, Q, adjQ);
61 
62  vec2 n_screen, t_screen, t;
63 
64  t = vec2(-n.y, n.x);
65  t_screen = fastuidraw_viewport_pixels * (Q * t);
66  n_screen = vec2(t_screen.y, -t_screen.x);
67 
68  /* NOTE!
69  * We do NOT divide by the det of Q, this is because
70  * we only care about the -direction- of return
71  * value, not the magnitude, thus the adjoint is
72  * good enough [and it avoids us needing to deal
73  * with a the case if the determinant is 0].
74  */
75  return adjQ * (fastuidraw_viewport_recip_pixels * n_screen);
76 }
77 /*! @} */
vecN< float, 2 > vec2
Definition: vecN.hpp:1231
vec2 fastuidraw_align_normal_to_screen(in vec3 clip_p, in vec2 n)
reference x(void)
Definition: vecN.hpp:435
vecN< float, 3 > vec3
Definition: vecN.hpp:1235