[Closed] SDK Custom Render Element, can't access element's bitmap
Hi,
I’m trying to correctly implement RenderElement plugin for open source renderer appleseed. Plugin is for 3ds max 2016 and up.
My problem is that I can’t access render element’s bitmap with GetPBBitmap(PBBitmap*& bitmap) function. I’m trying to access the bitmap in the Renderer::Render() function, after our renderer has done rendering and copy renderer’s information into 3ds max’s renderelement’s bitmap. But the result of the the call is never fully initilized – PBBitmap::bi field is correct and shows correct filename, but PBBitmap::bm field is never initilized.
RE plugin class inherits from IRenderElement. Render element correctly shown in the list of render elements and correctly builds its UI.
Is there anything I should do in the renderer or render element plugin to make the bitmap correctly initilized? Should the renderer allocate and set the bitmap for each render element or the system allocates and provides bitmap on each render session (in the way main output bitmap is provided to Renderer::Render() function)?
Thanks,
Sergo.
you should enable the elements, i found that appleseed always disable them:
IRenderElementMgr* re_manager = GetCOREInterface()->GetCurRenderElementMgr();
if (re_manager != nullptr)
{
re_manager->SetDisplayElements(false);
for (int i = 0, e = re_manager->NumRenderElements(); i < e; ++i)
{
auto factories = g_aov_factory_registrar.get_factories();
auto* render_element = re_manager->GetRenderElement(i);
render_element->SetEnabled(false); // it should be enabled
// other stuff
}
}
What you see in the appleseed right now is the workaround – render elements are disabled to prevent saving of the empty bitmaps. We are saving render elements with appleseed’s internal functions.
did you mean even after enabling the elements, their PBBitmap::bm field are still uninitialized?
Exactly!
Moreover, I’ve built standard render elements from sdk samples and while debugging them I see that they are getting normally initilized bitmap from scanline renderer. Which makes me think something has to be done on renderer’s side… but I’m not sure.
that’s strange :hmm:
i implemented RE in my renderer and never encountered such an issue.
3dsmax will manage these bitmaps properly, no extra thing need to do.
it’s not open-source, but the code is very simple, no special thing:
class KFX_RE_Interface {
// some stuff
};
class KFX_RE_Light_Group : public IRenderElement, public KFX_RE_Interface {
// some stuff
};
struct KFX_Renderer_Output {
KFX_RE_Interface *data;
PBBitmap *dest;
};
void init_rend_para_output_list (
Tab<KFX_Renderer_Output> *output_list)
{
output_list->Init();
auto *mgr = GetCOREInterface()->GetCurRenderElementMgr();
if (!mgr || !mgr->GetElementsActive())
return;
for (int i = 0; i < mgr->NumRenderElements(); ++i)
{
auto *elt = mgr->GetRenderElement(i);
if (!elt || !elt->IsEnabled())
continue;
KFX_Renderer_Output output = {};
output.data = dynamic_cast<KFX_RE_Interface *>(elt);
elt->GetPBBitmap(output.dest);
if (!output.data || !output.dest || !output.dest->bm)
continue;
output_list->Append(1, &output);
}
}
the init_rend_para_output_list() will be called in Renderer::Render() to collect render elements.
Remember that there are a ton of samples in the SDK directory, and many of the “samples” aren’t actually samples – it’s the actual code being run in max itself.
This includes some render elements code, for example in the maxsdk\samples\render\renderelements as well as maxsdk\samples\render\RapidRTRenderer\Plugins
I would start by looking there. (It’s what I would do to be able to answer this question directly, coz contrary to popular belief, I don’t actually remember all these things in my poor little head)
/Z
…and checking the render dispatcher code, yes you must have your element enabled to get the bitmap created!! And this is done by the render executor, not the renderer. (However, I found code to create bake elements in the scanline renderer, not sure why that is different…)
/Z
Nanhua thanks for the code. I’ll create a special branch with what I was trying to do and that probably be helpful.
MasterZap thanks for advice. I’ve checked the samples many times. Render elements were active when I was checking. I made our render element compatible with scanline and it did get proper bitmap from the scanline renderer. And I checked our renderer with standard elements from sample code and they didn’t get the bitmap. That made me think there is something else I should do in the renderer.
I’ll check samples again and I’ll push special testing branch so that I can refer to the actual code.
Thanks again.