@cesdk/node-native 1.77.0-nightly.20260610

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/LICENSE.md +137 -0
  2. package/README.md +474 -0
  3. package/ThirdPartyLicenses.md +1041 -0
  4. package/assets/ly.img.cesdk/fonts/imgly_font_inter_semibold.otf +0 -0
  5. package/assets/ly.img.cesdk/icons/ErrorAudio.svg +5 -0
  6. package/assets/ly.img.cesdk/icons/ErrorConnection.svg +5 -0
  7. package/assets/ly.img.cesdk/icons/ErrorImage.svg +6 -0
  8. package/assets/ly.img.cesdk/icons/ErrorUnknown.svg +3 -0
  9. package/assets/ly.img.cesdk/icons/ErrorVideo.svg +6 -0
  10. package/assets/ly.img.cesdk/icons/Move.svg +3 -0
  11. package/assets/ly.img.cesdk/icons/RotateIndicator.svg +5 -0
  12. package/assets/ly.img.cesdk/icu/icudt74l.dat +0 -0
  13. package/assets/ly.img.cesdk/presets/.keep +0 -0
  14. package/assets/ly.img.cesdk/shaders/adjustments.sksl +106 -0
  15. package/assets/ly.img.cesdk/shaders/black_and_white_color_mixer.sksl +152 -0
  16. package/assets/ly.img.cesdk/shaders/common/ubq_adjustments.sksl +102 -0
  17. package/assets/ly.img.cesdk/shaders/common/ubq_color_conversions.sksl +354 -0
  18. package/assets/ly.img.cesdk/shaders/common/ubq_constants.sksl +13 -0
  19. package/assets/ly.img.cesdk/shaders/common/ubq_hue_constants.sksl +86 -0
  20. package/assets/ly.img.cesdk/shaders/common/ubq_noise.sksl +82 -0
  21. package/assets/ly.img.cesdk/shaders/cross_cut.sksl +38 -0
  22. package/assets/ly.img.cesdk/shaders/dot_pattern.sksl +29 -0
  23. package/assets/ly.img.cesdk/shaders/duotone_filter.sksl +26 -0
  24. package/assets/ly.img.cesdk/shaders/extrude_blur.sksl +85 -0
  25. package/assets/ly.img.cesdk/shaders/glow.sksl +31 -0
  26. package/assets/ly.img.cesdk/shaders/half_tone.sksl +14 -0
  27. package/assets/ly.img.cesdk/shaders/linocut.sksl +30 -0
  28. package/assets/ly.img.cesdk/shaders/liquid.sksl +19 -0
  29. package/assets/ly.img.cesdk/shaders/lut_filter.sksl +70 -0
  30. package/assets/ly.img.cesdk/shaders/mask_color.sksl +16 -0
  31. package/assets/ly.img.cesdk/shaders/mirror.sksl +21 -0
  32. package/assets/ly.img.cesdk/shaders/outliner.sksl +40 -0
  33. package/assets/ly.img.cesdk/shaders/pixelize.sksl +10 -0
  34. package/assets/ly.img.cesdk/shaders/placeholder_overlay_lines.sksl +18 -0
  35. package/assets/ly.img.cesdk/shaders/posterize.sksl +8 -0
  36. package/assets/ly.img.cesdk/shaders/radial_pixel.sksl +22 -0
  37. package/assets/ly.img.cesdk/shaders/recolor.sksl +57 -0
  38. package/assets/ly.img.cesdk/shaders/sharpie.sksl +74 -0
  39. package/assets/ly.img.cesdk/shaders/shifter.sksl +22 -0
  40. package/assets/ly.img.cesdk/shaders/tiltshift.sksl +21 -0
  41. package/assets/ly.img.cesdk/shaders/tv_glitch.sksl +25 -0
  42. package/assets/ly.img.cesdk/shaders/vignette.sksl +12 -0
  43. package/example.js +31 -0
  44. package/lib/index.d.ts +4072 -0
  45. package/lib/index.js +4922 -0
  46. package/lib/index.js.map +7 -0
  47. package/package.json +59 -0
@@ -0,0 +1,85 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float amount;
4
+ uniform float time;
5
+
6
+ const int num_iter = 16;
7
+ const float reci_num_iter_f = 1.0 / float(num_iter);
8
+ const float gamma = 2.2;
9
+ const float MAX_DIST_PX = 200.0;
10
+
11
+ float2 barrelDistortion(float2 p, float2 amt) {
12
+ p = 2.0 * p - 1.0;
13
+ // float BarrelPower = 1.125;
14
+ const float maxBarrelPower = 3.0;
15
+ float theta = atan(p.y, p.x);
16
+ float radius = length(p);
17
+ radius = pow(radius, 1.0 + maxBarrelPower * amt.x);
18
+ p.x = radius * cos(theta);
19
+ p.y = radius * sin(theta);
20
+ return 0.5 * (p + 1.0);
21
+ }
22
+
23
+ float sat(float t) {
24
+ return clamp(t, 0.0, 1.0);
25
+ }
26
+
27
+ float linterp(float t) {
28
+ return sat(1.0 - abs(2.0 * t - 1.0));
29
+ }
30
+
31
+ float remap(float t, float a, float b) {
32
+ return sat((t - a) / (b - a));
33
+ }
34
+
35
+ float3 spectrum_offset(float t) {
36
+ float3 ret;
37
+ float lo = step(t, 0.5);
38
+ float hi = 1.0 - lo;
39
+ float w = linterp(remap(t, 1.0 / 6.0, 5.0 / 6.0));
40
+ ret = float3(lo, 1.0, hi) * float3(1.0 - w, w, 1.0 - w);
41
+
42
+ return pow(ret, float3(1.0 / 2.2));
43
+ }
44
+
45
+ float nrand(float2 n) {
46
+ return fract(sin(dot(n.xy, float2(12.9898, 78.233))) * 43758.5453);
47
+ }
48
+
49
+ float4 lin2srgb(float4 c) {
50
+ return pow(c, float4(gamma));
51
+ }
52
+
53
+ float4 srgb2lin(float4 c) {
54
+ return pow(c, float4(1.0 / gamma));
55
+ }
56
+
57
+ half4 main(float2 coord) {
58
+ float2 uv = coord / imageSize;
59
+ uv.y = 1.0 - uv.y;
60
+ // resolution independent
61
+ float2 max_distort = float2(amount);
62
+
63
+ float2 oversiz = barrelDistortion(float2(1, 1), max_distort);
64
+ uv = 2.0 * uv - 1.0;
65
+ uv = uv / (oversiz * oversiz);
66
+ uv = 0.5 * uv + 0.5;
67
+
68
+ float4 sumcol = float4(0.0);
69
+ float4 sumw = float4(0.0);
70
+ float rnd = nrand(uv + fract(time));
71
+ for (int i = 0; i < num_iter; ++i) {
72
+ float t = (float(i) + rnd) * reci_num_iter_f;
73
+ float4 w = float4(spectrum_offset(t), 1.0);
74
+ sumw += w;
75
+ float2 sampleUV = barrelDistortion(uv, max_distort * t);
76
+ float2 sampleCoord = imageSize * float2(sampleUV.x, 1.0 - sampleUV.y);
77
+ sumcol += w * srgb2lin(unpremul(image.eval(sampleCoord)));
78
+ }
79
+
80
+ sumcol /= sumw;
81
+ float4 outcol = lin2srgb(sumcol);
82
+ outcol += rnd / 255.0;
83
+ outcol.rgb *= outcol.a;
84
+ return outcol;
85
+ }
@@ -0,0 +1,31 @@
1
+ uniform shader image;
2
+ uniform float size;
3
+ uniform float amount;
4
+ uniform float darkness;
5
+ half4 main(float2 coord) {
6
+
7
+ float4 sum = float4(0.0);
8
+
9
+ float weights[4];
10
+ weights[0] = 0.1531;
11
+ weights[1] = 0.12245;
12
+ weights[2] = 0.0918;
13
+ weights[3] = 0.051;
14
+
15
+ float4 baseColor = unpremul(image.eval(coord));
16
+ for (int i = 1; i <= 4; i++) {
17
+ float weight = weights[i - 1];
18
+ float offset = size * float(i);
19
+ sum += weight * (unpremul(image.eval(coord + float2(offset, 0))) - darkness);
20
+ sum += weight * (unpremul(image.eval(coord + float2(-offset, 0))) - darkness);
21
+ sum += weight * (unpremul(image.eval(coord + float2(0, offset))) - darkness);
22
+ sum += weight * (unpremul(image.eval(coord + float2(0, -offset))) - darkness);
23
+ }
24
+ sum += 2.0 * 0.1633 * (baseColor - darkness);
25
+
26
+ // Additive Blend
27
+ float4 result = baseColor + max(sum, 0.0) * amount;
28
+ result = clamp(result, float4(0.0), float4(1.0));
29
+ result.rgb *= result.a;
30
+ return result;
31
+ }
@@ -0,0 +1,14 @@
1
+ uniform shader image;
2
+ uniform float angle;
3
+ uniform float scale;
4
+
5
+ half4 main(float2 coord) {
6
+ float4 color = unpremul(image.eval(coord));
7
+ float average = (color.r + color.g + color.b) / 3.0;
8
+ float s = sin(angle), c = cos(angle);
9
+ float2 point = float2(c * coord.x - s * coord.y, s * coord.x + c * coord.y) * scale;
10
+ float pattern = (sin(point.x) * sin(point.y)) * 4.0;
11
+ float4 result = float4(float3(average * 10.0 - 5.0 + pattern), color.a);
12
+ result.rbg *= result.a;
13
+ return result;
14
+ }
@@ -0,0 +1,30 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float scale;
4
+
5
+ float luma(float3 color) {
6
+ return dot(color, float3(0.299, 0.587, 0.114));
7
+ }
8
+
9
+ half4 main(float2 coord) {
10
+
11
+ float2 uv = coord / imageSize;
12
+ uv.y = 1.0 - uv.y;
13
+
14
+ float2 center = float2(0.5);
15
+ float noiseScale = 1.;
16
+ float radius = 0.5;
17
+ float2 d = uv - center;
18
+ float r = length(d * float2(1., imageSize.y / imageSize.x)) * scale;
19
+ float a = atan(d.y, d.x) + noiseScale * (radius - r) / radius;
20
+ float2 uvt = center + r * float2(cos(a), sin(a));
21
+
22
+ float c = (.75 + .25 * sin(uvt.x * 1000.));
23
+ float4 color = unpremul(image.eval(coord));
24
+ float l = luma(color.rgb);
25
+ float f = smoothstep(.5 * c, c, l);
26
+ f = smoothstep(0., .5, f);
27
+ float3 col = float3(f);
28
+
29
+ return float4(col * color.a, color.a);
30
+ }
@@ -0,0 +1,19 @@
1
+ // #include //ly.img.cesdk/shader/common/ubq_noise
2
+ uniform shader image;
3
+ uniform float2 imageSize;
4
+ uniform float amount;
5
+ uniform float scale;
6
+ uniform float speed;
7
+ uniform float time;
8
+
9
+ half4 main(float2 coord) {
10
+ float2 uv = coord / imageSize;
11
+ uv.y = 1 - uv.y;
12
+ float noise = getNoise(uv, time * 24.0, scale, speed);
13
+ float2 noiseUv = uv + amount * noise;
14
+ // wrap
15
+ noiseUv = fract(noiseUv);
16
+ noiseUv.y = 1 - noiseUv.y;
17
+ noiseUv *= imageSize;
18
+ return image.eval(noiseUv);
19
+ }
@@ -0,0 +1,70 @@
1
+ uniform shader image;
2
+ uniform shader lookupTable;
3
+ uniform float2 lookupTableSize;
4
+ uniform int2 tileCount;
5
+ uniform float intensity;
6
+
7
+ // Try to get the exact pixel of the lut map image
8
+ float3 lutColor(int texPosX, int texPosY) {
9
+ float2 pos = (0.5 + float2(float(texPosX), float(texPosY)));
10
+ return lookupTable.eval(pos).rgb;
11
+ }
12
+
13
+ float3 bilinearInterpolate(float3 cRfGf, float3 cRfGc, float3 cRcGf, float3 cRcGc, float redFract, float greenFract) {
14
+ return mix(mix(cRfGf, cRcGf, redFract), mix(cRfGc, cRcGc, redFract), greenFract);
15
+ }
16
+
17
+ half4 main(float2 coord) {
18
+ float2 lutResolution = lookupTableSize;
19
+ float u_horizontalTileCount = float(tileCount.x);
20
+ float u_verticalTileCount = float(tileCount.y);
21
+
22
+ float4 inputColor = clamp(unpremul(image.eval(coord)), 0.0, 1.0);
23
+ float3 sourceColor = inputColor.rgb;
24
+
25
+ float3 ranges = float3(floor(lutResolution.x / u_horizontalTileCount - 1.0),
26
+ floor(lutResolution.y / u_verticalTileCount - 1.0),
27
+ floor(u_horizontalTileCount * u_horizontalTileCount - 1.0));
28
+
29
+ float3 tmp = sourceColor * ranges;
30
+ int3 floors = int3(tmp);
31
+ int3 ceils = int3(ceil(tmp));
32
+ float3 fracts = fract(tmp);
33
+
34
+ // Map tile index to tile pixel pos.
35
+ int2 pixelsPerTile = int2(lutResolution.x / u_horizontalTileCount, lutResolution.y / u_verticalTileCount);
36
+
37
+ int2 tileFloor; // Blue tile index
38
+ tileFloor.y = floors.z / tileCount.x;
39
+ tileFloor.x = (floors.z - (tileFloor.y * tileCount.x));
40
+
41
+ int2 tileCeil; // Blue tile index
42
+ tileCeil.y = ceils.z / tileCount.x;
43
+ tileCeil.x = (ceils.z - (tileCeil.y * tileCount.x));
44
+
45
+ tileFloor *= pixelsPerTile;
46
+ tileCeil *= pixelsPerTile;
47
+
48
+ // Interpolate between red and green
49
+ float3 lutColorFB =
50
+ bilinearInterpolate(lutColor(tileFloor.x + floors.x, tileFloor.y + floors.y),
51
+ lutColor(tileFloor.x + floors.x, tileFloor.y + ceils.y),
52
+ lutColor(tileFloor.x + ceils.x, tileFloor.y + floors.y),
53
+ lutColor(tileFloor.x + ceils.x, tileFloor.y + ceils.y), fracts.x, fracts.y);
54
+ float3 lutColorCB =
55
+ bilinearInterpolate(lutColor(tileCeil.x + floors.x, tileCeil.y + floors.y),
56
+ lutColor(tileCeil.x + floors.x, tileCeil.y + ceils.y),
57
+ lutColor(tileCeil.x + ceils.x, tileCeil.y + floors.y),
58
+ lutColor(tileCeil.x + ceils.x, tileCeil.y + ceils.y), fracts.x, fracts.y);
59
+
60
+ // Interpolate between the blue values
61
+ float3 interpolation = mix(lutColorFB, lutColorCB, fracts.z);
62
+
63
+ // Round Color Values to prevent that for ex. 254.999999 is cutting to 254 instead of 255;
64
+ interpolation = clamp(floor(interpolation * 255. + .5) / 255., 0.0, 1.0);
65
+
66
+ float4 filteredColor = float4(interpolation.rgb, inputColor.a);
67
+ float4 color = mix(inputColor, filteredColor, intensity);
68
+ color.rgb *= color.a;
69
+ return color;
70
+ }
@@ -0,0 +1,16 @@
1
+ // #include //ly.img.cesdk/shader/common/ubq_constants
2
+ uniform shader image;
3
+ uniform float4 maskColor;
4
+ uniform float4 maskMultiplier;
5
+ uniform float4 notMaskMultiplier;
6
+ uniform float2 replaceInsteadMultiply;
7
+
8
+ half4 main(float2 coord) {
9
+ half4 color = image.eval(coord);
10
+ if (color == maskColor) {
11
+ color = mix(color * maskMultiplier, maskMultiplier, replaceInsteadMultiply.x);
12
+ } else {
13
+ color = mix(color * notMaskMultiplier, notMaskMultiplier, replaceInsteadMultiply.y);
14
+ }
15
+ return color;
16
+ }
@@ -0,0 +1,21 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float side;
4
+ half4 main(float2 coord) {
5
+ float2 uv = coord / imageSize;
6
+ if (side == 0) {
7
+ if (uv.x > 0.5)
8
+ uv.x = 1.0 - uv.x;
9
+ } else if (side == 1) {
10
+ if (uv.x < 0.5)
11
+ uv.x = 1.0 - uv.x;
12
+ } else if (side == 2) {
13
+ if (uv.y > 0.5)
14
+ uv.y = 1.0 - uv.y;
15
+ } else if (side == 3) {
16
+ if (uv.y < 0.5)
17
+ uv.y = 1.0 - uv.y;
18
+ }
19
+ uv *= imageSize;
20
+ return image.eval(uv);
21
+ }
@@ -0,0 +1,40 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float amount;
4
+ uniform float passthrough;
5
+ half4 main(float2 coord) {
6
+
7
+ float3x3 G[2];
8
+ G[0] = mat3(1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0);
9
+ G[1] = mat3(1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0);
10
+
11
+ // There used to be a bug in this shader which caused us to always use 1/512 as the
12
+ // relative texel size. Using correct pixel offsets instead results in far better
13
+ // outputs for lower resolution images but also makes the outline a lot less pronounced
14
+ // in higher resolution images. In order to mitigate this, we now always offset at
15
+ // least 1/512 of the image size so that the output is the same as before for higher resolution
16
+ // images.
17
+ float2 texelScale = max(float2(1.0), imageSize / float2(512.0));
18
+
19
+ /* fetch the 3x3 neighbourhood and use the RGB vectors length as intensity value */
20
+ float3x3 I;
21
+ for (float i = 0.0; i < 3.0; i++) {
22
+ for (float j = 0.0; j < 3.0; j++) {
23
+ float3 probe = unpremul(image.eval(coord + texelScale * float2(i - 1, j - 1))).rgb;
24
+ I[int(i)][int(j)] = length(probe);
25
+ }
26
+ }
27
+
28
+ /* calculate the convolution values for all the masks */
29
+ float cnv[2];
30
+ for (int i = 0; i < 2; i++) {
31
+ float dp3 = dot(G[i][0], I[0]) + dot(G[i][1], I[1]) + dot(G[i][2], I[2]);
32
+ cnv[i] = dp3 * dp3;
33
+ }
34
+
35
+ float4 orig = unpremul(image.eval(coord));
36
+
37
+ float4 color = orig * passthrough + float4(0.5 * sqrt(cnv[0] * cnv[0] + cnv[1] * cnv[1])) * amount;
38
+ color.rgb *= color.a;
39
+ return color;
40
+ }
@@ -0,0 +1,10 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float2 pixelCount;
4
+ half4 main(float2 coord) {
5
+ float2 tc = coord / imageSize;
6
+ tc.x = (floor(tc.x * pixelCount.x) + 0.5) / pixelCount.x;
7
+ tc.y = (floor(tc.y * pixelCount.y) + 0.5) / pixelCount.y;
8
+ tc *= imageSize;
9
+ return image.eval(tc);
10
+ }
@@ -0,0 +1,18 @@
1
+ uniform float4 backgroundColor;
2
+ uniform float imageWidth;
3
+ uniform float scaleX;
4
+ uniform float scaleY;
5
+ uniform float smoothness;
6
+
7
+ half4 main(float2 coord) {
8
+ float2 point = coord * float2(scaleX, scaleY);
9
+ float pattern = mod(point.x + point.y, 64.0);
10
+ float edge0 = smoothstep(32.0 - 11.31 - smoothness, 32.0 - 11.31 + smoothness, pattern);
11
+ float edge1 = smoothstep(32.0 + 11.31 + smoothness, 32.0 + 11.31 - smoothness, pattern);
12
+ float4 lines = 0.25 * float4(float3(edge0 * edge1), 1.0);
13
+
14
+ float4 darkening = float4(0, 0, 0, 0.25);
15
+ float4 linesColor = lines + (1 - lines.a) * darkening;
16
+ float4 outColor = linesColor + (1 - linesColor.a) * backgroundColor;
17
+ return outColor;
18
+ }
@@ -0,0 +1,8 @@
1
+ uniform shader image;
2
+ uniform float levels;
3
+ half4 main(float2 coord) {
4
+ float4 col = unpremul(image.eval(coord));
5
+ col.rgb = floor((col.rgb * levels) + float3(0.5)) / levels;
6
+ col.rgb *= col.a;
7
+ return col;
8
+ }
@@ -0,0 +1,22 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float radius;
4
+ uniform float segments;
5
+ half4 main(float2 coord) {
6
+ float2 uv = coord / imageSize;
7
+ float2 normCoord = 2.0 * uv - 1.0;
8
+
9
+ // to polar coords
10
+ float r = length(normCoord);
11
+ float phi = atan(normCoord.y, normCoord.x);
12
+
13
+ r = r - mod(r, radius) + 0.03;
14
+ phi = phi - mod(phi, segments);
15
+
16
+ normCoord.x = r * cos(phi);
17
+ normCoord.y = r * sin(phi);
18
+
19
+ float2 textureCoordinateToUse = normCoord / 2.0 + 0.5;
20
+ textureCoordinateToUse *= imageSize;
21
+ return image.eval(textureCoordinateToUse);
22
+ }
@@ -0,0 +1,57 @@
1
+ // #include //ly.img.cesdk/shader/common/ubq_color_conversions
2
+ // #include //ly.img.cesdk/shader/common/ubq_constants
3
+ uniform shader image;
4
+ uniform float3 fromRgb;
5
+ uniform float4 toRgba;
6
+ uniform float colorMatch;
7
+ uniform float brightnessMatch;
8
+ uniform float smoothness;
9
+ uniform float spill;
10
+
11
+ // zWeight influences the weight of the vertical distance (perceived brightness, in this shader).
12
+ float cylindricalDistance(float3 p1, float3 p2, float zWeight) {
13
+ p1.x *= TWO_PI;
14
+ p2.x *= TWO_PI;
15
+
16
+ float a = sin(p1.x) * p1.y - sin(p2.x) * p2.y;
17
+ float b = cos(p1.x) * p1.y - cos(p2.x) * p2.y;
18
+ float c = p1.z - p2.z;
19
+
20
+ return sqrt(a * a + b * b + (c * c) * zWeight);
21
+ }
22
+
23
+ half4 main(float2 coord) {
24
+ float4 rgba = unpremul(image.eval(coord));
25
+ float3 hsp = rgb2hsp(rgba.rgb);
26
+ float3 fromHsp = rgb2hsp(fromRgb);
27
+ float3 toHsp = rgb2hsp(toRgba.rgb);
28
+
29
+ float recolorBrightness = clamp(toHsp.z + (hsp.z - fromHsp.z), 0, 1);
30
+ float3 recolorHsp = float3(toHsp.x, toHsp.y, recolorBrightness);
31
+
32
+ // Since we'll want to keep transparent pixels transparent, the final alpha is the combination of the source and
33
+ // `to` alphas. This avoids recoloring pure transparent pixels which are typically "black", i.e. (0, 0, 0, 0).
34
+ float4 recolorRgba = float4(hsp2rgb(recolorHsp), rgba.a * toRgba.a);
35
+
36
+ // Measure the distance between the source and `from` colors, adjusting for brightness weight.
37
+ float distance = cylindricalDistance(hsp, fromHsp, brightnessMatch);
38
+
39
+ float mask = distance - colorMatch;
40
+
41
+ // Apply smoothness.
42
+ float smoothnessVal = pow(clamp(mask / smoothness, 0., 1.), 1.5);
43
+ recolorRgba = mix(recolorRgba, rgba, smoothnessVal);
44
+
45
+ // Apply spill.
46
+ // When greenscreening, spill will desaturate the color of the remaining pixels. This helps avoid a green halo around
47
+ // the subject.
48
+ // When recoloring to an opaque color, we rather want no spill adjustment. Thus, if spill is 0, ensure no spill is
49
+ // applied by bumping spillVal to 1.
50
+ float spillVal = pow(clamp(mask / spill, 0., 1.), 1.5);
51
+ spillVal = min(spillVal + step(spill, EPSILON), 1);
52
+ recolorRgba.rgb = mix(float3(hsp.z), recolorRgba.rgb, spillVal);
53
+
54
+ recolorRgba.rgb *= recolorRgba.a;
55
+
56
+ return recolorRgba;
57
+ }
@@ -0,0 +1,74 @@
1
+ // #include //ly.img.cesdk/shader/common/ubq_color_conversions
2
+ uniform shader image;
3
+ uniform float offset;
4
+ uniform float darkness;
5
+
6
+ // Obtaining the nearest value to the predefined HSL levels
7
+ float nearestLevel(float col) {
8
+ const int levCount = 6; // TODO: Include option for the user to choose the amount of levels
9
+ const float interval = 1.0 / float(levCount);
10
+
11
+ for (float i = 0.0; i <= 1.0; i += interval) {
12
+ if (col >= i && col <= (i + interval)) {
13
+ return (abs(col - i) < abs(col - (i + interval))) ? i : (i + interval);
14
+ }
15
+ }
16
+ return 0;
17
+ }
18
+
19
+ half4 main(float2 coord) {
20
+ float4 rgba = unpremul(image.eval(coord));
21
+ float3 origCol = rgba.rgb;
22
+ float alpha = rgba.a;
23
+
24
+ // Applying the edge detection filter to create an outline
25
+
26
+ // Obtaining the local 3x3 matrix
27
+ float4 A[9];
28
+ A[0] = unpremul(image.eval(coord + float2(-1, -1)));
29
+ A[1] = unpremul(image.eval(coord + float2(0, -1)));
30
+ A[2] = unpremul(image.eval(coord + float2(1, -1)));
31
+ A[3] = unpremul(image.eval(coord + float2(-1, 0)));
32
+ A[4] = rgba;
33
+ A[5] = unpremul(image.eval(coord + float2(1, 0)));
34
+ A[6] = unpremul(image.eval(coord + float2(-1, 1)));
35
+ A[7] = unpremul(image.eval(coord + float2(0, 1)));
36
+ A[8] = unpremul(image.eval(coord + float2(1, 1)));
37
+
38
+ // Computing the x-direction gradient
39
+ float4 sum_x = -A[0] + (A[2]) - (A[3] * 2.0) + (A[5] * 2.0) - (A[6]) + (A[8]);
40
+
41
+ // Computing the y-direction gradient
42
+ float4 sum_y = A[0] + (A[1] * 2.0) + A[2] - A[6] - (A[7] * 2.0) - A[8];
43
+
44
+ // Computing the sum
45
+ float4 sum = sqrt((sum_x * sum_x) + (sum_y * sum_y));
46
+
47
+ // Combining the colors to obtain a black color for the outline
48
+ float sumLength = length(sum);
49
+ float outlineShade = 1.0 - sumLength;
50
+ float4 outlineCol = float4(outlineShade, outlineShade, outlineShade, alpha);
51
+
52
+ // Thresholding
53
+ if (outlineShade > 0.5)
54
+ outlineShade = 1.0;
55
+
56
+ // Applying the cel-shading effect
57
+ float3 hslColor = rgb2hsl(origCol);
58
+ hslColor.x = nearestLevel(hslColor.x);
59
+ hslColor.y = nearestLevel(hslColor.y);
60
+ hslColor.z = nearestLevel(hslColor.z);
61
+
62
+ float3 outColor = hsl2rgb(hslColor);
63
+
64
+ float4 tc = float4(outColor.r, outColor.g, outColor.b, alpha);
65
+
66
+ // If pixel is an edge, set pixel to the outline color
67
+ if (outlineShade != 1.0) {
68
+ tc = outlineCol;
69
+ }
70
+
71
+ tc.rgb *= tc.a;
72
+
73
+ return tc;
74
+ }
@@ -0,0 +1,22 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float amount;
4
+ uniform float angle;
5
+
6
+ float4 imageEval(float2 uv) {
7
+ uv.y = 1.0 - uv.y;
8
+ float2 coord = uv * imageSize;
9
+ return unpremul(image.eval(coord));
10
+ }
11
+
12
+ half4 main(float2 coord) {
13
+ float2 uv = coord / imageSize;
14
+ uv.y = 1.0 - uv.y;
15
+ float2 offset = amount * float2(sin(angle), cos(angle));
16
+ float2 greenAlpha = unpremul(image.eval(coord)).ga;
17
+ float2 redAlpha = imageEval(uv + offset).ra;
18
+ float2 blueAlpha = imageEval(uv - offset).ba;
19
+ float3 color = float3(redAlpha.x, greenAlpha.x, blueAlpha.x);
20
+ float avgAlpha = (redAlpha.y + greenAlpha.y + blueAlpha.y) / 3.0;
21
+ return float4(color * avgAlpha, avgAlpha);
22
+ }
@@ -0,0 +1,21 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float amount;
4
+ uniform float position;
5
+ half4 main(float2 coord) {
6
+ float weights[5];
7
+ weights[0] = 0.1633;
8
+ weights[1] = 0.1531;
9
+ weights[2] = 0.12245;
10
+ weights[3] = 0.0918;
11
+ weights[4] = 0.051;
12
+
13
+ float vv = amount * abs((1 - position) * imageSize.y - coord.y);
14
+ float4 sum = 0.1633 * image.eval(coord);
15
+ for (int i = 1; i <= 4; i++) {
16
+ float weight = weights[i];
17
+ sum += weight * image.eval(coord - float2(0, float(i) * vv));
18
+ sum += weight * image.eval(coord + float2(0, float(i) * vv));
19
+ }
20
+ return sum;
21
+ }
@@ -0,0 +1,25 @@
1
+ // #include //ly.img.cesdk/shader/common/ubq_noise
2
+ uniform shader image;
3
+ uniform float2 imageSize;
4
+ uniform float time;
5
+ uniform float distortion;
6
+ uniform float distortion2;
7
+ uniform float speed;
8
+ uniform float rollSpeed;
9
+
10
+ half4 main(float2 coord) {
11
+ float2 uv = coord / imageSize;
12
+ uv.y = 1.0 - uv.y;
13
+ float ty = time * speed * 17.346;
14
+ float yt = uv.y - ty;
15
+
16
+ // thick distortion
17
+ float offset = noise2d(float2(yt * 3.0, 0.0)) * 0.2;
18
+ offset = offset * distortion * offset * distortion * offset;
19
+ // fine distortion
20
+ offset += noise2d(float2(yt * 50.0, 0.0)) * distortion2 * 0.002;
21
+
22
+ uv = float2(fract(uv.x + offset), fract(uv.y - time * rollSpeed));
23
+ uv.y = 1.0 - uv.y;
24
+ return image.eval(uv * imageSize);
25
+ }
@@ -0,0 +1,12 @@
1
+ uniform shader image;
2
+ uniform float2 imageSize;
3
+ uniform float offset;
4
+ uniform float darkness;
5
+ half4 main(float2 coord) {
6
+ float4 texel = unpremul(image.eval(coord));
7
+ float2 uv = coord / imageSize;
8
+ uv = (uv - float2(0.5)) * float2(offset);
9
+ float4 color = float4(mix(texel.rgb, float3(1.0 - darkness), dot(uv, uv)), texel.a);
10
+ color.rgb *= color.a;
11
+ return color;
12
+ }
package/example.js ADDED
@@ -0,0 +1,31 @@
1
+ /* eslint-disable no-console */
2
+
3
+ // Minimal example for @cesdk/node-native. See
4
+ // https://img.ly/docs/cesdk/node-native/ for complete documentation.
5
+
6
+ const fs = require('fs/promises');
7
+ const CreativeEngine = require('./lib/index.js');
8
+
9
+ const license = process.env.CESDK_LICENSE;
10
+
11
+ CreativeEngine.init({ license }).then(async (engine) => {
12
+ try {
13
+ console.log('Creating scene');
14
+ const scene = engine.scene.create();
15
+ const page = engine.block.create('page');
16
+ engine.block.appendChild(scene, page);
17
+ engine.block.setWidth(page, 1920);
18
+ engine.block.setHeight(page, 1080);
19
+
20
+ console.log('Exporting page as PNG');
21
+ const pngBlob = await engine.block.export(page, 'image/png', {});
22
+ const outPath = './example-output.png';
23
+ await fs.writeFile(outPath, Buffer.from(await pngBlob.arrayBuffer()));
24
+ console.log(`Wrote ${outPath}`);
25
+ } catch (err) {
26
+ console.error(err);
27
+ process.exitCode = 1;
28
+ } finally {
29
+ engine.dispose();
30
+ }
31
+ });