shader.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export const vertexShader = `
  2. attribute vec3 color;
  3. attribute float size;
  4. attribute float angle;
  5. attribute float opacity;
  6. attribute float visible;
  7. varying vec4 vColor;
  8. varying float vAngle;
  9. uniform float heightOfNearPlane;
  10. void main() {
  11. if(visible > 0.5) {
  12. vColor = vec4(color, opacity);
  13. } else {
  14. vColor = vec4(0.0, 0.0, 0.0, 0.0);
  15. }
  16. vAngle = angle;
  17. vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
  18. gl_Position = projectionMatrix * mvPosition;
  19. gl_PointSize = ( heightOfNearPlane * size ) / gl_Position.w;
  20. }
  21. `
  22. export const fragmentShader = `
  23. uniform sampler2D u_sampler;
  24. varying vec4 vColor;
  25. varying float vAngle;
  26. void main() {
  27. gl_FragColor = vColor;
  28. float u = cos(vAngle);
  29. float v = sin(vAngle);
  30. vec2 uv = vec2(
  31. u * (gl_PointCoord.x - 0.5) + v * (gl_PointCoord.y - 0.5) + 0.5,
  32. u * (gl_PointCoord.y - 0.5) - v * (gl_PointCoord.x - 0.5) + 0.5
  33. );
  34. vec4 texture = texture2D(u_sampler, uv);
  35. gl_FragColor = gl_FragColor * texture;
  36. }
  37. `