Browse Source

Fix conversion from Rec 601 to RGBA in WebGL shader

phoboslab 8 years ago
parent
commit
341de38ebc
1 changed files with 11 additions and 9 deletions
  1. 11 9
      src/webgl.js

+ 11 - 9
src/webgl.js View File

@@ -188,17 +188,19 @@ WebGLRenderer.SHADER = {
188 188
 		'uniform sampler2D textureCr;',
189 189
 		'varying vec2 texCoord;',
190 190
 
191
+		'mat4 rec601 = mat4(',
192
+			'1.16438,  0.00000,  1.59603, -0.87079,',
193
+			'1.16438, -0.39176, -0.81297,  0.52959,',
194
+			'1.16438,  2.01723,  0.00000, -1.08139,',
195
+			'0, 0, 0, 1',
196
+		');',
197
+
191 198
 		'void main() {',
192 199
 			'float y = texture2D(textureY, texCoord).r;',
193
-			'float cb = texture2D(textureCb, texCoord).r - 0.5;',
194
-			'float cr = texture2D(textureCr, texCoord).r - 0.5;',
195
-
196
-			'gl_FragColor = vec4(',
197
-				'y + 1.4 * cb,',
198
-				'y + -0.343 * cr - 0.711 * cb,',
199
-				'y + 1.765 * cr,',
200
-				'1.0',
201
-			');',
200
+			'float cb = texture2D(textureCb, texCoord).r;',
201
+			'float cr = texture2D(textureCr, texCoord).r;',
202
+
203
+			'gl_FragColor = vec4(y, cr, cb, 1.0) * rec601;',
202 204
 		'}'
203 205
 	].join('\n'),
204 206