1
2/*
3Copyright (c) 2019 The Khronos Group Inc.
4Use of this source code is governed by an MIT-style license that can be
5found in the LICENSE.txt file.
6*/
7
8
9attribute vec4 gtf_Vertex;
10attribute vec4 gtf_Color;
11uniform mat4 gtf_ModelViewProjectionMatrix;
12varying vec4 color;
13
14void main (void)
15{
16	const float M_PI = 3.14159265358979323846;
17	float c = 4.0 * 2.0 * (gtf_Color.r - 0.5);
18	float atan_c = 0.0;
19	float scale = 1.0;
20	float sign = 1.0;
21	vec4 result;
22
23	if(c < 0.0)
24	{
25		sign = -1.0;
26		c *= -1.0;
27	}
28
29	if(c <= 1.0)
30	{
31		// Taylors series expansion for atan
32		for(int i = 1; i < 12; i += 2)
33		{
34			atan_c += scale * pow(c, float(i)) / float(i);
35			scale *= -1.0;
36		}
37
38		result = vec4(sign * atan_c / M_PI + 0.5, 0.0, 0.0, 1.0);
39	}
40	else
41	{
42		c = 1.0 / c;
43
44		// Taylors series expansion for atan
45		for(int i = 1; i < 12; i += 2)
46		{
47			atan_c += scale * pow(c, float(i)) / float(i);
48			scale *= -1.0;
49		}
50
51		result = vec4(sign * (M_PI / 2.0 - atan_c) / M_PI + 0.5, 0.0, 0.0, 1.0);
52	}
53
54	color = result;
55	gl_Position = gtf_ModelViewProjectionMatrix * gtf_Vertex;
56}
57