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 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 "float atan_impl(float value) {", | |
31 " float atan_value = 0.0;", | |
32 " float scale = 1.0;", | |
33 " float sign = 1.0;", | |
34 "", | |
35 " if (value < 0.0) {", | |
36 " sign = -1.0;", | |
37 " value = -value;", | |
38 " }", | |
39 "", | |
40 " bool value_le_1 = value <= 1.0;", | |
41 " value = value_le_1 ? value : 1.0 / value;", | |
42 "", | |
43 " // Use Taylors series expansion for atan", | |
44 " for(int ii = 1; ii < 8; ii += 2) {", | |
45 " atan_value += scale * pow(value, float(ii)) / float(ii);", | |
46 " scale = -scale;", | |
47 " }", | |
48 "", | |
49 " return value_le_1 ? sign * atan_value : sign * (kHalfPI - atan_value);", | |
50 "}", | |
51 ].join("\n"); | |
52 | |
53 GLSLGenerator.runFeatureTest({ | |
54 feature: "atan", | |
55 args: "$(type) value", | |
56 baseArgs: "value$(field)", | |
57 testFunc: "$(func)($(type))", | |
58 emuFunc: [ | |
59 atanImplementation, | |
60 "", | |
61 "#define $(func)_base(value) atan_impl(value)" | |
62 ].join("\n"), | |
63 gridRes: 8, | |
64 tolerance: 4, | |
65 extra: piConstants, | |
66 tests: [ | |
67 ["$(output) = vec4(", | |
68 " $(func)($(input).x * 8.0 - 4.0) / k2PI + 0.5,", | |
69 " 0.5,", | |
70 " 0,", | |
71 " 1);"].join("\n"), | |
72 ["$(output) = vec4(", | |
73 " $(func)($(input).xy * 8.0 - vec2(4, 4)) / k2PI + vec2(0.5, 0.5),", | |
74 " 0, 1);"].join("\n"), | |
75 ["$(output) = vec4(", | |
76 " $(func)($(input).xyz * 8.0 - vec3(4, 4, 4)) / k2PI + vec3(0.5, 0.5, 0.
5),", | |
77 | |
78 " 1);"].join("\n"), | |
79 ["$(output) = ", | |
80 " $(func)($(input) * 8.0 - vec4(4, 4, 4, 4)) / k2PI + vec4(0.5, 0.5, 0.5
, 0.5);", | |
81 ].join("\n") | |
82 ] | |
83 }); | |
84 successfullyParsed = true; | |
85 </script> | |
86 </body> | |
87 </html> | |
88 | |
OLD | NEW |