Orthanc Stone - Shader

Hello,

I was looking at the shader to know more about how you are rendering the images. I just can’t understand why you are multiplying two times 256.0 at the red line.

From texture2D you get a value that goes from 0.0 to 1.0. First you must convert that value to a byte that goes from 0 to 255, then you multiply 256.0 to pack both bytes into i16.

I think it must be float v = (t.r * 256.0 + t.g) * 255.0;

I was browsing for some examples and found something similar from another code: https://github.com/jpambrun/webgl-demo/blob/master/index.html.

Regards,

TK

static const char* FRAGMENT_SHADER =
ORTHANC_STONE_OPENGL_SHADER_VERSION_DIRECTIVE
“uniform float u_offset; \n”
“uniform float u_slope; \n”
“uniform float u_windowCenter; \n”
“uniform float u_windowWidth; \n”
“uniform bool u_invert; \n”
“uniform sampler2D u_texture; \n”
“varying vec2 v_texcoord; \n”
“void main() \n”
“{ \n”
" vec4 t = texture2D(u_texture, v_texcoord); \n"
" float v = (t.r * 256.0 + t.g) * 256.0; \n"
" v = v * u_slope + u_offset; \n" // (*)
" float a = u_windowCenter - u_windowWidth / 2.0; \n"
" float dy = 1.0 / u_windowWidth; \n"
" if (v <= a) \n"
" v = 0.0; \n"
" else \n"
" { \n"
" v = (v - a) * dy; \n"
" if (v >= 1.0) \n"
" v = 1.0; \n"
" } \n"
" if (u_invert) \n"
" v = 1.0 - v; \n"
" gl_FragColor = vec4(v, v, v, 1); \n"
“}”;

Hello,

Thanks for investigating this issue and for providing a fix!

The patch is now available in the mainline:
https://hg.orthanc-server.com/orthanc-stone/rev/ee68ee732aa7

Kind Regards,

Sébastien-