【发布时间】:2015-05-21 01:30:03
【问题描述】:
如果您不设置,GLSL 中输出颜色的默认值是多少?
#version 330
uniform sampler2DRect colorTex;
uniform vec3 backgroundColor;
out vec4 outputColor;
void main(void)
{
vec4 frontColor = texture(colorTex, gl_FragCoord.xy);
outputColor.rgb = frontColor + backgroundColor * frontColor.a;
}
是 (0, 0, 0, 1) 吗?
Ps:该代码属于旧GL,尝试与GL3一起使用,我收到以下错误
错误 C7011:从“vec4”隐式转换为“vec3”
我认为在旧 GL 中允许隐式转换是正确的?
这是Nvidia的前后深度剥离示例的片段着色器,你可以找到代码here,org.jogl.demos.dualdepthpeeling\org.jogl.demos.dualdepthpeeling\src\demos\dualDepthPeeling\着色器\front_peeling_final_fragment.glsl
【问题讨论】:
-
要修复错误,请将其更改为
outputColor.rgb = frontColor.rgb + backgroundColor * frontColor.a; -
@RichardViney,是的,我知道,但是该代码是深度剥离示例的原始示例,我想了解作者的意思
-
也许他们将
backgroundColor声明为vec4。你不能这样直接vec4 + vec3。 -
@RichardViney 我不知道,我认为这不太可能,因为在代码中他们有效地加载了一个 vec3 制服。(ps:我在问题中插入了原始代码的链接)
-
这是一个非常古老的样本。来自 NVIDIA 的早期 GLSL 编译器可能会允许这样的自动转换(当它建立在他们的 Cg 编译器上时),但它在现代 GLSL 中肯定是无效的。幸运的是,修复很简单。
标签: vector glsl shader default-value opengl-3