从OpenGL ES着色语言中的vec4获取alpha浮点数

时间:2010-12-22 21:53:02

标签: opengl-es

这可能听起来很愚蠢,但我不太确定如何从输入的vec4中获取“W”组件。我在规范中读到你无法获得单独的组件,所以也许甚至提问也是错误的。

谢谢!

2 个答案:

答案 0 :(得分:4)

我认为您可能误读了规范 - 阅读单个组件完全有效。 GLSL甚至允许隐式排列和原始组件的组合,例如

lowp vec4 someVector;

// someVector.xy is a lowp vec2 containing the first two scalars from someVector
// someVector.zwx is a lowp vec3 containing the third, fourth and first scalars in that order
// someVector.w is a lowp float containing the fourth scalar

例如,我使用了片段着色器:

void main()
{
    lowp vec4 srcPixel = texture2D(tex2D, texCoordVarying);
    lowp vec4 yuvPixel = rgbToYuv * srcPixel;

    yuvPixel.r *= 3.0;

    gl_FragColor = yuvToRgb * yuvPixel;
}

使用合适的矩阵和变化来提升纹理的亮度三倍。

答案 1 :(得分:1)

我假设您可以计算点积。所以只需乘以另一个包含(0,0,0,1)的vec4。

编辑:但是,你确定你不能简单地使用.w吗?我找到的所有文档和示例都说你可以。