1+ {
2+ "name": "crop",
3+ "node_position": {
4+ "x": 0,
5+ "y": 0
6+ },
7+ "parameters": {
8+ "edge": 3,
9+ "edge_color": {
10+ "a": 1.0,
11+ "b": 0.0,
12+ "g": 0.0,
13+ "r": 0.0,
14+ "type": "Color"
15+ },
16+ "keep_aspect": false,
17+ "pa": 0.5,
18+ "x1": -0.5,
19+ "x2": 0.5,
20+ "y1": -0.5,
21+ "y2": 0.5
22+ },
23+ "seed_int": 0,
24+ "shader_model": {
25+ "code": "",
26+ "global": "",
27+ "inputs": [
28+ {
29+ "default": "vec4(0.0, 0.0, 0.0, 1.0)",
30+ "function": true,
31+ "label": "",
32+ "longdesc": "Input image to be cropped",
33+ "name": "in",
34+ "shortdesc": "Input image",
35+ "type": "rgba"
36+ }
37+ ],
38+ "instance": [
39+ "vec4 $(name)_crop(vec2 uv) {",
40+ "\tvec2 new_uv = uv * vec2( $x2 - $x1, $y2 - $y1) + vec2($x1 + 0.5, $y1 + 0.5);",
41+ "\tfloat mask = float(floor(uv) == vec2(0.0));",
42+ "\tif ($edge == 0) {",
43+ "\t\tvec4 col = $in(new_uv);",
44+ "\t\treturn col * mask;",
45+ "\t} else if ($edge == 1) {",
46+ "\t\tnew_uv = fract(uv) * vec2( $x2 - $x1, $y2 - $y1) + vec2($x1 + 0.5, $y1 + 0.5);",
47+ "\t\treturn $in(new_uv);",
48+ "\t} else if ($edge == 2){",
49+ "\t\treturn $in(new_uv);",
50+ "\t} else {",
51+ "\t\tvec4 col = $in(new_uv);",
52+ "\t\treturn mix($edge_color, col, mask);",
53+ "\t}",
54+ "}",
55+ "",
56+ "vec2 $(name)_sca_fac(vec2 uv) {",
57+ "\tvec2 sca = abs(vec2($x2 - $x1, $y2 - $y1));",
58+ "\treturn sca / max(sca.x, sca.y) * 0.5 + 0.5;",
59+ "}",
60+ "",
61+ "vec4 $(name)_crop2(vec2 uv) {",
62+ "\tuv -= vec2($x1 + 0.5, $y1 + 0.5);",
63+ "\tvec2 new_uv = mod(uv, vec2( $x2 - $x1, $y2 - $y1) ) + vec2($x1 + 0.5, $y1 + 0.5);",
64+ "\treturn $in(new_uv);",
65+ "}",
66+ "",
67+ "vec4 $(name)_crop_preview(vec2 uv) {",
68+ "\tfloat mask = uv.x - 0.5 > $x1 && uv.x - 0.5 < $x2 && uv.y - 0.5 > $y1 && uv.y - 0.5 < $y2 ? 1.0 : $pa;",
69+ "\treturn $in(uv) * mask;",
70+ "}",
71+ "",
72+ "float $(name)_fade_mask(vec2 uv, float fade_width) {",
73+ "\tuv -= vec2($x1 + 0.5, $y1 + 0.5);",
74+ "\tfloat vertical_mask = clamp(uv.x / fade_width + 0.5, 0.0, 1.0);",
75+ "\tuv -= vec2( $x2 - $x1, $y2 - $y1);",
76+ "\tvertical_mask *= clamp(-uv.x / fade_width + 0.5, 0.0, 1.0);",
77+ "\treturn vertical_mask;",
78+ "} "
79+ ],
80+ "longdesc": "Crops an image",
81+ "name": "Crop",
82+ "outputs": [
83+ {
84+ "longdesc": "Image cropping preview",
85+ "rgba": "$(name)_crop_preview($uv)",
86+ "shortdesc": "Preview",
87+ "type": "rgba"
88+ },
89+ {
90+ "longdesc": "Result of the crop operation",
91+ "rgba": "$keep_aspect ? $(name)_crop(($uv - 0.5) / (2.0*$(name)_sca_fac($uv)-1.0) + 0.5) : $(name)_crop($uv)",
92+ "shortdesc": "Cropped image",
93+ "type": "rgba"
94+ }
95+ ],
96+ "parameters": [
97+ {
98+ "default": 3.0,
99+ "label": "Edge",
100+ "longdesc": "Specifies filling mode beyond the crop area.",
101+ "name": "edge",
102+ "shortdesc": "Edge Mode",
103+ "type": "enum",
104+ "values": [
105+ {
106+ "name": "Alpha",
107+ "value": "0"
108+ },
109+ {
110+ "name": "Repeat",
111+ "value": "1"
112+ },
113+ {
114+ "name": "Continous",
115+ "value": "2"
116+ },
117+ {
118+ "name": "Color",
119+ "value": "3"
120+ }
121+ ]
122+ },
123+ {
124+ "default": false,
125+ "label": "Keep Aspect",
126+ "longdesc": "When set, cropped output is scaled to fit the unit square, centered with aspect ratio(based on the crop area) kept.",
127+ "name": "keep_aspect",
128+ "shortdesc": "Keep Aspect",
129+ "type": "boolean"
130+ },
131+ {
132+ "control": "P1.x",
133+ "default": -0.5,
134+ "label": "Corner 1",
135+ "longdesc": "Position for the first crop handle on the X axis.",
136+ "max": 0.5,
137+ "min": -0.5,
138+ "name": "x1",
139+ "shortdesc": "First Corner X",
140+ "step": 0.01,
141+ "type": "float"
142+ },
143+ {
144+ "control": "P1.y",
145+ "default": -0.5,
146+ "label": "3:",
147+ "longdesc": "Position for the first crop handle on the Y axis.",
148+ "max": 0.5,
149+ "min": -0.5,
150+ "name": "y1",
151+ "shortdesc": "First Corner Y",
152+ "step": 0.01,
153+ "type": "float"
154+ },
155+ {
156+ "control": "P2.x",
157+ "default": 0.5,
158+ "label": "Corner 2",
159+ "longdesc": "Position for the second crop handle on the X axis",
160+ "max": 0.5,
161+ "min": -0.5,
162+ "name": "x2",
163+ "shortdesc": "Second Corner X",
164+ "step": 0.01,
165+ "type": "float"
166+ },
167+ {
168+ "control": "P2.y",
169+ "default": 0.5,
170+ "label": "4:",
171+ "longdesc": "Position for the second crop handle on the Y axis.",
172+ "max": 0.5,
173+ "min": -0.5,
174+ "name": "y2",
175+ "shortdesc": "Second Corner Y",
176+ "step": 0.01,
177+ "type": "float"
178+ },
179+ {
180+ "control": "None",
181+ "default": 0.5,
182+ "label": "Preview",
183+ "longdesc": "Background opacity in preview output.",
184+ "max": 1.0,
185+ "min": 0.0,
186+ "name": "pa",
187+ "shortdesc": "Preview Alpha",
188+ "step": 0.01,
189+ "type": "float"
190+ },
191+ {
192+ "default": {
193+ "a": 1.0,
194+ "b": 0.0,
195+ "g": 0.0,
196+ "r": 0.0
197+ },
198+ "label": "1:",
199+ "longdesc": "Custom color to use beyond the cropped content. Only effective if 'Edge' is set to 'Color'.",
200+ "name": "edge_color",
201+ "shortdesc": "Edge Color",
202+ "type": "color"
203+ }
204+ ],
205+ "shortdesc": "Crop"
206+ },
207+ "type": "shader"
208+ }
0 commit comments