Page MenuHome

Fix inconsistency with the use of the RENDER_INIT event.
Needs ReviewPublic

Authored by Campbell Barton (campbellbarton) on Oct 19 2015, 4:33 AM.

Details

Reviewers
Alan Troth (Al)
Summary

This diff fixes an inconsistency with what can be done in a RENDER_INIT event handler called from rendering a frame (RE_BlenderFrame() ) compared to rendering a sequence of frames (RE_BlenderAnim() ).

RENDER_INIT handled from RE_BlenderFrame() allows elements in Scene.RenderData to be altered (e.g an AddOn may alter the dimensions of the rendered image) whereas RE_BlenderAnim() would lose any changes made by the RENDER_INIT handler.

I've made changes in RE_BlenderAnim() so that the local stack based version of RenderData is created after the handler is called rather than before.

RE_BlenderFrame() and RE_BlenderAnim() take a frame or range of frames as arguments, I've also made sure the RENDER_INIT event handlers can read these frame(s) from scene.RenderData if they want to.

Diff Detail

Repository
rB Blender
Branch
arcpatch-D1566

Event Timeline

Alan Troth (Al) retitled this revision from to Fix inconsistency with the use of the RENDER_INIT event..
Alan Troth (Al) updated this object.
Alan Troth (Al) set the repository for this revision to rB Blender.

Compile in GCC, use correct types for SWAP

Correct order of initialization, (lost from last commit)

Reorder initialization of other vars

In general, knowing what frame range you render is reasonable, however am not sure of this patch.

Pros:

  • Assigning rd = scene->r after executing the Python script so as to take the values modified by Python.
  • Assigning scene->r.cfra before rendering a frame seems OK too.

    However: render_init called from RE_BlenderAnim won't have the current frame set, where it would for RE_BlenderFrame

    (trivial to set to first frame - just noting it as an inconsistency in this patch).

Cons:

  • This adds some hidden logic, making render_init a special case.

    You can't - for example, access the real values on other handlers - render_pre/post/complete/cancel.

    This means developers need to know that temp values are used in a specific handler. (that can be documented of course, but is a bit awkward).

Possible alternative:

The current design doesn't fit well with Python accessing and manipulating these values.

However instead of this patch, it may be better to expose scene.render_runtime for eg. which will be None (NULL) when not actively rendering. Then scripts can access the stack render-data, and we don't have to fake swapping values.

An issue with this - is if a scene is being rendered more than once, (since it could have multiple render_runtime's), and it would get messy if we end up having our own internal code accessing this.

Interested what other devs thing - @Brecht Van Lommel (brecht)/@Bastien Montagne (mont29)/@Sergey Sharybin (sergey) ?

source/blender/render/intern/source/pipeline.c
3115–3121

This change seems OK, OTOH, the frame value will be set, but none of the data in the scene will be updated.

3494–3501

Needed to make some edits here since we use -Wdeclaration-after-statement still.

3506–3515

There are also layer and camera overrides,
these happen to be used for preview renders - but will have the same issue.

I can see my patch is the wrong way to go.

Regarding the current frame, it should probably be classed as undefined while in a render_init handler, but classed as defined while in later event handlers e,g. 'frame_change_post', 'render_pre'

I'm not sure it's relevant to the discussion you may have but the AddOn I was creating was to add an overscan border to a render - increase the image size of the render whilst keeping the 'non overscaned' part of the image, pixel perfect to an image rendered without overscan. This is achieved by changing the render resolution and the camera sensor size. The way I wanted to do this was to append the UI ('use ovescan' check-box + 'width' and 'height' properties) to the RENDER_PT_dimensions panel and change the render image size and sensor size in a render_init handler (and undo changes in render_cancel/complete). The way I ended up doing it was to create a separate UI panel with 'Render with Overscan' and 'Animation with Overscan' buttons and get the button operators to set up values before initiating the rendering.

For me, appending the UI to the RENDER_PT_dimensions panel just feels like the right way to do it.

Compile in GCC, use correct types for SWAP

Sorry, silly mistake - I must've been coding while sleeping.