Effects » DVE » User Effects » 2D DVE plus alpha


2D DVE plus alpha
Author(s):
Release date: Oct. 16, 2018
Creation date: Oct. 7, 2018
License: unknown

Lightworks user effect DVE_alpha.fx

This 2D DVE was built to emulate the Editshare original but respect alpha channels
in both foreground and background, as well any produced by the drop shadow. The
original plan was to buffer the foreground with a premultiply to clean up any non-
black transparent areas of the frame. That was then to feed the original 2D DVE
effect, but the end section of the original shader was to be modified to return the
combined alphas of Fg, Bg and the drop shadow.

That version was built and worked, but it felt a little clunky using the first pass
to do what was really just a buffering operation. The premultiply also felt a little
excessive for what had to be achieved. So pass one had the crop moved into it as
well, and instead of premultiplying the video to blank any fully transparent areas a
simple check for zero alpha was implemented.

This meant that a total rewrite of the main shader was required. It was no longer
necessary to have the half texel adjustments of the original, and scaling became a
great deal simpler, as did the position calculations. Pretty much the only things
in this code resembling the original effect now are the inputs and the parameters.

It still performs as the Editshare version does, but with some differences. The
first is the obvious one that Fg, Bg and drop shadow alphas are passed to the
output. This has the side effect that any transparent areas of the background
must also be blanked. The drop shadow is also different, and now scales along
with the foreground. Unlike the Bg blanking, this was a deliberate choice. It
was felt to be more logical when using the DVE to zoom an image up to full screen.

Fixed in this version of the 2D DVE is the half texel offset error which can
appear as a transparent boundary between the image and the drop shadow under the
right conditions in the Editshare version. Also fixed is the fact the shadow is
calculated from Fg frame boundaries regardless of whether they are opaque or not.
Finally, the presence of the drop shadow will not punch a transparent hole in
the composite when used with downstream blend and DVE effects.

PS: The creation date is an absolute fiction. I cannot recall when I first did
this, and it's been through too many modifications for me to track it. That date
is when I cleaned the code up and commented the source. The release date is when
I fully debugged the cleanup.

Modified jwrl 2018-10-14:
Added code to scale the drop shadow offsets so that the same values in the X and
Y parameters give the same visual displacement.
Inputs
Samplers
Parameters
Definitions and declarations
Transparent black
Carry over from Editshare original to match unity scaling
Shaders
First set up the scaling and position for the foreground. This all done with
float2's for efficiency. In Cg one float2 operation is better than 2 floats.
The modified and cropped foreground is now recovered. Legal address ranges
must be checked to prevent unexpected cross-platform issues.
Now recover the scaled foreground alpha, offset by the shadow amount. This
allows us to add the foreground drop shadow only where Fg alpha is present.
Mix the foreground alpha with the shadow alpha to produce the composite.
The background layer is now obtained and if transparent, set to empty.
The foreground is mixed into the background and we're done.
Techniques