question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LUTEffect produces incorrect results

See original GitHub issue

Description of the bug

The newly added LUTEffect currently produces inaccurate results. With a neutral LUT, the image becomes darker even when using HalfFloatType buffers and a highp LUT sampler with FloatType data. Upscaling with the TetrahedralUpscaler via LookupTexture3D.scaleUp() produces banding artifacts.

To Reproduce

The following example uses a neutral LUT which incorrectly darkens the image: https://codesandbox.io/s/fervent-kapitsa-3jikk

When using a 2x2x2 LUT, the image quality is greatly reduced which does not happen here: https://threejsfundamentals.org/threejs/lessons/threejs-post-processing-3dlut.html

Expected behavior

An identity LUT should not change the image. Color space should also not matter if a neutral LUT is used, but linear input colors currently produce even worse results.

Screenshots

Images taken from https://github.com/vanruesc/postprocessing/issues/231#issuecomment-753638346:

Neutral LUT 32 Neutral LUT scaled up to 128
image image

Library versions used

  • Three: 0.124.0
  • Post Processing: 6.19.0

Desktop

  • Windows 10
  • Firefox 84.0.1
  • NVIDIA GTX 1060

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:34 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
vanruesccommented, Jan 12, 2021

I’ve investigated this further and ended up implementing tetrahedral interpolation and custom input domains. I found out that the noisy errors we’re still seeing are indeed caused by hardware interpolation. This article by iq explains the details.

The tetrahedral interpolation algorithm performs all interpolations manually to avoid the quantization of fractional components. The following comparison shows the difference between the input colors and the output colors of the LUTEffect using a neutral 2³ LUT:

HW Trilinear 2D HW Trilinear 3D Manual Tetrahedral 3D
trilinear_2x2x2_2d trilinear_2x2x2_3d tetrahedral_2x2x2_3d

Tetrahedral interpolation eliminates all remaining errors.

@gkjohnson FYI: I learned that fract() actually uses floor() internally: “This is calculated as x - floor(x).” So the following is probably a bit more efficient for the 2D sampling algorithm:

float slice0 = floor(slice);
float interp = slice - slice0;
2reactions
gkjohnsoncommented, Jan 9, 2021

Good to know that looks like a useful site!

If the visual result looks good I think I’m content to leave it for now. I won’t rule out the sampling function still having some issues but with more calculations happening in the 2d sampling case I’d imagine you’d get some differences from floating rounding error, as well, so aiming for literally identical images may be an impossible goal.

And after taking a quick look at the TetrahedralUpscaler again I don’t think the sampling approach needs to be adjusted as I suggested in https://github.com/vanruesc/postprocessing/issues/250#issuecomment-755074282 and the visual result looks okay so I think that component is good.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LUTEffect produces incorrect results · Issue #250
The newly added LUTEffect currently produces inaccurate results. With a neutral LUT, the image becomes darker even when using HalfFloatType ...
Read more >
Get more from your LUTs when color grading (Pro Secrets)
Inside the color shift are 'Split toning' and 'Hue Shifts'. Split Toning gives the image a warmer highlight while creating cooler shadows, and ......
Read more >
Boris FX Sapphire 2022 Adds New Color LUT Effect
This new Sapphire LUT effect comes bundled with Boris FX LUT Starter pack to ... and mismatched color spaces can create undesirable results....
Read more >
Post tab - Chaos Vantage - Chaos Help
Higher values sharpen the shoulder, which results in an overall ... Amount – Specifies the LUT weight, where 0 is no LUT effect...
Read more >
Generate LUT from Analyzed Pattern on Resolve 17
To see this LUT's effect on another clip, select another clip, right-click a node in ... Is there any other way to achieve...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found