我在 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_TextureY 和 u_TextureUV 分开的 YUV 数据。
我知道 NV21 格式类似于:YYYYYY...UVUV... 但是如何将 YUYV422 转换为 RGB?
所以,我的问题是 texture2D(u_TextureY, vTextureCoord).r 和 .a 中的“r”和“a”是什么意思?那么我可以找到做YUYV422->RGB的方法。
Best Answer-推荐答案 strong>
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:
{x, y, z, w} Useful when accessing vectors that represent points or normals
{r, g, b, a} Useful when accessing vectors that represent colors
{s, t, p, q} Useful when accessing vectors that represent texture coordinates
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/
|