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:
- Operating System: Windows 10
- Graphics board: NVIDIA Quadro K2200