|
289 | 289 | opt.hardcodeConstants ? 'vec2 uTexSize = vec2('+texSize[0]+','+texSize[1]+');' : 'uniform vec2 uTexSize;', |
290 | 290 | 'varying vec2 vTexCoord;', |
291 | 291 | '', |
| 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;', |
| 296 | + '}', |
| 297 | + '', |
292 | 298 | opt.offsetRangeHack ? '#define OFFSET_HACK' : '', |
293 | 299 | '#ifndef OFFSET_HACK', |
294 | 300 | '/* Begin: http://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float */', |
|
301 | 307 | ' exponent = floor(log2(F) + 127.0) + floor(log2(mantissa));', |
302 | 308 | ' highp vec4 rgba;', |
303 | 309 | ' rgba.a = 128.0 * sign + floor(exponent*exp2(-1.0));', |
304 | | - ' rgba.b = 128.0 * mod(exponent,2.0) + mod(floor(mantissa*128.0),128.0);', |
305 | | - ' rgba.g = floor(mod(floor(mantissa*exp2(23.0 -8.0)),exp2(8.0)));', |
306 | | - ' rgba.r = floor(exp2(23.0)*mod(mantissa,exp2(-15.0)));', |
| 310 | + ' rgba.b = 128.0 * actuallyMod(exponent,2.0) + actuallyMod(floor(mantissa*128.0),128.0);', |
| 311 | + ' rgba.g = floor(actuallyMod(floor(mantissa*exp2(23.0 -8.0)),exp2(8.0)));', |
| 312 | + ' rgba.r = floor(exp2(23.0)*actuallyMod(mantissa,exp2(-15.0)));', |
307 | 313 | (endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'), |
308 | 314 | ' return rgba / 255.0;', |
309 | 315 | '}', |
|
312 | 318 | (endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'), |
313 | 319 | ' rgba *= 255.0;', |
314 | 320 | ' highp float sign = 1.0 - step(128.0,rgba.a)*2.0;', |
315 | | - ' highp float exponent = 2.0 * mod(rgba.a,128.0) + step(128.0,rgba.b) - 127.0; ', |
316 | | - ' highp float mantissa = mod(rgba.b,128.0)*65536.0 + rgba.g*256.0 +rgba.r + float(0x800000);', |
| 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);', |
317 | 323 | ' highp float result = sign * exp2(exponent) * (mantissa * exp2(-23.0 )); ', |
318 | 324 | ' return result;', |
319 | 325 | '}', |
|
354 | 360 | ' float z = floor(idx / (texDim.x * texDim.y));', |
355 | 361 | ' idx -= z * texDim.x * texDim.y;', |
356 | 362 | ' float y = floor(idx / texDim.x);', |
357 | | - ' float x = mod(idx, texDim.x);', |
| 363 | + ' float x = actuallyMod(idx, texDim.x);', |
358 | 364 | ' return vec3(x, y, z);', |
359 | 365 | '}', |
360 | 366 | '', |
|
363 | 369 | (opt.wraparound ? ' xyz = mod(xyz, texDim);' : ''), |
364 | 370 | ' float index = (xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x;', |
365 | 371 | ' float t = floor(index / texSize.x);', |
366 | | - ' float s = mod(index, texSize.x);', |
| 372 | + ' float s = actuallyMod(index, texSize.x);', |
367 | 373 | (opt.safeTextureReadHack ? 's += 1.0; t += 1.0;' : ''), |
368 | | - ' s = (s < 0.5) ? 0.0 : s + 0.5;', |
369 | | - ' t = (t < 0.5) ? 0.0 : t + 0.5;', |
370 | 374 | (opt.safeTextureReadHack ? 'return decode32(texture2D(tex, vec2(s / (texSize.x + 2.0), t / (texSize.y + 2.0))));' : ''), |
371 | 375 | ' return decode32(texture2D(tex, vec2(s / texSize.x, t / texSize.y)));', |
372 | 376 | '}', |
|
0 commit comments