Luminance Matte Node Fix
Open, NormalPublic

Description

Sets Luminance Matte node to use proper calculation for Luminance as opposed to YUV code path.

Details

Type
Patch
Sergey Sharybin (sergey) triaged this task as "Incomplete" priority.Jan 20 2016, 10:04 AM

What exactly you're fixing here and why you consider something wrong here? Do you have examples which fails dramatically here?

From what i see, this is how it was originally supposed to work (see [1]). I can only suppose that you're doing this to support luma coefficients but then proper solution should be to make YUV conversion aware of those coefficients instead.

[1] https://developer.blender.org/diffusion/B/browse/master/source/blender/nodes/composite/nodes/node_composite_lummaMatte.c;03747781a8b1027eb78914a2b92f289c10558226$87

Luminance will always depend on the chromaticity coordinates of the particular RGB reference.

In the case of YUV (wrong term, as YUV is an analog concept) it would be specifically referencing a particular encoding of YCbCr with particular weights relative to that encoding. Further, broadcast specifications require a scaled and offset Y to meet specifications.

All of these facets amount to the wrong result for a keying node that requires RGB luminance for the reference space.

On subject, it appears the line in rna_nodetree.c that restricts the maximum value to 1.0 should be changed to FLT_MAX to accommodate Cycles scene referred ranges as well.

RNA_def_property_range(prop, 0.0f, 1.0f);

should be

RNA_def_property_range(prop, 0.0f, FLT_MAX);

Luminance indeed depends on chromaticities, that was not the point of question. To make it short: why to switch to explicit luminance calculation instead of making YUV aware of custom chromaticities? There are quite some places which depends on YUV conversion which will be wrong when using non-standard luma coefficients i guess.

And please don't mix separate things in a single path.

Apologies for mixing. I will re-report two more.

YCbCr (and YUV) rely on specific weights that should never change. As they currently exist, they are somewhat confused as there are _many_ different weight settings for YCbCr, and several for YUV.

TL;DR the weights for encoding / decoding to YCbCr / YUV do not depend on the reference space, but rather the encoding specification aimed for. Luminance, on the other hand, would explicitly be related to the reference primaries in use.

Ok, some more things then:

  1. Luma coefficients are actually deprecated in OCIO [1], so shall we keep using it?
  2. The change will affect on existing setups, which is an unwanted thing to happen. It's nothing really broken here and we shall not break compatibility, IMO. Proposal could be to have a option how to calculate luminance (either via YUV or using Luma coefficients from the config, default to the new Luma, bt YUV for the existing files). Taking first point into account i'm not sure what would be the most proper way to go actually atm.

[1] http://opencolorio.org/userguide/config_syntax.html#luma

This is a tremendous question actually.

First, even though the ACES folks note it as depreciated, their information is based off of a message to the list from Mr. Selan. Nowhere is it actually depreciated, in code nor via your linked comment, last I looked. The comment itself can be read two ways, but I am reasonably sure that it was placed there to counter the claims that it was depreciated.

That said, I've also spoken with the lead developer of OCIO about these sorts of things as chromaticities are important for doing colour space conversions. His post house has several new features that they are putting in front of the OCIO developers soon for inclusion.

So short term we have two options, given that we have a real need to support variable reference spaces:

  1. Leave it for now and let Blender respect the variable. Check alternate configs (I've been working on an ACEScg wide gamut for example) to use appropriate values.
  2. Use @Lukas Stockner (lukasstockner97)'s evolutionary work on Cycles approach, which was discussed a bit with @Brecht Van Lommel (brecht) as well. We created a transform in OCIO that does a d65-sRGB from_reference transformation to XYZ, and crafted an API-friendly handle called chromaticity. The application then knows to look for the chromaticity role, and use that to glean the chromaticity of the reference space. To get the white point, 1,1,1 will return the achromatic values, and the Y position is the weights. It will frequently differ slightly from a specification's value, but it is technically the mathematical result, and is extremely accurate for our purposes.

I'd defer to the the second option currently, as Lukas' work is pretty important and is a very easy change for us in the code.

I understand on the front of changing existing setups. I'm relatively sure that many folks wouldn't notice a shift in the weights, but if this is an issue, I'd propose that we do exactly as you thought and put a toggle on, but also perhaps migrate a new node into a properly audited set so that artists are well aware that they are using "more correct" versions. I originally added the toggle actually in the node, but took it out for fear it wouldn't pass the review.

While this might seem overly-drastic, we also have to consider that the existing mix, blur, convert YCbCr, etc., nodes have many issues that do not make sense in B'ender's colour managed, linearized reference space, as well as being absolutely wrong with regard to scene referred values delivered from Cycles or any other raytracing image engine. In Mix blend modes, screen is an obvious example, with dodge and burn being wrong as well[1]. The blur node still has a moot gamma selection. YCbCr, YUV, and a few other places make hard assumptions about reference space, and are frequently inaccurate as well.

Anyways... just some thoughts on how to move forward without being too crippled with legacy node setups. What do you think of this approach for a 2.8 migration?\

[1] Nuke has a toggle (godawfully named "video space") that lets imagers select which variant of the formula they are using.

For the time being it's fine to add a "reference" to the keying node . Bigger reconsiderations are possible, but not as a longer term projects. But even then, i still don't' see comparison demonstrating it on an artist level what was actually improved. If it's so much more correct and gives better keys and keeps everyone happy with even existing setups why not just go for it and leave all the options out?

It is a step to getting Blender's internal logic up to date.

When the reference space changes, so too must these values. That is the rather extensive patch Lukas is working on for Cycles.

But also, and something that hasn't happened yet, the nodes need to become more scene referred aware as a whole to fully support Cycles renders, which they do not currently.

With specific attention to this node, the keys pulled would be "better" and more accurately reflect the luminance of 709 primaries that the imager's image encoding is. As it stands now, the weights are wrong, so the luminance won't be correct.

This means that semi-transparent regions will have incorrect weighting resulting in subtle fringing where none would occur with the proper weights.

TL;DR Why?

  1. This currently is not a luminance node, despite the title.
  2. This has no known set of primaries where this would ever be a luminance node.
  3. The result with the changed values would be a much more accurate key pull, resulting in faster and more correct work for imagers.

@Sergey Sharybin (sergey), would you be against a global flag in User Preferences that flips on a "Legacy Mode"?

It would allow us to move forward and properly fix these sorts of issues without adding the complexity of a toggle that shouldn't be there in the first place.

@Troy Sobotka (sobotka), no, that's a bad idea. *If* we want option for that, it should be aware of the fact that one might want to work on old projects with old settings and new projects with new settings.

Now, if the difference in the node behavior is subtle enough, we can just change it. But please, bother to get good demonstration file (like the techhead greesnscreen footage from Tears of Steel) and run the keying wit hand without the patch to show the difference in the matte output.

Bastien Montagne (mont29) raised the priority of this task from "Incomplete" to "Normal".Feb 19 2016, 12:47 PM

Sergey, can we just fix this? I am really hesitant to even attempt to fix anything else color related, of which there are hundreds of things, if we can't simply agree that:

  1. It is broken and totally incorrect.
  2. Forward looking, it is totally broken for all other reference spaces.
  3. It is a very easy fix.

Bump. Sergey? 2.8 please. kthxbai.