OpenInventor从9.8升级到10.4.2后,GLSL纹理返回零

GLSL texture returns zero after OpenInventor upgrade from 9.8 to 10.4.2

本文关键字:GLSL 纹理 返回 8升 OpenInventor      更新时间:2023-10-16

在将我们的源代码从OpenInventor 9.8升级到10.4.2时,我发现在10.4.2中碎片着色器中计算的某些颜色始终为黑色,而在9.8中一切正常。通常我们使用自己计算的纹理,但出于调试目的,我使用了OpenInventor示例中的示例纹理:

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 = "pathToImageimage.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);

这是一个碎片着色器,适用于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);
}

这是不适用于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);
}

查看器保持完全黑色,因此我假设对texture的调用始终返回零。取消对gl_FragColor = vec4(coord.xy, 0, 1);的注释会得到相同的结果。因此,我认为CCD_ 3的计算是正确的。

当我们从#120版本跳到#410版本时,我可以想象我需要做一些其他的事情来让texture在我们的片段着色器中工作。GLSL是否有任何相关变化。我需要做什么才能使着色器工作?

如果相关,这里有一些系统信息:

  • 操作系统:Windows 10
  • 显卡:NVIDIA Quadro K2200

这里的问题出现在场景图中,因为纹理textureUnit节点都在SoSeparator下,并且对位于SoSeparatorlocalRoot外部的shaderProgam不可见。请将这些节点移出localRoot,并将它们作为子节点添加到root节点以正确渲染。

它适用于Open Inventor 9.8,因为自Open Inventor 10以来修复了一个错误。希望这能有所帮助,如果问题为您解决了,请告诉我们。

以后,请随时联系Open Inventor支持人员(FRBOR.3d_hotline@thermofisher.com)回答您的问题。

Open Inventor支持部门通过邮件建议了另一个也在运行的解决方案:

更换

SoSeparator* localRoot = new SoSeparator;

带有

SoGroup* localRoot = new SoGroup;