sprites.vertex.fx 1.1 KB

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