|
315 | 315 | 'highp float decode32(highp vec4 rgba) {', |
316 | 316 | (endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'), |
317 | 317 | ' rgba *= 255.0;', |
318 | | - ' float sign = 1.0 - step(128.0,rgba.a)*2.0;', |
319 | | - ' float exponent = 2.0 * actuallyMod(rgba.a,128.0) + step(128.0,rgba.b) - 127.0;', |
320 | | - ' if (abs(exponent + 127.0) < 0.001) return 0.0;', |
321 | | - ' float mantissa = actuallyMod(rgba.b,128.0)*65536.0 + rgba.g*256.0 +rgba.r+ float(0x800000);', |
322 | | - ' return sign * exp2(exponent-23.0) * mantissa;', |
| 318 | + ' int r = int(rgba.r);', |
| 319 | + ' int g = int(rgba.g);', |
| 320 | + ' int b = int(rgba.b);', |
| 321 | + ' int a = int(rgba.a);', |
| 322 | + ' int sign = a > 127 ? -1 : 1;', |
| 323 | + ' int exponent = 2 * (a > 127 ? a - 128 : a) + (b > 127 ? 1 : 0);', |
| 324 | + ' if (exponent == 0) return float(sign) * 0.0;', |
| 325 | + ' exponent -= 127;', |
| 326 | + ' float f = exp2(float(exponent));', |
| 327 | + ' f += float(b > 127 ? b - 128 : b) * exp2(float(exponent-7));', |
| 328 | + ' f += float(g) * exp2(float(exponent-15));', |
| 329 | + ' f += float(r) * exp2(float(exponent-23));', |
| 330 | + ' f *= float(sign);', |
| 331 | + ' return f;', |
323 | 332 | '}', |
324 | 333 | '/* End: http://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float */', |
325 | 334 | '#else', |
|
368 | 377 | ' float index = (xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x;', |
369 | 378 | ' float t = floor(index / texSize.x);', |
370 | 379 | ' float s = actuallyMod(index, texSize.x);', |
| 380 | + ' if (s > texSize.x - 0.00001) s = 0.0;', |
371 | 381 | ' s += 0.5;', |
372 | 382 | ' t += 0.5;', |
373 | 383 | (opt.safeTextureReadHack ? 's += 1.0; t += 1.0;' : ''), |
|
0 commit comments