Skip to content

Commit 28278d5

Browse files
committed
Redo encode32
1 parent c908013 commit 28278d5

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

src/backend/mode_gpu.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,7 @@
290290
'varying vec2 vTexCoord;',
291291
'',
292292
'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);',
296294
'}',
297295
'',
298296
opt.offsetRangeHack ? '#define OFFSET_HACK' : '',
@@ -317,11 +315,11 @@
317315
'highp float decode32(highp vec4 rgba) {',
318316
(endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'),
319317
' 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;',
325323
'}',
326324
'/* End: http://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float */',
327325
'#else',
@@ -370,6 +368,8 @@
370368
' float index = (xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x;',
371369
' float t = floor(index / texSize.x);',
372370
' float s = actuallyMod(index, texSize.x);',
371+
' s += 0.5;',
372+
' t += 0.5;',
373373
(opt.safeTextureReadHack ? 's += 1.0; t += 1.0;' : ''),
374374
(opt.safeTextureReadHack ? 'return decode32(texture2D(tex, vec2(s / (texSize.x + 2.0), t / (texSize.y + 2.0))));' : ''),
375375
' return decode32(texture2D(tex, vec2(s / texSize.x, t / texSize.y)));',

0 commit comments

Comments
 (0)