在将我们的源代码从 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
。我需要做什么才能让着色器工作?
如果相关,以下是一些系统信息:
- 操作系统:Windows 10
- 显卡:NVIDIA Quadro K2200