Skip to content

Commit c908013

Browse files
committed
Testing mod workaround
1 parent 4a173b0 commit c908013

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

src/backend/mode_gpu.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,12 @@
289289
opt.hardcodeConstants ? 'vec2 uTexSize = vec2('+texSize[0]+','+texSize[1]+');' : 'uniform vec2 uTexSize;',
290290
'varying vec2 vTexCoord;',
291291
'',
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+
'',
292298
opt.offsetRangeHack ? '#define OFFSET_HACK' : '',
293299
'#ifndef OFFSET_HACK',
294300
'/* Begin: http://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float */',
@@ -301,9 +307,9 @@
301307
' exponent = floor(log2(F) + 127.0) + floor(log2(mantissa));',
302308
' highp vec4 rgba;',
303309
' 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)));',
307313
(endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'),
308314
' return rgba / 255.0;',
309315
'}',
@@ -312,8 +318,8 @@
312318
(endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'),
313319
' rgba *= 255.0;',
314320
' 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);',
317323
' highp float result = sign * exp2(exponent) * (mantissa * exp2(-23.0 )); ',
318324
' return result;',
319325
'}',
@@ -354,7 +360,7 @@
354360
' float z = floor(idx / (texDim.x * texDim.y));',
355361
' idx -= z * texDim.x * texDim.y;',
356362
' float y = floor(idx / texDim.x);',
357-
' float x = mod(idx, texDim.x);',
363+
' float x = actuallyMod(idx, texDim.x);',
358364
' return vec3(x, y, z);',
359365
'}',
360366
'',
@@ -363,10 +369,8 @@
363369
(opt.wraparound ? ' xyz = mod(xyz, texDim);' : ''),
364370
' float index = (xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x;',
365371
' float t = floor(index / texSize.x);',
366-
' float s = mod(index, texSize.x);',
372+
' float s = actuallyMod(index, texSize.x);',
367373
(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;',
370374
(opt.safeTextureReadHack ? 'return decode32(texture2D(tex, vec2(s / (texSize.x + 2.0), t / (texSize.y + 2.0))));' : ''),
371375
' return decode32(texture2D(tex, vec2(s / texSize.x, t / texSize.y)));',
372376
'}',

0 commit comments

Comments
 (0)