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 -- Note that unlike the values we get from Nageru, the resolution is per
36 -- frame and not per field, since we deinterlace.
37 local last_resolution = {}
39 -- Utility function to help creating many similar chains that can differ
40 -- in a free set of chosen parameters.
41 function make_cartesian_product(parms, callback)
42 return make_cartesian_product_internal(parms, callback, 1, {})
45 function make_cartesian_product_internal(parms, callback, index, args)
46 if index > #parms then
47 return callback(unpack(args))
50 for _, value in ipairs(parms[index]) do
52 ret[value] = make_cartesian_product_internal(parms, callback, index + 1, args)
57 function make_sbs_input(chain, signal, deint, hq)
58 local input = chain:add_live_input(not deint, deint) -- Override bounce only if not deinterlacing.
59 input:connect_signal(signal)
60 local wb_effect = chain:add_effect(WhiteBalanceEffect.new())
62 local resample_effect = nil
63 local resize_effect = nil
65 resample_effect = chain:add_effect(ResampleEffect.new())
67 resize_effect = chain:add_effect(ResizeEffect.new())
70 local padding_effect = chain:add_effect(IntegralPaddingEffect.new())
74 wb_effect = wb_effect,
75 resample_effect = resample_effect,
76 resize_effect = resize_effect,
77 padding_effect = padding_effect
81 -- The main live chain.
82 function make_sbs_chain(input0_deint, input1_deint, hq)
83 local chain = EffectChain.new(16, 9)
85 local input0 = make_sbs_input(chain, INPUT0_SIGNAL_NUM, input0_deint, hq)
86 local input1 = make_sbs_input(chain, INPUT1_SIGNAL_NUM, input1_deint, hq)
88 input0.padding_effect:set_vec4("border_color", 0.0, 0.0, 0.0, 1.0)
89 input1.padding_effect:set_vec4("border_color", 0.0, 0.0, 0.0, 0.0)
91 chain:add_effect(OverlayEffect.new(), input0.padding_effect, input1.padding_effect)
101 -- Make all possible combinations of side-by-side chains.
102 local sbs_chains = make_cartesian_product({
103 {"live", "livedeint"}, -- input0_type
104 {"live", "livedeint"}, -- input1_type
106 }, function(input0_type, input1_type, hq)
107 local input0_deint = (input0_type == "livedeint")
108 local input1_deint = (input1_type == "livedeint")
109 return make_sbs_chain(input0_deint, input1_deint, hq)
112 function make_fade_input(chain, signal, live, deint, scale)
113 local input, wb_effect, resample_effect, last
115 input = chain:add_live_input(false, deint)
116 wb_effect = chain:add_effect(WhiteBalanceEffect.new())
117 input:connect_signal(signal)
120 input = chain:add_effect(ImageInput.new("bg.jpeg"))
124 -- If we cared about this for the non-main inputs, we would have
125 -- checked hq here and invoked ResizeEffect instead.
127 resample_effect = chain:add_effect(ResampleEffect.new())
128 last = resample_effect
133 wb_effect = wb_effect,
134 resample_effect = resample_effect,
139 -- A chain to fade between two inputs, of which either can be a picture
140 -- or a live input. In practice only used live, but we still support the
142 function make_fade_chain(input0_live, input0_deint, input0_scale, input1_live, input1_deint, input1_scale, hq)
143 local chain = EffectChain.new(16, 9)
145 local input0 = make_fade_input(chain, INPUT0_SIGNAL_NUM, input0_live, input0_deint, input0_scale)
146 local input1 = make_fade_input(chain, INPUT1_SIGNAL_NUM, input1_live, input1_deint, input1_scale)
148 local mix_effect = chain:add_effect(MixEffect.new(), input0.last, input1.last)
155 mix_effect = mix_effect
159 -- Chains to fade between two inputs, in various configurations.
160 local fade_chains = make_cartesian_product({
161 {"static", "live", "livedeint"}, -- input0_type
162 {true, false}, -- input0_scale
163 {"static", "live", "livedeint"}, -- input1_type
164 {true, false}, -- input1_scale
166 }, function(input0_type, input0_scale, input1_type, input1_scale, hq)
167 local input0_live = (input0_type ~= "static")
168 local input1_live = (input1_type ~= "static")
169 local input0_deint = (input0_type == "livedeint")
170 local input1_deint = (input1_type == "livedeint")
171 return make_fade_chain(input0_live, input0_deint, input0_scale, input1_live, input1_deint, input1_scale, hq)
174 -- A chain to show a single input on screen.
175 function make_simple_chain(input_deint, input_scale, hq)
176 local chain = EffectChain.new(16, 9)
178 local input = chain:add_live_input(false, input_deint)
179 input:connect_signal(0) -- First input card. Can be changed whenever you want.
180 local wb_effect = chain:add_effect(WhiteBalanceEffect.new())
183 local resample_effect, resize_effect
186 resample_effect = chain:add_effect(ResampleEffect.new())
188 resize_effect = chain:add_effect(ResizeEffect.new())
195 wb_effect = wb_effect,
196 resample_effect = resample_effect,
197 resize_effect = resize_effect
201 -- Make all possible combinations of single-input chains.
202 local simple_chains = make_cartesian_product({
203 {"live", "livedeint"}, -- input_type
204 {true, false}, -- input_scale
206 }, function(input_type, input_scale, hq)
207 local input_deint = (input_type == "livedeint")
208 return make_simple_chain(input_deint, input_scale, hq)
211 -- A chain to show a single static picture on screen (HQ version).
212 local static_chain_hq = EffectChain.new(16, 9)
213 local static_chain_hq_input = static_chain_hq:add_effect(ImageInput.new("bg.jpeg"))
214 static_chain_hq:finalize(true)
216 -- A chain to show a single static picture on screen (LQ version).
217 local static_chain_lq = EffectChain.new(16, 9)
218 local static_chain_lq_input = static_chain_lq:add_effect(ImageInput.new("bg.jpeg"))
219 static_chain_lq:finalize(false)
221 -- Used for indexing into the tables of chains.
222 function get_input_type(signals, signal_num)
223 if signal_num == STATIC_SIGNAL_NUM then
225 elseif signals:get_interlaced(signal_num) then
232 function needs_scale(signals, signal_num, width, height)
233 if signal_num == STATIC_SIGNAL_NUM then
234 -- We assume this is already correctly scaled at load time.
237 assert(signal_num == INPUT0_SIGNAL_NUM or signal_num == INPUT1_SIGNAL_NUM)
238 return (signals:get_width(signal_num) ~= width or signals:get_height(signal_num) ~= height)
241 function set_scale_parameters_if_needed(chain_or_input, width, height)
242 if chain_or_input.resample_effect then
243 chain_or_input.resample_effect:set_int("width", width)
244 chain_or_input.resample_effect:set_int("height", height)
245 elseif chain_or_input.resize_effect then
246 chain_or_input.resize_effect:set_int("width", width)
247 chain_or_input.resize_effect:set_int("height", height)
251 -- Returns the number of outputs in addition to the live (0) and preview (1).
252 -- Called only once, at the start of the program.
253 function num_channels()
257 -- Helper function to write e.g. “60” or “59.94”.
258 function get_frame_rate(signal_num)
259 local nom = last_resolution[signal_num].frame_rate_nom
260 local den = last_resolution[signal_num].frame_rate_den
261 if nom % den == 0 then
264 return string.format("%.2f", nom / den)
268 -- Helper function to write e.g. “720p60”.
269 function get_channel_resolution(signal_num)
270 if last_resolution[signal_num] then
271 if last_resolution[signal_num].height == 0 or
272 last_resolution[signal_num].height == 525 then
274 elseif last_resolution[signal_num].interlaced then
275 return last_resolution[signal_num].height .. "i" .. get_frame_rate(signal_num)
277 return last_resolution[signal_num].height .. "p" .. get_frame_rate(signal_num)
284 -- Returns the name for each additional channel (starting from 2).
285 -- Called at the start of the program, and then each frame for live
286 -- channels in case they change resolution.
287 function channel_name(channel)
289 return "Input 1 (" .. get_channel_resolution(0) .. ")"
290 elseif channel == 3 then
291 return "Input 2 (" .. get_channel_resolution(1) .. ")"
292 elseif channel == 4 then
293 return "Side-by-side"
294 elseif channel == 5 then
295 return "Static picture"
299 -- Returns if a given channel supports setting white balance (starting from 2).
300 -- Called only once for each channel, at the start of the program.
301 function supports_set_wb(channel)
302 return channel == 2 or channel == 3
305 -- Gets called with a new gray point when the white balance is changing.
306 -- The color is in linear light (not sRGB gamma).
307 function set_wb(channel, red, green, blue)
309 input0_neutral_color = { red, green, blue }
310 elseif channel == 3 then
311 input1_neutral_color = { red, green, blue }
315 function finish_transitions(t)
316 -- If live is SBS but de-facto single, make it so.
317 if live_signal_num == SBS_SIGNAL_NUM and t >= transition_end and zoom_dst == 1.0 then
318 live_signal_num = zoom_poi
321 -- If live is fade but de-facto single, make it so.
322 if live_signal_num == FADE_SIGNAL_NUM and t >= transition_end then
323 live_signal_num = fade_dst_signal
327 -- Called every frame.
328 function get_transitions(t)
329 finish_transitions(t)
331 if live_signal_num == preview_signal_num then
335 if live_signal_num == SBS_SIGNAL_NUM and t >= transition_start and t <= transition_end then
340 if (live_signal_num == INPUT0_SIGNAL_NUM or
341 live_signal_num == INPUT1_SIGNAL_NUM or
342 live_signal_num == STATIC_SIGNAL_NUM) and
343 (preview_signal_num == INPUT0_SIGNAL_NUM or
344 preview_signal_num == INPUT1_SIGNAL_NUM or
345 preview_signal_num == STATIC_SIGNAL_NUM) then
346 return {"Cut", "", "Fade"}
350 if live_signal_num == SBS_SIGNAL_NUM and
351 (preview_signal_num == INPUT0_SIGNAL_NUM or preview_signal_num == INPUT1_SIGNAL_NUM) then
352 return {"Cut", "Zoom in"}
353 elseif (live_signal_num == INPUT0_SIGNAL_NUM or live_signal_num == INPUT1_SIGNAL_NUM) and
354 preview_signal_num == SBS_SIGNAL_NUM then
355 return {"Cut", "Zoom out"}
361 function transition_clicked(num, t)
364 if live_signal_num == FADE_SIGNAL_NUM then
365 -- Ongoing fade; finish it immediately.
366 finish_transitions(transition_end)
369 local temp = live_signal_num
370 live_signal_num = preview_signal_num
371 preview_signal_num = temp
373 if live_signal_num == SBS_SIGNAL_NUM then
374 -- Just cut to SBS, we need to reset any zooms.
377 transition_start = -2.0
378 transition_end = -1.0
383 finish_transitions(t)
385 if live_signal_num == preview_signal_num then
390 if (live_signal_num == INPUT0_SIGNAL_NUM and preview_signal_num == INPUT1_SIGNAL_NUM) or
391 (live_signal_num == INPUT1_SIGNAL_NUM and preview_signal_num == INPUT0_SIGNAL_NUM) then
392 -- We can't zoom between these. Just make a cut.
393 io.write("Cutting from " .. live_signal_num .. " to " .. live_signal_num .. "\n")
394 local temp = live_signal_num
395 live_signal_num = preview_signal_num
396 preview_signal_num = temp
400 if live_signal_num == SBS_SIGNAL_NUM and
401 (preview_signal_num == INPUT0_SIGNAL_NUM or preview_signal_num == INPUT1_SIGNAL_NUM) then
402 -- Zoom in from SBS to single.
404 transition_end = t + 1.0
407 zoom_poi = preview_signal_num
408 preview_signal_num = SBS_SIGNAL_NUM
409 elseif (live_signal_num == INPUT0_SIGNAL_NUM or live_signal_num == INPUT1_SIGNAL_NUM) and
410 preview_signal_num == SBS_SIGNAL_NUM then
411 -- Zoom out from single to SBS.
413 transition_end = t + 1.0
416 preview_signal_num = live_signal_num
417 zoom_poi = live_signal_num
418 live_signal_num = SBS_SIGNAL_NUM
421 finish_transitions(t)
424 if (live_signal_num ~= preview_signal_num) and
425 (live_signal_num == INPUT0_SIGNAL_NUM or
426 live_signal_num == INPUT1_SIGNAL_NUM or
427 live_signal_num == STATIC_SIGNAL_NUM) and
428 (preview_signal_num == INPUT0_SIGNAL_NUM or
429 preview_signal_num == INPUT1_SIGNAL_NUM or
430 preview_signal_num == STATIC_SIGNAL_NUM) then
432 transition_end = t + 1.0
433 fade_src_signal = live_signal_num
434 fade_dst_signal = preview_signal_num
435 preview_signal_num = live_signal_num
436 live_signal_num = FADE_SIGNAL_NUM
438 -- Fades involving SBS are ignored (we have no chain for it).
443 function channel_clicked(num)
444 preview_signal_num = num
447 -- Called every frame. Get the chain for displaying at input <num>,
448 -- where 0 is live, 1 is preview, 2 is the first channel to display
449 -- in the bottom bar, and so on up to num_channels()+1. t is the
450 -- current time in seconds. width and height are the dimensions of
451 -- the output, although you can ignore them if you don't need them
452 -- (they're useful if you want to e.g. know what to resample by).
454 -- <signals> is basically an exposed InputState, which you can use to
455 -- query for information about the signals at the point of the current
456 -- frame. In particular, you can call get_width() and get_height()
457 -- for any signal number, and use that to e.g. assist in chain selection.
459 -- You should return two objects; the chain itself, and then a
460 -- function (taking no parameters) that is run just before rendering.
461 -- The function needs to call connect_signal on any inputs, so that
462 -- it gets updated video data for the given frame. (You are allowed
463 -- to switch which input your input is getting from between frames,
464 -- but not calling connect_signal results in undefined behavior.)
465 -- If you want to change any parameters in the chain, this is also
468 -- NOTE: The chain returned must be finalized with the Y'CbCr flag
469 -- if and only if num==0.
470 function get_chain(num, t, width, height, signals)
471 local input_resolution = {}
472 for signal_num=0,1 do
474 width = signals:get_width(signal_num),
475 height = signals:get_height(signal_num),
476 interlaced = signals:get_interlaced(signal_num),
477 frame_rate_nom = signals:get_frame_rate_nom(signal_num),
478 frame_rate_den = signals:get_frame_rate_den(signal_num)
481 if res.interlaced then
482 -- Convert height from frame height to field height.
483 -- (Needed for e.g. place_rectangle.)
484 res.height = res.height * 2
486 -- Show field rate instead of frame rate; really for cosmetics only
487 -- (and actually contrary to EBU recommendations, although in line
488 -- with typical user expectations).
489 res.frame_rate_nom = res.frame_rate_nom * 2
492 input_resolution[signal_num] = res
494 last_resolution = input_resolution
496 if num == 0 then -- Live.
497 if live_signal_num == INPUT0_SIGNAL_NUM or live_signal_num == INPUT1_SIGNAL_NUM then -- Plain input.
498 local input_type = get_input_type(signals, live_signal_num)
499 local input_scale = needs_scale(signals, live_signal_num, width, height)
500 local chain = simple_chains[input_type][input_scale][true]
502 chain.input:connect_signal(live_signal_num)
503 set_scale_parameters_if_needed(chain, width, height)
504 set_neutral_color_from_signal(chain.wb_effect, live_signal_num)
506 return chain.chain, prepare
507 elseif live_signal_num == STATIC_SIGNAL_NUM then -- Static picture.
510 return static_chain_hq, prepare
511 elseif live_signal_num == FADE_SIGNAL_NUM then -- Fade.
512 local input0_type = get_input_type(signals, fade_src_signal)
513 local input0_scale = needs_scale(signals, fade_src_signal, width, height)
514 local input1_type = get_input_type(signals, fade_dst_signal)
515 local input1_scale = needs_scale(signals, fade_dst_signal, width, height)
516 local chain = fade_chains[input0_type][input0_scale][input1_type][input1_scale][true]
518 if input0_type == "live" then
519 chain.input0.input:connect_signal(fade_src_signal)
520 set_neutral_color_from_signal(chain.input0.wb_effect, fade_src_signal)
522 set_scale_parameters_if_needed(chain.input0, width, height)
523 if input1_type == "live" then
524 chain.input1.input:connect_signal(fade_dst_signal)
525 set_neutral_color_from_signal(chain.input1.wb_effect, fade_dst_signal)
527 set_scale_parameters_if_needed(chain.input1, width, height)
528 local tt = calc_fade_progress(t, transition_start, transition_end)
530 chain.mix_effect:set_float("strength_first", 1.0 - tt)
531 chain.mix_effect:set_float("strength_second", tt)
533 return chain.chain, prepare
536 -- SBS code (live_signal_num == SBS_SIGNAL_NUM).
537 local input0_type = get_input_type(signals, INPUT0_SIGNAL_NUM)
538 local input1_type = get_input_type(signals, INPUT1_SIGNAL_NUM)
539 if t > transition_end and zoom_dst == 1.0 then
540 -- Special case: Show only the single image on screen.
541 local input0_scale = needs_scale(signals, fade_src_signal, width, height)
542 local chain = simple_chains[input0_type][input0_scale][true]
544 chain.input:connect_signal(INPUT0_SIGNAL_NUM)
545 set_scale_parameters_if_needed(chain, width, height)
546 set_neutral_color(chain.wb_effect, input0_neutral_color)
548 return chain.chain, prepare
550 local chain = sbs_chains[input0_type][input1_type][true]
552 if t < transition_start then
553 prepare_sbs_chain(chain, zoom_src, width, height, input_resolution)
554 elseif t > transition_end then
555 prepare_sbs_chain(chain, zoom_dst, width, height, input_resolution)
557 local tt = (t - transition_start) / (transition_end - transition_start)
559 tt = math.sin(tt * 3.14159265358 * 0.5)
560 prepare_sbs_chain(chain, zoom_src + (zoom_dst - zoom_src) * tt, width, height, input_resolution)
563 return chain.chain, prepare
565 if num == 1 then -- Preview.
566 num = preview_signal_num + 2
569 -- Individual preview inputs.
570 if num == INPUT0_SIGNAL_NUM + 2 then
571 local input_type = get_input_type(signals, INPUT0_SIGNAL_NUM)
572 local input_scale = needs_scale(signals, INPUT0_SIGNAL_NUM, width, height)
573 local chain = simple_chains[input_type][input_scale][false]
575 chain.input:connect_signal(INPUT0_SIGNAL_NUM)
576 set_scale_parameters_if_needed(chain, width, height)
577 set_neutral_color(chain.wb_effect, input0_neutral_color)
579 return chain.chain, prepare
581 if num == INPUT1_SIGNAL_NUM + 2 then
582 local input_type = get_input_type(signals, INPUT1_SIGNAL_NUM)
583 local input_scale = needs_scale(signals, INPUT1_SIGNAL_NUM, width, height)
584 local chain = simple_chains[input_type][input_scale][false]
586 chain.input:connect_signal(INPUT1_SIGNAL_NUM)
587 set_scale_parameters_if_needed(chain, width, height)
588 set_neutral_color(chain.wb_effect, input1_neutral_color)
590 return chain.chain, prepare
592 if num == SBS_SIGNAL_NUM + 2 then
593 local input0_type = get_input_type(signals, INPUT0_SIGNAL_NUM)
594 local input1_type = get_input_type(signals, INPUT1_SIGNAL_NUM)
595 local chain = sbs_chains[input0_type][input1_type][false]
597 prepare_sbs_chain(chain, 0.0, width, height, input_resolution)
599 return chain.chain, prepare
601 if num == STATIC_SIGNAL_NUM + 2 then
604 return static_chain_lq, prepare
608 function place_rectangle(resample_effect, resize_effect, padding_effect, x0, y0, x1, y1, screen_width, screen_height, input_width, input_height)
615 if x0 > screen_width or x1 < 0.0 or y0 > screen_height or y1 < 0.0 then
616 resample_effect:set_int("width", 1)
617 resample_effect:set_int("height", 1)
618 resample_effect:set_float("zoom_x", screen_width)
619 resample_effect:set_float("zoom_y", screen_height)
620 padding_effect:set_int("left", screen_width + 100)
621 padding_effect:set_int("top", screen_height + 100)
627 srcx0 = -x0 / (x1 - x0)
631 srcy0 = -y0 / (y1 - y0)
634 if x1 > screen_width then
635 srcx1 = (screen_width - x0) / (x1 - x0)
638 if y1 > screen_height then
639 srcy1 = (screen_height - y0) / (y1 - y0)
643 if resample_effect ~= nil then
644 -- High-quality resampling.
645 local x_subpixel_offset = x0 - math.floor(x0)
646 local y_subpixel_offset = y0 - math.floor(y0)
648 -- Resampling must be to an integral number of pixels. Round up,
649 -- and then add an extra pixel so we have some leeway for the border.
650 local width = math.ceil(x1 - x0) + 1
651 local height = math.ceil(y1 - y0) + 1
652 resample_effect:set_int("width", width)
653 resample_effect:set_int("height", height)
655 -- Correct the discrepancy with zoom. (This will leave a small
656 -- excess edge of pixels and subpixels, which we'll correct for soon.)
657 local zoom_x = (x1 - x0) / (width * (srcx1 - srcx0))
658 local zoom_y = (y1 - y0) / (height * (srcy1 - srcy0))
659 resample_effect:set_float("zoom_x", zoom_x)
660 resample_effect:set_float("zoom_y", zoom_y)
661 resample_effect:set_float("zoom_center_x", 0.0)
662 resample_effect:set_float("zoom_center_y", 0.0)
664 -- Padding must also be to a whole-pixel offset.
665 padding_effect:set_int("left", math.floor(x0))
666 padding_effect:set_int("top", math.floor(y0))
668 -- Correct _that_ discrepancy by subpixel offset in the resampling.
669 resample_effect:set_float("left", srcx0 * input_width - x_subpixel_offset / zoom_x)
670 resample_effect:set_float("top", srcy0 * input_height - y_subpixel_offset / zoom_y)
672 -- Finally, adjust the border so it is exactly where we want it.
673 padding_effect:set_float("border_offset_left", x_subpixel_offset)
674 padding_effect:set_float("border_offset_right", x1 - (math.floor(x0) + width))
675 padding_effect:set_float("border_offset_top", y_subpixel_offset)
676 padding_effect:set_float("border_offset_bottom", y1 - (math.floor(y0) + height))
678 -- Lower-quality simple resizing.
679 local width = round(x1 - x0)
680 local height = round(y1 - y0)
681 resize_effect:set_int("width", width)
682 resize_effect:set_int("height", height)
684 -- Padding must also be to a whole-pixel offset.
685 padding_effect:set_int("left", math.floor(x0))
686 padding_effect:set_int("top", math.floor(y0))
690 -- This is broken, of course (even for positive numbers), but Lua doesn't give us access to real rounding.
692 return math.floor(x + 0.5)
695 function lerp(a, b, t)
696 return a + (b - a) * t
699 function prepare_sbs_chain(chain, t, screen_width, screen_height, input_resolution)
700 chain.input0.input:connect_signal(0)
701 chain.input1.input:connect_signal(1)
702 set_neutral_color(chain.input0.wb_effect, input0_neutral_color)
703 set_neutral_color(chain.input1.wb_effect, input1_neutral_color)
705 -- First input is positioned (16,48) from top-left.
706 local width0 = round(848 * screen_width/1280.0)
707 local height0 = round(width0 * 9.0 / 16.0)
709 local top0 = 48 * screen_height/720.0
710 local left0 = 16 * screen_width/1280.0
711 local bottom0 = top0 + height0
712 local right0 = left0 + width0
714 -- Second input is positioned (16,48) from the bottom-right.
715 local width1 = round(384 * screen_width/1280.0)
716 local height1 = round(216 * screen_height/720.0)
718 local bottom1 = screen_height - 48 * screen_height/720.0
719 local right1 = screen_width - 16 * screen_width/1280.0
720 local top1 = bottom1 - height1
721 local left1 = right1 - width1
723 -- Interpolate between the fullscreen and side-by-side views.
724 local scale0, tx0, tx0
725 if zoom_poi == INPUT0_SIGNAL_NUM then
726 local new_left0 = lerp(left0, 0, t)
727 local new_right0 = lerp(right0, screen_width, t)
728 local new_top0 = lerp(top0, 0, t)
729 local new_bottom0 = lerp(bottom0, screen_height, t)
731 scale0 = (new_right0 - new_left0) / width0 -- Same vertically and horizonally.
732 tx0 = new_left0 - left0 * scale0
733 ty0 = new_top0 - top0 * scale0
735 local new_left1 = lerp(left1, 0, t)
736 local new_right1 = lerp(right1, screen_width, t)
737 local new_top1 = lerp(top1, 0, t)
738 local new_bottom1 = lerp(bottom1, screen_height, t)
740 scale0 = (new_right1 - new_left1) / width1 -- Same vertically and horizonally.
741 tx0 = new_left1 - left1 * scale0
742 ty0 = new_top1 - top1 * scale0
745 top0 = top0 * scale0 + ty0
746 bottom0 = bottom0 * scale0 + ty0
747 left0 = left0 * scale0 + tx0
748 right0 = right0 * scale0 + tx0
750 top1 = top1 * scale0 + ty0
751 bottom1 = bottom1 * scale0 + ty0
752 left1 = left1 * scale0 + tx0
753 right1 = right1 * scale0 + tx0
754 place_rectangle(chain.input0.resample_effect, chain.input0.resize_effect, chain.input0.padding_effect, left0, top0, right0, bottom0, screen_width, screen_height, input_resolution[0].width, input_resolution[0].height)
755 place_rectangle(chain.input1.resample_effect, chain.input1.resize_effect, chain.input1.padding_effect, left1, top1, right1, bottom1, screen_width, screen_height, input_resolution[1].width, input_resolution[1].height)
758 function set_neutral_color(effect, color)
759 effect:set_vec3("neutral_color", color[1], color[2], color[3])
762 function set_neutral_color_from_signal(effect, signal)
763 if signal == INPUT0_SIGNAL_NUM then
764 set_neutral_color(effect, input0_neutral_color)
766 set_neutral_color(effect, input1_neutral_color)
770 function calc_fade_progress(t, transition_start, transition_end)
771 local tt = (t - transition_start) / (transition_end - transition_start)
778 -- Make the fade look maybe a tad more natural, by pumping it
779 -- through a sigmoid function.
781 tt = 1.0 / (1.0 + math.exp(-tt))