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 /* The following files are direct copies of each other: |
| 27 * |
| 28 * GL/acos/acos_vec3_frag_xvary_ref.frag |
| 29 * GL/asin/asin_vec3_frag_xvary_ref.frag |
| 30 * |
| 31 * Care should be taken to apply any changes to both. Only the last |
| 32 * line where gl_FragColor is assigned should be different. |
| 33 */ |
| 34 |
| 35 #ifdef GL_ES |
| 36 precision mediump float; |
| 37 #endif |
| 38 varying vec4 color; |
| 39 |
| 40 float lerp(float a, float b, float s) |
| 41 { |
| 42 return a + (b - a) * s; |
| 43 } |
| 44 |
| 45 void main (void) |
| 46 { |
| 47 float asinValues[17]; |
| 48 asinValues[0] = -1.5708; |
| 49 asinValues[1] = -1.06544; |
| 50 asinValues[2] = -0.848062; |
| 51 asinValues[3] = -0.675132; |
| 52 asinValues[4] = -0.523599; |
| 53 asinValues[5] = -0.384397; |
| 54 asinValues[6] = -0.25268; |
| 55 asinValues[7] = -0.125328; |
| 56 asinValues[8] = 0.0; |
| 57 asinValues[9] = 0.125328; |
| 58 asinValues[10] = 0.25268; |
| 59 asinValues[11] = 0.384397; |
| 60 asinValues[12] = 0.523599; |
| 61 asinValues[13] = 0.675132; |
| 62 asinValues[14] = 0.848062; |
| 63 asinValues[15] = 1.06544; |
| 64 asinValues[16] = 1.5708; |
| 65 |
| 66 const float M_PI = 3.14159265358979323846; |
| 67 vec3 c = 2.0 * (color.rgb - 0.5); |
| 68 |
| 69 vec3 arrVal = (c + vec3(1.0, 1.0, 1.0)) * 8.0; |
| 70 int arr0x = int(floor(arrVal.x)); |
| 71 int arr0y = int(floor(arrVal.y)); |
| 72 int arr0z = int(floor(arrVal.z)); |
| 73 vec3 weight = arrVal - floor(arrVal); |
| 74 vec3 asin_c = vec3(0.0); |
| 75 |
| 76 if (arr0x == 0) |
| 77 asin_c.x = lerp(asinValues[0], asinValues[1], weight.x); |
| 78 else if (arr0x == 1) |
| 79 asin_c.x = lerp(asinValues[1], asinValues[2], weight.x); |
| 80 else if (arr0x == 2) |
| 81 asin_c.x = lerp(asinValues[2], asinValues[3], weight.x); |
| 82 else if (arr0x == 3) |
| 83 asin_c.x = lerp(asinValues[3], asinValues[4], weight.x); |
| 84 else if (arr0x == 4) |
| 85 asin_c.x = lerp(asinValues[4], asinValues[5], weight.x); |
| 86 else if (arr0x == 5) |
| 87 asin_c.x = lerp(asinValues[5], asinValues[6], weight.x); |
| 88 else if (arr0x == 6) |
| 89 asin_c.x = lerp(asinValues[6], asinValues[7], weight.x); |
| 90 else if (arr0x == 7) |
| 91 asin_c.x = lerp(asinValues[7], asinValues[8], weight.x); |
| 92 else if (arr0x == 8) |
| 93 asin_c.x = lerp(asinValues[8], asinValues[9], weight.x); |
| 94 else if (arr0x == 9) |
| 95 asin_c.x = lerp(asinValues[9], asinValues[10], weight.x); |
| 96 else if (arr0x == 10) |
| 97 asin_c.x = lerp(asinValues[10], asinValues[11], weight.x); |
| 98 else if (arr0x == 11) |
| 99 asin_c.x = lerp(asinValues[11], asinValues[12], weight.x); |
| 100 else if (arr0x == 12) |
| 101 asin_c.x = lerp(asinValues[12], asinValues[13], weight.x); |
| 102 else if (arr0x == 13) |
| 103 asin_c.x = lerp(asinValues[13], asinValues[14], weight.x); |
| 104 else if (arr0x == 14) |
| 105 asin_c.x = lerp(asinValues[14], asinValues[15], weight.x); |
| 106 else if (arr0x == 15) |
| 107 asin_c.x = lerp(asinValues[15], asinValues[16], weight.x); |
| 108 else if (arr0x == 16) |
| 109 asin_c.x = asinValues[16]; |
| 110 |
| 111 if (arr0y == 0) |
| 112 asin_c.y = lerp(asinValues[0], asinValues[1], weight.y); |
| 113 else if (arr0y == 1) |
| 114 asin_c.y = lerp(asinValues[1], asinValues[2], weight.y); |
| 115 else if (arr0y == 2) |
| 116 asin_c.y = lerp(asinValues[2], asinValues[3], weight.y); |
| 117 else if (arr0y == 3) |
| 118 asin_c.y = lerp(asinValues[3], asinValues[4], weight.y); |
| 119 else if (arr0y == 4) |
| 120 asin_c.y = lerp(asinValues[4], asinValues[5], weight.y); |
| 121 else if (arr0y == 5) |
| 122 asin_c.y = lerp(asinValues[5], asinValues[6], weight.y); |
| 123 else if (arr0y == 6) |
| 124 asin_c.y = lerp(asinValues[6], asinValues[7], weight.y); |
| 125 else if (arr0y == 7) |
| 126 asin_c.y = lerp(asinValues[7], asinValues[8], weight.y); |
| 127 else if (arr0y == 8) |
| 128 asin_c.y = lerp(asinValues[8], asinValues[9], weight.y); |
| 129 else if (arr0y == 9) |
| 130 asin_c.y = lerp(asinValues[9], asinValues[10], weight.y); |
| 131 else if (arr0y == 10) |
| 132 asin_c.y = lerp(asinValues[10], asinValues[11], weight.y); |
| 133 else if (arr0y == 11) |
| 134 asin_c.y = lerp(asinValues[11], asinValues[12], weight.y); |
| 135 else if (arr0y == 12) |
| 136 asin_c.y = lerp(asinValues[12], asinValues[13], weight.y); |
| 137 else if (arr0y == 13) |
| 138 asin_c.y = lerp(asinValues[13], asinValues[14], weight.y); |
| 139 else if (arr0y == 14) |
| 140 asin_c.y = lerp(asinValues[14], asinValues[15], weight.y); |
| 141 else if (arr0y == 15) |
| 142 asin_c.y = lerp(asinValues[15], asinValues[16], weight.y); |
| 143 else if (arr0y == 16) |
| 144 asin_c.y = asinValues[16]; |
| 145 |
| 146 if (arr0z == 0) |
| 147 asin_c.z = lerp(asinValues[0], asinValues[1], weight.z); |
| 148 else if (arr0z == 1) |
| 149 asin_c.z = lerp(asinValues[1], asinValues[2], weight.z); |
| 150 else if (arr0z == 2) |
| 151 asin_c.z = lerp(asinValues[2], asinValues[3], weight.z); |
| 152 else if (arr0z == 3) |
| 153 asin_c.z = lerp(asinValues[3], asinValues[4], weight.z); |
| 154 else if (arr0z == 4) |
| 155 asin_c.z = lerp(asinValues[4], asinValues[5], weight.z); |
| 156 else if (arr0z == 5) |
| 157 asin_c.z = lerp(asinValues[5], asinValues[6], weight.z); |
| 158 else if (arr0z == 6) |
| 159 asin_c.z = lerp(asinValues[6], asinValues[7], weight.z); |
| 160 else if (arr0z == 7) |
| 161 asin_c.z = lerp(asinValues[7], asinValues[8], weight.z); |
| 162 else if (arr0z == 8) |
| 163 asin_c.z = lerp(asinValues[8], asinValues[9], weight.z); |
| 164 else if (arr0z == 9) |
| 165 asin_c.z = lerp(asinValues[9], asinValues[10], weight.z); |
| 166 else if (arr0z == 10) |
| 167 asin_c.z = lerp(asinValues[10], asinValues[11], weight.z); |
| 168 else if (arr0z == 11) |
| 169 asin_c.z = lerp(asinValues[11], asinValues[12], weight.z); |
| 170 else if (arr0z == 12) |
| 171 asin_c.z = lerp(asinValues[12], asinValues[13], weight.z); |
| 172 else if (arr0z == 13) |
| 173 asin_c.z = lerp(asinValues[13], asinValues[14], weight.z); |
| 174 else if (arr0z == 14) |
| 175 asin_c.z = lerp(asinValues[14], asinValues[15], weight.z); |
| 176 else if (arr0z == 15) |
| 177 asin_c.z = lerp(asinValues[15], asinValues[16], weight.z); |
| 178 else if (arr0z == 16) |
| 179 asin_c.z = asinValues[16]; |
| 180 |
| 181 // acos(x) = PI/2 - asin(x) |
| 182 gl_FragColor = vec4(0.5 - asin_c / M_PI, 1.0); |
| 183 } |
OLD | NEW |