Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

SDK : GLator transform 3D issue

Explorer ,
Sep 18, 2023 Sep 18, 2023

Hi everyone, 

 

Maybe someone can help me:

I have successfully run the GLator sample plugin, and modified it to display a different layer (user selects a layer in the UI, the plugin checkouts out the layer and passes it to OpenGL to display it). 

It works fine, however, I also want OpenGL to display the selected layer with its transform data (position, scale, rotation etc), even if it is 3D.

 

Here is the code I've modified inside of the RenderGL() method. 

.....
// view matrix, mimic windows coordinates
vmath::Matrix4 ModelviewProjection = vmath::Matrix4::translation(vmath::Vector3(-1.0f, -1.0f, 0.0f)) * vmath::Matrix4::scale(vmath::Vector3(2.0 / float(widthL), 2.0 / float(heightL), 1.0f));
vmath::Matrix4 transformMatrix = A_Matrix4ToMatrix4(layerTransformMatrix4x4);
vmath::Matrix4 resultMatrix = ModelviewProjection * transformMatrix;

glBindTexture(GL_TEXTURE_2D, inputFrameTexture);
glUseProgram(renderContext->mProgramObjSu);

// program uniforms
GLint location = glGetUniformLocation(renderContext->mProgramObjSu, "ModelviewProjection");
glUniformMatrix4fv(location, 1, GL_FALSE, (GLfloat*)&resultMatrix);
.....

 

Explanation:

layerTransformMatrix4x4 is the transform matrix of the selected layer, that was retrieved using AEGP_GetLayerToWorldXform(). It contains all the transform data, even 3D. I then transform the matrix into a column matrix using A_Matrix4ToMatrix4(), and multiplied it with the ModelViewProjection matrix. The result is then passed to the vertex shader.

 

The problem: it works fine for 2d translations, however 3d translations (with a different Z) results in a transparent layer. It does not draw anything!

 

Am I missing something ?

 

Thanks 

TOPICS
SDK
897
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Sep 24, 2023 Sep 24, 2023

Ok so I've managed to get it work !

The problem was that I was not multiplying the view matrix and the projection matrix in the correct order.

It should be 

modelViewProjectionMatrix = projectionMatrix * modelViewMatrix;

in this order !

 

Translate
Community Expert ,
Sep 18, 2023 Sep 18, 2023

did you check the content of resultMatrix on the 3D layer case? is any of the diagonal scale matrix entries a zero?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 18, 2023 Sep 18, 2023

Here are the content of the matrices if the Z position of the 3D layer is set to 50.0 (the other values are unchanged) :

 

> Model View Projection: 

0.000488281250   0.0                          0.0               -1.0

0.0                         0.000748783234    0.0               -1.0

0.0                         0.0                          1.0               0.0

0.0                         0.0                          0.0               1.0

 

> transformMatrix (the transform matrix of the selected layer) : 

1.0                         0.0                          0.0               0.0

0.0                         1.0                          0.0               0.0

0.0                         0.0                          1.0               50.0

0.0                         0.0                          0.0               1.0

 

> resultMatrix (which is sent to the vertex shader) : 

0.000488281250   0.0                          0.0               -1.0

0.0                         0.000748783234    0.0               -1.0

0.0                         0.0                          1.0               50.0

0.0                         0.0                          0.0               1.0

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 18, 2023 Sep 18, 2023

can you show the same matrices for a 2D trasnformation where the render is correct?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 18, 2023 Sep 18, 2023

Ok here are the content of the matrices for a translation on X axis of 50 pixels (other values unchanged):

 

> Model View Projection: 

0.000488281250   0.0                          0.0               -1.0

0.0                         0.000748783234    0.0               -1.0

0.0                         0.0                          1.0               0.0

0.0                         0.0                          0.0               1.0

 

> transformMatrix (the transform matrix of the selected layer) : 

1.0                         0.0                          0.0               50.0

0.0                         1.0                          0.0               0.0

0.0                         0.0                          1.0               0.0

0.0                         0.0                          0.0               1.0

 

> resultMatrix (which is sent to the vertex shader) : 

0.000488281250   0.0                          0.0               -0.975585938

0.0                         0.000748783234    0.0               -1.0

0.0                         0.0                          1.0               0.0

0.0                         0.0                          0.0               1.0

 

I was wondering if its not an issue related to the camera frustum ?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 19, 2023 Sep 19, 2023

it might be related to the frustum, but i also see the matrices don't contain any perspecitve info (f.o.v).

i'm not too versed in openGL, is that added by some other call?

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 21, 2023 Sep 21, 2023

Ok so after some documentation, I figured out that OpenGL only draws the shapes that are contained in the camera frustum. So any shape whose coordinates are outside of the (-1,-1) clip limits is not drawn (that's why the first modelViewProjection matrix posted in this thread was wrong). 

 

The modelViewProjection matrix provided in the GLator sample plugin is made like this :

2/width    0               0       -1

0              2/height    0       -1

0              0               1        0

0              0               0        1

 

So no information about the camera frustrum, or the Z position of the camera.

I tried to modify this matrix using this formula (found on internet) to include the far clipping plane, and the near clipping plane:

2/width    0               0                             -1

0              2/height    0                             -1

0              0              -1 / (far - near)        -(far + near) / (far - near)

0              0               0                              1

 

but... nothing, the render is still empty. Does anyone have an idea, or an example of code that works ?

Thanks a lot

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 24, 2023 Sep 24, 2023
LATEST

Ok so I've managed to get it work !

The problem was that I was not multiplying the view matrix and the projection matrix in the correct order.

It should be 

modelViewProjectionMatrix = projectionMatrix * modelViewMatrix;

in this order !

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines