OctahedralProjectionAtlasFS.glsl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. in vec2 v_textureCoordinates;
  2. uniform float originalSize;
  3. uniform sampler2D texture0;
  4. uniform sampler2D texture1;
  5. uniform sampler2D texture2;
  6. uniform sampler2D texture3;
  7. uniform sampler2D texture4;
  8. uniform sampler2D texture5;
  9. const float yMipLevel1 = 1.0 - (1.0 / pow(2.0, 1.0));
  10. const float yMipLevel2 = 1.0 - (1.0 / pow(2.0, 2.0));
  11. const float yMipLevel3 = 1.0 - (1.0 / pow(2.0, 3.0));
  12. const float yMipLevel4 = 1.0 - (1.0 / pow(2.0, 4.0));
  13. void main()
  14. {
  15. vec2 uv = v_textureCoordinates;
  16. vec2 textureSize = vec2(originalSize * 1.5 + 2.0, originalSize);
  17. vec2 pixel = 1.0 / textureSize;
  18. float mipLevel = 0.0;
  19. if (uv.x - pixel.x > (textureSize.y / textureSize.x))
  20. {
  21. mipLevel = 1.0;
  22. if (uv.y - pixel.y > yMipLevel1)
  23. {
  24. mipLevel = 2.0;
  25. if (uv.y - pixel.y * 3.0 > yMipLevel2)
  26. {
  27. mipLevel = 3.0;
  28. if (uv.y - pixel.y * 5.0 > yMipLevel3)
  29. {
  30. mipLevel = 4.0;
  31. if (uv.y - pixel.y * 7.0 > yMipLevel4)
  32. {
  33. mipLevel = 5.0;
  34. }
  35. }
  36. }
  37. }
  38. }
  39. if (mipLevel > 0.0)
  40. {
  41. float scale = pow(2.0, mipLevel);
  42. uv.y -= (pixel.y * (mipLevel - 1.0) * 2.0);
  43. uv.x *= ((textureSize.x - 2.0) / textureSize.y);
  44. uv.x -= 1.0 + pixel.x;
  45. uv.y -= (1.0 - (1.0 / pow(2.0, mipLevel - 1.0)));
  46. uv *= scale;
  47. }
  48. else
  49. {
  50. uv.x *= (textureSize.x / textureSize.y);
  51. }
  52. if(mipLevel == 0.0)
  53. {
  54. out_FragColor = texture(texture0, uv);
  55. }
  56. else if(mipLevel == 1.0)
  57. {
  58. out_FragColor = texture(texture1, uv);
  59. }
  60. else if(mipLevel == 2.0)
  61. {
  62. out_FragColor = texture(texture2, uv);
  63. }
  64. else if(mipLevel == 3.0)
  65. {
  66. out_FragColor = texture(texture3, uv);
  67. }
  68. else if(mipLevel == 4.0)
  69. {
  70. out_FragColor = texture(texture4, uv);
  71. }
  72. else if(mipLevel == 5.0)
  73. {
  74. out_FragColor = texture(texture5, uv);
  75. }
  76. else
  77. {
  78. out_FragColor = vec4(0.0);
  79. }
  80. }