@@ -95,85 +95,91 @@ cleanup_geo(const Param ¶m, const Input &input) {
9595
9696int
9797process_motion_blur (lua_State *L) {
98- constexpr std::size_t prev_pos = 7 ;
98+ try {
99+ constexpr std::size_t prev_pos = 7 ;
99100
100- Obj obj (L);
101- const auto param = obj.get_param ();
102- auto input = obj.get_input (param.ext );
101+ Obj obj (L);
102+ const auto param = obj.get_param ();
103+ auto input = obj.get_input (param.ext );
103104
104- if (input.obj_idx >= input.obj_num )
105- return 0 ;
106-
107- const bool on = param.is_valid && (param.ext || input.frame );
108- const bool save_ed = param.geo_cache == 2u ;
109- const bool save_st = param.geo_cache == 1u || (save_ed && (input.frame - 1 ) < param.ext );
110- std::uint32_t req_smp = 0u ;
105+ if (input.obj_idx >= input.obj_num )
106+ return 0 ;
111107
112- geo_map.resize (input.obj_id , input.obj_idx , input.obj_num , param.geo_cache );
108+ const bool on = param.is_valid && (param.ext || input.frame );
109+ const bool save_ed = param.geo_cache == 2u ;
110+ const bool save_st = param.geo_cache == 1u || (save_ed && (input.frame - 1 ) < param.ext );
111+ std::uint32_t req_smp = 0u ;
113112
114- if (save_st)
115- geo_map.overwrite (input.obj_id , input.obj_idx , input.frame + 1 , input.geo_curr );
113+ geo_map.resize (input.obj_id , input.obj_idx , input.obj_num , param.geo_cache );
116114
117- if (on) {
118- const float amt = param. shutter_angle / 360 . 0f ;
115+ if (save_st)
116+ geo_map. overwrite (input. obj_id , input. obj_idx , input. frame + 1 , input. geo_curr ) ;
119117
120- std::array<Vec2<float >, 2 > margin{};
121- Vec2<float > delta_res{};
122- std::uint32_t smp = 0u ;
118+ if (on) {
119+ const float amt = param.shutter_angle / 360 .0f ;
123120
124- if (param.geo_cache && !input.frame )
125- set_init_geo (param.ext , input);
121+ std::array<Vec2<float >, 2 > margin{};
122+ Vec2<float > delta_res{};
123+ std::uint32_t smp = 0u ;
126124
127- auto delta = calc_delta (param, input, (save_ed && input.frame ) ? prev_pos : input.frame );
125+ if (param.geo_cache && !input.frame )
126+ set_init_geo (param.ext , input);
128127
129- if (delta.is_moved ()) {
130- margin = calc_size (delta, amt, input);
131- delta_res = margin[0 ] + margin[1 ];
132- req_smp = static_cast <std::uint32_t >(delta_res.norm (2 ));
133- smp = std::min (req_smp, param.smp_lim - 1u );
134- }
128+ auto delta = calc_delta (param, input, (save_ed && input.frame ) ? prev_pos : input.frame );
135129
136- if (smp) {
137- auto init_htm = delta.calc_htm (amt, smp, true );
138- auto drift = delta.calc_drift (amt, smp);
139-
140- Vec2<float > res_new = input.res ;
141- Vec2<float > pivot_new = input.pivot ;
142- if (param.resize ) {
143- auto c_new = input.geo_curr .get_center () + (margin[0 ] - margin[1 ]) * 0 .5f ;
144- obj.resize (margin, c_new);
145- pivot_new = input.tf_curr .get_center () + c_new;
146- res_new += delta_res;
130+ if (delta.is_moved ()) {
131+ margin = calc_size (delta, amt, input);
132+ delta_res = margin[0 ] + margin[1 ];
133+ req_smp = static_cast <std::uint32_t >(delta_res.norm (2 ));
134+ smp = std::min (req_smp, param.smp_lim - 1u );
147135 }
148136
149- Vec2<float > ps_pivot = res_new * 0 .5f + pivot_new;
150- std::vector<float > constants = {
151- init_htm (0 , 0 ), init_htm (0 , 1 ), init_htm (0 , 2 ), 0 .0f ,
152- init_htm (1 , 0 ), init_htm (1 , 1 ), init_htm (1 , 2 ), 0 .0f ,
153- init_htm (2 , 0 ), init_htm (2 , 1 ), init_htm (2 , 2 ), 0 .0f ,
154- drift.get_x (), drift.get_y (), res_new.get_x (), res_new.get_y (),
155- ps_pivot.get_x (), ps_pivot.get_y (), static_cast <float >(smp), param.mix };
156-
157- obj.pixel_shader (param.shader_name , constants);
137+ if (smp) {
138+ auto init_htm = delta.calc_htm (amt, smp, true );
139+ auto drift = delta.calc_drift (amt, smp);
140+
141+ Vec2<float > res_new = input.res ;
142+ Vec2<float > pivot_new = input.pivot ;
143+ if (param.resize ) {
144+ auto c_new = input.geo_curr .get_center () + (margin[0 ] - margin[1 ]) * 0 .5f ;
145+ obj.resize (margin, c_new);
146+ pivot_new = input.tf_curr .get_center () + c_new;
147+ res_new += delta_res;
148+ }
149+
150+ Vec2<float > ps_pivot = res_new * 0 .5f + pivot_new;
151+ std::vector<float > constants = {
152+ init_htm (0 , 0 ), init_htm (0 , 1 ), init_htm (0 , 2 ), 0 .0f ,
153+ init_htm (1 , 0 ), init_htm (1 , 1 ), init_htm (1 , 2 ), 0 .0f ,
154+ init_htm (2 , 0 ), init_htm (2 , 1 ), init_htm (2 , 2 ), 0 .0f ,
155+ drift.get_x (), drift.get_y (), res_new.get_x (), res_new.get_y (),
156+ ps_pivot.get_x (), ps_pivot.get_y (), static_cast <float >(smp), param.mix };
157+
158+ obj.pixel_shader (param.shader_name , constants);
159+ }
158160 }
159- }
160161
161- if (save_ed)
162- geo_map.write (input.obj_id , input.obj_idx , prev_pos, input.geo_curr );
162+ if (save_ed)
163+ geo_map.write (input.obj_id , input.obj_idx , prev_pos, input.geo_curr );
163164
164- cleanup_geo (param, input);
165+ cleanup_geo (param, input);
165166
166- if (param.print_info ) {
167- std::string info = std::format (
168- " [INFO]\n "
169- " Object ID : {}\n "
170- " Index : {}\n "
171- " Required Samples: {}" ,
172- input.obj_id , input.obj_idx , req_smp);
173- obj.print (info);
174- }
167+ if (param.print_info ) {
168+ std::string info = std::format (
169+ " [INFO]\n "
170+ " Object ID : {}\n "
171+ " Index : {}\n "
172+ " Required Samples: {}" ,
173+ input.obj_id , input.obj_idx , req_smp);
174+ obj.print (info);
175+ }
175176
176- return 0 ;
177+ return 0 ;
178+ } catch (const std::exception &e) {
179+ return luaL_error (L, " Runtime Error: %s" , e.what ());
180+ } catch (...) {
181+ return luaL_error (L, " Unknown Exception occurred" );
182+ }
177183}
178184
179185static luaL_Reg functions[] = {{" process_motion_blur" , process_motion_blur}, {nullptr , nullptr }};
0 commit comments