当我们的源代码从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 = "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);这是片段着色器,它与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);给出了相同的结果。因此,我假定coord是正确计算的。
当我们从#120跳到#410时,我可以想象,我需要做一些其他的事情来使texture在我们的片段着色器中工作。GLSL是否有任何相关的变化。我该怎么做才能让着色器正常工作?
如果相关,以下是一些系统信息:
发布于 2020-02-26 19:46:41
这里的问题出现在场景图中,因为纹理和纹理单元节点都位于SoSeparator下,并且在SoSeparator localRoot之外的shaderProgam中不可见。请将这些节点移出localRoot,并将它们作为子节点添加到根节点中,以便正确呈现。
它是为您工作与开放发明家9.8,因为一个错误,这是固定的,是固定的,从10。希望这有帮助,并让我们知道如果问题是为您解决的。
在未来,请随时联系开放发明者支持( FRBOR.3d_hotline@thermofisher.com)与您的问题。
发布于 2020-02-27 15:38:15
通过邮件,Open支持建议了另一种解决方案,该解决方案也在发挥作用:
替换
SoSeparator* localRoot = new SoSeparator;使用
SoGroup* localRoot = new SoGroup;https://stackoverflow.com/questions/60390108
复制相似问题