Created
October 19, 2015 08:33
-
-
Save games/3015a9194d3823654d7e to your computer and use it in GitHub Desktop.
VideoShader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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