From ccfc5bf10ec230350b2cd279476eb308034efd52 Mon Sep 17 00:00:00 2001 From: Tom Kazimiers Date: Mon, 16 Jul 2018 13:08:38 -0400 Subject: [PATCH] 3D viewer: add forgotten shader update code This code was added to also handle buffer geometries alongside regular gemetries for picking. --- .../catmaid/static/libs/catmaid/shader.js | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 django/applications/catmaid/static/libs/catmaid/shader.js diff --git a/django/applications/catmaid/static/libs/catmaid/shader.js b/django/applications/catmaid/static/libs/catmaid/shader.js new file mode 100644 index 0000000000..67d36741d3 --- /dev/null +++ b/django/applications/catmaid/static/libs/catmaid/shader.js @@ -0,0 +1,56 @@ + +(function(CATMAID) { + + CATMAID.ShaderLib = { + + // Original by Mikola Lysenko. MIT License (c) 2014, from: + // https://github.com/mikolalysenko/glsl-read-float/blob/master/index.glsl + encodeFloat: [ + "#define FLOAT_MAX 1.70141184e38", + "#define FLOAT_MIN 1.17549435e-38", + "", + "lowp vec4 encode_float(highp float v) {", + " highp float av = abs(v);", + "", + " //Handle special cases", + " if(av < FLOAT_MIN) {", + " return vec4(0.0, 0.0, 0.0, 0.0);", + " } else if(v > FLOAT_MAX) {", + " return vec4(127.0, 128.0, 0.0, 0.0) / 255.0;", + " } else if(v < -FLOAT_MAX) {", + " return vec4(255.0, 128.0, 0.0, 0.0) / 255.0;", + " }", + "", + " highp vec4 c = vec4(0,0,0,0);", + "", + " //Compute exponent and mantissa", + " highp float e = floor(log2(av));", + " highp float m = av * pow(2.0, -e) - 1.0;", + " ", + " //Unpack mantissa", + " c[1] = floor(128.0 * m);", + " m -= c[1] / 128.0;", + " c[2] = floor(32768.0 * m);", + " m -= c[2] / 32768.0;", + " c[3] = floor(8388608.0 * m);", + " ", + " //Unpack exponent", + " highp float ebias = e + 127.0;", + " c[0] = floor(ebias / 2.0);", + " ebias -= c[0] * 2.0;", + " c[1] += floor(ebias) * 128.0; ", + "", + " //Unpack sign bit", + " c[0] += 128.0 * step(0.0, -v);", + "", + " //Scale back to range", + " return c / 255.0;", + "}" + ].join("\n") + }; + + CATMAID.insertSnippetIntoShader = function (shaderSource, insertionPoint, glsl) { + return shaderSource.replace(insertionPoint.regex, glsl + insertionPoint.replacement); + }; + +})(CATMAID);