Hi all, I have to admit that i am a newbie to GLSL - -. what I want to do is to access the exact pixel value(type: unsigned short, ranging from 0 to 65535) of a medical grayscale image in glsl frag shader. So that I can display a certain range of value in the image. The image is sent to the shader as a texture image.
At first, I use:
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16, pack->width, pack->height, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, pack->texture);
prerequisite:
I have used the function:
glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D,0,GL_TEXTURE_INTERNAL_FORMAT,actual_format);
to validate that GL_LUMINANCE16 is available on my box.
In the frag shader:
vec4 color = texture2D(myTexture, vTexCoord);
int pixel_value = int(color.g * 65535.0); //precision lost here
if(pixel_value <= 0 || pixel_value > 1500)//display range from 0 to 1500
{
color = vec4(1.0,1.0,1.0,1.0);
}
else
{
float value = float(pixel_value) / 1500.0;
color = vec4(value,value, value,1.0);
}
But as a result, the pixel value recovery have precision lost, for the fact that simpler will normalize the value of the pixel from 0.0 to 1.0. So I can not get the correct effect…
Form V-man’s suggestion on gamedev, I took a look at an opengl extension called “EXT_texture_integer”, I change the code to:
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16UI_EXT, pack->width, pack->height, 0,GL_LUMINANCE_INTEGER_EXT, GL_UNSIGNED_SHORT, pack->texture);
In frag shader:
vec4 color = texture2D(myTexture, vTexCoord);
int pixel_value = int(color.r);
if(pixel_value <= 0 || pixel_value > 1500)
{
color = vec4(1.0,1.0,1.0,1.0);
}
else
{
float value = float(pixel_value) / 1000;
color = vec4(value,value, value,1.0);
}
But it still have any effect…why???
Can Anyone give me any suggestion??? thx in advance…