View Full Version : Question on using short CT data create texture
04-24-2012, 03:51 AM
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!
04-24-2012, 04:55 AM
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.
04-24-2012, 07:59 PM
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?
04-25-2012, 02:17 PM
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.
04-25-2012, 07:14 PM
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.
04-25-2012, 08:23 PM
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)).
04-26-2012, 01:27 AM
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.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.