|
290 | 290 | 'varying vec2 vTexCoord;', |
291 | 291 | '', |
292 | 292 | 'float actuallyMod(float x, float y) {', |
293 | | - ' float f = mod(x, y);', |
294 | | - ' if (abs(f-y) < 0.001) return 0.0;', |
295 | | - ' return f;', |
| 293 | + ' return x - y * floor(x/y);', |
296 | 294 | '}', |
297 | 295 | '', |
298 | 296 | opt.offsetRangeHack ? '#define OFFSET_HACK' : '', |
|
317 | 315 | 'highp float decode32(highp vec4 rgba) {', |
318 | 316 | (endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'), |
319 | 317 | ' rgba *= 255.0;', |
320 | | - ' highp float sign = 1.0 - step(128.0,rgba.a)*2.0;', |
321 | | - ' highp float exponent = 2.0 * actuallyMod(rgba.a,128.0) + step(128.0,rgba.b) - 127.0; ', |
322 | | - ' highp float mantissa = actuallyMod(rgba.b,128.0)*65536.0 + rgba.g*256.0 +rgba.r + float(0x800000);', |
323 | | - ' highp float result = sign * exp2(exponent) * (mantissa * exp2(-23.0 )); ', |
324 | | - ' return result;', |
| 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;', |
325 | 323 | '}', |
326 | 324 | '/* End: http://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float */', |
327 | 325 | '#else', |
|
370 | 368 | ' float index = (xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x;', |
371 | 369 | ' float t = floor(index / texSize.x);', |
372 | 370 | ' float s = actuallyMod(index, texSize.x);', |
| 371 | + ' s += 0.5;', |
| 372 | + ' t += 0.5;', |
373 | 373 | (opt.safeTextureReadHack ? 's += 1.0; t += 1.0;' : ''), |
374 | 374 | (opt.safeTextureReadHack ? 'return decode32(texture2D(tex, vec2(s / (texSize.x + 2.0), t / (texSize.y + 2.0))));' : ''), |
375 | 375 | ' return decode32(texture2D(tex, vec2(s / texSize.x, t / texSize.y)));', |
|
0 commit comments