Blender AgX in darktable (proof of concept)

If you want to play around, the original function:

vec3 agxEotf(vec3 val) {
  const mat3 agx_mat_inv = mat3(
    1.19687900512017, -0.0528968517574562, -0.0529716355144438,
    -0.0980208811401368, 1.15190312990417, -0.0980434501171241,
    -0.0990297440797205, -0.0989611768448433, 1.15107367264116);
    
  // Undo input transform
  val = agx_mat_inv * val;
  
  // sRGB IEC 61966-2-1 2.2 Exponent Reference EOTF Display
  //val = pow(val, vec3(2.2));

  return val;
}

That commented-out val = pow(val, vec3(2.2)) line would take the display-encoded value back into linear, but the shader does not need that (it goes directly to the display).

Altered:

vec3 agxEotf(vec3 val) {
  const mat3 agx_mat_inv = mat3(
    1.19687900512017, -0.0528968517574562, -0.0529716355144438,
    -0.0980208811401368, 1.15190312990417, -0.0980434501171241,
    -0.0990297440797205, -0.0989611768448433, 1.15107367264116);
    
  // Undo input transform
  val = pow(val, vec3(2.2));
  val = agx_mat_inv * val;
  val = pow(val, vec3(1.0/2.2));
  
  // sRGB IEC 61966-2-1 2.2 Exponent Reference EOTF Display
  //val = pow(val, vec3(2.2));

  return val;
}

The important part is:

  val = pow(val, vec3(2.2));
  val = agx_mat_inv * val;
  val = pow(val, vec3(1.0/2.2));

We return to linear, apply the matrix, go back to gamma 2.2.

:innocent:

I’ve checked by entering your params manually. No fallback was activated, and the scaling limit was not reached, either.

The log:

scale_toe: -0.773515, scale_shoulder: 334.205383
need_convex_toe: 0, need_concave_shoulder: 0

The curve has the kink (blue). The other one, where you used a higher power value, is much smoother (red):

The ‘scale’ values are also a lot lower. From what I have seen, they are usually at most in the low 2 digits, usually – that 334 is already high. The original curve demo at desmos does not allow power < 1.

scale_toe: -0.688216, scale_shoulder: 0.603477
need_convex_toe: 0, need_concave_shoulder: 0

BTW, the original documentation of the params are available here: SB2383-Configuration-Generation/README.md at main · sobotka/SB2383-Configuration-Generation · GitHub

Here is the curve with params toe/shoulder power = 1, linear slope = 2.4 (using your relative exposure settings):

1 Like

I left some versions out for testing but tried now the last version. I still think that AgX is the mightiest tonemapper. But anyway I think there is plenty of work to be done regarding UX.

Anyway I’m sure @kofa and the other developers will offer a brilliant tool when the time has come.

My thoughts regarding the ease of use:

  • I preferred the Offset slider with the whitepoint limit.
  • Black and whitepoint settings are working differently from what I would expect.
  • Maybe it would help the user if there would be a graph, showing the curve and how it is treated (like it is in filmic)

By the way a very good image for testing the abilities of the different tone mappers is this:

Do you mean the relative exposures (input black and white point), or the target black and white point?
Relative exposures, I think, behave in the same way as in filmic?

The output black/white are not well supported and need work (some of the code just uses 0 and 1, no matter what you set).

In the link I shared above it seemed to suggest the application ofsaturation once the calculations were completed. Blender AgX in darktable (proof of concept) - #156 by priort

I mean the relative exposures.

For me it is not logical, that the slider just has an effect until a specific position but when I move the slider further there is no visible change anymore . I don’t know if it works differently in filmic. I hardly use it.

compare the black point settings and its effect:


I see your point. I think that’s because of the shape of the curve. Here are the curves with black at -10 EV, white at 6.5 EV (green) and 20 EV; for 20 EV, the slope was the same high value as for 6.5 EV (orange), or it was dropped to 1 (purple):

They look quite different, but mid-grey (the dot) appears shifted much more to the left on the curve that runs to 20 EV. Suppose you have a pixel at 6 EV. That would be around the 0.97 mark for the green curve, mapped to almost 1. However, even though it is at around 0.53 for the orange curve, there is not so much difference at the Y output, it’s also very close to 1. Reducing the shoulder power extends the shoulder; that same 0.53 is mapped to about 0.8, if the power is set to 1.

Try this:

  • set the toe/shoulder power to 1
  • move the black and white exposure points
  • once you found the boundaries you want to keep, set the toe/shoulder power to taste.
1 Like

Folks, with all this tuning, let’s not forget that AgX was developed to reflect certain properties of film. The original work is an opinionated mapper, one where certain values (relative exposures, toe and shoulder power, midtone contrast) were all pre-determined, and I assume the in/outset matrices were tuned to give pleasing colours using those values. Right now, the matrix is not tunable – I hope to get to it later. But it may be the case that for very different dynamic ranges and contrast settings, some other curve would be a better fit.

4 Likes

Hey there, I’ve been following this thread and I’m enjoying the work that is been done here. I want to implement it in darktable to test it but I have no idea how to do it, could someone please instruct me to try it out and thank you

Yes, that is the most important thing. Agx works very well together with color balance RGB. You can adapt Agx, as it is now, wonderfully well to the different scenes. In my experience so far, much better than other two tone mappers.

And I’ve also found that a very good starting point for most cases is “Punchy” preset with the sholder power set to 5:

You just have to correct the exposure and apply the “Punchy” preset.

6 Likes

That is so funny. I was having the same experience but wondered if it was just the sample of images that I had worked on. I have found right from the start even when there were just the 4 sliders I could get a very nice base image to tweak with RBG CB :grinning:

3 Likes

What OS…if for Windows or Linux some builds have been posted…just scroll the tread…

…and don’t forget to backup your config folder.

Yes I use windows, guess I’ll look fot it thanks

You need to keep it separate…so at least what I did was install it in its own DIrectory…DT_AGX and I made a config folder in that directory.

THen you run DT with a modified shortcut using --configdir and point it there… also I turned off writing xmp just to be sure I didn’t screw up and finally I only edited test images with this version and I placed them all in a test folder…

3 Likes

I can really recommend using --appimage-portable-home. All files created by the app will be located in an appfilename.AppImage.home/ subdir.

You only need to use --appimage-portable-home the first time you launch the .AppImage.

1 Like

I was referring to windows…but I suspect this is a good route to go for Linux users

As an experiment, I added a control that allows you to adjust the ‘internal gamma’ of the curve.
The module takes linear input, tweaks the matrix, and then performs a log before applying the sigmoid. The output of the sigmoid is actually ready for a display: not only is it between 0 and 1 (or the selected target points), but it also has a ‘gamma’ applied. This is, by default, 2.2. I’ve now exposed that as a control. After the sigmoid, the power is applied to ‘decode the gamma’, and the output is display-referred (0…1, or target bounds), but linearly encoded.

So, this value shifts the numerical value used to represent the output (y) of the pivot point (not its meaning, or brightness at the output, just its representation). This means the toe and the shoulder join the linear section (if there is none, the pivot) at a different y value. It behaves a bit like a contrast control. Maybe it can be used well with the toe/shoulder controls.

Anyway, experiment with it, and let me know if it’s useful (honestly, I did not find the effect mind-blowing, but I only tried it on one image). If it’s useless, we can quickly get rid of it.

Next up: target black/white, pivot x (sometime later this week, probably only during the weekend).

Linux build:
https://tech.kovacs-telekes.org/dt-agx/Darktable-5.1.0%2B562~gad1401131f-x86_64.AppImage

1 Like

Actually, now that I tried it with more images, it makes a decent contrast control (I think).

1 Like