Hello I am trying to combine data from main Computer tomography image with multiple masks - when I tried to use it with single mask all worked well - with multiple id do not. Basically I bind multiple integer textures to usamplers for unsigned int and isampler for integer
Then on the basis of the value of the main CT image I set the gray value - in case of mask it should give color when isvisibile is set to true and associated mask value is >0
is visible and color uniforms set on runtime
Below Fragment shader
#extension GL_EXT_gpu_shader4 : enable //Include support for this extension, which defines usampler2D
out vec4 FragColor;
in vec3 ourColor;
smooth in vec2 TexCoord0;
uniform int min_shown_white = 400;//400 ;// value of cut off - all values above will be shown as white
uniform int max_shown_black = -200;//value cut off - all values below will be shown as black
uniform float displayRange = 600.0;
uniform isampler2D CTIm; // main image sampler
uniform int CTImisVisible = 1; // controllin main texture visibility
//in case of int texture controlling color display of main image we keep all above some value as white and all below some value as black
vec4 mainColor(in int texel)
{
if(CTImisVisible==0){
return vec4(0.0, 0.0, 0.0, 1.0);
}
else if(texel >min_shown_white){
return vec4(1.0, 1.0, 1.0, 1.0);
}
else if (texel< max_shown_black){
return vec4(0.0, 0.0, 0.0, 1.0);
}
else{
float fla = float(texel-max_shown_black) ;
float fl = fla/displayRange ;
return vec4(fl, fl, fl, 1.0);
}
}
uniform usampler2D mainLab; // mask image sampler
uniform vec4 mainLabColorMask= vec4(0.4,0.7,0.8,0.9); //controlling colors
uniform int mainLabisVisible= 1; // controlling visibility
uniform usampler2D testLab1; // mask image sampler
uniform vec4 testLab1ColorMask= vec4(0.4,0.7,0.8,0.9); //controlling colors
uniform int testLab1isVisible= 1; // controlling visibility
void main()
{
uint mainLabRes = texture2D(mainLab, TexCoord0).r * mainLabisVisible ; // is visible is 0 texture2D also evaluates to either 0 or 1
uint testLab1Res = texture2D(testLab1, TexCoord0).r * testLab1isVisible ;
vec4 CTImRes = mainColor(texture2D(CTIm, TexCoord0).r);
FragColor = vec4(( (mainLabColorMask.r * mainLabRes) + (testLab1ColorMask.r * testLab1Res)
+CTImRes.r )/3 ,( (mainLabColorMask.g * mainLabRes) + (testLab1ColorMask.g * testLab1Res)
+CTImRes.g) /3, ( (mainLabColorMask.b * mainLabRes) + (testLab1ColorMask.b * testLab1Res)
+CTImRes.b ) /3, 1.0 ); //long product, if mask is invisible it just has full transparency
}
Here is how I initialize each texture
glGenTextures(1, texture);
glBindTexture(GL_TEXTURE_2D, texture[]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RType, width, height);
and I update by
glBindTexture(GL_TEXTURE_2D, textSpec.ID);
glTexSubImage2D(GL_TEXTURE_2D,0,xoffset,yoffset, widthh,
heightt, GL_RED_INTEGER, textSpec.OpGlType, data)
glBindTexture(GL_TEXTURE_2D, 0)
So after initializing all textures to random values (in case of masks it is 0 or 1 ) and get sth like below ( clearly there should be multiple colors as some values of the integer textures are 1 in some texels and in others not , as random generator will output 1 in different places in different textures)
Thanks for help !