用OpenGL shader实现将YUV转RGB
最近看到开源的OpenGL ES用shader实现YUV转RGB,但是有一点看不太懂,请教各位大侠指导指导哇,谢谢啦!以下为片段着色器的代码
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D t_texture_y;
uniform sampler2D t_texture_u;
uniform sampler2D t_texture_v;
varying vec2 uvVarying;
void main()
{
float y,u,v,r,g,b, gradx, grady;
y = texture2D(t_texture_y, uvVarying).r;
u = texture2D(t_texture_u, uvVarying).r;
v = texture2D(t_texture_v, uvVarying).r;
y = 1.16438355 * (y - 0.0625);
u = u - 0.5;
v = v - 0.5;
r = clamp(y + 1.596 * v, 0.0, 1.0);
g = clamp(y - 0.391 * u - 0.813 * v, 0.0, 1.0);
b = clamp(y + 2.018 * u, 0.0, 1.0);
gl_FragColor = vec4(r,g,b,1.0);
}
不知道其中的texture2D(t_texture_y, uvVarying).r,为什么是r值,而且都是r值赋给y,u,v ??
还有其中的顶点着色器代码如下
attribute vec2 position;
attribute vec2 uv;
uniform mat4 proj_matrix;
uniform float rotation;
varying vec2 uvVarying;
void main()
{
mat3 rot = mat3(vec3(cos(rotation), sin(rotation),0.0), vec3(-sin(rotation), cos(rotation), 0.0), vec3(0.0, 0.0, 1.0));
gl_Position = proj_matrix * vec4(rot * vec3(position.xy, 0.0), 1.0);
uvVarying = uv;
}
关于main()中的第一行代码,为什么那么多三角函数? 有什么用吗?
本人初学OpenGL,很多都不太懂,忘各位大侠多多指导啊,谢谢啦!
补充:移动开发 , Android