forked from Phantom-Studio/natron-plugins
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Bulge_GL.py
660 lines (527 loc) · 18.9 KB
/
Bulge_GL.py
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# -*- coding: utf-8 -*-
# DO NOT EDIT THIS FILE
# This file was automatically generated by Natron PyPlug exporter version 10.
# Hand-written code should be added in a separate file named Bulge_GLExt.py
# See http://natron.readthedocs.org/en/master/devel/groups.html#adding-hand-written-code-callbacks-etc
# Note that Viewers are never exported
import NatronEngine
import sys
# Try to import the extensions file where callbacks and hand-written code should be located.
try:
from Bulge_GLExt import *
except ImportError:
pass
def getPluginID():
return "natron.community.plugins.Bulge_GL"
def getLabel():
return "Bulge_GL"
def getVersion():
return 1.0
def getIconPath():
return "Bulge_GL.png"
def getGrouping():
return "Community/GLSL/Distort"
def getPluginDescription():
return "Bulge effect."
def createInstance(app,group):
# Create all nodes in the group
# Create the parameters of the group node the same way we did for all internal nodes
lastNode = group
lastNode.setColor(0.07451, 0.5686, 0.4863)
# Create the user parameters
lastNode.Controls = lastNode.createPageParam("Controls", "Controls")
param = lastNode.createStringParam("sep01", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep01 = param
del param
param = lastNode.createStringParam("sep02", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep02 = param
del param
param = lastNode.createSeparatorParam("SETUP", "Setup")
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setPersistent(False)
param.setEvaluateOnChange(False)
lastNode.SETUP = param
del param
param = lastNode.createStringParam("sep03", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep03 = param
del param
param = lastNode.createStringParam("sep04", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep04 = param
del param
param = lastNode.createDouble2DParam("Shadertoy1_2mousePosition", "Center : ")
param.setMinimum(-1.79769e+308, 0)
param.setMaximum(1.79769e+308, 0)
param.setDisplayMinimum(-1.79769e+308, 0)
param.setDisplayMaximum(1.79769e+308, 0)
param.setDefaultValue(664, 0)
param.restoreDefaultValue(0)
param.setMinimum(-1.79769e+308, 1)
param.setMaximum(1.79769e+308, 1)
param.setDisplayMinimum(-1.79769e+308, 1)
param.setDisplayMaximum(1.79769e+308, 1)
param.setDefaultValue(582, 1)
param.restoreDefaultValue(1)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setAnimationEnabled(True)
param.setUsePointInteract(True)
lastNode.Shadertoy1_2mousePosition = param
del param
param = lastNode.createStringParam("sep05", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep05 = param
del param
param = lastNode.createDoubleParam("Shadertoy1_2paramValueFloat0", "Strength : ")
param.setMinimum(-0.5, 0)
param.setMaximum(5, 0)
param.setDisplayMinimum(-0.5, 0)
param.setDisplayMaximum(5, 0)
param.setDefaultValue(0.6, 0)
param.restoreDefaultValue(0)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setAddNewLine(True)
param.setAnimationEnabled(True)
lastNode.Shadertoy1_2paramValueFloat0 = param
del param
param = lastNode.createStringParam("sep06", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep06 = param
del param
param = lastNode.createDoubleParam("Shadertoy1_2paramValueFloat1", "Radius : ")
param.setMinimum(0, 0)
param.setMaximum(1, 0)
param.setDisplayMinimum(0, 0)
param.setDisplayMaximum(1, 0)
param.setDefaultValue(0.172, 0)
param.restoreDefaultValue(0)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setAddNewLine(True)
param.setAnimationEnabled(True)
lastNode.Shadertoy1_2paramValueFloat1 = param
del param
param = lastNode.createStringParam("sep07", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep07 = param
del param
param = lastNode.createStringParam("sep08", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Controls.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep08 = param
del param
lastNode.Credits = lastNode.createPageParam("Credits", "Credits")
param = lastNode.createStringParam("sep101", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep101 = param
del param
param = lastNode.createStringParam("sep102", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep102 = param
del param
param = lastNode.createSeparatorParam("NAME", "Bulge_GL v1.0")
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setPersistent(False)
param.setEvaluateOnChange(False)
lastNode.NAME = param
del param
param = lastNode.createStringParam("sep103", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep103 = param
del param
param = lastNode.createStringParam("sep104", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep104 = param
del param
param = lastNode.createSeparatorParam("LINE01", "")
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setPersistent(False)
param.setEvaluateOnChange(False)
lastNode.LINE01 = param
del param
param = lastNode.createStringParam("sep105", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep105 = param
del param
param = lastNode.createStringParam("sep106", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep106 = param
del param
param = lastNode.createSeparatorParam("FR", "ShaderToy 0.8.8")
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setPersistent(False)
param.setEvaluateOnChange(False)
lastNode.FR = param
del param
param = lastNode.createStringParam("sep107", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep107 = param
del param
param = lastNode.createStringParam("sep108", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep108 = param
del param
param = lastNode.createSeparatorParam("CONVERSION", "(2019)")
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setPersistent(False)
param.setEvaluateOnChange(False)
lastNode.CONVERSION = param
del param
param = lastNode.createStringParam("sep109", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep109 = param
del param
param = lastNode.createStringParam("sep110", "")
param.setType(NatronEngine.StringParam.TypeEnum.eStringTypeLabel)
# Add the param to the page
lastNode.Credits.addParam(param)
# Set param properties
param.setHelp("")
param.setAddNewLine(True)
param.setEvaluateOnChange(False)
param.setAnimationEnabled(False)
lastNode.sep110 = param
del param
# Refresh the GUI with the newly created parameters
lastNode.setPagesOrder(['Controls', 'Credits', 'Node', 'Settings'])
lastNode.refreshUserParamsGUI()
del lastNode
# Start of node "Output1"
lastNode = app.createNode("fr.inria.built-in.Output", 1, group)
lastNode.setLabel("Output2")
lastNode.setPosition(4139, 4134)
lastNode.setSize(90, 33)
lastNode.setColor(0.7, 0.7, 0.7)
groupOutput1 = lastNode
del lastNode
# End of node "Output1"
# Start of node "Source"
lastNode = app.createNode("fr.inria.built-in.Input", 1, group)
lastNode.setScriptName("Source")
lastNode.setLabel("Source")
lastNode.setPosition(4139, 3601)
lastNode.setSize(90, 36)
lastNode.setColor(1, 1, 1)
groupSource = lastNode
del lastNode
# End of node "Source"
# Start of node "Crop_Source"
lastNode = app.createNode("net.sf.openfx.CropPlugin", 1, group)
lastNode.setScriptName("Crop_Source")
lastNode.setLabel("Crop_Source")
lastNode.setPosition(4139, 3757)
lastNode.setSize(90, 36)
lastNode.setColor(0.7, 0.3, 0.1)
groupCrop_Source = lastNode
param = lastNode.getParam("rectangleInteractEnable")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("NatronParamFormatChoice")
if param is not None:
param.set("PC_Video")
del param
param = lastNode.getParam("size")
if param is not None:
param.setValue(1920, 0)
param.setValue(1080, 1)
del param
param = lastNode.getParam("reformat")
if param is not None:
param.setValue(True)
del param
del lastNode
# End of node "Crop_Source"
# Start of node "Shadertoy1_2"
lastNode = app.createNode("net.sf.openfx.Shadertoy", 1, group)
lastNode.setScriptName("Shadertoy1_2")
lastNode.setLabel("Shadertoy1")
lastNode.setPosition(4144, 3878)
lastNode.setSize(80, 32)
lastNode.setColor(0.3, 0.5, 0.2)
groupShadertoy1_2 = lastNode
param = lastNode.getParam("mousePosition")
if param is not None:
param.setValue(664, 0)
param.setValue(582, 1)
del param
param = lastNode.getParam("paramValueFloat0")
if param is not None:
param.setValue(0.6, 0)
del param
param = lastNode.getParam("paramValueFloat1")
if param is not None:
param.setValue(0.172, 0)
del param
param = lastNode.getParam("imageShaderSource")
if param is not None:
param.setValue("// iChannel0: Source (Source image.), filter=linear, wrap=clamp\n// BBox: iChannel0\n\nuniform float bulgeRadius = 0.5; // Radius (The radius of the bulge effect), min=0., max=1.\nuniform float bulgeStrength = 2.0; // Strength (The strength of the bulge effect), min=-0.5., max=5.\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord )\n{\n vec2 R = iResolution.xy,\n uv = fragCoord / R.y,\n mouse = iMouse.xy / R.y;\n\n vec2 ratioCenter = mouse,\n distVec = uv - ratioCenter;\n \n float dist = distance(ratioCenter, uv),\n normDist = dist / bulgeRadius;\n\n if (normDist < 1.) {\n float a = atan(distVec.y, distVec.x);\n normDist = smoothstep(0.,1., normDist);\n float newRadius = pow(normDist, bulgeStrength) * dist;\n uv = newRadius * vec2(cos(a),sin(a)) + ratioCenter;\n }\n fragColor = texture(iChannel0, uv*R.y/R);\n}\n")
del param
param = lastNode.getParam("mipmap0")
if param is not None:
param.set("linear")
del param
param = lastNode.getParam("wrap0")
if param is not None:
param.set("clamp")
del param
param = lastNode.getParam("inputLabel0")
if param is not None:
param.setValue("Source")
del param
param = lastNode.getParam("inputHint0")
if param is not None:
param.setValue("Source image.")
del param
param = lastNode.getParam("inputEnable1")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("inputEnable2")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("inputEnable3")
if param is not None:
param.setValue(False)
del param
param = lastNode.getParam("bbox")
if param is not None:
param.set("iChannel0")
del param
param = lastNode.getParam("NatronParamFormatChoice")
if param is not None:
param.set("PC_Video")
del param
param = lastNode.getParam("paramCount")
if param is not None:
param.setValue(2, 0)
del param
param = lastNode.getParam("paramType0")
if param is not None:
param.set("float")
del param
param = lastNode.getParam("paramName0")
if param is not None:
param.setValue("bulgeStrength")
del param
param = lastNode.getParam("paramLabel0")
if param is not None:
param.setValue("Strength")
del param
param = lastNode.getParam("paramHint0")
if param is not None:
param.setValue("The strength of the bulge effect")
del param
param = lastNode.getParam("paramDefaultFloat0")
if param is not None:
param.setValue(2, 0)
del param
param = lastNode.getParam("paramMinFloat0")
if param is not None:
param.setValue(-0.5, 0)
del param
param = lastNode.getParam("paramMaxFloat0")
if param is not None:
param.setValue(5, 0)
del param
param = lastNode.getParam("paramType1")
if param is not None:
param.set("float")
del param
param = lastNode.getParam("paramName1")
if param is not None:
param.setValue("bulgeRadius")
del param
param = lastNode.getParam("paramLabel1")
if param is not None:
param.setValue("Radius")
del param
param = lastNode.getParam("paramHint1")
if param is not None:
param.setValue("The radius of the bulge effect")
del param
param = lastNode.getParam("paramDefaultFloat1")
if param is not None:
param.setValue(0.5, 0)
del param
param = lastNode.getParam("paramMinFloat1")
if param is not None:
param.setValue(0, 0)
del param
param = lastNode.getParam("paramMaxFloat1")
if param is not None:
param.setValue(1, 0)
del param
del lastNode
# End of node "Shadertoy1_2"
# Now that all nodes are created we can connect them together, restore expressions
groupOutput1.connectInput(0, groupShadertoy1_2)
groupCrop_Source.connectInput(0, groupSource)
groupShadertoy1_2.connectInput(0, groupCrop_Source)
param = groupCrop_Source.getParam("size")
param.setExpression("myWidth = Source.getOutputFormat().width()\nret = myWidth", True, 0)
param.setExpression("myWidth = Source.getOutputFormat().height()\nret = myWidth", True, 1)
del param
param = groupShadertoy1_2.getParam("mousePosition")
group.getParam("Shadertoy1_2mousePosition").setAsAlias(param)
del param
param = groupShadertoy1_2.getParam("paramValueFloat0")
group.getParam("Shadertoy1_2paramValueFloat0").setAsAlias(param)
del param
param = groupShadertoy1_2.getParam("paramValueFloat1")
group.getParam("Shadertoy1_2paramValueFloat1").setAsAlias(param)
del param
try:
extModule = sys.modules["Bulge_GLExt"]
except KeyError:
extModule = None
if extModule is not None and hasattr(extModule ,"createInstanceExt") and hasattr(extModule.createInstanceExt,"__call__"):
extModule.createInstanceExt(app,group)