Artisan Data Types¶
Below are the data types most commonly used in the Artisan API.
Data Types Used In The Artisan API¶
Type | Describes |
---|---|
AEGP_RenderLayerContextH |
State information at the time of a render request, sent to an Artisan by After Effects. |
PR_RenderContextH |
A collection of settings defining what is to be rendered, and how. |
AEGP_SoundDataH |
The audio settings used for a given layer. |
AEGP_RenderReceiptH AEGP_FrameReceiptH |
Used by Artisans when rendering. |
AEGP_WorldH |
A frame of pixels. |
AEGP_RenderOptionsH |
The settings associated with a render queue item. |
Horz? Vert?¶
After Effects' matrix is row based; OpenGL's is column based. This means more work for you. Yay, billable hours!
Implementation And Design¶
An Artisan is nearly an application unto itself. Because we realized early in the After Effects 5.0 that there are many ways to approach the problems inherent in 3D rendering; intersections and shading, for example.
We provided an API with which we and third parties (yes, we really do use our own APIs) could implement any 3D rendering scheme desired.
3D Compositing, Not Modeling¶
After Effects is not a 3D modeling application. Users work in a responsive mode, switching to higher quality only at for proofing or final output. Consider providing at least two quality modes, one for layout and another for final output. Be conscious of render time in low quality mode.
Registering An Artisan¶
An Artisan is an AEGP, and has a single entry point. Artisans must also register their own function entry points and have a special callback for this purpose. See AEGP_RegisterArtisan()
from AEGP_RegisterSuites5.
This tables shows the functions that Artisans can support as defined by PR_ArtisanEntryPoints
: only render_func
is required.
Artisan Entry Points¶
PR_ArtisanEntryPoints | |
---|---|
global_setup_func0 |
Called only once, right after GP_Main . The global data is common across all instances of the plug-in.If you allocate memory during Global Setup, you must free it during your global_setdown_func .PR_GlobalSetupFunc( |
global_setdown_func0 |
Dispose of any global data you allocated.PR_GlobalSetdownFunc( |
global_do_about_func0 |
Tell the world about yourself! Use in_dataP>msg_func to display your dialog.PR_GlobalDoAboutFunc( |
setup_instance_func0 |
Allocate and instantiate any data specific to this instance of your Artisan.PR_InstanceSetupFunc( |
setdown_instance_func0 |
Deallocate and free any data specific to this instance of your Artisan.PR_InstanceSetdownFunc( |
flatten_instance_func0 |
Flatten your data in preparation to being written to disk. (making sure it's OS independent, if your Artisan is).PR_FlattenInstanceFunc( |
do_instance_dialog_func0 |
If your Artisan has a additional parameters (accessed through its Options dialog), this function will be called to get and set them.PR_DoInstanceDialogFunc( PR_DialogResultis is either PR_DialogResult_NO_CHANGE or PR_DialogResult_CHANGE_MADE . |
frame_setup_func0 |
Perform any setup necessary to render a frame (called immediately before rendering).PR_FrameSetupFunc( |
frame_setdown_func0 |
Dispose of any setup data allocated during frame_setup (sent immediately after rendering).PR_FrameSetdownFunc( |
render_func |
Render the scene.PR_FrameRenderFunc( |
query_func0 |
Artisans can draw their own projection axes, should the need arise. After Effects will call this function to obtain the transform between the composition world and those axes, as well as for a number of other functions related to on- and off-screen preview drawing (the former is relevant only to interactive artisans). PR_QueryFunc( PR_QueryType can be one of the following:
|
The World Is Your Canvas¶
AEGP_RenderTexture()
supplies the raw pixels of a layer, untransformed, into an arbitrarily-sized buffer.
AEGP_RenderLayer()
invokes the entire After Effects render pipeline, including transforms, masking, et cetera, providing the layer as it appears in its composition, in a composition-sized buffer.
If the layer being rendered is 3D, the default (Standard 3D) Artisan is invoked to perform any 3D geometrics.
Your Artisan can use this to render track matte layers, and apply them only in a strictly 2D sense, to the transformed 3D layer.
Before rendering, the Artisans that ship with After Effects apply an inverse transform to get square pixels, then re-apply the transform before display.
For example, if the pixel aspect ratio is 10/11 (DV NTSC), we multiply by 11/10 to get square pixels. We process and composite 3D layers, then re-divide to get back to the original pixel aspect ratio.
The following suite supplies the layers, compositions, texture and destination buffers. This is a vital suite for all artisans.
AEGP_CanvasSuite8¶
Function | Purpose |
---|---|
AEGP_GetCompToRender |
Given the render context provided to the Artisan at render time, returns a handle to the composition.AEGP_GetCompToRender( |
AEGP_GetNumLayersToRender |
Given the render context, returns the number of layers the Artisan needs to render.AEGP_GetNumLayersToRender( |
AEGP_GetNthLayerContextToRender |
Used to build a list of layers to render after determining the total number of layers that need rendering by the Artisan.AEGP_GetNthLayerContextToRender( |
AEGP_GetLayerFromLayerContext |
Given a AEGP_RenderLayerContextH ,retrieves the associated AEGP_LayerH (required by many suite functions).AEGP_GetLayerFromLayerContext( |
AEGP_GetLayerAndSubLayerFromLayerContext |
Allows for rendering of sub-layers (as within a Photoshop file).AEGP_GetLayerAndSubLayerFromLayerContext( |
AEGP_GetTopLayerFromLayerContext |
With collapsed geometrics "on" this gives the layer in the root composition containing the layer context. With collapsed geometrics off this is the same as AEGP_GetLayerFromLayerContext .AEGP_GetTopLayerFromLayerContext( |
AEGP_GetCompRenderTime |
Given the render context, returns the current point in (composition) time to render.AEGP_GetNthLayerIndexToRender( |
AEGP_GetCompDestinationBuffer |
Given the render context, returns a buffer in which to place the final rendered output.AEGP_GetCompToRender( |
AEGP_GetROI |
Given the render context provided to the Artisan at render time, returns a handle to the composition.AEGP_GetROI( |
AEGP_RenderTexture |
Given the render context and layer, returns the layer texture. All parameters with a trailing '0' are optional; the returned PF_EffectWorld can be NULL.AEGP_RenderTexture( AEGP_RenderHints contains one or more of the following:
AEGP_RenderHints_NO_TRANSFER_MODE prevents application of opacity & transfer mode; for use with RenderLayer calls. |
AEGP_DisposeTexture |
Disposes of an acquired layer texture.AEGP_DisposeTexture( |
AEGP_GetFieldRender |
Returns the field settings of the given PR_RenderContextH .AEGP_GetFieldRender( |
AEGP_ReportArtisanProgress |
Given the render context provided to the Artisan at render time, returns a handle to the composition. Note: this is NOT thread-safe on macOS; only use this function when the current thread ID is 0. AEGP_ReportArtisanProgress( |
AEGP_GetRenderDownsampleFactor |
Returns the downsample factor of the PR_RenderContextH .AEGP_GetRenderDownsampleFactor( |
AEGP_IsBlankCanvas |
Determines whether the PR_RenderContextH is blank (empty).AEGP_IsBlankCanvas( |
AEGP_GetRenderLayerToWorldXform |
Given a render context and a layer (at a given time), retrieves the 4 by 4 transform to move between their coordinate spaces.AEGP_GetRenderLayerToWorldXform( |
AEGP_GetRenderLayerBounds |
Retrieves the bounding rectangle of the layer_contextH (at a given time) within the render_contextH.AEGP_GetRenderLayerBounds( |
AEGP_GetRenderOpacity |
Returns the opacity of the given layer context at the given time, within the render context.AEGP_GetRenderOpacity( |
AEGP_IsRenderLayerActive |
Returns whether or not a given layer context is active within the render context, at the given time.AEGP_IsRenderLayerActive( |
AEGP_SetArtisanLayerProgress |
Sets the progress information for a rendering Artisan. countL is the number of layers completed,num_layersL is the total number of layers the Artisan is rendering.AEGP_SetArtisanLayerProgress( |
AEGP_RenderLayerPlus |
Similar to AEGP_RenderLayer , but takes into account the AEGP_RenderLayerContextH .AEGP_RenderLayerPlus( |
AEGP_GetTrackMatteContext |
Retrieves the AEGP_RenderLayerContextH for the specified render and fill contexts.AEGP_GetTrackMatteContext( |
AEGP_RenderTextureWithReceipt |
Renders a texture into an AEGP_WorldH , and provides an AEGP_RenderReceiptH for the operation.The returned receiptPH must be disposed of with AEGP_DisposeRenderReceipt .AEGP_RenderTextureWithReceipt( |
AEGP_GetNumberOfSoftwareEffects |
Returns the number of software effects applied in the given AEGP_RenderLayerContextH .AEGP_GetNumberOfSoftwareEffects( |
AEGP_RenderLayerPlusWithReceipt |
An improvement over AEGP_RenderLayerPlus , this function also provides an AEGP_RenderReceiptH for caching purposes.AEGP_RenderLayerPlusWithReceipt( |
AEGP_DisposeRenderReceipt |
Frees an AEGP_RenderReceiptH .AEGP_DisposeRenderReceipt( |
AEGP_CheckRenderReceipt |
Checks with After Effects' internal caching to determine whether a given AEGP_RenderReceiptH is still valid.AEGP_CheckRenderReceipt( |
AEGP_GenerateRenderReceipt |
Generates a AEGP_RenderReceiptH for a layer as if the first num_effectsS have been rendered.AEGP_GenerateRenderReceipt( |
AEGP_GetNumBinsToRender |
Returns the number of bins After Effects wants the artisan to render.AEGP_GetNumBinsToRender( |
AEGP_SetNthBin |
Sets the given render context to be the n-th bin to be rendered by After Effects.AEGP_SetNthBin( |
AEGP_GetBinType |
Retrieves the type of the given bin.AEGP_GetBinType( AEGP_BinType will be one of the following:
|
AEGP_GetRenderLayerToWorldXform2D3D |
Retrieves the transform to correctly orient the layer being rendered with the output world. Pass TRUE for only_2dB to constrain the transform to two dimensions.AEGP_GetRenderLayerToWorldXform2D3D( |
Note
Functions below are for interactive artisans only.
Function | Purpose |
---|---|
AEGP_GetPlatformWindowRef |
Retrieves the platform-specific window context into which to draw the given PR_RenderContextH .AEGP_GetPlatformWindowRef( |
AEGP_GetViewportScale |
Retrieves the source-to-frame downsample factor for the given PR_RenderContextH .AEGP_GetViewportScale( |
AEGP_GetViewportOrigin |
Retrieves to origin of the source, within the frame (necessary to translate between the two), for the given PR_RenderContextH .AEGP_GetViewportOrigin( |
AEGP_GetViewportRect |
Retrieves the bounding rectangle for the area to be drawn, for the given PR_RenderContextH .AEGP_GetViewportRect( |
AEGP_GetFallowColor |
Retrieves the color used for the fallow regions in the given PR_RenderContextH .AEGP_GetFallowColor( |
AEGP_GetInteractiveCheckerboard |
Retrieves whether or not the checkerboard is currently active for the given PR_RenderContextH .AEGP_GetInteractiveCheckerboard( |
AEGP_GetInteractiveCheckerboardColors |
Retrieves the colors used in the checkerboard.AEGP_GetInteractiveCheckerboardColors( |
AEGP_GetInteractiveCheckerboardSize |
Retrieves the width and height of one checkerboard square.AEGP_GetInteractiveCheckerboardSize( |
AEGP_GetInteractiveCachedBuffer |
Retrieves the cached AEGP_WorldH last used for the PR_RenderContextH .AEGP_GetInteractiveCachedBuffer( |
AEGP_ArtisanMustRenderAsLayer |
Determines whether or not the artisan must render the current AEGP_RenderLayerContextH as a layer.AEGP_ArtisanMustRenderAsLayer( |
AEGP_GetInteractiveDisplayChannel |
Returns which channels should be displayed by the interactive artisan.AEGP_GetInteractiveDisplayChannel( AEGP_DisplayChannelType will be one of the following:
|
AEGP_GetInteractiveExposure |
Returns the exposure for the given PR_RenderContextH , expressed as a floating point number.AEGP_GetInteractiveExposure( |
AEGP_GetColorTransform |
Returns the color transform for the given PR_RenderContextH .AEGP_GetColorTransform)( |
AEGP_GetCompShutterTime |
Returns the shutter angle for the given PR_RenderContextH .AEGP_GetCompShutterTime)( |
AEGP_MapCompToLayerTime |
New in CC. Unlike AEGP_ConvertCompToLayerTime, this handles time remapping with collapsed or nested comps. AEGP_MapCompToLayerTime( |
Convert Between Different Contexts¶
Convert between render and instance contexts, and manage global data specific to the artisan.
AEGP_ArtisanUtilSuite1¶
Function | Purpose |
---|---|
AEGP_GetGlobalContextFromInstanceContext |
Given an instance context, returns a handle to the global context.AEGP_GetGlobalContextFromInstanceContext( |
AEGP_GetInstanceContextFromRenderContext |
Given the render context, returns a handle to the instance context.AEGP_GetInstanceContextFromRenderContext( |
AEGP_GetInstanceContextFromQueryContext |
Given a query context, returns a handle to the instance context.AEGP_GetInstanceContextFromQueryContext( |
AEGP_GetGlobalData |
Given the global context, returns a handle to global data.AEGP_GetGlobalData( |
AEGP_GetInstanceData |
Given an instance context, return the associated instance data.AEGP_GetInstanceData( |
AEGP_GetRenderData |
Given a render context, returns the associated render data.AEGP_GetRenderData( |
Smile! Cameras¶
Obtains the camera geometry, including camera properties (type, lens, depth of field, focal distance, aperture, et cetera).
AEGP_CameraSuite2¶
Function | Purpose |
---|---|
AEGP_GetCamera |
Given a layer handle and time, returns the current camera layer handle.AEGP_GetCamera( |
AEGP_GetCameraType |
Given a layer, returns the camera type of the layer.AEGP_GetCameraType( The camera type can be the following:
|
AEGP_GetDefaultCameraDistanceToImagePlane |
Given a composition handle, returns the camera distance to the image plane.AEGP_GetDefaultCamera DistanceToImagePlane( |
AEGP_GetCameraFilmSize |
Retrieves the size (and units used to measure that size) of the film used by the designated camera.AEGP_GetCameraFilmSize( |
AEGP_SetCameraFilmSize |
Sets the size (and unites used to measure that size) of the film used by the designated camera.AEGP_SetCameraFilmSize)( |
Notes Regarding Camera Behavior¶
Camera orientation is in composition coordinates, and the rotations are in layer (the camera's layer) coordinates.
If the camera layer has a parent, the position is in a coordinate space relative to the parent.
Orthographic Camera Matrix¶
Internally, we use composition width and height to set the matrix described by the OpenGL specification as
glOrtho(-width/2, width/2, -height/2, height/2, -1, 100);
The orthographic matrix describes the projection. The position of the camera is described by another, scaled matrix. The inverse of the camera position matrix provides the "eye" coordinates.
Focus On Focal¶
Remember, focal length affects field of view; focal distance only affects depth of field.
Film Size¶
In the real world, film size is measured in millimeters. In After Effects, it's measured in pixels. Multiply by 72 and divide by 25.4 to move from millimeters to pixels.
Field of view is more complex;
ϴ = 1/2 field of view
tan(ϴ) = 1/2 composition height / focal length
focal length = 2 tan(ϴ) / composition height
Hit The Lights!¶
Get and set the type of lights in a composition.
AEGP_LightSuite2¶
Function | Purpose |
---|---|
AEGP_GetLightType |
Retrieves the AEGP_LightType of the specified camera layer.AEGP_GetLightType( AEGP_LightType will be one of the following:
|
AEGP_SetLightType |
Sets the AEGP_LightType for the specified camera layer.AEGP_SetLightType( |
Notes On Light Behavior¶
The formula for parallel lights is found in Foley and Van Dam's "Introduction to Computer Graphics" (ISBN 0-201-60921-5) as is the formula for point lights.
We use the half angle variant proposed by Jim Blinn instead.
Suppose we have a point on a layer and want to shade it with the light.
Let V be the unit vector from the layer point to the eye point. Let L be the unit vector to the light (in the parallel light case this is constant). Let H be (V+L)/2 (normalized). Let N be the unit normal vector to the layer.
The amount of specular reflected light is S * power(H Dot N, shine), where S is the specular coefficient.
How Should I Draw That?¶
After Effects relies upon Artisans to draw 3D layer handles. If your Artisan chooses not to respond to this call, the default Artisan will draw 3D layer handles for you. Querying transforms is important for optimization of After Effects' caching.
The coordinate system is positive x to right, positive y down, positive z into the screen. The origin is the upper left corner. Rotations are x then y then z. For matrices the translate is the bottom row, orientations are quaternions (which are applied first), then any x-y-z rotation after that. As a general rule, use orientation or rotation but not both. Also use rotations if you need control over angular velocity.
Query Transform Functions¶
These functions give artisans information about the transforms they'll need in order to correctly place layers within a composition and respond appropriately to the various queries After Effects will send to their PR_QueryFunc
entry point function.
As that entry point is optional, so is your artisan's response to the queries; however, if you don't, your users may be disappointed that (while doing interactive preview drawing) all the camera and light indicators vanish, until they stop moving! Artisans are complex beasts; contact us if you have any questions.
AEGP_QueryXFormSuite2¶
Function | Purpose |
---|---|
AEGP_QueryXformGetSrcType |
Given a query context, returns trasnsform source currently being modified.AEGP_QueryXformGetSrcType( The query context will be one of the following:
|
AEGP_QueryXformGetDstType |
Given a query context, returns the currently requested transform destination.AEGP_QueryXformGetDstType( |
AEGP_QueryXformGetLayer |
Used if the source or destination type is a layer. Given a query context, returns the layer handle.AEGP_QueryXformGetLayer( |
AEGP_QueryXformGetComp |
Given a query context, returns the current composition handle.AEGP_QueryXformGetComp( |
AEGP_QueryXformGetTransformTime |
Given a query context, returns the time of the transformation.AEGP_QueryXformGetTransformTime( |
AEGP_QueryXformGetViewTime |
Given a query context, returns the time of the associated view.AEGP_QueryXformGetViewTime( |
AEGP_QueryXformGetCamera |
Given a query context, returns the current camera layer handle.AEGP_QueryXformGetCamera( |
AEGP_QueryXformGetXform |
Given a query context, returns the current matrix transform.AEGP_QueryXformGetXform( |
AEGP_QueryXformSetXform |
Given a query context, return the matrix transform you compute in xform .AEGP_QueryXformSetXform( |
AEGP_QueryWindowRef |
Sets the window reference to be used (by After Effects) for the given PR_QueryContextH .AEGP_QueryWindowRef( |
AEGP_QueryWindowClear |
Returns which AEGP_PlatformWindowRef (and A_Rect ) to clear, for the given PR_QueryContextH .AEGP_QueryWindowClear( |
AEGP_QueryFrozenProxy |
Returns whether or not the textures used in the given PR_QueryContextH should be frozen.AEGP_QueryFrozenProxy( |
AEGP_QuerySwapBuffer |
Sent after rendering and camera/light handle drawing is complete; After Effects returns the buffer into which the artisan should draw its output.AEGP_QuerySwapBuffer( |
AEGP_QueryDrawProcs |
Sets the interactive drawing functions After Effects will call while drawing camera and lighting handles into the artisan's provided context.AEGP_QueryDrawProcs( |
AEGP_QueryPrepareForLineDrawing |
Informs After Effects about the context into which it will be drawing.AEGP_QueryPrepareForLineDrawing( |
AEGP_QueryUnprepareForLineDrawing |
As far as After Effects is concerned, the artisan is done drawing lines.AEGP_QueryUnprepareForLineDrawing( |
Interactive Drawing Functions¶
We've added the ability for artisans to provide functions After Effects can use to do basic drawing functions for updating the comp window display during preview, including camera, light, and wireframe preview modeling.
PR_InteractiveDrawProcs¶
Function | Purpose |
---|---|
PR_Draw_MoveToFunc |
PR_Draw_MoveToFunc( |
PR_Draw_LineToFunc |
PR_Draw_LineToFunc( |
PR_Draw_ForeColorFunc |
PR_Draw_ForeColorFunc( |
PR_Draw_FrameRectFunc |
PR_Draw_FrameRectFunc( |
PR_Draw_PaintRectFunc |
PR_Draw_PaintRectFunc( |
Notes On Query Time Functions¶
AEGP_QueryXformGetTransformTime()
and AEGP_QueryXformGetViewTime()
are both necessary for an artisan to build a representation of the scene to render.
AEGP_QueryXformGetTransformTime()
gets the time of the transform, which is then passed to AEGP_GetCompShutterFrameRange()
from AEGP_CompSuite11.
AEGP_QueryXformGetViewTime()
gets the time of the view, which is used in calling AEGP_GetLayerToWorldXformFromView()
from AEGP_LayerSuite9.