Guest User

Untitled

a guest
Feb 13th, 2026
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 KB | None | 0 0
  1. #bind layer src
  2. #bind layer !&dst
  3. #bind parm pixelSize float val=16.0
  4. #bind parm radiusScale float val=0.8
  5. #bind parm gooeyness float val=0.5
  6. #bind parm dotAspect float val=1.0
  7. #bind parm cStrength float val=1.0
  8. #bind parm mStrength float val=1.0
  9. #bind parm yStrength float val=1.0
  10. #bind parm kStrength float val=1.0
  11.  
  12. // Helper: RGB to CMYK
  13. float4 RGBtoCMYK(float3 rgb) {
  14. float k = 1.0f - max(rgb.r, max(rgb.g, rgb.b));
  15. float invK = 1.0f - k;
  16. float3 cmy = (float3)(0.0f);
  17. if (invK != 0.0f) {
  18. cmy.x = (1.0f - rgb.r - k) / invK;
  19. cmy.y = (1.0f - rgb.g - k) / invK;
  20. cmy.z = (1.0f - rgb.b - k) / invK;
  21. }
  22. return (float4)(cmy, k);
  23. }
  24.  
  25. // Helper: 2D Rotation
  26. float2 rotate_vec(float2 p, float angle) {
  27. float s = sin(angle);
  28. float c = cos(angle);
  29. return (float2)(p.x * c - p.y * s, p.x * s + p.y * c);
  30. }
  31.  
  32. // Helper: Smooth Min (Gooeyness)
  33. float smin_func(float a, float b, float k) {
  34. float h = clamp(0.5f + 0.5f * (b - a) / k, 0.0f, 1.0f);
  35. return mix(b, a, h) - k * h * (1.0f - h);
  36. }
  37.  
  38. @KERNEL
  39. {
  40. float2 res = (float2)(@xres, @yres);
  41. float screen_aspect = res.x / res.y;
  42.  
  43. // Normalized UVs
  44. float2 uv = @P;
  45.  
  46. // Scale for grid (how many dots fit vertically)
  47. float gridScale = res.y / @pixelSize;
  48. float rScale = @radiusScale;
  49. float gooey = @gooeyness / gridScale;
  50.  
  51. float angles[4] = {0.2618f, 1.3090f, 0.0000f, 0.7854f}; // C, M, Y, K
  52. float dots[4] = {0.0f, 0.0f, 0.0f, 0.0f};
  53.  
  54. for(int c=0; c<4; c++) {
  55. float angle = angles[c];
  56.  
  57. // Use a simple coordinate space where Y is 0..1 and X is 0..ScreenAspect
  58. float2 p_space = (float2)(uv.x * screen_aspect, uv.y);
  59. float2 center_space = (float2)(0.5f * screen_aspect, 0.5f);
  60.  
  61. // Rotate around center
  62. float2 rotatedP = rotate_vec(p_space - center_space, angle) + center_space;
  63.  
  64. float2 gridCoord = rotatedP * gridScale;
  65. float2 baseCellIndex = floor(gridCoord);
  66.  
  67. float min_dist = 1000.0f;
  68.  
  69. for (int dx = -1; dx <= 1; dx++) {
  70. for (int dy = -1; dy <= 1; dy++) {
  71. float2 cellIndex = baseCellIndex + (float2)(dx, dy);
  72. float2 cellCenterGrid = cellIndex + 0.5f;
  73. float2 cellCenterSpace = cellCenterGrid / gridScale;
  74.  
  75. // Inverse rotate to find where to sample luma in UV space
  76. float2 rel_center = cellCenterSpace - center_space;
  77. float2 sampleP = rotate_vec(rel_center, -angle) + center_space;
  78. float2 sampleUv = (float2)(sampleP.x / screen_aspect, sampleP.y);
  79.  
  80. // Sample luma at center
  81. float4 sampleClr = @src.imageSample(sampleUv);
  82. float4 cmyk = RGBtoCMYK(sampleClr.xyz);
  83.  
  84. float coverage = (c == 0) ? cmyk.x : (c == 1) ? cmyk.y : (c == 2) ? cmyk.z : cmyk.w;
  85.  
  86. // Radius
  87. float r = (0.5f * rScale * sqrt(clamp(coverage, 0.0f, 1.0f))) / gridScale;
  88.  
  89. // Distance with Aspect Control
  90. float2 diff = rotatedP - cellCenterSpace;
  91. diff.x *= @dotAspect; // Manual squash/stretch
  92. float d = length(diff);
  93.  
  94. float dist = d - r;
  95. if(gooey > 0.00001f)
  96. min_dist = smin_func(min_dist, dist, gooey);
  97. else
  98. min_dist = min(min_dist, dist);
  99. }
  100. }
  101. float pixel_w = 1.0f / res.y;
  102. dots[c] = 1.0f - smoothstep(-pixel_w, pixel_w, min_dist);
  103. }
  104.  
  105. float3 outColor = (float3)(1.0f);
  106. outColor.r *= (1.0f - @cStrength * dots[0]);
  107. outColor.g *= (1.0f - @mStrength * dots[1]);
  108. outColor.b *= (1.0f - @yStrength * dots[2]);
  109. outColor *= (1.0f - @kStrength * dots[3]);
  110.  
  111. @dst.set((float4)(outColor, 1.0f));
  112. }
  113.  
Advertisement
Add Comment
Please, Sign In to add comment