本文介绍了texture2D().r和texture2D().a是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using OpenGL ES in Android programming, when I transform YUV(NV21) to RGB in shader, like:

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数据.

then I'll get YUV data that seperating from u_TextureY and u_TextureUV.

我知道NV21格式是:YYYYYY ... UVUV ...但是如何将YUYV422转换为RGB?所以,我的问题是texture2D(u_TextureY, vTextureCoord).r和.a中的"r"和"a"是什么意思?然后我找到了做YUYV422-> RGB的方法.

I know that NV21 format is like: YYYYYY...UVUV... BUT how can I transform YUYV422 to RGB?So, my problem is what do "r" and "a" mean in texture2D(u_TextureY, vTextureCoord).r and .a ? then I can find the way to do YUYV422->RGB.

推荐答案

texture2D的返回类型为vec4.在GLSL中,可以分别访问向量的组成部分:

The return type of texture2D is vec4. In GLSL the components of the vector can be separately accessed:

请参见 OpenGL阴影语言规范:

向量或标量的组成部分的名称用单个字母表示.为方便起见,基于位置,颜色或纹理坐标矢量的常用用法,几个字母与每个组件相关联.可以通过跟随变量来选择各个组件 带有句点(.)的名称,然后是组件名称.

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.

支持的组件名称为:

  • {x, y, z, w}在访问表示点或法线的向量时很有用

  • {x, y, z, w} Useful when accessing vectors that represent points or normals

{r, g, b, a}在访问代表颜色的矢量时很有用

{r, g, b, a} Useful when accessing vectors that represent colors

{s, t, p, q}在访问表示纹理坐标的矢量时很有用

{s, t, p, q} Useful when accessing vectors that represent texture coordinates

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的第4个组成部分.


This means, that .r gives the 1st component of the vec4 and .a gives the 4th component of the vec4.

这篇关于texture2D().r和texture2D().a是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 12:37