-
Notifications
You must be signed in to change notification settings - Fork 219
/
lightspark.frag
45 lines (37 loc) · 992 Bytes
/
lightspark.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
uniform sampler2D g_tex1;
uniform vec2 texScale;
//We abuse of default varying to pass variou data
//gl_Color: Selector of current shader function
//gl_TexCoord[0]: Fill color/Texture coordinate
const mat3 YUVtoRGB = mat3( 1, 1, 1, //First coloumn
0, -0.344, 1.772, //Second coloumn
1.402, -0.714, 0); //Third coloumn
vec4 solid_color()
{
return gl_TexCoord[0];
}
vec4 linear_gradient()
{
//vec2 coord=vec2(float(gl_FragCoord.x)/1000.0,0);
//return texture2D(g_tex1,coord);
//TODO: not working, accessing gl_FragCoord causes access violation
return vec4(0,0,1,1);
}
vec4 tex_lookup()
{
return texture2D(g_tex1,gl_TexCoord[0].xy*texScale);
}
vec4 tex_lookup_yuv()
{
//Pixel format is VUYA
vec4 val=texture2D(g_tex1,gl_TexCoord[0].xy*texScale).bgra-vec4(0,0.5,0.5,0);
val.rgb=YUVtoRGB*(val.rgb);
return val;
}
void main()
{
gl_FragColor=(solid_color()*gl_Color.x)+
(linear_gradient()*gl_Color.y)+
(tex_lookup()*gl_Color.z)+
(tex_lookup_yuv()*gl_Color.w);
}