-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
3D viewer: add forgotten shader update code
This code was added to also handle buffer geometries alongside regular gemetries for picking.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |