Physical render - Progressive [SOLVED]

On 26/01/2017 at 02:50, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R16 
Platform:   Windows  ; Mac  ;  
Language(s) :     C++  ;

I have a plugin that renders real-time using threads and show the render result in a preview window.
This preview window works ok for most render options. 
However, when the render settings are Physical and Progressive, things go wrong. No result is shown and cinema is quite busy._<_o:_<_o:p_>_o:p>
I think this is because the renderer keeps rendering and does not signal to the plugin that is it ready (Progressive Pass 1, 2, 3, … and s_<_o:_<_o:p_>_
In the plugin I wait for the render to finish, but because it never ends, no result is shown.
Only when the render ends, the preview window is updated.
How can I solves this issue and show the intermediate Physical and Progressive render results (the results after each Progressive Pass)?

On 27/01/2017 at 06:37, xxxxxxxx wrote:

Hi Pim, thanks for writing us.

In the initial sentence of your post isn't 100% clear if your plugin actually computes the rendering data on its own or if it just delivers "somehow" the rendering data computed by Cinema built-in "Physical" rendering engine (e.g. Magic Preview).
It's pretty relevant to us to know your final intent in order to properly deliver support.

Cheers, Riccardo

On 28/01/2017 at 04:33, xxxxxxxx wrote:

Yes, indeed, it is something like Magic Preview.
What I do:
- select a region
- give a render command and save it in a file
- display the file in the preview window
- next region
- etc...

So, if the render settings are set to Physical and progressive, it seems no (intermediate) result is give back.

Hope this explains better.


On 31/01/2017 at 07:44, xxxxxxxx wrote:

Here some more information, hopefully this explains better.

I am using

res = RenderDocument(doc, data, nullptr, nullptr, renderbmp, RENDERFLAGS_IRR | RENDERFLAGS_SHOWERRORS, nullptr);

What I would like to know how to use this when render settings are physical and progressive.
What must I do to get all "intermediate" results?


On 31/01/2017 at 08:50, xxxxxxxx wrote:

Hi Pim, thanks for providing the additional information.

First let me apologize for getting back lately to you.

In order to get notified about progress done during a rendering process it's indeed helpful to pass a ProgressHook(...) callback function as third parameter of the RenderDocument(...) call. By passing such a callback you will have means to get notified about the rendering progress and, hence, perform a redraw of the portion of screen actually displaying the render bitmap.
Just define something like

  void MyProgressHook(Float p, RENDERPROGRESSTYPE progress_type, void *context)  
      String phase;  
      switch (progress_type)  
          phase = "Before Rendering";  
          phase = "During Rendering";  
          phase = "After Rendering";  
          phase = "GI";  
          phase = "Quick Preview";  
          phase = "AO";  
      GePrint(" ProgressHook called ["+phase+" / p:"+String::FloatToString(p*100)+"]");  

and pass it to your RenderDocument(...) call

RenderDocument(doc, renderSettings, MyProgressHook, nullptr, bitmap, flags, thread);  

On top of this it's indeed relevant to note that whilst the RenderDocument() should be executed in a separate thread the GUI elements update responsible for showing the rendered bitmap should be executed in the main thread context.

Hoping this few notes help you to implement the desired functionality, feel free to share any further feedback.

Best, Riccardo.

On 31/01/2017 at 11:58, xxxxxxxx wrote:

Hi Riccardo,

Thanks for the information.
Just a question on how to implement.

So I have a call to RenderDocument including MyProgressHook.
When will I be notified that a Progressive Pass finished (which progress_type)?
And where is the bitmap that I can display in the preview window?

And yes, renderdocument is done in a thread,but showing the resulting bitmap in the main part.


On 01/02/2017 at 00:22, xxxxxxxx wrote:

Hi Pim,

having a ProgressHook passed to the RenderDocument(...) call gives you the chance to get notified for each single type of progress the rendering is achieving and for each single progress increase the rendering is doing.
The text below is took directly from the console log whilst running a prototype plugin like the one you're implementing

MyProgressHook [Before Rendering / p:0]  
MyProgressHook [Quick Preview / p:0]  
MyProgressHook [Quick Preview / p:20]  
MyProgressHook [Quick Preview / p:40]  
MyProgressHook [Quick Preview / p:60]  
MyProgressHook [Quick Preview / p:80]  
MyProgressHook [Quick Preview / p:100]  
MyProgressHook [During Rendering / p:0.1]  
MyProgressHook [During Rendering / p:0.2]  
MyProgressHook [During Rendering / p:0.3]  
MyProgressHook [During Rendering / p:0.4]  
MyProgressHook [During Rendering / p:0.5]  
MyProgressHook [During Rendering / p:0.6]  
MyProgressHook [During Rendering / p:0.7]  
MyProgressHook [During Rendering / p:0.8]  
MyProgressHook [During Rendering / p:0.9]  
MyProgressHook [During Rendering / p:1]  
MyProgressHook [During Rendering / p:1.1]  
MyProgressHook [During Rendering / p:100] <when rendering aborted prematurely>  
MyProgressHook [After Rendering / p:100] <when rendering actually finished>

That said you can decide to refresh your UI showing the bitmap every time you're informed via the ProgressHoook about a progress or by defining a timer to update the UI on equal time basis.
Finally the bitmap storing the rendering data is actually the one you're passing by pointer as 5th parameter of the RenderDocument(...) call.

Hope this help a little bit more to make progress on your side.


On 01/02/2017 at 00:49, xxxxxxxx wrote:

Great, thank you.
I will give it a try and report back.