OGeek|极客世界-中国程序员成长平台

标题: android - texture2D().r 和 texture2D().a 是什么意思? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-9 06:50
标题: android - texture2D().r 和 texture2D().a 是什么意思?

我在 Android 编程中使用 OpenGL ES,当我在着色器中将 YUV(NV21) 转换为 RGB 时,例如:

vec3 yuv = vec3(
        (texture2D(u_TextureY, vTextureCoord).r - 0.0625),
        texture2D(u_TextureUV, vTextureCoord).a - 0.5,
        texture2D(u_TextureUV, vTextureCoord).r - 0.5
    );

然后我会得到与 u_TextureYu_TextureUV 分开的 YUV 数据。

我知道 NV21 格式类似于:YYYYYY...UVUV... 但是如何将 YUYV422 转换为 RGB? 所以,我的问题是 texture2D(u_TextureY, vTextureCoord).r 和 .a 中的“r”和“a”是什么意思?那么我可以找到做YUYV422->RGB的方法。



Best Answer-推荐答案


texture2D的返回类型是vec4。在 GLSL 中,向量的分量可以单独访问:

The OpenGL Shading Language specification :

5.5 Vector and Scalar Components and Length

The names of the components of a vector or scalar are denoted by a single letter. As a notational convenience, several letters are associated with each component based on common usage of position, color or texture coordinate vectors. The individual components can be selected by following the variable name with period ( . ) and then the component name.

The component names supported are:

The order of the components can be different to swizzle them, or replicated:

vec4 pos = vec4(1.0, 2.0, 3.0, 4.0);
vec4 swiz= pos.wzyx; // swiz = (4.0, 3.0, 2.0, 1.0)
vec4 dup = pos.xxyy; // dup = (1.0, 1.0, 2.0, 2.0)
float f = 1.2;
vec4 dup = f.xxxx; // dup = (1.2, 1.2, 1.2, 1.2)


这意味着,.r 给出了 vec4 的第一个组件,而 .a 给出了 vec4 的第四个组件>.

关于android - texture2D().r 和 texture2D().a 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47671934/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://www.ogeek.cn/) Powered by Discuz! X3.4