alemart / encantar-js

encantAR.js: GPU-accelerated Augmented Reality for the web. Fast, easy to use and device-agnostic WebAR.
https://alemart.github.io/encantar-js/
GNU Lesser General Public License v3.0
56 stars 10 forks source link

Camera freezes on Chrome Android #8

Closed devlak2001 closed 4 months ago

devlak2001 commented 4 months ago

Hello, sorry I noticed another issue. When I try to open the camera on Chrome Android, the camera freezes. I get the following error in the console.

`Tracking error:

GLError: WebGL error.

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

0:59: S0032: no default precision defined for variable 'vec4[9]'

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

  1. version 300 es

    1. if 0 == 0

    2. precision mediump float;
    3. precision mediump sampler2D;
    4. precision highp int;
    5. endif

    6. if 0 == 0

    7. define OUT_TYPE mediump vec4

    8. elif 0 == 1

    9. define OUT_TYPE mediump ivec4

    10. elif 0 == 2

    11. define OUT_TYPE mediump uvec4

    12. else

    13. error Unknown FS_OUTPUT_TYPE

    14. endif

    15. out OUT_TYPE color;
    16. in highp vec2 texCoord;
    17. uniform highp vec2 texSize;
    18. ifndef _GLOBAL_GLSL

    19. define _GLOBAL_GLSL

    20. define threadLocation() ivec2(texCoord * texSize)

    21. define outputSize() ivec2(texSize)

    22. define threadPixel(img) textureLod((img), texCoord, 0.0f)

    23. define pixelAt(img, pos) texelFetch((img), (pos), 0)

    24. define pixelAtShortOffset(img, offset) textureLodOffset((img), texCoord, 0.0f, (offset))

    25. define pixelAtLongOffset(img, offset) textureLod((img), texCoord + vec2(offset) / texSize, 0.0f)

    26. endif

    27. ifndef _PYRAMIDS_GLSL

    28. define _PYRAMIDS_GLSL

    29. define pyrPixel(pyr, lod) textureLod((pyr), texCoord, (lod))

    30. define pyrPixelAtOffset(pyr, lod, pot, offset) textureLod((pyr), texCoord + ((pot) * vec2(offset)) / texSize, (lod))

    31. define pyrPixelAt(pyr, pos, lod) textureLod((pyr), (vec2(pos) + vec2(0.5f)) / texSize, (lod))

    32. define pyrPixelAtEx(pyr, pos, lod, pyrBaseSize) textureLod((pyr), (vec2(pos) + vec2(0.5f)) / vec2(pyrBaseSize), (lod))

    33. define pyrSubpixelAtEx(pyr, pos, lod, pyrBaseSize) textureLod((pyr), ((pos) + vec2(0.5f)) / vec2(pyrBaseSize), (lod))

    34. define pyrSubpixelAtExOffset(pyr, pos, lod, pot, offset, pyrBaseSize) textureLod((pyr), (((pos) + vec2(0.5f)) + ((pot) * vec2(offset))) / vec2(pyrBaseSize), (lod))

    35. const int PYRAMID_MAX_LEVELS = int(8);
    36. const float F_PYRAMID_MAX_LEVELS = float(8);
    37. const float LOG2_PYRAMID_MAX_SCALE = float(0);
    38. define encodeLod(lod) ((LOG2_PYRAMID_MAX_SCALE + (lod)) / (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS))

    39. float decodeLod(float encodedLod)
    40. {
    41. float lod = encodedLod * (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS) - LOG2_PYRAMID_MAX_SCALE;
    42. return lod - lod * step(1.0f, encodedLod);
    43. }
    44. define LOD_EPS 0.0625f

    45. const float ENCODED_LOD_EPS = (LOD_EPS / (LOG2_PYRAMID_MAX_SCALE + F_PYRAMID_MAX_LEVELS));
    46. define isSameLod(lod1, lod2) (abs((lod1) - (lod2)) < LOD_EPS)

    47. define isSameEncodedLod(alpha1, alpha2) (abs((alpha1) - (alpha2)) < ENCODED_LOD_EPS)

    48. endif

    49. ifndef _FLOAT16_GLSL

    50. define _FLOAT16_GLSL

    51. define encodeFloat16(f) (vec2(packf16(f)) / 255.0f)

    52. define decodeFloat16(v) unpackf16(uvec2((v) * 255.0f))

    53. define encodePairOfFloat16(f) vec4(encodeFloat16((f).x), encodeFloat16((f).y))

    54. define decodePairOfFloat16(v) vec2(decodeFloat16((v).rg), decodeFloat16((v).ba))

    55. define encodeNullPairOfFloat16() vec4(1.0f)

    56. define isNullPairOfFloat16(v) all(equal((v), encodeNullPairOfFloat16()))

    57. define encodeDiscardedPairOfFloat16() vec4(0.0f, 1.0f, 0.0f, 1.0f)

    58. define isDiscardedPairOfFloat16(v) all(equal((v), encodeDiscardedPairOfFloat16()))

    59. define encodeFloat16NaN() vec2(0.5f, 1.0f)

    60. define isEncodedFloat16NaN(v) all(equal((v), encodeFloat16NaN()))

    61. uvec2 packf16( float f)
    62. {
    63. uint y = packHalf2x16(vec2(f, 0.0f));
    64. return uvec2(y, y >> 8u) & 0xFFu;
    65. }
    66. float unpackf16(uvec2 v)
    67. {
    68. v &= 0xFFu;
    69. return unpackHalf2x16(v.x | (v.y << 8u)).x;
    70. }
    71. bool isEncodedFloat16Zero(vec2 v)
    72. {
    73. uvec2 w = uvec2(v * 255.0f);
    74. return 0u == w.x + w.y * (0x80u - w.y);
    75. }
    76. endif

    77. uniform sampler2D corners;
    78. void main()
    79. {
    80. ivec2 thread = threadLocation();
    81. vec4 pixel = threadPixel(corners);
    82. float encodedLod = pixel.a;
    83. float score = decodeFloat16(pixel.rb);
    84. float lod = decodeLod(encodedLod);
    85. float pot = exp2(lod);
    86. color = pixel;
    87. if(score == 0.0f)
    88. return;
    89. if 1

    90. vec2 gridSize = vec2(pot);
    91. vec2 gridLocation = floor(mod(texCoord * texSize, gridSize));
    92. vec2 gridDelta = gridLocation / gridSize - vec2(0.5f);
    93. float gridStep = 1.0f / pot;
    94. const float adjustment = 1.25f;
    95. color.rb = encodeFloat16(0.0f);
  2. if(max(abs(gridDelta.x), abs(gridDelta.y)) > adjustment * gridStep)
  3. return;
  4. endif

  5. define P(x,y) textureLod(corners, texCoord + pot * vec2((x), (y)) / texSize, 0.0f)

  6. vec4 pix[9] = vec4[9](
  7. P(-1,-1), P(0,-1), P(1,-1),
  8. P(-1,0), pixel, P(1,0),
  9. P(-1,1), P(0,1), P(1,1)
  10. );
  11. define S(j) decodeFloat16(pix[j].rb)

  12. mat3 scores = mat3(
  13. S(0), S(1), S(2),
  14. S(3), S(4), S(5),
  15. S(6), S(7), S(8)
  16. );
  17. define B(j) float(isSameLod(decodeLod(pix[j].a), lod))

  18. mat3 sameLod = mat3(
  19. B(0), B(1), B(2),
  20. B(3), B(4), B(5),
  21. B(6), B(7), B(8)
  22. );
  23. mat3 sameLodScores = matrixCompMult(scores, sameLod);
  24. vec3 maxScore3 = max(sameLodScores[0], max(sameLodScores[1], sameLodScores[2]));
  25. float maxScore = max(maxScore3.x, max(maxScore3.y, maxScore3.z));
  26. color.rb = encodeFloat16(score * step(maxScore, score));
  27. }`
alemart commented 4 months ago

Hello! Please upgrade to version 0.2.0. This was already fixed in speedy-vision.

https://github.com/alemart/martins-js/releases

devlak2001 commented 4 months ago

Thanks!