Community
Arnold General Rendering Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Questions about AiRenderBegin()

8 REPLIES 8
Reply
Message 1 of 9
AaronWPowell
385 Views, 8 Replies

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!

Tags (3)
Labels (3)
8 REPLIES 8
Message 2 of 9
AaronWPowell
in reply to: AaronWPowell

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

Message 3 of 9

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()


// Stephen Blair
// Arnold Renderer Support
Message 4 of 9

I think Image Engine prefers something simple like AiRender for batch renders


// Stephen Blair
// Arnold Renderer Support
Message 5 of 9
AaronWPowell
in reply to: AaronWPowell

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?

Message 6 of 9
thiago.ize
in reply to: AaronWPowell

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

Message 7 of 9
AaronWPowell
in reply to: thiago.ize

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)
Message 8 of 9
AaronWPowell
in reply to: AaronWPowell

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?

Message 9 of 9
AaronWPowell
in reply to: AaronWPowell

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!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report