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

GLator for dummies (and from dummy...)

Enthusiast ,
Mar 12, 2015 Mar 12, 2015

Copy link to clipboard

Copied

Hi every one!

I open this post to summarize what I've been grabing here and there about the GLator sample. It's been discussed a lot already, but it still drives a lot of people nuts!

If you have any usefull info about it, please share! And may be one day we'll all have a proper OpenGL structure to work with...

Finally, here is a complete working version of GLator:

So let's take it point by point:

First of all, one shoud start from the CC example as it's more stable. If you build for lower versions and some suites are not available, just change the suites number.

For simplicity's sake, I have (and probably will) edited this post.

1_Window / context:

The GLator example doesn't set context's size, and it crashes when the size of the picture is over 1024x1024, when user purge the cache...

To solve this, one has to remove the AESDK_OpenGL_InitResources() function from GlobalSetup(), and paste it in Render() call. Now in render call, one can set width and height like this:

First use SetPluginContext()

Then

if( (error_desc = AESDK_OpenGL_InitResources(S_GLator_EffectCommonData, Width, Height)) != AESDK_OpenGL_OK)

  {

  PF_SPRINTF(out_data->return_msg, ReportError(error_desc).c_str());

  CHECK(PF_Err_INTERNAL_STRUCT_DAMAGED);

  }

Then, all the functions using S_GLator_EffectCommonData.mRenderBufferWidthSu and S_GLator_EffectCommonData.mRenderBufferHeightSu should be replaced by width and height.

And then switch back to AE with SetHostContext()

EDIT: once the context has been switched back to AE, I used to delete the plugin context and window like so (windows code):

wglDeleteContext( S_GLator_EffectCommonData.mHRC );

DestroyWindow( S_GLator_EffectCommonData.mHWnd);

It's working in CS5 and CS5.5, but mess everything up starting from CS6! So let opengl do the cleaning...

IMPORTANT EDIT: what's written above does work, but something important is missing: the use of AESDK_OpenGL_Startup() and AESDK_OpenGL_Shutdown()

In the sample, AESDK_OpenGL_Startup() is set during GlobalSetup, while AESDK_OpenGL_Shutdown() is called during SequenceSetdown. This is a mistake! One should add a GlobalSetdown function and move the AESDK_OpenGL_Shutdown() from SequenceSetdown to GlobalSetdown. Otherwise, the plugin will seem to work fine, but won't be able to render if a new project is opened. It would work again if you close and re-open AE. The reason is GlobalSetup (and so AESDK_OpenGL_Startup()) will be called only once per AE session, and SequenceSetdown (and so AESDK_OpenGL_Shutdown()) will be called everytime a project is closed.

2_AE to OpenGL camera

Use the code in the Resizer sample (getting camera matrix) as a base.

Then I see 2 options:

A_The matrix conversion:

You can find more details in this thread (the whole code's a bit long): Help with AE camera matrix >> Opengl Matrix? | Adobe Community

and this one https://forums.adobe.com/thread/1357716

convert the output matrix from AEGP_GetLayerToWorldXform() to column-order and serializing it in a float array.

On the OpenGL side, use the following snippet before drawing:

Thanks to Tobias Fleischer (reduxFX) for sharing his code:

void my_gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar)

{

  GLdouble xmin, xmax, ymin, ymax;

  ymax = zNear * tan(fovy * 3.14159265358979323 / 360.0);

  ymin = -ymax;

  xmin = ymin * aspect;

  xmax = ymax * aspect;

  glFrustum(xmin, xmax, ymin, ymax, zNear, zFar);

}


then


{

    ...

    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    my_gluPerspective(45.0, (GLdouble)widthL / heightL, 0.1, 1000.0 );

    glViewport(0, 0, (int)(dataP->w[0]), (int)(dataP->h[0]));

    glMatrixMode(GL_MODELVIEW);

    glLoadIdentity();   

    glClearDepth(1.0f);                           

    glEnable(GL_DEPTH_TEST);                       

    glDepthFunc(GL_LEQUAL);                           

    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    dataP->glMatrix[12] -= widthL*0.5f;

    dataP->glMatrix[13] -= heightL*0.5f;

    glLoadMatrixf(dataP->glMatrix);

    ...

}


With this code, we're almost there. I must say I still had troubles to get the proper perspective distortion when I tried to include it in my own OpenGL process. But I'm far from being an opengl expert!

So I finally tried to develop my own camera conversion:

B_the gluLookAt() option:

I grab the camera matrix the same way. Then I define:

A_longWidth, Height, FullWidth, FullHeight;

Width = outputP->width;
Height = outputP->height;
FullWidth = Width*in_data->downsample_x.den;
FullHeight = Height*in_data->downsample_y.den;

//Define th Fov

float Fov = 2.0 * PF_DEGREE_PER_RAD * atan(FullHeight / (2.0 * camDataD.zoom));

  gluPerspective( Fov, (GLdouble)Width / Height, 10.0, 10000.0 );

  glViewport( 0, 0, Width, Height);

  glMatrixMode( GL_MODELVIEW );

  glLoadIdentity();

  point3 target;

  float distCam = distance3D(    camDataD.matrix.mat[3][0] - FullWidth*.5,

                                              camDataD.matrix.mat[3][1] - FullHeight*.5,

                                              camDataD.matrix.mat[3][2]);

  target.x = camDataD.matrix.mat[2][0] * distCam + camDataD.matrix.mat[3][0];

  target.y = camDataD.matrix.mat[2][1] * distCam + camDataD.matrix.mat[3][1];

  target.z = camDataD.matrix.mat[2][2] * distCam + camDataD.matrix.mat[3][2];

A_Matrix4invMat = camDataD.matrix;

ScaleMatrix4(&invMat, 1.0,1.0,-1.0);
invMat = invertMatrix4(invMat);

point3orientation_vector = {0,1,0};

orientation_vector.x = invMat.mat[0][1];
orientation_vector.y = invMat.mat[1][1];
orientation_vector.z = invMat.mat[2][1];

normalize( &orientation_vector);

gluLookAt(camDataD.matrix.mat[3][0],
camDataD.matrix.mat[3][1],
-camDataD.matrix.mat[3][2],
target.x,
target.y,
-target.z,
orientation_vector.x,
orientation_vector.y,

orientation_vector.z);


If like me you're more used to AE than OpenGL, then this method is more intuitive. The lookAt function acts just like an after effects camera, showing a world using the same coordinates than AE world. Then grabing lights or other layers becomes "easy" as developping can be...

This part caused me the biggest headaches, so if you want to use it, you owe me a beer!

3_Using GLator to render polygons.

I've tried rendering polygons and hit a wall: antialiasing. Though you can still use glEnable(GL_LINE_SMOOTH); for antialiased lines, GL_POLYGON_SMOOTH is now deprecated. It means antialiasing has to be done another way. I couldn't figure it out, but see 2 options: MultiSampling, or post-process AA through Shader. If someone successfully used MultiSampling, I'm curious to see how.

EDIT: another option is superSampling (write to a bigger buffer, and resize it to layer's size). Though it's a bit of an overkill, openGL speed makes it a not so bad option...

4_Using Shaders:

In the sample, in order to use Shaders, one has to define

#define USE_SHADERS 1

I personnally took the option to add a checkbox parameter and embed the shader functions in a "if (params[USE_SHADER]->u.bd.value) {}" statement.

To use the shaders properly, one should replace "GL_TEXTURE_2D" by "GL_TEXTURE_RECTANGLE_ARB", and in the Shaders, "sampler2D" by "sampler2DRect" and "texture2D" by "texture2DRect".

This tip comes from Gutsblow in this thread: GLator Quirks..Help needed!

Anyway, I must say, though the shaders compile fine and are actually used by my plugin, I can't see it act on the final render... I probably set the functions in a wrong place, so any help will be appreciated...

Edit: in fact, the shaders work just fine! My knowledge of shaders was too close to the ground to see it was actually working...

Actually, the "GL_TEXTURE_2D" to "GL_TEXTURE_RECTANGLE_ARB" switch is not only for shaders and should be done anyway to avoid troubles.

5_Red and Alpha channels swap

When using OpenGL colors, Red and Alpha channels will be swapped.

One shoud use glReadPixels() with GL_ABGR_EXT instead of GL_RGBA, only colors will be swapped, and alpha operations (blending and so on...) will be OK. If you swap the BLUE/RED colors before rendering, it should work without losing speed.


This depends on what you ask OpenGL to render: textures or polygons.



I write this post as answered, but if any of you have any tip to share and make it better / stronger, please share!


Cheers,

François

TOPICS
SDK

Views

2.2K

Translate

Translate

Report

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 ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

Hi Francois,

I'm looking at the SDK for AE 2018 and looks like all the issues you mention above are fixed.

Still, the plugin doesn't work in Premiere Pro as expected.

Did you have a chance to look at it?

Best,

Tom

Votes

Translate

Translate

Report

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
Enthusiast ,
Apr 08, 2018 Apr 08, 2018

Copy link to clipboard

Copied

Hi Tom,

Unfortunately, I'm not a premiere user, so I can't tell you.

Hope someone here can!

Cheers,

François

Votes

Translate

Translate

Report

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
Contributor ,
Oct 23, 2021 Oct 23, 2021

Copy link to clipboard

Copied

LATEST

On of the linked threads is still available on Wayback - 

 

https://web.archive.org/web/20111223234233/http://forums.adobe.com/thread/570135

Votes

Translate

Translate

Report

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