Home Reference Source

src/renderer/GPURenderer/Desktop/shaders/vertexShader.js

  1. import { DATA_TEXTURE_SIZE } from '../../common/TextureAtlas/constants';
  2. import { SIZE_ATTENUATION_FACTOR } from '../../common/shaders/constants';
  3.  
  4. export const vertexShader = () => {
  5. return `
  6. uniform sampler2D uTexture;
  7. //atlasIndex is a 256x1 float texture of tile rectangles as r=minx g=miny b=maxx a=maxy
  8. uniform sampler2D atlasIndex;
  9.  
  10. attribute float size;
  11. attribute vec3 color;
  12. attribute float alpha;
  13. attribute float texID;
  14. attribute float rotation;
  15.  
  16. varying float vRotation;
  17. varying vec3 targetColor;
  18. varying float targetAlpha;
  19. varying vec4 tileRect;
  20. varying float tileID;
  21.  
  22. void main() {
  23. vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
  24. targetColor = color;
  25. targetAlpha = alpha;
  26. vRotation = rotation;
  27.  
  28. tileID = texID;
  29. //get the tile rectangle from the atlasIndex texture..
  30. tileRect = texture2D(atlasIndex, vec2((tileID + 0.5) / ${DATA_TEXTURE_SIZE}.0, 0.5));
  31.  
  32. gl_PointSize = ((size * ${SIZE_ATTENUATION_FACTOR}) / -mvPosition.z);
  33. gl_Position = projectionMatrix * mvPosition;
  34. }
  35. `;
  36. };