@@ -48,6 +48,7 @@ def sync(self, context):
4848 depsgraph = context .evaluated_depsgraph_get ()
4949 self .rpr_context .blender_data ['depsgraph' ] = depsgraph
5050 scene = depsgraph .scene
51+ material_override = depsgraph .view_layer .material_override
5152
5253 scene .rpr .init_rpr_context (self .rpr_context )
5354
@@ -60,43 +61,53 @@ def sync(self, context):
6061 # cache blur data
6162 self .rpr_context .do_motion_blur = scene .render .use_motion_blur and \
6263 not math .isclose (scene .camera .data .rpr .motion_blur_exposure , 0.0 )
63- if self .rpr_context .do_motion_blur :
64- self .cache_blur_data (depsgraph )
65- self .set_motion_blur_mode (scene )
66-
67- # camera, objects, particles
68- for obj in self .depsgraph_objects (depsgraph , with_camera = True ):
69- indirect_only = obj .original .indirect_only_get (view_layer = depsgraph .view_layer )
70- object .sync (self .rpr_context , obj , indirect_only = indirect_only ,
71- frame_current = scene .frame_current )
72-
73- # instances
74- for inst in self .depsgraph_instances (depsgraph ):
75- indirect_only = inst .parent .original .indirect_only_get (view_layer = depsgraph .view_layer )
76- instance .sync (self .rpr_context , inst , indirect_only = indirect_only ,
77- frame_current = scene .frame_current )
78-
79- # rpr_context parameters
80- self .rpr_context .set_parameter (pyrpr .CONTEXT_PREVIEW , False )
81- scene .rpr .export_ray_depth (self .rpr_context )
82- self .rpr_context .texture_compression = scene .rpr .texture_compression
83-
84- # EXPORT CAMERA
85- camera_key = object .key (scene .camera ) # current camera key
86- rpr_camera = self .rpr_context .create_camera (camera_key )
87- self .rpr_context .scene .set_camera (rpr_camera )
88- camera_obj = depsgraph .objects .get (camera_key , None )
89- if not camera_obj :
90- camera_obj = scene .camera
91-
92- camera_data = camera .CameraData .init_from_camera (camera_obj .data , camera_obj .matrix_world ,
93- self .rpr_context .width / self .rpr_context .height )
94- camera_data .export (rpr_camera )
95-
96- if self .rpr_context .do_motion_blur :
97- rpr_camera .set_exposure (scene .camera .data .rpr .motion_blur_exposure )
98- object .export_motion_blur (self .rpr_context , camera_key ,
99- object .get_transform (camera_obj ))
64+
65+ # with enabled motion blur, cache_blur_data() can change frame,
66+ # therefore we store current frame and set it back after export process
67+ cur_frame = (scene .frame_current , 0.0 )
68+
69+ try :
70+ if self .rpr_context .do_motion_blur :
71+ self .cache_blur_data (depsgraph )
72+ self .set_motion_blur_mode (scene )
73+
74+ # camera, objects, particles
75+ for obj in self .depsgraph_objects (depsgraph , with_camera = True ):
76+ indirect_only = obj .original .indirect_only_get (view_layer = depsgraph .view_layer )
77+ object .sync (self .rpr_context , obj , indirect_only = indirect_only , material_override = material_override ,
78+ frame_current = scene .frame_current )
79+
80+ # instances
81+ for inst in self .depsgraph_instances (depsgraph ):
82+ indirect_only = inst .parent .original .indirect_only_get (view_layer = depsgraph .view_layer )
83+ instance .sync (self .rpr_context , inst , indirect_only = indirect_only , material_override = material_override ,
84+ frame_current = scene .frame_current )
85+
86+ # rpr_context parameters
87+ self .rpr_context .set_parameter (pyrpr .CONTEXT_PREVIEW , False )
88+ scene .rpr .export_ray_depth (self .rpr_context )
89+ self .rpr_context .texture_compression = scene .rpr .texture_compression
90+
91+ # EXPORT CAMERA
92+ camera_key = object .key (scene .camera ) # current camera key
93+ rpr_camera = self .rpr_context .create_camera (camera_key )
94+ self .rpr_context .scene .set_camera (rpr_camera )
95+ camera_obj = depsgraph .objects .get (camera_key , None )
96+ if not camera_obj :
97+ camera_obj = scene .camera
98+
99+ camera_data = camera .CameraData .init_from_camera (camera_obj .data , camera_obj .matrix_world ,
100+ self .rpr_context .width / self .rpr_context .height )
101+ camera_data .export (rpr_camera )
102+
103+ if self .rpr_context .do_motion_blur :
104+ rpr_camera .set_exposure (scene .camera .data .rpr .motion_blur_exposure )
105+ object .export_motion_blur (self .rpr_context , camera_key ,
106+ object .get_transform (camera_obj ))
107+
108+ finally :
109+ if self .rpr_context .do_motion_blur :
110+ self ._set_scene_frame (scene , * cur_frame )
100111
101112 # adaptive subdivision will be limited to the current scene render size
102113 self .rpr_context .enable_aov (pyrpr .AOV_COLOR )
0 commit comments