Question on using short CT data create texture

My CT volume is 12-bits short data, but the negative values can be simply ignored.

I want ask what’s the difference between:

glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, imgWidth_, imgHeight_, imgSlice_, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, volume_);


glTexImage3D(GL_TEXTURE_3D, 0, GL_LUMINANCE, imgWidth_, imgHeight_, imgSlice_, 0, GL_LUMINANCE, GL_SHORT, volume_);

which one is better for creating 3d texture? and when I use GLSL doing the sampling, should I times 16.0 to let the 12-bits value normalized to (0.0 - 1.0).

Thanks a lot!

Did you check :

Use GL_SHORT, otherwise the 12bits negative values will become big positive values in your GLSL sampler wich will become hard to detect and ugly to interpolate.
Edit : scratch that, you should set your negative 12bits values to 0, in any case.

Then, to keep precision, you have to specify something better for internalFormat, rather than a default GL_LUMINANCE (which will probably be interpreted as GL_LUMINANCE8). I advise using at least GL_LUMINANCE16 to keep precision if your hardware supports it. Otherwise the x16 in shader will amplify precision errors.

Thank you ZBuffeR.

And I want ask, after I setting the negative values to 0.

Then I create Short texture and UShort texture with GL_LUMINANCE16.

Then I doing the sampling in GLSL, the value at the same coordinate will be same or, the value in Short Texture will be 2 times as in UShort texture?

Sorry I can seem to parse your question.
Short or ushort only differs of interpretation of large values as negative or not.
Say you enter 0x00FF as short value in the data, it will come out in the GLSL shader as 255/65636 = 0.003885… something.

Hi, ZbuffeR. Are you sure of that? Because I think the maximum value of a short should be 32767.

If the GL_SHORT and GL_UNSIGNED_SHORT are totally same, why they need 2 symbols.

GL_UNSIGNED_SHORT means values in the range [0, 65535] which will be normalized to the range [0.0,1.0] (0 -> 0.0, 65535 -> 1.0).
GL_SHORT means values in the range [-32768, 32767] which in your case will be normalized to the range [0.0,1.0] but every negative value will be clamped to zero (0 -> 0.0, 32767 -> 1.0). If you use a signed texture internal format then you can use the negative values too, but not with GL_LUMINANCE.

As a side note: GL_LUMINANCE is deprecated, use GL_RED and sized internal formats like GL_R8 and use ARB_texture_swizzle to map the single red channel to the others (i.e. swizzle as (R, R, R, 1)).

Thank you very much!

I won’t use the negative value, so let them clamped to 0 with GL_LUMINANCE16 is the best way for me.