Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is the completed shader with all channels and RGB conversion (no filtering is performed however):</p> <pre><code>#version 130 #extension GL_EXT_gpu_shader4 : enable in vec2 texcoord; uniform mediump sampler2D tex; out mediump vec4 color; // YUV offset const vec3 yuvOffset = vec3(-0.0625, -0.5, -0.5); // RGB coefficients // BT.601 colorspace const vec3 Rcoeff = vec3(1.1643, 0.000, 1.5958); const vec3 Gcoeff = vec3(1.1643, -0.39173, -0.81290); const vec3 Bcoeff = vec3(1.1643, 2.017, 0.000); // U Y V A | Y U Y A | V Y U A | Y V Y A int GROUP_FOR_INDEX(int i) { return i / 4; } int SUBINDEX_FOR_INDEX(int i) { return i % 4; } int _y(int i) { return 2 * i + 1; } int _u(int i) { return 4 * (i/2); } int _v(int i) { return 4 * (i / 2) + 2; } int offset(int i) { return i + (i / 3); } vec3 ycbcr2rgb(vec3 yuvToConvert) { vec3 pix; yuvToConvert += yuvOffset; pix.r = dot(yuvToConvert, Rcoeff); pix.g = dot(yuvToConvert, Gcoeff); pix.b = dot(yuvToConvert, Bcoeff); return pix; } void main(void) { ivec2 size = textureSize2D(tex, 0).xy; // 480x486 ivec2 sizeOrig = ivec2(size.x * 1.5, size.y); // 720x486 // interpolate 0,0 -&gt; 1,1 texcoords to 0,0 -&gt; 720,486 ivec2 texcoordDenorm = ivec2(texcoord * sizeOrig); // 0 1 1 2 3 3 4 5 5 6 7 7 etc. int yOffset = offset(_y(texcoordDenorm.x)); int sourceColumnIndexY = GROUP_FOR_INDEX(yOffset); // 0 0 1 1 2 2 4 4 5 5 6 6 etc. int uOffset = offset(_u(texcoordDenorm.x)); int sourceColumnIndexU = GROUP_FOR_INDEX(uOffset); // 0 0 2 2 3 3 4 4 6 6 7 7 etc. int vOffset = offset(_v(texcoordDenorm.x)); int sourceColumnIndexV = GROUP_FOR_INDEX(vOffset); // 1 0 2 1 0 2 1 0 2 etc. int compY = SUBINDEX_FOR_INDEX(yOffset); // 0 0 1 1 2 2 0 0 1 1 2 2 etc. int compU = SUBINDEX_FOR_INDEX(uOffset); // 2 2 0 0 1 1 2 2 0 0 1 1 etc. int compV = SUBINDEX_FOR_INDEX(vOffset); vec4 y = texelFetch(tex, ivec2(sourceColumnIndexY, texcoordDenorm.y), 0); vec4 u = texelFetch(tex, ivec2(sourceColumnIndexU, texcoordDenorm.y), 0); vec4 v = texelFetch(tex, ivec2(sourceColumnIndexV, texcoordDenorm.y), 0); vec3 outColor = ycbcr2rgb(vec3(y[compY], u[compU], v[compV])); color = vec4(outColor, 1.0); } </code></pre> <p>If the image is going to be scaled up on the screen then you will likely want to do bilinear filtering, but this will need to be performed within the shader.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload