[vlc-devel] [PATCH 2/2] opengl: renderer: respect spherical-v2 for cubemap

Alexandre Janniaux ajanni at videolabs.io
Thu Jul 9 21:12:26 CEST 2020


The metadata signalling the usage of a cubemap are defined in the
spatial-media repository[1] and enforce a specific layout for layout
identifier 0, which is the only one specified.

Implement this layout instead of the previous one, which was Facebook
one (using Mongolfiere 360 sample), especially given that Facebook has
mostly gone to equirectangular 360 videos since then.

It fixes the definition of each face so that they match their natual
axis with the following coordinate system (x being forward, and z being
a vector to the left, the whole in right-hand convention):

       y     x
          \ |
           \|
   z <-----(+)

It now uses the following picture layout:

1
 +-------+-------+------+
 | right | left  | up   |
 +-------+-------+------+      v
 | down  | front | back |      |
 +-------+-------+------+      +-- u
0                        1

For testing purpose, one can generate a sample for this format by using
ffmpeg, for example by converting an equirectangular video into cubemap
using the v360 filter.

   -lavfi v360=input=equirect:output=c3x2

Matroska projection can also be set, for example with:

   mkvpropedit sample --edit track:v1 --set projection-type=2

[1]: https://github.com/google/spatial-media/blob/master/docs/spherical-video-v2-rfc.md#cubemap-projection-box-cbmp
---
 modules/video_output/opengl/renderer.c | 42 +++++++++++++-------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/modules/video_output/opengl/renderer.c b/modules/video_output/opengl/renderer.c
index 1bdcdeea300..cb94c73caeb 100644
--- a/modules/video_output/opengl/renderer.c
+++ b/modules/video_output/opengl/renderer.c
@@ -548,15 +548,15 @@ static int BuildCube(float padW, float padH,
     swap(value,  1.f,  1.f), \
     swap(value,  1.f, -1.f)
 
-#define X_FACE(v, a, b) (v), (b), (a)
+#define X_FACE(v, a, b) (v), (a), (b)
 #define Y_FACE(v, a, b) (a), (v), (b)
 #define Z_FACE(v, a, b) (a), (b), (v)
 
     static const GLfloat coord[] = {
-        CUBEFACE(Z_FACE, -1.f), // FRONT
-        CUBEFACE(Z_FACE, +1.f), // BACK
-        CUBEFACE(X_FACE, -1.f), // LEFT
-        CUBEFACE(X_FACE, +1.f), // RIGHT
+        CUBEFACE(X_FACE, -1.f), // FRONT
+        CUBEFACE(X_FACE, +1.f), // BACK
+        CUBEFACE(Z_FACE, +1.f), // LEFT
+        CUBEFACE(Z_FACE, -1.f), // RIGHT
         CUBEFACE(Y_FACE, -1.f), // BOTTOM
         CUBEFACE(Y_FACE, +1.f), // TOP
     };
@@ -572,15 +572,15 @@ static int BuildCube(float padW, float padH,
     float row[] = {0.f, 1.f/2, 1.0};
 
     const GLfloat tex[] = {
-        col[1] + padW, row[1] - padH, // front
-        col[1] + padW, row[0] + padH,
-        col[2] - padW, row[1] - padH,
-        col[2] - padW, row[0] + padH,
-
-        col[3] - padW, row[1] - padH, // back
-        col[3] - padW, row[0] + padH,
-        col[2] + padW, row[1] - padH,
+        col[1] + padW, row[0] - padH, // front
         col[2] + padW, row[0] + padH,
+        col[1] - padW, row[1] - padH,
+        col[2] - padW, row[1] + padH,
+
+        col[3] - padW, row[0] - padH, // back
+        col[2] - padW, row[0] + padH,
+        col[3] + padW, row[1] - padH,
+        col[2] + padW, row[1] + padH,
 
         col[2] - padW, row[2] - padH, // left
         col[2] - padW, row[1] + padH,
@@ -592,15 +592,15 @@ static int BuildCube(float padW, float padH,
         col[1] - padW, row[2] - padH,
         col[1] - padW, row[1] + padH,
 
-        col[0] + padW, row[0] + padH, // bottom
-        col[0] + padW, row[1] - padH,
-        col[1] - padW, row[0] + padH,
-        col[1] - padW, row[1] - padH,
+        col[0] + padW, row[1] + padH, // bottom
+        col[1] + padW, row[1] - padH,
+        col[0] - padW, row[0] + padH,
+        col[1] - padW, row[0] - padH,
 
-        col[2] + padW, row[2] - padH, // top
-        col[2] + padW, row[1] + padH,
-        col[3] - padW, row[2] - padH,
-        col[3] - padW, row[1] + padH,
+        col[2] + padW, row[1] - padH, // top
+        col[3] + padW, row[1] + padH,
+        col[2] - padW, row[2] - padH,
+        col[3] - padW, row[2] + padH,
     };
 
     memcpy(*textureCoord, tex,
-- 
2.27.0



More information about the vlc-devel mailing list