1 -- The theme is what decides what's actually shown on screen, what kind of
2 -- transitions are available (if any), and what kind of inputs there are,
3 -- if any. In general, it drives the entire display logic by creating Movit
4 -- chains, setting their parameters and then deciding which to show when.
6 -- Themes are written in Lua, which reflects a simplified form of the Movit API
7 -- where all the low-level details (such as texture formats) are handled by the
8 -- C++ side and you generally just build chains.
10 local transition_start = -2.0
11 local transition_end = -1.0
14 local zoom_poi = 0 -- which input to zoom in on
15 local fade_src_signal = 0
16 local fade_dst_signal = 0
18 local input0_neutral_color = {0.5, 0.5, 0.5}
19 local input1_neutral_color = {0.5, 0.5, 0.5}
21 local live_signal_num = 0
22 local preview_signal_num = 1
24 -- Valid values for live_signal_num and preview_signal_num.
25 local INPUT0_SIGNAL_NUM = 0
26 local INPUT1_SIGNAL_NUM = 1
27 local SBS_SIGNAL_NUM = 2
28 local STATIC_SIGNAL_NUM = 3
30 -- “fake” signal number that signifies that we are fading from one input
32 local FADE_SIGNAL_NUM = 4
34 -- Last width/height/resolution for each channel, if we have it.
35 local last_resolution = {}
37 -- Utility function to help creating many similar chains that can differ
38 -- in a free set of chosen parameters.
39 function make_cartesian_product(parms, callback)
40 return make_cartesian_product_internal(parms, callback, 1, {})
43 function make_cartesian_product_internal(parms, callback, index, args)
44 if index > #parms then
45 return callback(unpack(args))
48 for _, value in ipairs(parms[index]) do
50 ret[value] = make_cartesian_product_internal(parms, callback, index + 1, args)
55 function make_sbs_input(chain, signal, deint, hq)
56 local input = chain:add_live_input(not deint, deint) -- Override bounce only if not deinterlacing.
57 input:connect_signal(signal)
58 local wb_effect = chain:add_effect(WhiteBalanceEffect.new())
60 local resample_effect = nil
61 local resize_effect = nil
63 resample_effect = chain:add_effect(ResampleEffect.new())
65 resize_effect = chain:add_effect(ResizeEffect.new())
68 local padding_effect = chain:add_effect(IntegralPaddingEffect.new())
72 wb_effect = wb_effect,
73 resample_effect = resample_effect,
74 resize_effect = resize_effect,
75 padding_effect = padding_effect
79 -- The main live chain.
80 function make_sbs_chain(input0_deint, input1_deint, hq)
81 local chain = EffectChain.new(16, 9)
83 local input0 = make_sbs_input(chain, INPUT0_SIGNAL_NUM, input0_deint, hq)
84 local input1 = make_sbs_input(chain, INPUT1_SIGNAL_NUM, input1_deint, hq)
86 input0.padding_effect:set_vec4("border_color", 0.0, 0.0, 0.0, 1.0)
87 input1.padding_effect:set_vec4("border_color", 0.0, 0.0, 0.0, 0.0)
89 chain:add_effect(OverlayEffect.new(), input0.padding_effect, input1.padding_effect)
99 -- Make all possible combinations of side-by-side chains.
100 local sbs_chains = make_cartesian_product({
101 {"live", "livedeint"}, -- input0_type
102 {"live", "livedeint"}, -- input1_type
104 }, function(input0_type, input1_type, hq)
105 local input0_deint = (input0_type == "livedeint")
106 local input1_deint = (input1_type == "livedeint")
107 return make_sbs_chain(input0_deint, input1_deint, hq)
110 function make_fade_input(chain, signal, live, deint, scale)
111 local input, wb_effect, resample_effect, last
113 input = chain:add_live_input(false, deint)
114 wb_effect = chain:add_effect(WhiteBalanceEffect.new())
115 input:connect_signal(signal)
118 input = chain:add_effect(ImageInput.new("bg.jpeg"))
122 -- If we cared about this for the non-main inputs, we would have
123 -- checked hq here and invoked ResizeEffect instead.
125 resample_effect = chain:add_effect(ResampleEffect.new())
126 last = resample_effect
131 wb_effect = wb_effect,
132 resample_effect = resample_effect,
137 -- A chain to fade between two inputs, of which either can be a picture
138 -- or a live input. In practice only used live, but we still support the
140 function make_fade_chain(input0_live, input0_deint, input0_scale, input1_live, input1_deint, input1_scale, hq)
141 local chain = EffectChain.new(16, 9)
143 local input0 = make_fade_input(chain, INPUT0_SIGNAL_NUM, input0_live, input0_deint, input0_scale)
144 local input1 = make_fade_input(chain, INPUT1_SIGNAL_NUM, input1_live, input1_deint, input1_scale)
146 local mix_effect = chain:add_effect(MixEffect.new(), input0.last, input1.last)
153 mix_effect = mix_effect
157 -- Chains to fade between two inputs, in various configurations.
158 local fade_chains = make_cartesian_product({
159 {"static", "live", "livedeint"}, -- input0_type
160 {true, false}, -- input0_scale
161 {"static", "live", "livedeint"}, -- input1_type
162 {true, false}, -- input1_scale
164 }, function(input0_type, input0_scale, input1_type, input1_scale, hq)
165 local input0_live = (input0_type ~= "static")
166 local input1_live = (input1_type ~= "static")
167 local input0_deint = (input0_type == "livedeint")
168 local input1_deint = (input1_type == "livedeint")
169 return make_fade_chain(input0_live, input0_deint, input0_scale, input1_live, input1_deint, input1_scale, hq)
172 -- A chain to show a single input on screen.
173 function make_simple_chain(input_deint, input_scale, hq)
174 local chain = EffectChain.new(16, 9)
176 local input = chain:add_live_input(false, input_deint)
177 input:connect_signal(0) -- First input card. Can be changed whenever you want.
178 local wb_effect = chain:add_effect(WhiteBalanceEffect.new())
181 local resample_effect, resize_effect
184 resample_effect = chain:add_effect(ResampleEffect.new())
186 resize_effect = chain:add_effect(ResizeEffect.new())
193 wb_effect = wb_effect,
194 resample_effect = resample_effect,
195 resize_effect = resize_effect
199 -- Make all possible combinations of single-input chains.
200 local simple_chains = make_cartesian_product({
201 {"live", "livedeint"}, -- input_type
202 {true, false}, -- input_scale
204 }, function(input_type, input_scale, hq)
205 local input_deint = (input_type == "livedeint")
206 return make_simple_chain(input_deint, input_scale, hq)
209 -- A chain to show a single static picture on screen (HQ version).
210 local static_chain_hq = EffectChain.new(16, 9)
211 local static_chain_hq_input = static_chain_hq:add_effect(ImageInput.new("bg.jpeg"))
212 static_chain_hq:finalize(true)
214 -- A chain to show a single static picture on screen (LQ version).
215 local static_chain_lq = EffectChain.new(16, 9)
216 local static_chain_lq_input = static_chain_lq:add_effect(ImageInput.new("bg.jpeg"))
217 static_chain_lq:finalize(false)
219 -- Used for indexing into the tables of chains.
220 function get_input_type(signals, signal_num)
221 if signal_num == STATIC_SIGNAL_NUM then
223 elseif signals:get_interlaced(signal_num) then
230 function needs_scale(signals, signal_num, width, height)
231 return (signals:get_width(signal_num) ~= width or signals:get_height(signal_num) ~= height)
234 function set_scale_parameters_if_needed(chain_or_input, width, height)
235 if chain_or_input.resample_effect then
236 chain_or_input.resample_effect:set_int("width", width)
237 chain_or_input.resample_effect:set_int("height", height)
238 elseif chain_or_input.resize_effect then
239 chain_or_input.resize_effect:set_int("width", width)
240 chain_or_input.resize_effect:set_int("height", height)
244 -- Returns the number of outputs in addition to the live (0) and preview (1).
245 -- Called only once, at the start of the program.
246 function num_channels()
250 -- Helper function to write e.g. “720p”.
251 function get_channel_resolution(signal_num)
252 if last_resolution[signal_num] then
253 if last_resolution[signal_num].height == 0 or
254 last_resolution[signal_num].height == 525 then
256 elseif last_resolution[signal_num].interlaced then
257 return (last_resolution[signal_num].height * 2) .. "i"
259 return last_resolution[signal_num].height .. "p"
266 -- Returns the name for each additional channel (starting from 2).
267 -- Called at the start of the program, and then each frame for live
268 -- channels in case they change resolution.
269 function channel_name(channel)
271 return "Input 1 (" .. get_channel_resolution(0) .. ")"
272 elseif channel == 3 then
273 return "Input 2 (" .. get_channel_resolution(1) .. ")"
274 elseif channel == 4 then
275 return "Side-by-side"
276 elseif channel == 5 then
277 return "Static picture"
281 -- Returns if a given channel supports setting white balance (starting from 2).
282 -- Called only once for each channel, at the start of the program.
283 function supports_set_wb(channel)
284 return channel == 2 or channel == 3
287 -- Gets called with a new gray point when the white balance is changing.
288 -- The color is in linear light (not sRGB gamma).
289 function set_wb(channel, red, green, blue)
291 input0_neutral_color = { red, green, blue }
292 elseif channel == 3 then
293 input1_neutral_color = { red, green, blue }
297 function finish_transitions(t)
298 -- If live is SBS but de-facto single, make it so.
299 if live_signal_num == SBS_SIGNAL_NUM and t >= transition_end and zoom_dst == 1.0 then
300 live_signal_num = zoom_poi
303 -- If live is fade but de-facto single, make it so.
304 if live_signal_num == FADE_SIGNAL_NUM and t >= transition_end then
305 live_signal_num = fade_dst_signal
309 -- Called every frame.
310 function get_transitions(t)
311 finish_transitions(t)
313 if live_signal_num == preview_signal_num then
317 if live_signal_num == SBS_SIGNAL_NUM and t >= transition_start and t <= transition_end then
322 if (live_signal_num == INPUT0_SIGNAL_NUM or
323 live_signal_num == INPUT1_SIGNAL_NUM or
324 live_signal_num == STATIC_SIGNAL_NUM) and
325 (preview_signal_num == INPUT0_SIGNAL_NUM or
326 preview_signal_num == INPUT1_SIGNAL_NUM or
327 preview_signal_num == STATIC_SIGNAL_NUM) then
328 return {"Cut", "", "Fade"}
332 if live_signal_num == SBS_SIGNAL_NUM and
333 (preview_signal_num == INPUT0_SIGNAL_NUM or preview_signal_num == INPUT1_SIGNAL_NUM) then
334 return {"Cut", "Zoom in"}
335 elseif (live_signal_num == INPUT0_SIGNAL_NUM or live_signal_num == INPUT1_SIGNAL_NUM) and
336 preview_signal_num == SBS_SIGNAL_NUM then
337 return {"Cut", "Zoom out"}
343 function transition_clicked(num, t)
346 if live_signal_num == FADE_SIGNAL_NUM then
347 -- Ongoing fade; finish it immediately.
348 finish_transitions(transition_end)
351 local temp = live_signal_num
352 live_signal_num = preview_signal_num
353 preview_signal_num = temp
355 if live_signal_num == SBS_SIGNAL_NUM then
356 -- Just cut to SBS, we need to reset any zooms.
359 transition_start = -2.0
360 transition_end = -1.0
365 finish_transitions(t)
367 if live_signal_num == preview_signal_num then
372 if (live_signal_num == INPUT0_SIGNAL_NUM and preview_signal_num == INPUT1_SIGNAL_NUM) or
373 (live_signal_num == INPUT1_SIGNAL_NUM and preview_signal_num == INPUT0_SIGNAL_NUM) then
374 -- We can't zoom between these. Just make a cut.
375 io.write("Cutting from " .. live_signal_num .. " to " .. live_signal_num .. "\n")
376 local temp = live_signal_num
377 live_signal_num = preview_signal_num
378 preview_signal_num = temp
382 if live_signal_num == SBS_SIGNAL_NUM and
383 (preview_signal_num == INPUT0_SIGNAL_NUM or preview_signal_num == INPUT1_SIGNAL_NUM) then
384 -- Zoom in from SBS to single.
386 transition_end = t + 1.0
389 zoom_poi = preview_signal_num
390 preview_signal_num = SBS_SIGNAL_NUM
391 elseif (live_signal_num == INPUT0_SIGNAL_NUM or live_signal_num == INPUT1_SIGNAL_NUM) and
392 preview_signal_num == SBS_SIGNAL_NUM then
393 -- Zoom out from single to SBS.
395 transition_end = t + 1.0
398 preview_signal_num = live_signal_num
399 zoom_poi = live_signal_num
400 live_signal_num = SBS_SIGNAL_NUM
403 finish_transitions(t)
406 if (live_signal_num ~= preview_signal_num) and
407 (live_signal_num == INPUT0_SIGNAL_NUM or
408 live_signal_num == INPUT1_SIGNAL_NUM or
409 live_signal_num == STATIC_SIGNAL_NUM) and
410 (preview_signal_num == INPUT0_SIGNAL_NUM or
411 preview_signal_num == INPUT1_SIGNAL_NUM or
412 preview_signal_num == STATIC_SIGNAL_NUM) then
414 transition_end = t + 1.0
415 fade_src_signal = live_signal_num
416 fade_dst_signal = preview_signal_num
417 preview_signal_num = live_signal_num
418 live_signal_num = FADE_SIGNAL_NUM
420 -- Fades involving SBS are ignored (we have no chain for it).
425 function channel_clicked(num)
426 preview_signal_num = num
429 -- Called every frame. Get the chain for displaying at input <num>,
430 -- where 0 is live, 1 is preview, 2 is the first channel to display
431 -- in the bottom bar, and so on up to num_channels()+1. t is the
432 -- current time in seconds. width and height are the dimensions of
433 -- the output, although you can ignore them if you don't need them
434 -- (they're useful if you want to e.g. know what to resample by).
436 -- <signals> is basically an exposed InputState, which you can use to
437 -- query for information about the signals at the point of the current
438 -- frame. In particular, you can call get_width() and get_height()
439 -- for any signal number, and use that to e.g. assist in chain selection.
441 -- You should return two objects; the chain itself, and then a
442 -- function (taking no parameters) that is run just before rendering.
443 -- The function needs to call connect_signal on any inputs, so that
444 -- it gets updated video data for the given frame. (You are allowed
445 -- to switch which input your input is getting from between frames,
446 -- but not calling connect_signal results in undefined behavior.)
447 -- If you want to change any parameters in the chain, this is also
450 -- NOTE: The chain returned must be finalized with the Y'CbCr flag
451 -- if and only if num==0.
452 function get_chain(num, t, width, height, signals)
453 for signal_num=0,1 do
454 last_resolution[signal_num] = {
455 width = signals:get_width(signal_num),
456 height = signals:get_height(signal_num),
457 interlaced = signals:get_interlaced(signal_num)
461 if num == 0 then -- Live.
462 if live_signal_num == INPUT0_SIGNAL_NUM or live_signal_num == INPUT1_SIGNAL_NUM then -- Plain input.
463 local input_type = get_input_type(signals, live_signal_num)
464 local input_scale = needs_scale(signals, live_signal_num, width, height)
465 local chain = simple_chains[input_type][input_scale][true]
467 chain.input:connect_signal(live_signal_num)
468 set_scale_parameters_if_needed(chain, width, height)
469 set_neutral_color_from_signal(chain.wb_effect, live_signal_num)
471 return chain.chain, prepare
472 elseif live_signal_num == STATIC_SIGNAL_NUM then -- Static picture.
475 return static_chain_hq, prepare
476 elseif live_signal_num == FADE_SIGNAL_NUM then -- Fade.
477 local input0_type = get_input_type(signals, fade_src_signal)
478 local input0_scale = needs_scale(signals, fade_src_signal, width, height)
479 local input1_type = get_input_type(signals, fade_dst_signal)
480 local input1_scale = needs_scale(signals, fade_dst_signal, width, height)
481 local chain = fade_chains[input0_type][input0_scale][input1_type][input1_scale][true]
483 if input0_type == "live" then
484 chain.input0.input:connect_signal(fade_src_signal)
485 set_neutral_color_from_signal(chain.input0.wb_effect, fade_src_signal)
487 set_scale_parameters_if_needed(chain.input0, width, height)
488 if input1_type == "live" then
489 chain.input1.input:connect_signal(fade_dst_signal)
490 set_neutral_color_from_signal(chain.input1.wb_effect, fade_dst_signal)
492 set_scale_parameters_if_needed(chain.input1, width, height)
493 local tt = calc_fade_progress(t, transition_start, transition_end)
495 chain.mix_effect:set_float("strength_first", 1.0 - tt)
496 chain.mix_effect:set_float("strength_second", tt)
498 return chain.chain, prepare
501 -- SBS code (live_signal_num == SBS_SIGNAL_NUM).
502 local input0_type = get_input_type(signals, INPUT0_SIGNAL_NUM)
503 local input1_type = get_input_type(signals, INPUT1_SIGNAL_NUM)
504 if t > transition_end and zoom_dst == 1.0 then
505 -- Special case: Show only the single image on screen.
506 local input0_scale = needs_scale(signals, fade_src_signal, width, height)
507 local chain = simple_chains[input0_type][input0_scale][true]
509 chain.input:connect_signal(INPUT0_SIGNAL_NUM)
510 set_scale_parameters_if_needed(chain, width, height)
511 set_neutral_color(chain.wb_effect, input0_neutral_color)
513 return chain.chain, prepare
515 local chain = sbs_chains[input0_type][input1_type][true]
517 if t < transition_start then
518 prepare_sbs_chain(chain, zoom_src, width, height)
519 elseif t > transition_end then
520 prepare_sbs_chain(chain, zoom_dst, width, height)
522 local tt = (t - transition_start) / (transition_end - transition_start)
524 tt = math.sin(tt * 3.14159265358 * 0.5)
525 prepare_sbs_chain(chain, zoom_src + (zoom_dst - zoom_src) * tt, width, height)
528 return chain.chain, prepare
530 if num == 1 then -- Preview.
531 num = preview_signal_num + 2
534 -- Individual preview inputs.
535 if num == INPUT0_SIGNAL_NUM + 2 then
536 local input_type = get_input_type(signals, INPUT0_SIGNAL_NUM)
537 local input_scale = needs_scale(signals, INPUT0_SIGNAL_NUM, width, height)
538 local chain = simple_chains[input_type][input_scale][false]
540 chain.input:connect_signal(INPUT0_SIGNAL_NUM)
541 set_scale_parameters_if_needed(chain, width, height)
542 set_neutral_color(chain.wb_effect, input0_neutral_color)
544 return chain.chain, prepare
546 if num == INPUT1_SIGNAL_NUM + 2 then
547 local input_type = get_input_type(signals, INPUT1_SIGNAL_NUM)
548 local input_scale = needs_scale(signals, INPUT1_SIGNAL_NUM, width, height)
549 local chain = simple_chains[input_type][input_scale][false]
551 chain.input:connect_signal(INPUT1_SIGNAL_NUM)
552 set_scale_parameters_if_needed(chain, width, height)
553 set_neutral_color(chain.wb_effect, input1_neutral_color)
555 return chain.chain, prepare
557 if num == SBS_SIGNAL_NUM + 2 then
558 local input0_type = get_input_type(signals, INPUT0_SIGNAL_NUM)
559 local input1_type = get_input_type(signals, INPUT1_SIGNAL_NUM)
560 local chain = sbs_chains[input0_type][input1_type][false]
562 prepare_sbs_chain(chain, 0.0, width, height)
564 return chain.chain, prepare
566 if num == STATIC_SIGNAL_NUM + 2 then
569 return static_chain_lq, prepare
573 function place_rectangle(resample_effect, resize_effect, padding_effect, x0, y0, x1, y1, screen_width, screen_height, input_width, input_height)
580 if x0 > screen_width or x1 < 0.0 or y0 > screen_height or y1 < 0.0 then
581 resample_effect:set_int("width", 1)
582 resample_effect:set_int("height", 1)
583 resample_effect:set_float("zoom_x", screen_width)
584 resample_effect:set_float("zoom_y", screen_height)
585 padding_effect:set_int("left", screen_width + 100)
586 padding_effect:set_int("top", screen_height + 100)
592 srcx0 = -x0 / (x1 - x0)
596 srcy0 = -y0 / (y1 - y0)
599 if x1 > screen_width then
600 srcx1 = (screen_width - x0) / (x1 - x0)
603 if y1 > screen_height then
604 srcy1 = (screen_height - y0) / (y1 - y0)
608 if resample_effect ~= nil then
609 -- High-quality resampling.
610 local x_subpixel_offset = x0 - math.floor(x0)
611 local y_subpixel_offset = y0 - math.floor(y0)
613 -- Resampling must be to an integral number of pixels. Round up,
614 -- and then add an extra pixel so we have some leeway for the border.
615 local width = math.ceil(x1 - x0) + 1
616 local height = math.ceil(y1 - y0) + 1
617 resample_effect:set_int("width", width)
618 resample_effect:set_int("height", height)
620 -- Correct the discrepancy with zoom. (This will leave a small
621 -- excess edge of pixels and subpixels, which we'll correct for soon.)
622 local zoom_x = (x1 - x0) / (width * (srcx1 - srcx0))
623 local zoom_y = (y1 - y0) / (height * (srcy1 - srcy0))
624 resample_effect:set_float("zoom_x", zoom_x)
625 resample_effect:set_float("zoom_y", zoom_y)
626 resample_effect:set_float("zoom_center_x", 0.0)
627 resample_effect:set_float("zoom_center_y", 0.0)
629 -- Padding must also be to a whole-pixel offset.
630 padding_effect:set_int("left", math.floor(x0))
631 padding_effect:set_int("top", math.floor(y0))
633 -- Correct _that_ discrepancy by subpixel offset in the resampling.
634 resample_effect:set_float("left", srcx0 * input_width - x_subpixel_offset / zoom_x)
635 resample_effect:set_float("top", srcy0 * input_height - y_subpixel_offset / zoom_y)
637 -- Finally, adjust the border so it is exactly where we want it.
638 padding_effect:set_float("border_offset_left", x_subpixel_offset)
639 padding_effect:set_float("border_offset_right", x1 - (math.floor(x0) + width))
640 padding_effect:set_float("border_offset_top", y_subpixel_offset)
641 padding_effect:set_float("border_offset_bottom", y1 - (math.floor(y0) + height))
643 -- Lower-quality simple resizing.
644 local width = round(x1 - x0)
645 local height = round(y1 - y0)
646 resize_effect:set_int("width", width)
647 resize_effect:set_int("height", height)
649 -- Padding must also be to a whole-pixel offset.
650 padding_effect:set_int("left", math.floor(x0))
651 padding_effect:set_int("top", math.floor(y0))
655 -- This is broken, of course (even for positive numbers), but Lua doesn't give us access to real rounding.
657 return math.floor(x + 0.5)
660 function lerp(a, b, t)
661 return a + (b - a) * t
664 function prepare_sbs_chain(chain, t, screen_width, screen_height)
665 chain.input0.input:connect_signal(0)
666 chain.input1.input:connect_signal(1)
667 set_neutral_color(chain.input0.wb_effect, input0_neutral_color)
668 set_neutral_color(chain.input1.wb_effect, input1_neutral_color)
670 -- First input is positioned (16,48) from top-left.
671 local width0 = round(848 * screen_width/1280.0)
672 local height0 = round(width0 * 9.0 / 16.0)
674 local top0 = 48 * screen_height/720.0
675 local left0 = 16 * screen_width/1280.0
676 local bottom0 = top0 + height0
677 local right0 = left0 + width0
679 -- Second input is positioned (16,48) from the bottom-right.
680 local width1 = round(384 * screen_width/1280.0)
681 local height1 = round(216 * screen_height/720.0)
683 local bottom1 = screen_height - 48 * screen_height/720.0
684 local right1 = screen_width - 16 * screen_width/1280.0
685 local top1 = bottom1 - height1
686 local left1 = right1 - width1
688 -- Interpolate between the fullscreen and side-by-side views.
689 local scale0, tx0, tx0
690 if zoom_poi == INPUT0_SIGNAL_NUM then
691 local new_left0 = lerp(left0, 0, t)
692 local new_right0 = lerp(right0, screen_width, t)
693 local new_top0 = lerp(top0, 0, t)
694 local new_bottom0 = lerp(bottom0, screen_height, t)
696 scale0 = (new_right0 - new_left0) / width0 -- Same vertically and horizonally.
697 tx0 = new_left0 - left0 * scale0
698 ty0 = new_top0 - top0 * scale0
700 local new_left1 = lerp(left1, 0, t)
701 local new_right1 = lerp(right1, screen_width, t)
702 local new_top1 = lerp(top1, 0, t)
703 local new_bottom1 = lerp(bottom1, screen_height, t)
705 scale0 = (new_right1 - new_left1) / width1 -- Same vertically and horizonally.
706 tx0 = new_left1 - left1 * scale0
707 ty0 = new_top1 - top1 * scale0
710 top0 = top0 * scale0 + ty0
711 bottom0 = bottom0 * scale0 + ty0
712 left0 = left0 * scale0 + tx0
713 right0 = right0 * scale0 + tx0
715 top1 = top1 * scale0 + ty0
716 bottom1 = bottom1 * scale0 + ty0
717 left1 = left1 * scale0 + tx0
718 right1 = right1 * scale0 + tx0
719 place_rectangle(chain.input0.resample_effect, chain.input0.resize_effect, chain.input0.padding_effect, left0, top0, right0, bottom0, screen_width, screen_height, 1280, 720)
720 place_rectangle(chain.input1.resample_effect, chain.input1.resize_effect, chain.input1.padding_effect, left1, top1, right1, bottom1, screen_width, screen_height, 1280, 720)
723 function set_neutral_color(effect, color)
724 effect:set_vec3("neutral_color", color[1], color[2], color[3])
727 function set_neutral_color_from_signal(effect, signal)
728 if signal == INPUT0_SIGNAL_NUM then
729 set_neutral_color(effect, input0_neutral_color)
731 set_neutral_color(effect, input1_neutral_color)
735 function calc_fade_progress(t, transition_start, transition_end)
736 local tt = (t - transition_start) / (transition_end - transition_start)
743 -- Make the fade look maybe a tad more natural, by pumping it
744 -- through a sigmoid function.
746 tt = 1.0 / (1.0 + math.exp(-tt))