Skip to content

Instantly share code, notes, and snippets.

@jedypod
Last active May 31, 2017 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jedypod/849ba8dd0a2180b234ab to your computer and use it in GitHub Desktop.
Save jedypod/849ba8dd0a2180b234ab to your computer and use it in GitHub Desktop.
Simple grain node with with intensity response LUT adjustment.
Group {
name GrainResponse
help "Adds synthetic grain. Push \"presets\" to get predefined types of grain, these are the correct size for 2K scans.\n\nYou can also adjust the sliders to match a sample piece of grain. Find a sample with a rather constant background, blur it to remove the grain, and use as input to this. View with a wipe in the viewer so you can make a match. It helps to view and match each of the red, green, blue separately."
addUserKnob {20 GrainTab l Grain}
addUserKnob {3 seed t "Change this value to make different instances of this operator produce different noise"}
seed 134
addUserKnob {35 presets l "" -STARTLINE M {"presets/Kodak 5248" "knobs this \{red_size 3.30 green_size 2.90 blue_size 2.5 red_i 0.60 green_i 0.60 blue_i 0.60 red_m 0.42 green_m 0.46 blue_m 0.85 black 0.00 label \{Kodak 5248\}\}" "presets/Kodak 5279" "knobs this \{red_size 2.70 green_size 2.60 blue_size 2.40 red_i 1.00 green_i 0.76 blue_i 0.65 red_m 0.37 green_m 0.60 blue_m 1.65 black 0.00 label \{Kodak 5279\}\}" "presets/Kodak FX214" "knobs this \{red_size 1.87 green_size 2.60 blue_size 2.44 red_i 1 green_i 0.76 blue_i 0.79 red_m 0.41 green_m 0.60 blue_m 1.80 black 0.00 label \{Kodak FX214\}\}" "presets/Kodak GT5274" "knobs this \{red_size 0.04 green_size 0.10 blue_size 0.90 red_i 0.90 green_i 0.76 blue_i 0.81 red_m 0.49 green_m 0.50 blue_m 1.55 black 0.00 label \{Kodak GT5274\}\}" "presets/Kodak 5217" "knobs this \{red_size 0.23 green_size 1.20 blue_size 1.40 red_i 0.60 green_i 0.86 blue_i 0.60 red_m 0.48 green_m 0.42 blue_m 0.87 black 0.00 label \{Kodak 5217\}\}" "presets/Kodak 5218" "knobs this \{red_size 0.10 green_size 1.60 blue_size 1.91 red_i 0.60 green_i 0.86 blue_i 0.73 red_m 0.38 green_m 0.17 blue_m 0.87 black 0.00 label \{Kodak 5218\}\}" presets/other "knobs this \{label other\}"}}
addUserKnob {26 "" l "@b;Size"}
addUserKnob {14 red_size l red R 0 100}
red_size 1.8
addUserKnob {14 green_size l green R 0 100}
green_size 1.8
addUserKnob {14 blue_size l blue R 0 100}
blue_size 2.2
addUserKnob {26 "" l "@b;Irregularity"}
addUserKnob {7 red_i l red}
red_i 0.6
addUserKnob {7 green_i l green}
green_i 0.6
addUserKnob {7 blue_i l blue}
blue_i 0.6
addUserKnob {26 "" l "@b;Intensity"}
addUserKnob {7 red_m l red t "Amount of grain to add to a white pixel"}
red_m 0.205
addUserKnob {7 green_m l green}
green_m 0.15
addUserKnob {7 blue_m l blue}
blue_m 0.285
addUserKnob {18 black t "Amount of grain to add everywhere"}
black 0.77
addUserKnob {6 black_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {18 minimum t "Minimum black level" R 0 0.01}
minimum {0 0 0}
addUserKnob {6 minimum_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
addUserKnob {26 "" l "@b;Mask"}
addUserKnob {41 mask_channel l channel t "Choose the channel to use as the mask" T _KEYMIX_.maskChannel}
addUserKnob {6 use_input_alpha l "use input alpha" t "Use incoming alpha channel to mask the grain application." -STARTLINE}
use_input_alpha true
addUserKnob {6 invert_grain_mask l invert -STARTLINE}
addUserKnob {7 harden_alpha l harden t "Harden the incoming alpha so that grain on motionblurred edges is applied with the correct intensity."}
harden_alpha 0.75
addUserKnob {20 LUTTab l Response t "Modify the grain intensity over luminance."}
addUserKnob {41 lut l "" -STARTLINE T _GrainResponse_.lut}
}
Input {
inputs 0
name InputMask
label "\[value number]\n"
xpos -480
ypos -232
number 1
}
Input {
inputs 0
name Input
label "\[value number]"
xpos -40
ypos -232
}
Dot {
name Dot1
note_font_size 42
note_font_color 0x7f7f7f01
xpos -6
ypos -126
}
set Nea596140 [stack 0]
Shuffle {
red white
green white
blue white
alpha white
name Shuffle1
tile_color 0xffffffff
xpos -260
ypos -130
}
set Ne4e82180 [stack 0]
Copy {
inputs 2
from0 -rgba.alpha
to0 -rgba.alpha
channels all
bbox B
name Copy1
xpos -480
ypos -142
}
push $Nea596140
Dot {
name Dot3
note_font_size 42
note_font_color 0x7f7f7f01
xpos -6
ypos -54
}
set Nb8ee6cd0 [stack 0]
push $Ne4e82180
Switch {
inputs 2
which {{parent.use_input_alpha}}
name _USE_INPUT_ALPHA_
xpos -260
ypos -58
}
Switch {
inputs 2
which {{"\[exists parent.input1]"}}
name _MASK_INPUT_SWITCH_
xpos -260
ypos 38
}
CCorrect {
gray 1
contrast {{1-parent.harden_alpha}}
name _CONTRAST_ALPHA_
xpos -260
ypos 182
}
Clamp {
channels rgba
name Clamp
xpos -260
ypos 230
}
push $Nb8ee6cd0
Dot {
name Dot5
note_font_size 42
note_font_color 0x7f7f7f01
xpos 104
ypos -54
}
set Ne651b6e0 [stack 0]
Dot {
name Dot4
note_font_size 42
note_font_color 0x7f7f7f01
xpos 214
ypos -54
}
ColorLookup {
lut {master {curve C 0.01470589638 0.4137254953}
red {}
green {}
blue {}
alpha {}}
name _GrainResponse_
xpos 180
ypos 134
}
push $Nea596140
Dot {
name Dot2
note_font_size 42
note_font_color 0x7f7f7f01
xpos 324
ypos -126
}
Noise {
output {rgba.red -rgba.green -rgba.blue -rgba.alpha}
cliptype none
replace true
size {{parent.red_size.w} {parent.red_size.h}}
zoffset {{frame+seed+red_i/2}}
octaves 2
gamma 1
xrotate {{red_i*45}}
yrotate {{red_i*45}}
name red
xpos 290
ypos -58
}
Noise {
output {-rgba.red rgba.green -rgba.blue -rgba.alpha}
cliptype none
replace true
size {{parent.green_size.w} {parent.green_size.h}}
zoffset {{frame+2*seed+green_i/2}}
octaves 2
gamma 1
xrotate {{green_i*45}}
yrotate {{green_i*45}}
name green
xpos 290
ypos -10
}
Noise {
output {-rgba.red -rgba.green rgba.blue -rgba.alpha}
cliptype none
replace true
size {{parent.blue_size.w} {parent.blue_size.h}}
zoffset {{frame+3*seed+blue_i/2}}
octaves 2
gamma 1
xrotate {{blue_i*45}}
yrotate {{blue_i*45}}
name blue
xpos 290
ypos 38
}
Add {
channels rgba
value -0.5
name Add1
xpos 290
ypos 134
}
Multiply {
channels rgba
value {{red_m+black} {green_m+black} {blue_m+black} {curve}}
name Intensity
xpos 290
ypos 182
}
Merge2 {
inputs 2
operation multiply
bbox B
name Merge1
xpos 180
ypos 231
}
push $Ne651b6e0
MergeExpression {
inputs 2
expr0 "max( minimum.r, r + Ar )"
expr1 "max( minimum.g, g + Ag )"
expr2 "max( minimum.b, b + Ab )"
channel3 none
name MergeExpression2
xpos 70
ypos 231
}
push $Nb8ee6cd0
Keymix {
inputs 3
channels rgba
invertMask {{parent.invert_grain_mask}}
bbox B
name _KEYMIX_
xpos -40
ypos 230
}
Output {
name Output1
xpos -40
ypos 399
}
end_group
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment