Previous topicNext topic

bug or feature? alpha channel ignored when background black

Questions, comments, feedback, etc.
Post Reply
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

bug or feature? alpha channel ignored when background black

Post by blackdot »

made a small animation with an alpha channel in blender
bug.jpg
bug.jpg (119.77 KiB) Viewed 11287 times
to use it as a video file in magic. works fine and as expected, but only as long as i dont have a black background. if there is a black background (black polygon or nothing), the fading of the object isnt visible anymore. made a little screen capture to elaborate: https://mega.co.nz/#!RJBSQKpb!fMRk4P_PJ ... CLjE3VAPlE .

strange thing: if i play the video in the vlc (by default a black background too "nothing"), the behaviour is the same, the fadeout is not visible. coincidence?
\\edit: i think vlc just doesnt support an alpha channel anyway. why should it.


here's the clip itself if that helps: https://mega.co.nz/#!ZFp2lSoS!161okDe5x ... wJyhLrrnkE . it's compressed with the png video codec and includes RGBA.

any ideas?
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: bug or feature? alpha channel ignored when background bl

Post by Magic »

The issue here is premultiplied alpha. Referencing your earlier post (http://magicmusicvisuals.com/forums/vie ... p?f=2&t=88):
If you create your content in blender from the beginning, rendering as png image sequence or video sequence as described above, is not the only thing important. you'll also need to tick "transparent" under rendersettings>Film to make the "world background transparent with premultiplied alpha".
Does that help? If not, let me know. It could still be a bug.
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: bug or feature? alpha channel ignored when background bl

Post by Magic »

Also, as an interim fix, you can use this shader in the GLSLShader module:

Code: Select all

void main()
{
    // get the current pixel coordinate:
    vec2 pixelLocation = gl_FragCoord.xy / iResolution.xy;

    // get the color at the current pixel coordinate:
    gl_FragColor = texture2D(iChannel0, pixelLocation);

    // multiply the rgb value by the alpha value:
    gl_FragColor.rgb *= gl_FragColor.a;
}
Premultiply.txt
(179 Bytes) Downloaded 537 times
Hook it up directly after each Video module in your scene.
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: bug or feature? alpha channel ignored when background bl

Post by blackdot »

without premultiplied alpha, the video file doesnt seem to include an alpha channel. it looks like this then:
2015-03-11_2205.png
2015-03-11_2205.png (225.47 KiB) Viewed 11279 times
even using a colour HSB node and putting "alpha" to 0 doesnt help (dont know if it's supposed to though).

\\Edit: wow that was quick. your temp fix as glsl module works perfectly. everything as expected now, thanks a lot! :O
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: bug or feature? alpha channel ignored when background bl

Post by Magic »

Great, I'm glad it worked. The only thing though is that using the GLSLShader module to premultiply the alpha is a bit inefficient. The best thing would still be if the video could be exported from Blender with alpha already premultiplied; then you wouldn't have to use GPU resources to do it. Does this page help at all? http://wiki.blender.org/index.php/Dev:R ... ansparency

The problem is that some video codecs premultiply, and some don't. So it's impossible for Magic to know how to deal with the alpha channel. In general, alpha channels in video aren't widely supported. The only other solution would be for me to add another toggle parameter to the Video module, which you'd have to manually set. I'm not sure if that's the best way to go about it. But maybe it's necessary... I'll think about it a bit more.
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: bug or feature? alpha channel ignored when background bl

Post by blackdot »

hmm. the clip i initially made, acuatlly was with premultiplied alpha. at least i think this is what the "film>transparent (premultiplied blabla)" setting does. the wiki link you posted states "The Transparent option remains unchanged, when it is enabled a render with premultiplied alpha will be created" (at cycles render alpha). maybe this is only true if you export to png images though. maybe using that png-video-codec produces streight-alpha ?

Videos with alpha are rare anyway as we found out. maybe you want to scratch this support anyway and provide support for masking (assuming this allows for semi transparency)? i mean i could easily render out the alpha channel as another greyscale clip and use that instead. incase this would be more convienient for other people as well. (apparently noone uses videos with alpha :D , even the blender guys were surprized that there is a png-video codec hidden inside blender).
Terry Payman
Posts: 711
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: bug or feature? alpha channel ignored when background bl

Post by Terry Payman »

Eric wrote:...other solution would be for me to add another toggle parameter to the Video module
Yes please! That would be perfect for handling existing video assets regardless of codec. Re-rendering is not always an option, and pre-multiplied alpha can be disadvantageous http://dvd-hq.info/alpha_matting.php
blackdot wrote:..apparently noone uses videos with alpha...
With great respect, lots of people (myself included) use videos with alpha in video post-production.
There are some nice clips with alpha on videoblocks http://www.videoblocks.com/videos/transparent+alpha, illustrating the utility of these.

Further examples in this article http://www.provideocoalition.com/alpha- ... s-straight
(I'm not claiming to understand any of this :D ).

In the wild I would agree that videos with alpha are rare, but in video compositing they are in common use.
IMHO it would be valuable for Magic's Video module to handle as many variants as possible.
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: bug or feature? alpha channel ignored when background bl

Post by blackdot »

what container and codec are you using for your videos with alpha? as far as i understand image-sequences with alpha are much more often used in compositing, no? at least in non-realtime stuff.

anyway glad to see, i'm not the only one, so scratch my previous statement. in that case a toggle for the user straight/premultiplied would be great.
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: bug or feature? alpha channel ignored when background bl

Post by Magic »

maybe you want to scratch this support anyway and provide support for masking (assuming this allows for semi transparency)? i mean i could easily render out the alpha channel as another greyscale clip and use that instead.
You could do that right now actually. You would just need a very simple shader, similar to my Alpha Mask, but tweaked a bit:

Code: Select all

void main()
{
    vec2 pixelLocation = gl_FragCoord.xy / iResolution.xy;

    gl_FragColor = texture2D(iChannel0, pixelLocation) * texture2D(iChannel1, pixelLocation).rrrr;
}
With that shader loaded into the GLSLShader module, hook up two Video modules as inputs, the first with the RGB video, and the second with the greyscale video. They get multiplied together to create the mask.

But having 2 videos is still inefficient. The toggle parameter is a better solution, or maybe I can figure out how to actually fix the transparency issue properly :).
Terry Payman
Posts: 711
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: bug or feature? alpha channel ignored when background bl

Post by Terry Payman »

@blackdot, with apologies for my delayed reply.
blackdot wrote:what container and codec are you using for your videos with alpha?
Currently, AVI RGBA with Lagarith lossless codec (reducing them to half-huge :D ) http://lags.leetcode.net/codec.html.
I'm considering using Quicktime RLE format for certain footage, but haven't yet tried. I'm working entirely on PC, which is sometimes restrictive.
blackdot wrote:as far as i understand image-sequences with alpha are much more often used in compositing.
I'm sure you're correct, but some footage in libraries such as VideoBlocks does not have an image-sequence option. I'm keen to be able to handle any footage without re-rendering, so a toggle on the Video module could be an efficient solution.
blackdot
Posts: 528
Joined: Sun Jul 06, 2014 10:18 pm

Re: bug or feature? alpha channel ignored when background bl

Post by blackdot »

Thanks. Never heard of either container nor codec :). But yeah those royalty free footage platforms dont support imgseqs. I often noticed them offering masks though where at the end of a clip, it's extended by a masked version of it.

Sincr your codec is also lostless i doubt my exports will get much smaller than with the png video codec. Will have to try this ouz though.

Thanks
Post Reply