• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

android - texture2D().r 和 texture2D().a 是什么意思?

[复制链接]
菜鸟教程小白 发表于 2022-12-9 06:50:46 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我在 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:

  • {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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap