question

Aaron Powell avatar image
Aaron Powell asked

Questions about AiRenderBegin()

I've been using a callback function with the deprecated AiRender() function for a bit now and it's worked perfectly fine, but I'm interested in adding interactive rendering to my app and think it's time to seriously look at AiRenderBegin() instead. I'm not sure I fully understand how it works in relation to the callback though.

At the moment, I'm creating a callback function and assigning it like this with the Python API (simplified for clarity):

def my_callback_function(param1, param2, param3, param4):
    # render pixels to the screen

arnold.AiNodeSetPtr(display_driver_node, "callback", my_callback_function)

With AiRenderBegin(), it looks like the callback should be passed directly to the render function. Is this right? I tried simply swapping out AiRender() for AiRenderBegin(), leaving the rest of the callback code the same, and it exited with a memory allocation error. But, I'm assuming the callback would need to put all of the data that previous passed as parameters into an iterable of some kind that gets passed with *private_data.

I know I'm starting to ramble, but I'm hoping someone can confirm whether I'm on the right track or not. I appreciate it!

arnoldapicore
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Aaron Powell avatar image
Aaron Powell answered

As a follow up, it looks like Image Engine uses both AiRender() and AiRenderBegin() in their Gaffer application depending on whether it's a batch render or an interactive render. Maybe this is the approach to go with? I still have a memory access error to address when rendering with an interactive session, but I'd be happy to open a new question for that.


https://github.com/GafferHQ/gaffer/blob/master/src/GafferArnold/IECoreArnoldPreview/Renderer.cpp

1 comment
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

I think Image Engine prefers something simple like AiRender for batch renders
0 Likes 0 ·
Stephen Blair avatar image
Stephen Blair answered

Here's a simple example:


import arnold
import time

def ai_render_update_callback(private_data, update_type, display_output):
    print("------------ Arnold Render Update Callback Function ----------------")
    return arnold.AI_RENDER_STATUS_FINISHED.value

# Create data to pass to AiRenderBegin
render_mode = arnold.AI_RENDER_MODE_CAMERA
update_callback = ai_render_update_callback
private_data = None

arnold.AiBegin()

camera = arnold.AiNode("persp_camera", "myCamera")

tiff = arnold.AiNode("driver_tiff", "outTiff")
arnold.AiNodeSetStr(tiff, "filename", "out.tif")

gauss = arnold.AiNode("gaussian_filter", "gauss")

options = arnold.AiUniverseGetOptions()
arnold.AiNodeSetStr(options, "outputs", "myCamera RGBA RGBA gauss outTiff")

# Pass render_mode, update_callback function, and private_data to AiRenderBegin 
renderResult = arnold.AiRenderBegin(render_mode, update_callback, private_data)
if renderResult == arnold.AI_SUCCESS.value:
    status = arnold.AiRenderGetStatus()
    while status == arnold.AI_RENDER_STATUS_RENDERING.value:
        time.sleep(0.001)
        status = arnold.AiRenderGetStatus()

renderResult = arnold.AiRenderEnd();

arnold.AiEnd()
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Aaron Powell avatar image
Aaron Powell answered

Thanks, Stephen. This example makes sense.

Can you help me understand what the display_output parameter in the callback function is for? Ultimately I'd like this callback to be able to take pixel data and display it on screen like my current callback does, if possible. Unless the driver callback is different from the render callback here?

3 comments
10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

The documentation that comes with the SDK explains what the arguments do. In your arnold SDK directory take a look at: doc/html/group__ai__render.html

0 Likes 0 ·

The documentation says the third argument is a

const AtRenderUpdateInfo *update_info

Which is why I was confused. This is the full typedef:

typedef AtRenderStatus(* AtRenderUpdateCallback) (void *private_data, AtRenderUpdateType update_type, const AtRenderUpdateInfo *update_info)
0 Likes 0 ·

I'm starting to understand now - apparently I'm just a little slow today. The display_output parameter IS an AiRenderUpdateInfo object like the docs say.

So I guess that means I just have some questions about the callback at this point.

1. How do you interact with the AiRenderUpdateInfo object in the callback? I understand it's a struct but it's not iterable in Python and doesn't seem to have any keys. I can't find anything in the docs about this either.

2. How would this callback interact with a custom display driver to get pixel data? Is it even meant for that?

0 Likes 0 ·
Aaron Powell avatar image
Aaron Powell answered

I hate to bump the thread but I'm still hoping I can get some more clarification here. Ultimately, I want to be able to use the render callback to display pixel data on screen during a render, but I see how I can access the pixel data from the callback. Is this even how it's supposed to work with AiRenderBegin()? Right now I'm using AiRender() in combination with a custom driver and driver callback, which is working great. I just don't fully understand how it could translate to this approach.

Thanks!

10 |600 characters needed characters left characters exceeded

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 2.0 MiB each and 9.8 MiB total.

Welcome to the Arnold Answers community.

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using.

Please include images, scene and log files whenever possible as this helps the community answer your questions.

Instructions for generating full verbosity log files are available for MtoA, MaxtoA, C4DtoA, HtoA, KtoA, and Kick.

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

Bottom No panel present for this section.