OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
3 Use of this source code is governed by a BSD-style license that can be | |
4 found in the LICENSE file. | |
5 --> | |
6 <!DOCTYPE html> | |
7 <html> | |
8 <head> | |
9 <meta charset="utf-8"> | |
10 <title>GLSL atan-xy function test</title> | |
11 <link rel="stylesheet" href="../../../resources/js-test-style.css"/> | |
12 <link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/> | |
13 <script src="../../../resources/js-test-pre.js"></script> | |
14 <script src="../../resources/webgl-test.js"> </script> | |
15 <script src="../../resources/webgl-test-utils.js"> </script> | |
16 <script src="../../resources/glsl-generator.js"> </script> | |
17 </head> | |
18 <body> | |
19 <div id="description"></div> | |
20 <div id="console"></div> | |
21 <script> | |
22 | |
23 var piConstants = [ | |
24 "const float kPI = 3.14159265358979323846;", | |
25 "const float kHalfPI = (kPI * 0.5);", | |
26 "const float k2PI = (kPI * 2.0);" | |
27 ].join("\n"); | |
28 | |
29 var atanImplementation = [ | |
30 "const float kEpsilon = 0.0001;", | |
31 "", | |
32 "float atan_impl(float y, float x) {", | |
33 " float atan_value = 0.0;", | |
34 " float scale = 1.0;", | |
35 " float sign = 1.0;", | |
36 "", | |
37 " if (x > kEpsilon || abs(y) > kEpsilon) {", | |
38 " if (x < 0.0 ^^ y < 0.0) {", | |
39 " sign = -1.0;", | |
40 " }", | |
41 "", | |
42 " bool y_gt_x = abs(y) < abs(x);", | |
43 " float value = y_gt_x ? abs(y / x) : abs(x / y);", | |
44 "", | |
45 " // Use Taylors series expansion for atan", | |
46 " for(int ii = 1; ii < 8; ii += 2) {", | |
47 " atan_value += scale * pow(value, float(ii)) / float(ii);", | |
48 " scale = -scale;", | |
49 " }", | |
50 "", | |
51 " atan_value = (y_gt_x) ? sign * atan_value : sign * (kHalfPI - atan_value)
;", | |
52 " }", | |
53 "", | |
54 " if (x < 0.0) {", | |
55 " if (y < 0.0) {", | |
56 " atan_value -= kHalfPI;", | |
57 " } else if (y > 0.0) {", | |
58 " atan_value += kHalfPI;", | |
59 " }", | |
60 " }", | |
61 "", | |
62 " return atan_value;", | |
63 "}" | |
64 ].join("\n"); | |
65 | |
66 GLSLGenerator.runFeatureTest({ | |
67 feature: "atan", | |
68 args: "$(type) y, $(type) x", | |
69 baseArgs: "y$(field), x$(field)", | |
70 testFunc: "$(func)($(type), $(type))", | |
71 emuFunc: [ | |
72 atanImplementation, | |
73 "float $(func)_base(float y, float x) {", | |
74 " return atan_impl(y, x);", | |
75 "}" | |
76 ].join("\n"), | |
77 gridRes: 8, | |
78 tolerance: 4, | |
79 extra: piConstants, | |
80 tests: [ | |
81 ["$(output) = vec4(", | |
82 " $(func)($(input).x + 0.1, $(input).y) / k2PI + 0.5,", | |
83 " 0,", | |
84 " 0,", | |
85 " 1);"].join("\n"), | |
86 ["$(output) = vec4(", | |
87 " $(func)($(input).xy + vec2(0.1, 0.1), $(input).yx) / ", | |
88 " k2PI + vec2(0.5, 0.5),", | |
89 " 0, 1);"].join("\n"), | |
90 ["$(output) = vec4(", | |
91 " $(func)($(input).xyz + vec3(0.1, 0.1, 0.1), $(input).yzx) / ", | |
92 " k2PI + vec3(0.5, 0.5, 0.5),", | |
93 " 1);"].join("\n"), | |
94 ["$(output) = ", | |
95 " $(func)($(input) + vec4(0.1, 0.1, 0.1, 0.1), $(input).wzyx) / ", | |
96 " k2PI + vec4(0.5, 0.5, 0.5, 0.5);", | |
97 ].join("\n") | |
98 ] | |
99 }); | |
100 successfullyParsed = true; | |
101 </script> | |
102 </body> | |
103 </html> | |
104 | |
OLD | NEW |