Skip to content

refacto(nuke): DRT prototypage and improvements #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 50 additions & 24 deletions nuke/AgXcDRT.nk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Group {
use_gpu true
addUserKnob {26 "" +STARTLINE}
addUserKnob {26 txt_purity l "" +STARTLINE T "<h2> Purity </h2>"}
addUserKnob {6 use_luma_compensation l "Use Luminance Compensation." t "Affect very saturated colors on gamut boundaries." +STARTLINE}
use_luma_compensation true
addUserKnob {7 inset1 +STARTLINE l "inset" t "reduce chroma purity" R 0 1}
inset1 0.4
addUserKnob {7 purity_amount +STARTLINE l "purity amount" t "higher values restore chroma purity using an outset" R 0 1}
Expand All @@ -27,7 +29,7 @@ Group {
addUserKnob {18 print_contrast l "print contrast" R 0.8 4}
print_contrast {1.0 1.0 1.0}
addUserKnob {18 print_contrast_pivot l "print contrast pivot" R 0.1 1.0}
print_contrast_pivot {0.65 0.65 0.65}
print_contrast_pivot {0.355 0.355 0.355}
addUserKnob {7 print_contrast_amount l "print contrast amount" R 0 1}
print_contrast_amount 1.0
addUserKnob {26 "" +STARTLINE}
Expand Down Expand Up @@ -87,7 +89,7 @@ Group {
addUserKnob {20 endGroup n -1}
addUserKnob {20 About}
addUserKnob {26 toolName l name T AgXcDRT}
addUserKnob {26 toolVersion l version T 1.1.1}
addUserKnob {26 toolVersion l version T 1.3.0}
addUserKnob {26 toolAuthor l author T "<a style=\"color: rgb(200,200,200);\" href=\"https://mrlixm.github.io/\">Liam Collod</a>"}
addUserKnob {26 toolDescription l description T "AgX(custom) Display Rendering Transform."}
addUserKnob {26 toolUrl l url T "<a style=\"color: rgb(200,200,200);\" href=\"https://github.com/MrLixm/AgXc\">https://github.com/MrLixm/AgXc</a>"}
Expand Down Expand Up @@ -120,6 +122,44 @@ Group {
xpos 0
ypos 0
}
set Nd508a50 [stack 0]
# Under expression is:
# 1. extracting chroma by finding luma
# 2. applying offset
# 3. applying power
# 4. multiplying back chroma with luma, which have been compensated for chroma changes
# 5. lerping with luma to only apply changes on higher values
Expression {
name ExpressionLuminanceCompensation
xpos 100
ypos 50
temp_name0 L
temp_expr0 wR*r+wG*g+wB*b
expr0 "lerp(r, pow((L==0? 0: r / L) + Coffset, 1 / Cpower) * (L * Lgain), L)"
expr1 "lerp(g, pow((L==0? 0: g / L) + Coffset, 1 / Cpower) * (L * Lgain), L)"
expr2 "lerp(b, pow((L==0? 0: b / L) + Coffset, 1 / Cpower) * (L * Lgain), L)"
addUserKnob {20 User l "Parameters"}
addUserKnob {7 Cpower "chroma power"}
Cpower 0.5
addUserKnob {7 Coffset "chroma offset" R -2 2}
Coffset 1
addUserKnob {7 Lgain "luma gain"}
Lgain 0.25
addUserKnob {7 wR}
wR 0.26270021
addUserKnob {7 wG}
wG 0.67799807
addUserKnob {7 wB}
wB 0.05930171
}
push $Nd508a50
Switch {
name SwitchLuminanceCompensation
inputs 2
xpos 0
ypos 100
which {{parent.use_luma_compensation}}
}
# startfrom: https://github.com/MrLixm/Foundry_Nuke/raw/823438ebda0d92614355932a2ecb7264774e2562/src/primaries_inset/PrimariesInset.nk
Group {
name PrimariesInsetFirst
Expand Down Expand Up @@ -573,13 +613,6 @@ Group {
ypos 300
}
end_group
Colorspace {
name LINEARIZE_TONESCALE_OUTSET
xpos 0
ypos 400
label "cctf: [value colorspace_in] > [value colorspace_out]"
colorspace_in "2.40"
}
Dot {
name DotPurityInput
xpos 0
Expand Down Expand Up @@ -800,13 +833,6 @@ Group {
ypos 550
mix {{parent.purity_amount}}
}
Colorspace {
name UNLINEARIZE_TONESCALE_OUTSET
xpos 0
ypos 600
label "cctf: [value colorspace_in] > [value colorspace_out]"
colorspace_out "2.40"
}
Dot {
name Dot2ndTonescale
xpos 0
Expand Down Expand Up @@ -1272,6 +1298,13 @@ Group {
xpos 0
ypos 850
}
Colorspace {
name LINEARIZE_TONESCALE
xpos 0
ypos 900
label "cctf: [value colorspace_in] > [value colorspace_out]"
colorspace_in "2.40"
}
# startfrom: https://github.com/jedypod/nuke-colortools/raw/b0912ff8c9ffd0438d208847ef49d0ecc89655cf/toolsets/transfer_function/SigmoidParabolic.nk
#MIT License
#
Expand All @@ -1295,16 +1328,9 @@ Group {
p {{parent.print_contrast} {parent.print_contrast} {parent.print_contrast}}
mix {{parent.print_contrast_amount}}
xpos 0
ypos 900
}
# endfrom
Colorspace {
name LINEARIZE_TONESCALE
xpos 0
ypos 950
label "cctf: [value colorspace_in] > [value colorspace_out]"
colorspace_in "2.40"
}
# endfrom
Dot {
name DotDisplay
xpos 0
Expand Down
49 changes: 42 additions & 7 deletions nuke/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,43 @@ of the input and high values the white ones.

![screenshot of AgXcDRT plot option result in Nuke](doc/img/AgXcDRT-plot.png)


### purity

#### luminance compensation

A personal "trick" to reduce purity in gamut boundaries values.

The algorithm is as follows :

1. find luma using R-G-B weights computed from colorspace primaries and whitepoint
2. extract chroma by dividing luma
3. apply +1 offset on chroma
4. apply 0.5 power on chroma
5. apply 0.25 gain on luma to compensate for chroma change
6. multiplying back chroma with luma to recombine image
7. lerping 6. with luma calculated in 1. to only apply changes on higher values


#### inset

Control the amount of chroma purity in bright values where higher values will
produce a less chroma-intense look.

The default value of 0.4 might be a bit strong.

#### purity amount

Apply the invert inset operation called outset (the inset being a 3x3 matrix
this is just the matrix inverted) and control how much is applied.

The outset retrieve purity in midtones and shadows but reintroduce skews and
artefacts.

Note the outset is applied after teh first tonescale meaning you can play with
the second inset to compensate for its artefact.


### tonescale

"Luminance mapping" of the image with additional grading possibilities to emulate
Expand All @@ -101,13 +138,6 @@ Original AgX implementation applied the tonescale a single time. This one can ap
it 2 times, producing an extra softness that can be comparable to the look
of analog film.

#### inset

Control the amount of chroma purity in bright values where higher values will
produce a less chroma-intense look.

The default value of 0.4 might be a bit strong.

#### contrast

Control the contrast of the 2 tonescale curves. It is interesting to see them
Expand All @@ -123,11 +153,16 @@ on the `print contrast` control, with the additional pivot control to refine fur
the look (do not hesitate to check `Show Plot` to have an alternative representation
of your changes).

The pivot correspond to the center of the "S curve" and a value of 0.18 map to
scene-linear middle grey.


### display

Pick the target display the image should be intended to be displayed on.

The grade options help achieve an optimal rendering for that display.

# Developer

Check the [src/](src) directory.
Expand Down
62 changes: 44 additions & 18 deletions nuke/src/AgXcDRT/AgXcDRT-template.nk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Group {
use_gpu true
addUserKnob {26 "" +STARTLINE}
addUserKnob {26 txt_purity l "" +STARTLINE T "<h2> Purity </h2>"}
addUserKnob {6 use_luma_compensation l "Use Luminance Compensation." t "Affect very saturated colors on gamut boundaries." +STARTLINE}
use_luma_compensation true
addUserKnob {7 inset1 +STARTLINE l "inset" t "reduce chroma purity" R 0 1}
inset1 0.4
addUserKnob {7 purity_amount +STARTLINE l "purity amount" t "higher values restore chroma purity using an outset" R 0 1}
Expand All @@ -27,7 +29,7 @@ Group {
addUserKnob {18 print_contrast l "print contrast" R 0.8 4}
print_contrast {1.0 1.0 1.0}
addUserKnob {18 print_contrast_pivot l "print contrast pivot" R 0.1 1.0}
print_contrast_pivot {0.65 0.65 0.65}
print_contrast_pivot {0.355 0.355 0.355}
addUserKnob {7 print_contrast_amount l "print contrast amount" R 0 1}
print_contrast_amount 1.0
addUserKnob {26 "" +STARTLINE}
Expand Down Expand Up @@ -87,7 +89,7 @@ Group {
addUserKnob {20 endGroup n -1}
addUserKnob {20 About}
addUserKnob {26 toolName l name T AgXcDRT}
addUserKnob {26 toolVersion l version T 1.1.1}
addUserKnob {26 toolVersion l version T 1.3.0}
addUserKnob {26 toolAuthor l author T "<a style=\"color: rgb(200,200,200);\" href=\"https://mrlixm.github.io/\">Liam Collod</a>"}
addUserKnob {26 toolDescription l description T "AgX(custom) Display Rendering Transform."}
addUserKnob {26 toolUrl l url T "<a style=\"color: rgb(200,200,200);\" href=\"https://github.com/MrLixm/AgXc\">https://github.com/MrLixm/AgXc</a>"}
Expand Down Expand Up @@ -120,6 +122,44 @@ Group {
xpos 0
ypos 0
}
set Nd508a50 [stack 0]
# Under expression is:
# 1. extracting chroma by finding luma
# 2. applying offset
# 3. applying power
# 4. multiplying back chroma with luma, which have been compensated for chroma changes
# 5. lerping with luma to only apply changes on higher values
Expression {
name ExpressionLuminanceCompensation
xpos 100
ypos 50
temp_name0 L
temp_expr0 wR*r+wG*g+wB*b
expr0 "lerp(r, pow((L==0? 0: r / L) + Coffset, 1 / Cpower) * (L * Lgain), L)"
expr1 "lerp(g, pow((L==0? 0: g / L) + Coffset, 1 / Cpower) * (L * Lgain), L)"
expr2 "lerp(b, pow((L==0? 0: b / L) + Coffset, 1 / Cpower) * (L * Lgain), L)"
addUserKnob {20 User l "Parameters"}
addUserKnob {7 Cpower "chroma power"}
Cpower 0.5
addUserKnob {7 Coffset "chroma offset" R -2 2}
Coffset 1
addUserKnob {7 Lgain "luma gain"}
Lgain 0.25
addUserKnob {7 wR}
wR 0.26270021
addUserKnob {7 wG}
wG 0.67799807
addUserKnob {7 wB}
wB 0.05930171
}
push $Nd508a50
Switch {
name SwitchLuminanceCompensation
inputs 2
xpos 0
ypos 100
which {{parent.use_luma_compensation}}
}
%NODE_PrimariesInset:{"ypos": 200, "xpos": 0, "name": "PrimariesInsetFirst", "colorspace_preset": "\"ITU-R BT.2020\"", "primary_r": "{0.708 0.292}", "primary_g": "{0.17 0.797}", "primary_b": "{0.131 0.046}", "whitepoint": "{0.3127 0.329}", "inset": "{{parent.inset1}}", "u_inset_r": 0.125, "u_inset_b": 0.15, "rotate_r": 5, "rotate_b": -5, "use_gpu": "{{parent.use_gpu}}"}%
%NODE_Log2Shaper:{"ypos": 250, "xpos": 0, "name": "Log2ShaperTonescaleFirst", "min_exp": "{{parent.tonescale1_min_exposure}}", "max_exp": "{{parent.tonescale1_max_exposure}}"}%
set N543acf70 [stack 0]
Expand All @@ -133,13 +173,6 @@ Group {
ypos 300
}
%NODE_AgXcTonescale:{"ypos": 350, "xpos": 0,"name": "AgXcTonescaleFirst", "min_exposure": "{{parent.tonescale1_min_exposure}}", "max_exposure": "{{parent.tonescale1_max_exposure}}", "general_contrast": "{{parent.contrast1}}", "use_gpu": "{{parent.use_gpu}}"}%
Colorspace {
name LINEARIZE_TONESCALE_OUTSET
xpos 0
ypos 400
label "cctf: [value colorspace_in] > [value colorspace_out]"
colorspace_in "2.40"
}
Dot {
name DotPurityInput
xpos 0
Expand All @@ -160,13 +193,6 @@ Group {
ypos 550
mix {{parent.purity_amount}}
}
Colorspace {
name UNLINEARIZE_TONESCALE_OUTSET
xpos 0
ypos 600
label "cctf: [value colorspace_in] > [value colorspace_out]"
colorspace_out "2.40"
}
Dot {
name Dot2ndTonescale
xpos 0
Expand Down Expand Up @@ -194,14 +220,14 @@ Group {
xpos 0
ypos 850
}
%NODE_SigmoidParabolic:{"ypos": 900, "xpos": 0, "name": "PRINT_CONTRAST_SigmoidParabolic", "mix": "{{parent.print_contrast_amount}}", "p": "{{parent.print_contrast} {parent.print_contrast} {parent.print_contrast}}", "t0": "{{parent.print_contrast_pivot} {parent.print_contrast_pivot} {parent.print_contrast_pivot}}"}%
Colorspace {
name LINEARIZE_TONESCALE
xpos 0
ypos 950
ypos 900
label "cctf: [value colorspace_in] > [value colorspace_out]"
colorspace_in "2.40"
}
%NODE_SigmoidParabolic:{"ypos": 950, "xpos": 0, "name": "PRINT_CONTRAST_SigmoidParabolic", "mix": "{{parent.print_contrast_amount}}", "p": "{{parent.print_contrast} {parent.print_contrast} {parent.print_contrast}}", "t0": "{{parent.print_contrast_pivot} {parent.print_contrast_pivot} {parent.print_contrast_pivot}}"}%
Dot {
name DotDisplay
xpos 0
Expand Down