- Use consts for the transform's offset and cofficients values
- Use dot product instead of mult and add
- Avoid unneeded texture lookups
"precision mediump float;"
"varying vec2 opos;"
"uniform sampler2D Ytex,Utex,Vtex;"
"precision mediump float;"
"varying vec2 opos;"
"uniform sampler2D Ytex,Utex,Vtex;"
+ "const vec3 offset = vec3(-0.0625, -0.5, -0.5);"
+ "const vec3 rcoeff = vec3(1.164, 0.000, 1.596);"
+ "const vec3 gcoeff = vec3(1.164,-0.391,-0.813);"
+ "const vec3 bcoeff = vec3(1.164, 2.018, 0.000);"
+ " float r,g,b;"
+ " vec3 yuv;"
- " y=texture2D(Ytex,nxy).r;"
- " u=texture2D(Utex,nxy).r;"
- " v=texture2D(Vtex,nxy).r;"
- " y=1.1643*(y-0.0625);"
- " u=u-0.5;"
- " v=v-0.5;"
- " r=y+1.5958*v;"
- " g=y-0.39173*u-0.81290*v;"
- " b=y+2.017*u;"
+ " yuv.x=texture2D(Ytex,nxy).r;"
+ " yuv.y=texture2D(Utex,nxy).r;"
+ " yuv.z=texture2D(Vtex,nxy).r;"
+ " yuv += offset;"
+ " r = dot(yuv, rcoeff);"
+ " g = dot(yuv, gcoeff);"
+ " b = dot(yuv, bcoeff);"
" gl_FragColor=vec4(r,g,b,1.0);"
"}"
};
" gl_FragColor=vec4(r,g,b,1.0);"
"}"
};
"precision mediump float;"
"varying vec2 opos;"
"uniform sampler2D Ytex,UVtex;"
"precision mediump float;"
"varying vec2 opos;"
"uniform sampler2D Ytex,UVtex;"
+ "const vec3 offset = vec3(-0.0625, -0.5, -0.5);"
+ "const vec3 rcoeff = vec3(1.164, 0.000, 1.596);"
+ "const vec3 gcoeff = vec3(1.164,-0.391,-0.813);"
+ "const vec3 bcoeff = vec3(1.164, 2.018, 0.000);"
+ " float r,g,b;"
+ " vec3 yuv;"
- " y=texture2D(Ytex,nxy).r;"
- " u=texture2D(UVtex,nxy).%c;"
- " v=texture2D(UVtex,nxy).%c;"
- " y=1.1643*(y-0.0625);"
- " u=u-0.5;"
- " v=v-0.5;"
- " r=y+1.5958*v;"
- " g=y-0.39173*u-0.81290*v;"
- " b=y+2.017*u;"
+ " yuv.x=texture2D(Ytex,nxy).r;"
+ " yuv.y=texture2D(UVtex,nxy).%c;"
+ " yuv.z=texture2D(UVtex,nxy).%c;"
+ " yuv += offset;"
+ " r = dot(yuv, rcoeff);"
+ " g = dot(yuv, gcoeff);"
+ " b = dot(yuv, bcoeff);"
" gl_FragColor=vec4(r,g,b,1.0);"
"}"
};
" gl_FragColor=vec4(r,g,b,1.0);"
"}"
};