While upgrading our source code from OpenInventor 9.8 to 10.4.2 I encountered that some color computed in the fragment-shader is always black in 10.4.2 while in 9.8 everything works fine. Normally we use our own computed texture, but for debugging purposes I used an example texture from the OpenInventor examples:
SoSwitch* root = new SoSwitch;
// Fill root with geometry
root->addChild(...)
SoSeparator* localRoot = new SoSeparator;
SoFragmentShader* fragShader = new SoFragmentShader;
SoShaderProgram* shaderProgram = new SoShaderProgram;
SoTexture2 texture = new SoTexture2;
texture->filename = "pathToImage\image.png"
SoTextureUnit textureUnit = new SoTextureUnit;
texture Unit->unit = 1;
localRoot->addChild(textureUnit);
localRoot->addChild(texture);
fragShader->addShaderParameter1i("myTexture", 1);
shaderProgram->shaderObject.set1Value(1, fragShader);
root->addChild(localRoot);
root->addChild(shaderProgram);
This is the fragment-shader which works fine with 9.8:
#version 120
uniform sampler2D myTexture;
in vec3 coord; // Computed in vertex-shader
int main() {
gl_FragColor = texture2D(myTexture, coord.xy);
// For Debugging:
// gl_FragColor = vec4(coord.xy, 0, 1);
}
This is the fragment-shader which does not work with 10.4.2:
#version 410 compatibility
//!oiv_include <Inventor/oivShaderState.h>
//!oiv_include <Inventor/oivShapeAttribute.h>
//!oiv_include <Inventor/oivShaderVariables.h>
uniform sampler2D myTexture;
in vec3 coord;
int main() {
OivFragmentOutput(texture(myTexture, coord.xy)); // Is the same as gl_FragColor =
// For Debugging:
// gl_FragColor = vec4(coord.xy, 0, 1);
}
The viewer stays completely black, so I assume the call to texture
returns always zero.
Uncommenting gl_FragColor = vec4(coord.xy, 0, 1);
gives the same result. Therefor I assume that coord
is computed correctly.
As we are jumping from version #120 to #410, I could imagine that I need to do something else to get texture
work in our fragment-shader. Were there any relevant changes in GLSL
. What do I need to do to get the shader working?
If relevant, here are some system information:
The issue here is in your scene graph as both texture and textureUnit nodes are under a SoSeparator and are not visible to the shaderProgam, which is outside the SoSeparator localRoot. Please move these nodes out of localRoot and add them as a child to the root node to render correctly.
It was working for you with Open Inventor 9.8 because of a bug which is fixed since Open Inventor 10. Hope this helps and let us know if the issue is resolved for you.
In future, please feel free to contact Open Inventor support ( FRBOR.3d_hotline@thermofisher.com) with your questions.