WebGL – GLSL – “vec3.rgb” 和 “vec3.xyz” 之间有什么区别?

huangapple go评论61阅读模式
英文:

WebGL - GLSL - What's the difference between vec3.rgb and vec3.xyz?

问题

使用.rgb.xyz处理GLSL着色器中的vec3时有什么区别?

例如,在一些示例中,我看到了.rgb

void main() {
    vec3 color = vec3(1.0, 0.0, 0.0);
    gl_FragColor = vec4(color.rgb, 1.0); // <-- 使用 color.rgb
}

但在其他示例中,我看到了.xyz

void main() {
    vec3 color = vec3(1.0, 0.0, 0.0);
    gl_FragColor = vec4(color.xyz, 1.0); // <-- 使用 color.xyz
}
英文:

What is the difference between using .rgb and .xyz when dealing with a vec3 in a GLSL shader?

For example, in some examples I see .rgb:

void main() {
    vec3 color = vec3(1.0, 0.0, 0.0);
    gl_FragColor = vec4(color.rgb, 1.0); // <-- using color.rgb
}

But in other examples I see .xyz:

void main() {
    vec3 color = vec3(1.0, 0.0, 0.0);
    gl_FragColor = vec4(color.xyz, 1.0); // <-- using color.xyz
}

答案1

得分: 2

没有真正的区别。它们是用来引用相同数据的“语法糖”。

参见:数据类型“swizzling”

英文:

There is no real difference. They're "syntactic sugar" for referencing the same data.

See: Data type "swizzling"

huangapple
  • 本文由 发表于 2023年7月18日 05:41:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76708247.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定