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 precision mediump float; |
| 28 #endif |
| 29 varying vec4 color; |
| 30 |
| 31 float lerp(float a, float b, float s) |
| 32 { |
| 33 return a + (b - a) * s; |
| 34 } |
| 35 |
| 36 void main (void) |
| 37 { |
| 38 float sinValues[17]; |
| 39 sinValues[0] = 0.0; |
| 40 sinValues[1] = 0.382683; |
| 41 sinValues[2] = 0.707107; |
| 42 sinValues[3] = 0.92388; |
| 43 sinValues[4] = 1.0; |
| 44 sinValues[5] = 0.92388; |
| 45 sinValues[6] = 0.707107; |
| 46 sinValues[7] = 0.382683; |
| 47 sinValues[8] = 0.0; |
| 48 sinValues[9] = -0.382683; |
| 49 sinValues[10] = -0.707107; |
| 50 sinValues[11] = -0.92388; |
| 51 sinValues[12] = -1.0; |
| 52 sinValues[13] = -0.923879; |
| 53 sinValues[14] = -0.707107; |
| 54 sinValues[15] = -0.382683; |
| 55 sinValues[16] = 0.0; |
| 56 |
| 57 const float M_PI = 3.14159265358979323846; |
| 58 float c = 2.0 * M_PI * color.r; |
| 59 |
| 60 float arrVal = c * 2.546478971; |
| 61 int arr0 = int(floor(arrVal)); |
| 62 float weight = arrVal - floor(arrVal); |
| 63 float sin_c = 0.0; |
| 64 |
| 65 if (arr0 == 0) |
| 66 sin_c = lerp(sinValues[0], sinValues[1], weight); |
| 67 else if (arr0 == 1) |
| 68 sin_c = lerp(sinValues[1], sinValues[2], weight); |
| 69 else if (arr0 == 2) |
| 70 sin_c = lerp(sinValues[2], sinValues[3], weight); |
| 71 else if (arr0 == 3) |
| 72 sin_c = lerp(sinValues[3], sinValues[4], weight); |
| 73 else if (arr0 == 4) |
| 74 sin_c = lerp(sinValues[4], sinValues[5], weight); |
| 75 else if (arr0 == 5) |
| 76 sin_c = lerp(sinValues[5], sinValues[6], weight); |
| 77 else if (arr0 == 6) |
| 78 sin_c = lerp(sinValues[6], sinValues[7], weight); |
| 79 else if (arr0 == 7) |
| 80 sin_c = lerp(sinValues[7], sinValues[8], weight); |
| 81 else if (arr0 == 8) |
| 82 sin_c = lerp(sinValues[8], sinValues[9], weight); |
| 83 else if (arr0 == 9) |
| 84 sin_c = lerp(sinValues[9], sinValues[10], weight); |
| 85 else if (arr0 == 10) |
| 86 sin_c = lerp(sinValues[10], sinValues[11], weight); |
| 87 else if (arr0 == 11) |
| 88 sin_c = lerp(sinValues[11], sinValues[12], weight); |
| 89 else if (arr0 == 12) |
| 90 sin_c = lerp(sinValues[12], sinValues[13], weight); |
| 91 else if (arr0 == 13) |
| 92 sin_c = lerp(sinValues[13], sinValues[14], weight); |
| 93 else if (arr0 == 14) |
| 94 sin_c = lerp(sinValues[14], sinValues[15], weight); |
| 95 else if (arr0 == 15) |
| 96 sin_c = lerp(sinValues[15], sinValues[16], weight); |
| 97 else if (arr0 == 16) |
| 98 sin_c = sinValues[16]; |
| 99 |
| 100 gl_FragColor = vec4(0.5 * sin_c + 0.5, 0.0, 0.0, 1.0); |
| 101 } |
OLD | NEW |