Skip navigation
Currently Being Moderated

After Effects + OpenGL

May 14, 2012 5:18 AM

Tags: #opengl #effect_api

I know that this subject was already touched upon here a couple of years ago but I want to refresh it.

I'm interested in implementing OpenGL in After Effects' plugin. Is is possible yet? If yes - how?

This is my simple example code I would like to use in After Effects plugin:

 

int size = 500;

glColor4f(1, 0, 0, 1);

glBegin(GL_POLYGON);

     glVertex2f(-size, -size);

     glVertex2f(-size, size);

     glVertex2f(size, size);

     glVertex2f(size, -size);

glEnd();

 

Any help would be appreciated.

 
Replies
  • Currently Being Moderated
    May 14, 2012 6:09 AM   in reply to DaveProx

    There is an example called "GLator" in the AE SDK which apparently shows how to use OpenGL and AE together (by getting the input buffer, copying that to a texture, using that texture on a FBO, then reading the pixels form that FBO back into the output buffer), but this example crashes on my PCs (because of an incomplete FBO configuration). Maybe you have more luck :-)
    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    May 14, 2012 6:47 AM   in reply to DaveProx

    I have been trying to get an OpenGL example plugin in AfterEffects working for about 2 weeks now, but no success yet.
    If you manage to come up with even a simple example of drawing something in OpenGL and then copying that back to the AE buffer, I would be so happy to see it :-)
    Cheers,
    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    May 29, 2012 1:22 AM   in reply to DaveProx

    Hi Dave,

    did you have any success getting OpenGL to work?

     

    And for anyone else - did the "GLator" example from the SDK ever work for you?

    I tried it with the CS4 SDK as a 32bit plugin and the 64-bit versions from the CS5 and CS6 SDKs, with different ATI and NVidia graphic cards.

    Although it compiles and loads, it crashes immediately. On debugging, I found out that the OpenGL FBO framebuffer initialisation return OK, but when wanting to use it in the render function, glCheckFramebufferStatus complains with GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT.

    The same OpenGL code put into a standalone program works correctly, so I assume that one of the needed ressources has gone out of scope between the init and render functions.

    Therefore my question if this specific "GLator" SDK example ever worked for anyone? I assume so, since it wouldn't have made sense to put it in the SDK, but I would like to have positive feedback from anyone.

    And I am still very much looking for any OpenGL related integration into AE, so if anyone has only the simplest code example to share, I would be very happy :-)

     

    Cheers,

    Mike

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 2:58 AM   in reply to mdoepfer1234

    Hello,

    I did use openGL in AE but not directly... not like GLator.

    I used MesaGL and software rendering... so i did not use the graphic card.

    I used a Offscreen context: OSMesaContext

    I did not check if ti worked without offscreen methods.

     
    |
    Mark as:
  • Currently Being Moderated
    May 30, 2012 6:07 PM   in reply to DaveProx

    Here are a few pointers, I have learned from the past years with OpenGL in AE. I can't give you the code for specific things, but this might help you in the general direction.

     

    1. Don't use AE's OpenGL Context.  In the GLator example, the plugin uses AE's OpenGL context directly and it can cause many issues. You should always create your own context (Offscreen/Hidden Window/Native GL Context). On the Mac look into CGL Framework for context management. For Windows, the GLator sample already should give you an idea on how to create contexts, but you can use libraries like WGL to ease the pain. Also, having your own context gives you more control over the pixel types and other things.

     

    2. Create and Store Contexts/Textures/Shaders. If you are using multiple contexts or multiple textures and using shaders, its always wise to create them once and re-use them every frame later. I usually create them and store them in the Sequence data. You can always do this globally using global data, instead of Sequence data, but you should be extra careful. If you are using shaders, always compile them at startup, since compiling them every frame takes too much time.

     

    3. Switching Contexts: Since AE already has a context, when it executes the plugin, make sure to switch the GL context to your plugin's context and most importantly switch the context back to AE's default context after you are done rendering, every frame. This is very important, since AE doesn't expect its context to change during rendering process. If you don't do this, severe pain will ensue.

     

    4. Pixel Packing/Unpacking: OpenGL buffers are usually created with RGBA pixel order (depends on what you choose), whereas AE's Effectworld's are in ARGB pixel order. So make sure to convert the Pixel Order approriately while downloading/uploading textures/frame buffers.

     

    These are the few things I can think of right now.

     

    Hope that helps!

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 3:51 AM   in reply to gutsblow

    Wow gutsbow, thank you very much for the information!

    I'll see how far I can get with that regarding OpenGL, but especially for cross platform (Mac+Win), it might be a bit difficult fo rme yet.

    Dave - you mind sharing your working GLator example?

    T

     
    |
    Mark as:
  • Currently Being Moderated
    May 31, 2012 1:26 PM   in reply to DaveProx

    Yeah, Dave, that would be great! Please send it to michaeldoepfer[AT]web.de

    Thanks!

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 1, 2012 1:13 PM   in reply to mdoepfer1234

    While I've never used the GLator plugin, I've gotten opengl rendering to work in AE.  A few thoughts:

    1.  Like gutsbow says, don't use the AE context.  Create a hidden window and use that context.

    2.  Do *everything* opengl related on one thread.  I'd recommend making a background "worker" thread.  In theory, opengl is thread safe.  In reality, opengl drivers have so many bugs that you're just asking for trouble.  So I'd make sure to create/destroy all shaders/textures/buffers/etc on a single thread, and ideally do all opengl calls there.

    3.  A good percentage of your users won't actually have support for things you need, like FBOs.  For example, on windows, the ATI legacy driver doesn't support ANY opengl extensions (at least when I checked).

    http://support.amd.com/us/gpudownload/windows/Legacy/Pages/radeonaiw_v ista32.aspx

     

    So make sure you have a CPU backup!

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 13, 2012 3:28 PM   in reply to DaveProx

    1. forcing a re-render.

    the PF_OutFlag_FORCE_RERENDER flag goes to the "out_data->out_flags", and not the param UI flags.

    having set it there might be the reason that setting PF_ChangeFlag_CHANGED_VALUE doesn't trigger the render.

    in any case, you can use setStreamValue() to change your slider's value, which seems to work much better than the "regular" method you're using, and triggers the render with no additional flags needed to be set.

    in my humble opinion, you should do just fine with the PF_OutFlag_FORCE_RERENDER flag and you shouldn't have that re-render slider at all.

     

    2. openGL in premier.

    i have no idea.

     

    3. text filed.

    as you said, there is no text field param.

    you can store text either in the sequence_data, or in a param of type "arbitrary", which let's you keep a chunk of memory containing anything you like.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2012 10:21 AM   in reply to DaveProx

    Hi Dave,

     

    OpenGL in PPro could definitely be it's own forum topic since the original question here was about AE.  But one big difference with PPro that you'd need to take into account is the multiple render threads.  However, it sounds like the crash you're seeing is when the plug-in is first loaded?

     

    Zac

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2012 6:29 AM   in reply to DaveProx

    Are you sure you are clearing your buffer before drawing? That looks like some memory junk in the FBO. AE does call Render when you open a new project.

     

    Global Variables - Avoid using them, it will get very complicated to find issues as the project gets more complex.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 30, 2012 6:32 AM   in reply to DaveProx

    do you make sure the draw buffer is cleared before each render?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 31, 2012 7:47 AM   in reply to DaveProx

    as i mentioned earlier, i have 0 (zero, none, null) experience with openGL, but what you're seeing reminds me of a problem i had with a non-openGL plug-in in AE.

    eventually, i found that the problem was that the output buffer AE hands me to fill, was not clean.

    (it actually contained my last output... it drove me insane!)

    the solution was to clean the output world before i operate on it.

     

    now, i don't know if you copy your openGL buffer into the output world, or if it's done by other means in an openGL plug-in, but i suggest a methodic strip down of the code.

    disable the draw_scene() function. are the artifacts still there?

    try to gradually disable all the openGL code and see if the artifacts are still there.

    you might be surprised to see where the error sprouts.

     

    i know this advice is kind of vague, but in the absence of any other solution... perhaps it's time to brute-force the problem.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 4, 2012 6:06 AM   in reply to DaveProx

    you can change param values at any time using SetStreamValue().

    but if you do so while rendering, you're actually invalidating the render

    iteself.

    the result would be that AE will not cache that frame for ram preview and

    will regard it as no yet rendered.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 4, 2012 7:03 AM   in reply to DaveProx

    you don't have to include anything out of the ordinary.

    AEGP_SetStreamValue() is part of the stream suite.

    in some cases it's easier to access params as streams as opposed to

    accessing them directly.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 5, 2012 5:02 AM   in reply to DaveProx

    dude! you really messed up the stream thingie!

     

    you start with:

    AEGP_GetNewEffectForEffect to get the effectRef for your own effect.

    AEGP_GetNewEffectStreamByIndex to get the specific param from the effectRef

    by it's index.

     

    now you can access set the value of the stream with the gotten stream ref.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (1)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points