opengl - 从 gl_FragColor 切换到“out”值没有渲染
问题描述
我正在升级很多旧的 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变量,它将正常工作,但是当我写入meshColor而不是gl_FragData[0]时,我看不到屏幕上显示任何内容,也没有 GL 错误。
我是否需要在着色器中或 C++ 代码外部执行任何其他操作才能使用此输出变量?
解决方案
我想到了。我在着色器中隐藏了一个参数,所以它实际上并没有写入输出变量。
layout(location = 0) out vec4 meshColor;
...
vec4 meshColor = texture(meshTexture, uvs);
...
meshColor = vec4(diffuseColor, 0); // writing to the local instance
}
推荐阅读
- html - Angular 6如何在html的表格行上正确应用条件
- c# - Entity Framework Core 1:n 关系导致循环
- r - 使用 `future_lapply()` 时如何将消息打印到控制台?
- javascript - 如何在 Node.js 中将 Markdown 解析为 HTML 树?
- flutter - listView 中的分组单选按钮
- node.js - server.js 未读取 Dotenv 文件
- php - Gravity 表单条目的 if else 语句
- javascript - 触发跨度不工作的 onchange 事件
- amazon-cloudformation - 我可以在 CloudFormation 中创建一个运行 aws cli 命令来更新注册域的名称服务器的 lambda 函数吗?
- clojure - 在 Clojure 中将地图列表转换为地图