Opengl 从gl_FragColor切换到";“出去”;值不呈现任何内容

Opengl 从gl_FragColor切换到";“出去”;值不呈现任何内容,opengl,glsl,Opengl,Glsl,我正在升级我的很多老OpenGL代码,包括一个片段着色器,试图删除对gl_FragColor的引用似乎不起作用 #version 330 varying vec2 uvs; uniform vec3 cameraPos; uniform vec4 brushColor; uniform sampler2D meshTexture; uniform sampler2D paintTexture; uniform int paintFboWidth; layout(location = 0) o

我正在升级我的很多老OpenGL代码,包括一个片段着色器,试图删除对gl_FragColor的引用似乎不起作用

#version 330

varying vec2 uvs;
uniform vec3 cameraPos;
uniform vec4 brushColor;
uniform sampler2D meshTexture;
uniform sampler2D paintTexture;
uniform int paintFboWidth;

layout(location = 0) out vec4 meshColor; // added this

void main() {
    vec2 paintUvs = vec2(gl_FragCoord.x/paintFboWidth, gl_FragCoord.y/paintFboWidth);
    float paintIntensity = texture(paintTexture, paintUvs).r;
    vec4 meshColor = texture(meshTexture, uvs);
    vec3 diffuseColor = mix(meshColor.rgb, brushColor.rgb, paintIntensity);

    meshColor = vec4(diffuseColor, 0); // added this
    //gl_FragData[0] = vec4(diffuseColor, 0); // trying to remove this
}
据我所知,如果切换到out变量,它将正常工作,但当我写入MESHCLOR而不是gl_FragData[0]时,我在屏幕上看不到任何显示,也没有gl错误


我需要做任何其他的着色器或外部的C++代码来使用这个变量吗?p> 我明白了。我对着色器中的一个参数进行了阴影处理,因此它实际上没有写入输出变量

layout(location = 0) out vec4 meshColor;
...
    vec4 meshColor = texture(meshTexture, uvs);
    ...

    meshColor = vec4(diffuseColor, 0); // writing to the local instance
}

尝试“out vec4 meshColor”而不是布局(location=0)out vec4 meshColor;在glsl版本3.30中,片段着色器输入由中的kyword
指定,而不是由
变量指定。因此,在vec2 UV中它必须是
删除布局(…)内容没有帮助。我想我最终需要这种语法来处理多种颜色的附件。另外,将“variang”改为“in”似乎也没有什么帮助。