sprites.vertex.fx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifdef GL_ES
  2. precision highp float;
  3. #endif
  4. // Attributes
  5. attribute vec4 position;
  6. attribute vec4 options;
  7. attribute vec4 cellInfo;
  8. attribute vec4 color;
  9. // Uniforms
  10. uniform vec2 textureInfos;
  11. uniform mat4 view;
  12. uniform mat4 projection;
  13. // Output
  14. varying vec2 vUV;
  15. varying vec4 vColor;
  16. #ifdef FOG
  17. varying float fFogDistance;
  18. #endif
  19. void main(void) {
  20. vec3 viewPos = (view * vec4(position.xyz, 1.0)).xyz;
  21. vec2 cornerPos;
  22. float angle = position.w;
  23. vec2 size = vec2(options.x, options.y);
  24. vec2 offset = options.zw;
  25. vec2 uvScale = textureInfos.xy;
  26. cornerPos = vec2(offset.x - 0.5, offset.y - 0.5) * size;
  27. // Rotate
  28. vec3 rotatedCorner;
  29. rotatedCorner.x = cornerPos.x * cos(angle) - cornerPos.y * sin(angle);
  30. rotatedCorner.y = cornerPos.x * sin(angle) + cornerPos.y * cos(angle);
  31. rotatedCorner.z = 0.;
  32. // Position
  33. viewPos += rotatedCorner;
  34. gl_Position = projection * vec4(viewPos, 1.0);
  35. // Color
  36. vColor = color;
  37. // Texture
  38. vec2 uvOffset = vec2(abs(offset.x - cellInfo.x), 1.0 - abs(offset.y - cellInfo.y));
  39. vUV = (uvOffset + cellInfo.zw) * uvScale;
  40. // Fog
  41. #ifdef FOG
  42. fFogDistance = viewPos.z;
  43. #endif
  44. }