Skip to content

Instantly share code, notes, and snippets.

@games
Created October 19, 2015 08:33
Show Gist options
  • Select an option

  • Save games/3015a9194d3823654d7e to your computer and use it in GitHub Desktop.

Select an option

Save games/3015a9194d3823654d7e to your computer and use it in GitHub Desktop.
VideoShader
namespace trio {
var vertexShader = `
precision lowp float;
attribute vec2 aVertexPosition;
attribute vec2 aTextureCoord;
attribute vec4 aColor;
uniform mat3 projectionMatrix;
varying vec2 vTextureCoord;
varying vec4 vColor;
void main(void){
gl_Position = vec4((projectionMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);
vTextureCoord = aTextureCoord;
vColor = vec4(aColor.rgb * aColor.a, aColor.a);
}`;
var fragmentShader = `
precision lowp float;
varying vec2 vTextureCoord;
varying vec4 vColor;
uniform sampler2D uSampler;
void main(void) {
float texelAlpha = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t * 0.5 + 0.5)).r;
vec4 color = texture2D(uSampler, vec2(vTextureCoord.s, vTextureCoord.t * 0.5)) * vColor;
gl_FragColor = vec4(color.rgb, color.a * texelAlpha);
}`;
export class VideoShader extends PIXI.Shader {
constructor(shaderManager: PIXI.ShaderManager) {
var uniforms = {
uSampler: { type: 'sampler2D', value: 0 },
projectionMatrix: { type: 'mat3', value: new Float32Array([1, 0, 0,
0, 1, 0,
0, 0, 1]) }
};
var attributes = {
aVertexPosition: 0,
aTextureCoord: 0,
aColor: 0
};
super(shaderManager, vertexShader, fragmentShader, uniforms, attributes);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment