Source: particles/webgl/ParticleShader.js

particles/webgl/ParticleShader.js

  1. import Shader from '../../core/Shader';
  2. /**
  3. * @class
  4. * @extends PIXI.Shader
  5. * @memberof PIXI
  6. */
  7. export default class ParticleShader extends Shader
  8. {
  9. /**
  10. * @param {PIXI.Shader} gl - The webgl shader manager this shader works for.
  11. */
  12. constructor(gl)
  13. {
  14. super(
  15. gl,
  16. // vertex shader
  17. [
  18. 'attribute vec2 aVertexPosition;',
  19. 'attribute vec2 aTextureCoord;',
  20. 'attribute vec4 aColor;',
  21. 'attribute vec2 aPositionCoord;',
  22. 'attribute float aRotation;',
  23. 'uniform mat3 projectionMatrix;',
  24. 'uniform vec4 uColor;',
  25. 'varying vec2 vTextureCoord;',
  26. 'varying vec4 vColor;',
  27. 'void main(void){',
  28. ' float x = (aVertexPosition.x) * cos(aRotation) - (aVertexPosition.y) * sin(aRotation);',
  29. ' float y = (aVertexPosition.x) * sin(aRotation) + (aVertexPosition.y) * cos(aRotation);',
  30. ' vec2 v = vec2(x, y);',
  31. ' v = v + aPositionCoord;',
  32. ' gl_Position = vec4((projectionMatrix * vec3(v, 1.0)).xy, 0.0, 1.0);',
  33. ' vTextureCoord = aTextureCoord;',
  34. ' vColor = aColor * uColor;',
  35. '}',
  36. ].join('\n'),
  37. // hello
  38. [
  39. 'varying vec2 vTextureCoord;',
  40. 'varying vec4 vColor;',
  41. 'uniform sampler2D uSampler;',
  42. 'void main(void){',
  43. ' vec4 color = texture2D(uSampler, vTextureCoord) * vColor;',
  44. ' gl_FragColor = color;',
  45. '}',
  46. ].join('\n')
  47. );
  48. }
  49. }