Skip to content

Commit 951824c

Browse files
committed
Rewrite decode32 again
1 parent 28278d5 commit 951824c

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

src/backend/mode_gpu.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,20 @@
315315
'highp float decode32(highp vec4 rgba) {',
316316
(endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'),
317317
' 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;',
323332
'}',
324333
'/* End: http://stackoverflow.com/questions/7059962/how-do-i-convert-a-vec4-rgba-value-to-a-float */',
325334
'#else',
@@ -368,6 +377,7 @@
368377
' float index = (xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x;',
369378
' float t = floor(index / texSize.x);',
370379
' float s = actuallyMod(index, texSize.x);',
380+
' if (s > texSize.x - 0.00001) s = 0.0;',
371381
' s += 0.5;',
372382
' t += 0.5;',
373383
(opt.safeTextureReadHack ? 's += 1.0; t += 1.0;' : ''),

0 commit comments

Comments
 (0)