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
|
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
from mathutils import Vector
class AMTH_NODE_OT_AddTemplateVignette(bpy.types.Operator):
bl_idname = "node.template_add_vignette"
bl_label = "Add Vignette"
bl_description = "Add a vignette effect"
bl_options = {"REGISTER", "UNDO"}
@classmethod
def poll(cls, context):
space = context.space_data
return space.type == "NODE_EDITOR" \
and space.node_tree is not None \
and space.tree_type == "CompositorNodeTree"
# used as reference the setup scene script from master nazgul
def _setupNodes(self, context):
scene = context.scene
space = context.space_data
tree = scene.node_tree
has_act = True if tree.nodes.active else False
bpy.ops.node.select_all(action="DESELECT")
ellipse = tree.nodes.new(type="CompositorNodeEllipseMask")
ellipse.width = 0.8
ellipse.height = 0.4
blur = tree.nodes.new(type="CompositorNodeBlur")
blur.use_relative = True
blur.factor_x = 30
blur.factor_y = 50
ramp = tree.nodes.new(type="CompositorNodeValToRGB")
ramp.color_ramp.interpolation = "B_SPLINE"
ramp.color_ramp.elements[1].color = (0.6, 0.6, 0.6, 1)
overlay = tree.nodes.new(type="CompositorNodeMixRGB")
overlay.blend_type = "OVERLAY"
overlay.inputs[0].default_value = 0.8
overlay.inputs[1].default_value = (0.5, 0.5, 0.5, 1)
tree.links.new(ellipse.outputs["Mask"], blur.inputs["Image"])
tree.links.new(blur.outputs["Image"], ramp.inputs[0])
tree.links.new(ramp.outputs["Image"], overlay.inputs[2])
if has_act:
tree.links.new(tree.nodes.active.outputs[0], overlay.inputs[1])
if has_act:
overlay.location = tree.nodes.active.location
overlay.location += Vector((350.0, 0.0))
else:
overlay.location += Vector(
(space.cursor_location[0], space.cursor_location[1]))
ellipse.location = overlay.location
ellipse.location += Vector((-715.0, -400))
ellipse.inputs[0].hide = True
ellipse.inputs[1].hide = True
blur.location = ellipse.location
blur.location += Vector((300.0, 0.0))
blur.inputs["Size"].hide = True
ramp.location = blur.location
ramp.location += Vector((175.0, 0))
ramp.outputs["Alpha"].hide = True
for node in (ellipse, blur, ramp, overlay):
node.select = True
node.show_preview = False
bpy.ops.node.join()
frame = ellipse.parent
frame.label = "Vignette"
frame.use_custom_color = True
frame.color = (0.1, 0.1, 0.1)
overlay.parent = None
overlay.label = "Vignette Overlay"
def execute(self, context):
self._setupNodes(context)
return {"FINISHED"}
|