OLD | NEW |
(Empty) | |
| 1 |
| 2 /* |
| 3 ** Copyright (c) 2012 The Khronos Group Inc. |
| 4 ** |
| 5 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 6 ** copy of this software and/or associated documentation files (the |
| 7 ** "Materials"), to deal in the Materials without restriction, including |
| 8 ** without limitation the rights to use, copy, modify, merge, publish, |
| 9 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 10 ** permit persons to whom the Materials are furnished to do so, subject to |
| 11 ** the following conditions: |
| 12 ** |
| 13 ** The above copyright notice and this permission notice shall be included |
| 14 ** in all copies or substantial portions of the Materials. |
| 15 ** |
| 16 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 20 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 21 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 22 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 23 */ |
| 24 |
| 25 |
| 26 #ifdef GL_ES |
| 27 #ifdef GL_FRAGMENT_PRECISION_HIGH |
| 28 precision highp float; |
| 29 #else |
| 30 precision mediump float; |
| 31 #endif |
| 32 #endif |
| 33 varying vec4 color; |
| 34 |
| 35 void main (void) |
| 36 { |
| 37 const float M_PI = 3.14159265358979323846; |
| 38 float x = 2.0 * (color.g - 0.5); |
| 39 float y = 2.0 * (color.b - 0.5); |
| 40 float atan_c = 0.0; |
| 41 float scale = 1.0; |
| 42 float sign = 1.0; |
| 43 vec4 result = vec4(0.0, 0.0, 0.0, 1.0); |
| 44 const float epsilon = 1.0e-4; |
| 45 |
| 46 // Avoid evaluating atan(0, x) for x < epsilon because it's implementati
on-dependent |
| 47 if(x > epsilon || abs(y) > epsilon) |
| 48 { |
| 49 if(x < 0.0 ^^ y < 0.0) |
| 50 { |
| 51 sign = -1.0; |
| 52 } |
| 53 |
| 54 if(abs(y) <= abs(x)) |
| 55 { |
| 56 float c = abs(y / x); |
| 57 |
| 58 // Taylors series expansion for atan |
| 59 for(int i = 1; i < 12; i += 2) |
| 60 { |
| 61 atan_c += scale * pow(c, float(i)) / float(i); |
| 62 scale *= -1.0; |
| 63 } |
| 64 |
| 65 result = vec4(sign * atan_c / (2.0 * M_PI) + 0.5, 0.0, 0
.0, 1.0); |
| 66 } |
| 67 else |
| 68 { |
| 69 float c = abs(x / y); |
| 70 |
| 71 // Taylors series expansion for atan |
| 72 for(int i = 1; i < 12; i += 2) |
| 73 { |
| 74 atan_c += scale * pow(c, float(i)) / float(i); |
| 75 scale *= -1.0; |
| 76 } |
| 77 |
| 78 result = vec4(sign * (M_PI / 2.0 - atan_c) / (2.0 * M_PI
) + 0.5, 0.0, 0.0, 1.0); |
| 79 } |
| 80 |
| 81 if(x < 0.0) |
| 82 if(y < 0.0) result.r -= 0.5; |
| 83 else if(y > 0.0) result.r += 0.5; |
| 84 } |
| 85 |
| 86 gl_FragColor = result; |
| 87 } |
| 88 |
OLD | NEW |