text.vert.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * Copyright (c) 2019-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. export const text_vert = `
  7. precision highp float;
  8. precision highp int;
  9. #include common
  10. #include read_from_texture
  11. #include common_vert_params
  12. #include color_vert_params
  13. #include size_vert_params
  14. #include common_clip
  15. uniform mat4 uModelView;
  16. attribute vec3 aPosition;
  17. attribute vec2 aMapping;
  18. attribute float aDepth;
  19. attribute vec2 aTexCoord;
  20. attribute mat4 aTransform;
  21. attribute float aInstance;
  22. attribute float aGroup;
  23. uniform float uOffsetX;
  24. uniform float uOffsetY;
  25. uniform float uOffsetZ;
  26. // uniform bool ortho;
  27. uniform float uPixelRatio;
  28. uniform vec4 uViewport;
  29. varying vec2 vTexCoord;
  30. #include matrix_scale
  31. void main(void){
  32. #include assign_group
  33. #include assign_color_varying
  34. #include assign_marker_varying
  35. #include assign_clipping_varying
  36. #include assign_size
  37. vTexCoord = aTexCoord;
  38. float scale = matrixScale(uModelView);
  39. float offsetX = uOffsetX * scale;
  40. float offsetY = uOffsetY * scale;
  41. float offsetZ = (uOffsetZ + aDepth * 0.95) * scale;
  42. vec4 position4 = vec4(aPosition, 1.0);
  43. vec4 mvPosition = uModelView * aTransform * position4;
  44. vModelPosition = (uModel * aTransform * position4).xyz; // for clipping in frag shader
  45. // TODO
  46. // #ifdef FIXED_SIZE
  47. // if (ortho) {
  48. // scale /= pixelRatio * ((uViewport.w / 2.0) / -uCameraPosition.z) * 0.1;
  49. // } else {
  50. // scale /= pixelRatio * ((uViewport.w / 2.0) / -mvPosition.z) * 0.1;
  51. // }
  52. // #endif
  53. vec4 mvCorner = vec4(mvPosition.xyz, 1.0);
  54. if (vTexCoord.x == 10.0) { // indicates background plane
  55. // move a bit to the back, taking distance to camera into account to avoid z-fighting
  56. offsetZ -= 0.001 * distance(uCameraPosition, (uProjection * mvCorner).xyz);
  57. }
  58. mvCorner.xy += aMapping * size * scale;
  59. mvCorner.x += offsetX;
  60. mvCorner.y += offsetY;
  61. // TODO
  62. // if(ortho){
  63. // mvCorner.xyz += normalize(-uCameraPosition) * offsetZ;
  64. // } else {
  65. // mvCorner.xyz += normalize(-mvCorner.xyz) * offsetZ;
  66. // }
  67. mvCorner.xyz += normalize(-mvCorner.xyz) * offsetZ;
  68. gl_Position = uProjection * mvCorner;
  69. vViewPosition = -mvCorner.xyz;
  70. #include clip_instance
  71. }
  72. `;