0
\$\begingroup\$

I have a shader to perform LUT coloring of a texture and a c++/c# programs that call it which work perfectly when i use a 1D texture.
Since i need to support computers that don't support the 1D texture in the shader i thought the easiest would be to convert the 1D texture to a 2D texture with the height==1.
After the conversion (1D -> 2D) when i run the program it seems that the LUT 2D texture is received gray in the shader. I render the exact same texture in another place (not using a shader) in the program and the texture looks fine (same as it did when i used a 1D texture).
The shader code:

uniform sampler2D FluorImage;  
uniform sampler2D FluorColorLutRGBA;  

void main(void)  
{  
  vec3 FluorPix = texture2D(FluorImage, gl_TexCoord[0].st).rgb;  
  vec2 Coord = vec2(FluorPix.g, 0.0);  
  vec4 NewColorFluor = texture2D(FluorColorLutRGBA, Coord).rgba;  
  gl_FragColor.rgb  = NewColorFluor.rgb;  
}  

The texture creation code

glGenTextures(1, &m_FluorShadersParams[fpsFused].m_LutTexture);  
glBindTexture(GL_TEXTURE_2D, m_FluorShadersParams[fpsFused].m_LutTexture);  
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);  
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);  
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);  
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  

glActiveTexture(FluorTextureIndexes[fpsFused]);  
glBindTexture(GL_TEXTURE_2D, m_FluorShadersParams[fpsFused].m_LutTexture);  

glActiveTexture(GL_TEXTURE0);  
glBindTexture(GL_TEXTURE_2D, 0);  

Filling the texture with data

glActiveTexture(a_FluorTextureIndexes[fpsFused]);  
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i, 256, 1, GL_RGBA, GL_UNSIGNED_BYTE, pLUT);  
glActiveTexture(GL_TEXTURE0);  

Calling the shader

glUseProgram(m_progObj[fsFluorFused]);

glActiveTexture(FluorTextureIndexes[fpsFused]);
glBindTexture(GL_TEXTURE_2D, FluorTextureIndexesNum[fpsFused]);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, inputTextures[eftIR]); // Fluor image

glBindFramebuffer(GL_FRAMEBUFFER,outputFBO.m_FBO[eftFused]);

uniformLoc = glGetUniformLocation(m_progObj[fsFluorFused], "FluorImage");
if (uniformLoc != -1)
{
  glUniform1i(uniformLoc, 1);
}

uniformLoc = glGetUniformLocation(m_progObj[fsFluorFused], "FluorColorLutRGBA");
if (uniformLoc != -1)
{
  glUniform1i(uniformLoc, FluorTextureIndexesNum[fpsFused]); 
}

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_QUADS);
 glTexCoord2f(0,    fTextureRatioY);            
 glVertex2f(0,      fTextureRatioY);
 glTexCoord2f(fTextureRatioX,   fTextureRatioY);      
 glVertex2f(fTextureRatioX,     fTextureRatioY);
 glTexCoord2f(fTextureRatioX,   0);         
 glVertex2f(fTextureRatioX,     0);
 glTexCoord2f(0,        0);      
 glVertex2f(0,          0);
glEnd();

glUseProgram(0);
glActiveTexture(GL_TEXTURE0);

glBindFramebuffer(GL_FRAMEBUFFER,0);
glBindTexture(GL_TEXTURE_2D,0);

The strange thing is that if i change all the places in the code back from Texture2D into Texture1D and the sampler in the shader to 1D everything works great.
Anyone has any idea where the issue can be?

\$\endgroup\$
  • 2
    \$\begingroup\$ Should you try putting a 0.5 as an y texture coordinate instead of 0.0? \$\endgroup\$ – Matic Oblak Sep 9 '14 at 19:03
  • 1
    \$\begingroup\$ Add a code where you load and configure that LUT texture. \$\endgroup\$ – Kromster Sep 10 '14 at 4:20
  • \$\begingroup\$ I tried to use both 0.5 and 1.0 in the shader as the Y index but it has no effect. \$\endgroup\$ – Shachar Sep 10 '14 at 8:10
  • \$\begingroup\$ How is pLUT filled? The problem might be there. \$\endgroup\$ – BezierHelpMe Sep 10 '14 at 15:46
  • \$\begingroup\$ The definition of pLUT is unsigned char LUT[256][4]. It is loaded from a text file and i checked with a debugger and the values in it are ok. As i said above this code is identical for 1D and 2D textures and works perfectly with 1D texture \$\endgroup\$ – Shachar Sep 11 '14 at 6:08
1
\$\begingroup\$

Try using this instead:

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 256, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, pLUT);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.