alemart / martins-js

GPU-accelerated Augmented Reality for the web.

Home Page:https://alemart.github.io/martins-js/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

live demos not working on Safari or Chrome IOS

gavan1 opened this issue · comments

commented

Video stream freezes and motion from device motion not being pickup up.

Feature tracking is working and 3d objects are appearing.#3

I'm seeing the same result. This is the error-

martins.min.js:20 [martins-js] Tracking error: o: WebGL error.

---------- ERROR ----------

0:73: S0032: no default precision defined for variable 'vec4[9]'�
Program has not been successfully linked.

---------- SOURCE CODE ----------

  1. #version 300 es
  2. #if 0 == 0
  3. precision mediump float;
  4. precision mediump sampler2D;
  5. precision highp int;
  6. #endif
  7. #if 0 == 0
  8. #define OUT_TYPE mediump vec4
  9. #elif 0 == 1
  10. #define OUT_TYPE mediump ivec4
  11. #elif 0 == 2
  12. #define OUT_TYPE mediump uvec4
  13. #else
  14. #error Unknown FS_OUTPUT_TYPE
  15. #endif
  16. out OUT_TYPE color;
  17. in highp vec2 texCoord;
  18. uniform highp vec2 texSize;
  19. #ifndef _GLOBAL_GLSL
  20. #define _GLOBAL_GLSL
  21. #define threadLocation() ivec2(texCoord * texSize)
  22. #define outputSize() ivec2(texSize)
  23. #define threadPixel(img) textureLod((img), texCoord, 0.0f)
  24. #define pixelAt(img, pos) texelFetch((img), (pos), 0)
  25. #define pixelAtShortOffset(img, offset) textureLodOffset((img), texCoord, 0.0f, (offset))
  26. #define pixelAtLongOffset(img, offset) textureLod((img), texCoord + vec2(offset) / texSize, 0.0f)
  27. #endif
  28. #ifndef _PYRAMIDS_GLSL
  29. #define _PYRAMIDS_GLSL
  30. #define pyrPixel(pyr, lod) textureLod((pyr), texCoord, (lod))
  31. #define pyrPixelAtOffset(pyr, lod, pot, offset) textureLod((pyr), texCoord + ((pot) * vec2(offset)) / texSize, (lod))
  32. #define pyrPixelAt(pyr, pos, lod) textureLod((pyr), (vec2(pos) + vec2(0.5f)) / texSize, (lod))
  33. #define pyrPixelAtEx(pyr, pos, lod, pyrBaseSize) textureLod((pyr), (vec2(pos) + vec2(0.5f)) / vec2(pyrBaseSize), (lod))
  34. #define pyrSubpixelAtEx(pyr, pos, lod, pyrBaseSize) textureLod((pyr), ((pos) + vec2(0.5f)) / vec2(pyrBaseSize), (lod))
  35. #define pyrSubpixelAtExOffset(pyr, pos, lod, pot, offset, pyrBaseSize) textureLod((pyr), (((pos) + vec2(0.5f)) + ((pot) * vec2(offset))) / vec2(pyrBaseSize), (lod))
  36. const int PYRAMID_MAX_LEVELS = int(8);
  37. const float F_PYRAMID_MAX_LEVELS = float(8);
  38. const float LOG2_PYRAMID_MAX_SCALE = float(0);
  39. #define encodeLod(lod) ((LOG2_PYRAMID_MAX_SCALE + (lod)) / (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS))
  40. float decodeLod(float encodedLod)
  41. {
  42. float lod = encodedLod * (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS) - LOG2_PYRAMID_MAX_SCALE;
  43. return lod - lod * step(1.0f, encodedLod);
  44. }
  45. #define LOD_EPS 0.0625f
  46. const float ENCODED_LOD_EPS = (LOD_EPS / (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS));
  47. #define isSameLod(lod1, lod2) (abs((lod1) - (lod2)) < LOD_EPS)
  48. #define isSameEncodedLod(alpha1, alpha2) (abs((alpha1) - (alpha2)) < ENCODED_LOD_EPS)
  49. #endif
  50. #ifndef _FLOAT16_GLSL
  51. #define _FLOAT16_GLSL
  52. #define encodeFloat16(f) (vec2(packf16(f)) / 255.0f)
  53. #define decodeFloat16(v) unpackf16(uvec2((v) * 255.0f))
  54. #define encodePairOfFloat16(f) vec4(encodeFloat16((f).x), encodeFloat16((f).y))
  55. #define decodePairOfFloat16(v) vec2(decodeFloat16((v).rg), decodeFloat16((v).ba))
  56. #define encodeNullPairOfFloat16() vec4(1.0f)
  57. #define isNullPairOfFloat16(v) all(equal((v), encodeNullPairOfFloat16()))
  58. #define encodeDiscardedPairOfFloat16() vec4(0.0f, 1.0f, 0.0f, 1.0f)
  59. #define isDiscardedPairOfFloat16(v) all(equal((v), encodeDiscardedPairOfFloat16()))
  60. #define encodeFloat16NaN() vec2(0.5f, 1.0f)
  61. #define isEncodedFloat16NaN(v) all(equal((v), encodeFloat16NaN()))
  62. uvec2 packf16( float f)
  63. {
  64. uint y = packHalf2x16(vec2(f, 0.0f));
  65. return uvec2(y, y >> 8u) & 0xFFu;
  66. }
  67. float unpackf16(uvec2 v)
  68. {
  69. v &= 0xFFu;
  70. return unpackHalf2x16(v.x | (v.y << 8u)).x;
  71. }
  72. bool isEncodedFloat16Zero(vec2 v)
  73. {
  74. uvec2 w = uvec2(v * 255.0f);
  75. return 0u == w.x + w.y * (0x80u - w.y);
  76. }
  77. #endif
  78. uniform sampler2D corners;
  79. void main()
  80. {
  81. ivec2 thread = threadLocation();
  82. vec4 pixel = threadPixel(corners);
  83. float encodedLod = pixel.a;
  84. float score = decodeFloat16(pixel.rb);
  85. float lod = decodeLod(encodedLod);
  86. float pot = exp2(lod);
  87. color = pixel;
  88. if(score == 0.0f)
  89. return;
  90. #if 1
  91. vec2 gridSize = vec2(pot);
  92. vec2 gridLocation = floor(mod(texCoord * texSize, gridSize));
  93. vec2 gridDelta = gridLocation / gridSize - vec2(0.5f);
  94. float gridStep = 1.0f / pot;
  95. const float adjustment = 1.25f;
  96. color.rb = encodeFloat16(0.0f);
  97. if(max(abs(gridDelta.x), abs(gridDelta.y)) > adjustment * gridStep)
  98. return;
  99. #endif
  100. #define P(x,y) textureLod(corners, texCoord + pot * vec2((x), (y)) / texSize, 0.0f)
  101. vec4 pix[9] = vec4[9](
  102. P(-1,-1), P(0,-1), P(1,-1),
  103. P(-1,0), pixel, P(1,0),
  104. P(-1,1), P(0,1), P(1,1)
  105. );
  106. #define S(j) decodeFloat16(pix[j].rb)
  107. mat3 scores = mat3(
  108. S(0), S(1), S(2),
  109. S(3), S(4), S(5),
  110. S(6), S(7), S(8)
  111. );
  112. #define B(j) float(isSameLod(decodeLod(pix[j].a), lod))
  113. mat3 sameLod = mat3(
  114. B(0), B(1), B(2),
  115. B(3), B(4), B(5),
  116. B(6), B(7), B(8)
  117. );
  118. mat3 sameLodScores = matrixCompMult(scores, sameLod);
  119. vec3 maxScore3 = max(sameLodScores[0], max(sameLodScores[1], sameLodScores[2]));
  120. float maxScore = max(maxScore3.x, max(maxScore3.y, maxScore3.z));
  121. color.rb = encodeFloat16(score * step(maxScore, score));
  122. }

-> [speedy-vision.js]
warning @ martins.min.js:20

@skeegan Thanks for the feedback. I intend to get it working on Safari and iOS.

The error you are seeing has to do with a shader not being compiled due to a driver bug. I fix these kinds of errors in my library Speedy Vision. Once they are fixed, the AR demos here will work.

May I ask you to test the following Speedy Vision demos?

  1. https://alemart.github.io/speedy-vision/demos/best-features.html
  2. https://alemart.github.io/speedy-vision/demos/feature-matching.html
  3. https://alemart.github.io/speedy-vision/demos/feature-matching-lsh.html

You are expected to see points and lines. If you see errors in the console, please let me know.

Hi @alemart , Thanks for your response. Each of those three works for me in Chrome on a Google Pixel 7A (no errors in console).

Any idea on when the other AR demo will be working?

@skeegan Thanks for testing. I have updated the Speedy Vision version used in the demos.

May you test the AR demos again? Try the basic webcam and the WebGL demos. You are expected to see an animation in augmented reality. If you see any errors in the console, let me know.

You should see MARTINS.js version 0.1.2-wip and Speedy Vision version 0.9.1-wip in the console. Please clear the browser cache if you don't.

Hi @alemart,

I'm seeing the correct versions for MARTINS.js and for Speedy Vision. However, I'm now getting a different error:

martins.min.js:20 [martins-js] Tracking error: r: WebGL error.

_---------- ERROR ----------

0:207: S0032: no default precision defined for variable 'mat3[2]'�
Program has not been successfully linked._

[
alemart.github.io-1704882393420.log
](url)
(full log attached)

@skeegan This is a similar driver bug that has to do with an initializer. Would you try again? If you see the same error, please clear the browser cache.

it works now- thanks.

Quick question: You say that Safari support is coming soon. Any idea when that might be ready?

it works now- thanks.

Awesome!

Quick question: You say that Safari support is coming soon. Any idea when that might be ready?

Yes: when a volunteer helps me test it on Safari. Support for Safari is probably just a tiny change ahead.

Since I started this project back in 2022, the Epiphany browser (WebKit-based) received WebGL2 support. I was able to run the demos on a version of Epiphany.

I don't own a Mac nor an iOS device at the present time, so I'm using Epiphany as a suitable alternative to Safari. I would like to have this project tested on actual Apple hardware as well.

Could your code be adapted to enable floor detection (for tap-to-place)?

That would require implementing a new tracker. I don't have this feature in mind at this moment. I thank you for your interest in my work.

To whom it might interest: Safari 15 is the minimum required version.

If you're a Safari user, your feedback is appreciated.

I have good news: now we have Safari support.

I managed to test the WebAR demos on several iOS devices. After a small adjustment, I could get them to work on versions 15.2 or newer of the Safari browser (though not on Safari 15.0-15.1).

I have tested the demos on the following devices: iPhone 11 Pro (iOS 15.5), iPhone 12 (iOS 15.6.1), iPhone 12 Pro (iOS 15.0.2), iPhone 13 (iOS 15.0.2), iPhone 13 Pro (iOS 15.2), iPhone 13 Pro Max (iOS 15.1), iPhone 14 (iOS 16.1 and iOS 16.6.1), iPhone XR (iOS 16.4), iPad mini (iPadOS 15.1) and iPad Air (iPadOS 15.4.1). The demos work on every device with Safari 15.2 or newer. Tested on the AWS Device Farm.

If you're a iOS or a macOS user, your feedback is much appreciated. I was not able to test the camera feed on the cloud, and yet the engine seemed to work as expected.

Here is a video of a demo working on iOS (the FPS/GPU rates indicate good performance):

safari-demo.mp4