Linear to Log for Film Emulation in Darktable - Are 1D LUTs possible?

Dumb question but can the Luts be converted rather than modifying DT?? Note I said dumb :slight_smile:

Perhaps a dumb question, but I’d assume a 1D LUT operates on lightness only, right? How is it different from a tone curve?

So far I was able to get some kind of reasonable result using the ‘unbreak input profile’ module. It is very tedious to setup though. Since ‘unbreak’ is a lin2log, it is possible to create the reverse log2lin in Resolve or Nuke and bake an appropriate custom 3D LUT that expects the weirdo log coming out of ‘unbreak’… This is very very far from user friendly but I got it to work.

I wonder if it’s possible to get the ‘output color profile’ module to do the lin2log instead of ‘unbreak’?

Does anyone know if the ICC modules in DT (or anywhere else) are able to deal gracefully with values outside of 0-1 on input?

Converting a 1D LUT to a 3D LUT is often not practical. 3D LUTs do not have enough resolution to take high dynamic range linear values on input. This is why most 3D LUTs expect LOG values on input.

Resolve .cube files include the option to include both a 1D LUT (i.e. shaper) and a 3D LUT in the file to work around this problem.

Even if we wanted to create a super-high-rez 3D LUT from our desired 1D LUT, the ‘LUT 3D’ module in DT clamps all values outside of the 0-1 range on input… destroying all pixels with a value above 1.0 (i.e. all values +2.5EVs above .18 mid gray).

Yes a 1D LUT is essentially a tone curve driven by an array of numbers. As long as the Tone Curve module expects to get values well outside the 0-1 range, than it could be possible to convert a 1D LUT to a DT Tone Curve. However, I’m not sure the Tone Curve module would be happy with tens of thousands of points on the curve. :slight_smile:

I don’t know about the latter point, but the rgb curve module operates in unbounded conditions I think…

Is the problem not the lut module itself as it works in DT… So if I understand or at least from the recent comments by @kofa suggested to me … you might for example normally have DT in a working space…that would be say wide gamut rec2020. Now the lut module in DT seems to have an input setting that is going to take that rec2020 or whatever is presented to it and convert that to what you have selected is needed for the lut input to match your lut table of the associated LUT and therefore yield the expected result… since DT doesn’t have a bypass for this function in the module and has about 5 options none of which are any variety of log I don’t think you can ever use it to apply a lut designed for log input… but I could be wrong… to me it would seem that your lut can be fed only rbg rec709 lin or gamma rec2020 or prophoto…because the module will first put the data in one of those colorspaces before passing it to the lut… Is this what you are trying to circumvent with unbreak and then trying to revert that to a linear space acceptable to the lut module… I would think with all that and any clipping as you note might happen would the lut still provide the same utility or would it end up distorted??

You might find this post of some interest and perhaps the wider thread that it comes from…

Hi,
I agree with @priort. I think the best way to keep using dt is to extend the lut3d module. You could either make it accept some log space, or simply extend it to support aces clf luts. I would go for the latter, as it gives you more flexibility and can be done in a few lines of code by simply offloading the job to ocio.

HTH

It does. However, the UI doesn’t expose that and is limited to the 0-1 range.

1 Like

Yes, the LUT3D module does apply a shaper LUT to the input via the ‘application color space’ option. Simply adding a few LOG options (ACEScc/ACESAP1, sLog3/sGamut3.cine, AlexaV3LogC/AlexaWideGamut, RedLog3G10/RedWideGamut… maybe a couple more for Fuji and Canon…) to this list would make LUT3D way more versatile.

Yes. By having an ‘unbreak’ before the LUT3D, I convert linear/rec2020 pixels to log/rec2020.

Since ‘Unbreak’ doesn’t change the color profile metadata, you can leave LUT3D’s ‘application color space’ to ‘linear/rec2020’… the built-in shaper does nothing since it thinks there is no conversion required.

Another thing to keep in mind is that DT applies a lin to sRGB conversion at the end of the pipe since LUT3D doesn’t change the color profile metadata either.

This means our special homebaked 3D LUT converts from weirdo-log/rec2020 to tonemapped linear (i.e. gamma 0.45-ish), then DT converts that to sRGB.

Since DT is 32-bits float, despite fighting useless conversions, the end result looks surprisingly good.

That would be fantastic. Does DT use OCIO anywhere right now?

1 Like

No but @agriggio is doing some cool things in ART… https://bitbucket.org/agriggio/art/wiki/Home

Thanks for the reply and breakdown…

It would be nice to see an example of one worked through when you get it all sorted…

For brave souls that want to replicate my workflow, here’s how I have managed to bake LUTs to make them work with ‘unbreak’ log in Darktable using the Fusion page in DaVinci Resolve.

In theory any display/film emulation/tonemapping LUT could be converted to work in Darktable this way.

This is extremely clunky and hopefully a better workflow could be achieved in the future with a few extra features in Darktable.

In Darktable:

  • Make sure to work in a linear workflow (i.e. Input Color Profile → Working Profile → linear rec 2020)
  • Develop your image as usual
  • DO NOT include ‘filmic’ or ‘sigmoid’ modules (our 3D LUT is going to do the tonemapping for us)
  • The last 3 steps of your stack should be:
  • Unbreak input profile
    Middle gray = 18%
    Black relative exposure: -8 EV
    Dynamic range: 16 EV
  • LUT 3D
    Application colorspace: linear rec2020
    Load the .cube file exported from Resolve/Fusion here.
  • Output color profile
    Export profile: sRGB

In Davinci Resolve/Fusion, see this screenshot:

The key is to use the LUTCubeCreator/LUTCubeAnalyzer nodes to ‘bake’ our LUT to a cube file that Darktable can use.

I use the Fusion page instead of the Color page because I need the CineonLog node to convert our weirdo ‘unbreak’-log to linear. This is required to have a standard starting point that we can convert to whatever our film emulation LUT expects.

For a 16 EV ‘unbreak’ log (-8/+8EV centered on 18% mid gray) the following values are required in CineonLog:

Black: 0
White: 670
Soft clip: 0
Film Stock Gamma: 0.42
Conversion gamma: 1.0

I’ve been able to use a LUT designed for Sony sLog3/sGamut3.cine in Darktable this way.

I was also able to use the ACES sRGB display LUT in DT too. This opens great workflow options between DT and Blender/Nuke/Krita/Fusion etc… You can preview your image in DT with the ACES display transform and export non-tonemapped EXR linear/rec2020 files for use in other ACES aware software.

(Linear/AP1 (aka ACEScg) export is also possible by using Elle Stone’s ICC profiles)

Again, this is clunky because you have to remember to disable ‘unbreak’ and ‘LUT3D’ before exporting your EXR files.

Both ACES sRGB display and the sLog3 LUT behave as expected in Darktable once you’ve jumped through all the hoops in Resolve.

I understand that full OCIO/ACES integration might be overkill for casual photographers, but hopefully the benefit of using ‘video’ LUTs in DT might be able to convince developers that adding better ‘shaper’ LUT support in DT is worth their time.

If anyone has figured a more streamlined way to achieve similar results, please share! I think custom ICC profiles might achieve similar results, but I don’t know how to create ICC profiles that describe a ‘known’ log profile.

Thanks to @priort for pointing me to the ‘unbreak profile’ module… this is the key that unlocks this workflow.

3 Likes

Well thanks for such a nice descriptive post… This will be fun to try and might even inspire those with the time interest talent or all 3 to think of ways that we could enhance some of these sorts of things in DT. I appreciate you taking the time to share… All the best

I think the easiest way for developers to enable this workflow would be to enable 2 things the LUT3D module:

1- Add standard ‘log’ profiles to the ‘application color space’ menu in the LUT3D module (or let users define custom profiles somehow). This would be the ‘shaper LUT’ that converts from linear/rec2020 to whatever LOG/gamut format is expected by your 3DLUT.

2- Add an ‘output color space’ menu to the LUT3D module so that LUT3D can communicate what colorspace is coming out of itself to the rest of the pixel pipe. This option should not modify pixels in any way… just add metadata on output.

What is the best way to do feature requests for Darktable?

Here’s the ACES sRGB display transform baked into a DT-friendly .cube LUT if you want to try this workflow without jumping through all the hoops in Resolve.

DT_unbreak_rec2020_to_ACES_sRGB_Display.zip (773.1 KB)

2 Likes

GitHub.

There have been a couple of topics pop up about enhancing LUT3d (there might be others these are just the ones I recall)

That looks very interesting. A little over my head at present - I’ll have to do a bit more reading, but thanks for writing it up in full. :slight_smile:

I’ve opened a new feature request on GitHub… reading the comments on these 2 request… I think it might be non-trivial to get this one through. Color management is very tricky to discuss when not everyone is on the same page.

What do they say… you can’t win without a ticket…
:grin:

1 Like

I threw this at a couple of playraw files and it works pretty well. Now the challenge will be to try and make one of those cooked luts :slight_smile:

First off thanks for sharing this with us. I thought I would try to work through this myself to see if I could run the process on a different lut…

For your current framework as presented would something like this be a candidate??

https://freshluts.com/luts/1438

I think I might still need a little hand holding when and if you have the time… please feel free to ignore me as well…

I have fired up Davinci in which I am almost a pure novice. I added the tools that you show in your layout diagram and followed your suggestion to change the settings to match as best I can.

I just have a few questions… ie of the so what next sort of thing. I looked at the overall diagram and there seems to be 3 parts or groups in the toolchain. The four modules in the OCiO/ACES section

image

This bit

And this bit…

If I understand and I don’t but I will take a run at it , the main string of modules across the middle makes the “baked” in LUT and the string of 4 at the end are added in the case where you want to preview the lut on a DT export that is generated with unbreak??

I am not sure exactly the role of the first four tools that are not linked but include the ACEStransform… (EDIT: would it be that you replace the FIleLUT1 and slide down the these four to introduce the lut via an ACES display transform)… Hence why you label it FileLUT1_1… I’ll stop speculating now until I see a comment from someone what actually understands it :slight_smile: )

So I guess basically I am not sure with certainty what goes where. If I have a lut with a similar gamut and color space as the one you used I would guess I can simply plug that in…

I’ll poke around a bit more on my own but any direction on this from yourself or someone proficient in DR would be welcomed…

Thanks in advance…