Source: core/graphics/webgl/shaders/PrimitiveShader.js

core/graphics/webgl/shaders/PrimitiveShader.js

  1. import Shader from '../../../Shader';
  2. /**
  3. * This shader is used to draw simple primitive shapes for {@link PIXI.Graphics}.
  4. *
  5. * @class
  6. * @memberof PIXI
  7. * @extends PIXI.Shader
  8. */
  9. export default class PrimitiveShader extends Shader
  10. {
  11. /**
  12. * @param {WebGLRenderingContext} gl - The webgl shader manager this shader works for.
  13. */
  14. constructor(gl)
  15. {
  16. super(gl,
  17. // vertex shader
  18. [
  19. 'attribute vec2 aVertexPosition;',
  20. 'attribute vec4 aColor;',
  21. 'uniform mat3 translationMatrix;',
  22. 'uniform mat3 projectionMatrix;',
  23. 'uniform float alpha;',
  24. 'uniform vec3 tint;',
  25. 'varying vec4 vColor;',
  26. 'void main(void){',
  27. ' gl_Position = vec4((projectionMatrix * translationMatrix * vec3(aVertexPosition, 1.0)).xy, 0.0, 1.0);',
  28. ' vColor = aColor * vec4(tint * alpha, alpha);',
  29. '}',
  30. ].join('\n'),
  31. // fragment shader
  32. [
  33. 'varying vec4 vColor;',
  34. 'void main(void){',
  35. ' gl_FragColor = vColor;',
  36. '}',
  37. ].join('\n')
  38. );
  39. }
  40. }