forked from jedypod/nuke-colortools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotSlice.nk
221 lines (221 loc) · 7.08 KB
/
PlotSlice.nk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
set cut_paste_input [stack 0]
push $cut_paste_input
Group {
name PlotSlice
addUserKnob {20 PlotSlice_tab l PlotSlice}
addUserKnob {41 useGPUIfAvailable l "Use GPU if available" T PlotSlice.useGPUIfAvailable}
addUserKnob {12 pos1 l p1}
addUserKnob {12 pos2 l p2 -STARTLINE}
pos2 {256 256}
addUserKnob {7 max_value l "max value" R 1 10}
max_value 1.1
addUserKnob {7 min_value l "min value" R -1 0}
min_value -0.05
addUserKnob {4 style M {replace over right bottom ""}}
addUserKnob {6 antialias t "enable antialiasing. prettier, at the cost of speed." -STARTLINE}
addUserKnob {6 draw_lines l "draw lines" t "draw horizontal lines every whole number" -STARTLINE}
draw_lines true
addUserKnob {18 lines_color l "lines color"}
lines_color 0.1
addUserKnob {6 lines_color_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
}
Input {
inputs 0
name Input
xpos -810
ypos -658
}
Dot {
name Dot13
note_font_size 42
note_font_color 0x7f7f7f01
xpos -776
ypos -558
}
set N33c4d4b0 [stack 0]
Dot {
name Dot12
note_font_size 42
note_font_color 0x7f7f7f01
xpos -556
ypos -558
}
set N33c52320 [stack 0]
Transform {
translate {{-parent.pos1} {-parent.pos1}}
black_outside false
name Transform4
label T
xpos -590
ypos -520
}
Transform {
rotate {{"-degrees( atan2(parent.pos2.y-parent.pos1.y, parent.pos2.x-parent.pos1.x) )"}}
black_outside false
name Transform5
label "R\n"
xpos -590
ypos -472
}
Transform {
scale {{"width / sqrt(pow(parent.pos2.x-parent.pos1.x,2) + pow(parent.pos2.y-parent.pos1.y,2))"}}
black_outside false
name Transform6
label S
xpos -590
ypos -424
}
set N33c73a50 [stack 0]
Crop {
box {0 0 {Input.width} 1}
reformat true
crop false
name Crop1
xpos -700
ypos -418
}
Expression {
expr0 r/max_val-(min_val/max_val)
expr1 g/max_val-(min_val/max_val)
expr2 b/max_val-(min_val/max_val)
expr3 a/max_val-(min_val/max_val)
name Fit
xpos -700
ypos -394
addUserKnob {20 Param}
addUserKnob {7 max_val R 1 10}
max_val {{parent.max_value+fabs(parent.min_value)}}
addUserKnob {7 min_val R -1 0}
min_val {{parent.min_value}}
}
Reformat {
type "to box"
box_width {{Input.width}}
box_height {{Input.height}}
box_fixed true
resize distort
filter impulse
name Reformat1
xpos -700
ypos -370
}
Expression {
temp_name0 c
temp_expr0 0.8
expr0 "fabs((y/height)-r)<=tolerance ? c : 0"
expr1 "fabs((y/height)-g)<=tolerance ? c : 0"
expr2 "fabs((y/height)-b)<=tolerance ? c : 0"
expr3 "fabs((y/height)-a)<=tolerance ? c : 0"
name PlotSlice_
selected true
xpos -700
ypos -322
addUserKnob {20 User}
addUserKnob {7 tolerance}
tolerance 0.0007
}
push $N33c73a50
Reformat {
type "to box"
box_width {{"\[exists input] ? input.width : root.width"}}
box_height {{"\[exists input] ? input.height : root.height"}}
box_fixed true
box_pixel_aspect {{"\[exists input] ? input.pixel_aspect : root.pixel_aspect"}}
resize none
black_outside true
name BboxRemove
xpos -590
ypos -370
}
BlinkScript {
recompileCount 1
KernelDescription "2 \"PlotSlice\" iterate pixelWise a85c49a08f78aaad29c10667611d0922f3ade835175dd677155ef71c6ca45491 2 \"src\" Read Random \"dst\" Write Random 7 \"plot_input\" Bool 1 AA== \"color\" Float 1 AAAAAA== \"max_val\" Float 1 AAAAAA== \"min_val\" Float 1 AAAAAA== \"draw_lines\" Bool 1 AA== \"tolerance\" Float 1 AAAAAA== \"lines_color\" Float 3 AAAAAAAAAAAAAAAAAAAAAA== 7 \"plot_input\" 1 1 \"color\" 1 1 \"max_val\" 1 1 \"min_val\" 1 1 \"draw_lines\" 1 1 \"tolerance\" 1 1 \"lines_color\" 3 1 0"
kernelSource "kernel PlotSlice : public ImageComputationKernel<ePixelWise>\n\{\n Image<eRead, eAccessRandom, eEdgeClamped> src;\n Image<eWrite, eAccessRandom> dst;\n\n param:\n bool plot_input;\n float color;\n float max_val;\n float min_val;\n bool draw_lines;\n float tolerance;\n float3 lines_color;\n\n float gaussian(float d, float a, float expv) \{\n return max(0.0f, exp(-a*d*d)-expv);\n \}\n\n float gaussian_filter(float x, float y, float r) \{\n // return gaussian weighted distance from origin (0, 0)\n // given coordinate (x, y) and radius r\n float a = 1.5f; // rate falloff\n float expv = exp(-a*r*r);\n return gaussian(x, a, expv) * gaussian(y, a, expv);\n \}\n\n void write(float x, float y, int k, float c) \{\n int n = 2;\n int u0 = round(x);\n int v0 = round(y);\n // skip if center pixel weight is greater than tolerance\n // if ( dst.bounds.inside(u0, v0)) \{\n // if (dst(u0, v0, 3) >= tolerance) return;\n // \}\n // loop over neighborhood\n for (int j = -n; j <= n; j++) \{\n int v = v0 + j;\n for (int i = -n; i <= n; i++) \{\n int u = u0 + i;\n if ( dst.bounds.inside(u, v)) \{\n // get filter weight for coord (u,v)\n float w = gaussian_filter(u-x, v-y, float(n));\n float c0 = dst(u, v, k); // existing color\n float w0 = dst(u, v, 3); // existing alpha\n // merge current color sample over existing color sample\n dst(u, v, k) = c*w+c0*(1-w);\n // merge current weight over existing weight\n dst(u, v, 3) = w+w0*(1-w);\n \}\n \}\n \}\n \}\n\n float scale(float x) \{\n return (x*dst.bounds.height())/(max_val)-((min_val/max_val)*dst.bounds.height());\n \}\n\n void process(int2 pos) \{\n if (pos.y == 0) \{\n if (draw_lines) \{\n for (int i = 0; i < max_val; i++) \{\n for (int k = 0; k < 3; k++) \{\n write(pos.x, scale(i), k, lines_color\[k]);\n \}\n \}\n \}\n if (plot_input) \{\n float4 source = src(pos.x, pos.y);\n for (int i = 0; i < 3; i++)\{\n write(pos.x, scale(source\[i]), i, color);\n \}\n \}\n \}\n \}\n\};"
rebuild ""
PlotSlice_plot_input {{parent.antialias}}
PlotSlice_color 0.6
PlotSlice_max_val {{parent.max_value}}
PlotSlice_min_val {{parent.min_value}}
PlotSlice_draw_lines {{parent.draw_lines}}
PlotSlice_tolerance 1.01
PlotSlice_lines_color {{parent.lines_color.r} {parent.lines_color.g} {parent.lines_color.b}}
rebuild_finalise ""
name PlotSlice
xpos -590
ypos -328
}
Merge2 {
inputs 2
bbox B
name Switch_Method
xpos -590
ypos -273
disable {{parent.antialias}}
}
Matrix {
channels rgba
matrix {
{1 2 1}
{2 4 2}
{1 2 1}
}
normalize true
name Antialias
xpos -590
ypos -226
}
Keyer {
operation "luminance key"
name Keyer1
xpos -590
ypos -184
}
set N33ca88c0 [stack 0]
push $N33c52320
ContactSheet {
inputs 2
width {{Input.width}}
height {{Input.height*2}}
rows 2
columns 1
roworder TopBottom
name ContactSheet2
label Bottom
xpos -370
ypos -184
}
push $N33ca88c0
push $N33c52320
ContactSheet {
inputs 2
width {{Input.width*2}}
height {{Input.height}}
rows 1
columns 2
name ContactSheet1
label Right
xpos -480
ypos -184
}
push $N33ca88c0
push $N33c4d4b0
Merge2 {
inputs 2
name Merge1
xpos -810
ypos -178
}
push $N33ca88c0
Switch {
inputs 4
which {{parent.style}}
name switch_plot_type
xpos -810
ypos -106
}
Output {
name Output
xpos -810
ypos -34
}
end_group