compositor for 2d glitch effects
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

effects.pde 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. final static int SINE = 0; //add 0.25 to phase to get cos
  2. final static int SAWTOOTH = 1;
  3. final static int SAWTOOTHINVERSE = 2;
  4. final static int SQUARE = 3; //switches between -1 and 1, that's all
  5. final static int TRIANGLE = 4;
  6. final static int TAN = 5;
  7. final static int TANINVERSE = 6;
  8. final static int RAMP = 7; //line for half the sequence up to 1, then stay at 1 for the other half
  9. final static int RAMPINVERSE = 8; //line for half the sequence up to 1, then stay at 1 for the other half
  10. final static int RAMPUPDOWN = 9; //line up, stay, line down, stay
  11. final static int RANDOM = 10;
  12. final static int RANDOMIZE_ALL = 777; //not for wave-generation. meant for low frequency oscillator that calls a function after every beat
  13. /*
  14. ASDFPIXELSORT
  15. */
  16. class ASDFPIXELSORT extends Shader {
  17. ASDFPIXELSORT() {
  18. name = "fxASDFPixelSort";
  19. params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE}));
  20. params.add(new Param("mode", INTVAL, 0, 2, new int[]{RANDOM}));
  21. }
  22. int previousMode;
  23. void apply() {
  24. if (previousMode != int(params.get(1).value)) {
  25. if (params.get(1).value == 0) changeParam(0, new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE}));
  26. if (params.get(1).value == 1) changeParam(0, new Param("brightness", INTVAL, 0, 200, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE}));
  27. if (params.get(1).value == 2) changeParam(0, new Param("white", INTVAL, -15000000, -700000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE}));
  28. }
  29. previousMode = int(params.get(1).value);
  30. row = 0;
  31. column = 0;
  32. renderer.beginDraw();
  33. renderer.colorMode(RGB);
  34. colorMode(RGB);
  35. while (column < renderer.width-1) {
  36. renderer.loadPixels();
  37. sortColumn();
  38. column++;
  39. renderer.updatePixels();
  40. }
  41. while (row < renderer.height-1) {
  42. renderer.loadPixels();
  43. sortRow();
  44. row++;
  45. renderer.updatePixels();
  46. }
  47. renderer.endDraw();
  48. }
  49. int row = 0;
  50. int column = 0;
  51. void sortRow() {
  52. int x = 0;
  53. int y = row;
  54. int xend = 0;
  55. while (xend < renderer.width-1) {
  56. switch((int)params.get(1).value) {
  57. case 0:
  58. x = getFirstNotBlackX(x, y);
  59. xend = getNextBlackX(x, y);
  60. break;
  61. case 1:
  62. x = getFirstBrightX(x, y);
  63. xend = getNextDarkX(x, y);
  64. break;
  65. case 2:
  66. x = getFirstNotWhiteX(x, y);
  67. xend = getNextWhiteX(x, y);
  68. break;
  69. default:
  70. break;
  71. }
  72. if (x < 0) break;
  73. int sortLength = xend-x;
  74. color[] unsorted = new color[sortLength];
  75. color[] sorted = new color[sortLength];
  76. for (int i=0; i<sortLength; i++) {
  77. unsorted[i] = renderer.pixels[x + i + y * renderer.width];
  78. }
  79. sorted = sort(unsorted);
  80. for (int i=0; i<sortLength; i++) {
  81. renderer.pixels[x + i + y * renderer.width] = sorted[i];
  82. }
  83. x = xend+1;
  84. }
  85. }
  86. void sortColumn() {
  87. int x = column;
  88. int y = 0;
  89. int yend = 0;
  90. while (yend < renderer.height-1) {
  91. switch((int)params.get(1).value) {
  92. case 0:
  93. y = getFirstNotBlackY(x, y);
  94. yend = getNextBlackY(x, y);
  95. break;
  96. case 1:
  97. y = getFirstBrightY(x, y);
  98. yend = getNextDarkY(x, y);
  99. break;
  100. case 2:
  101. y = getFirstNotWhiteY(x, y);
  102. yend = getNextWhiteY(x, y);
  103. break;
  104. default:
  105. break;
  106. }
  107. if (y < 0) break;
  108. int sortLength = yend-y;
  109. color[] unsorted = new color[sortLength];
  110. color[] sorted = new color[sortLength];
  111. for (int i=0; i<sortLength; i++) {
  112. unsorted[i] = renderer.pixels[x + (y+i) * renderer.width];
  113. }
  114. sorted = sort(unsorted);
  115. for (int i=0; i<sortLength; i++) {
  116. renderer.pixels[x + (y+i) * renderer.width] = sorted[i];
  117. }
  118. y = yend+1;
  119. }
  120. }
  121. //BLACK
  122. int getFirstNotBlackX(int _x, int _y) {
  123. int x = _x;
  124. int y = _y;
  125. color c;
  126. while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
  127. x++;
  128. if (x >= renderer.width) return -1;
  129. }
  130. return x;
  131. }
  132. int getNextBlackX(int _x, int _y) {
  133. int x = _x+1;
  134. int y = _y;
  135. color c;
  136. while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
  137. x++;
  138. if (x >= renderer.width) return renderer.width-1;
  139. }
  140. return x-1;
  141. }
  142. //BRIGHTNESS
  143. int getFirstBrightX(int _x, int _y) {
  144. int x = _x;
  145. int y = _y;
  146. color c;
  147. while (brightness (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
  148. x++;
  149. if (x >= renderer.width) return -1;
  150. }
  151. return x;
  152. }
  153. int getNextDarkX(int _x, int _y) {
  154. int x = _x+1;
  155. int y = _y;
  156. color c;
  157. while (brightness (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
  158. x++;
  159. if (x >= renderer.width) return renderer.width-1;
  160. }
  161. return x-1;
  162. }
  163. //WHITE
  164. int getFirstNotWhiteX(int _x, int _y) {
  165. int x = _x;
  166. int y = _y;
  167. color c;
  168. while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
  169. x++;
  170. if (x >= renderer.width) return -1;
  171. }
  172. return x;
  173. }
  174. int getNextWhiteX(int _x, int _y) {
  175. int x = _x+1;
  176. int y = _y;
  177. color c;
  178. while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
  179. x++;
  180. if (x >= renderer.width) return renderer.width-1;
  181. }
  182. return x-1;
  183. }
  184. //BLACK
  185. int getFirstNotBlackY(int _x, int _y) {
  186. int x = _x;
  187. int y = _y;
  188. color c;
  189. if (y < renderer.height) {
  190. while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
  191. y++;
  192. if (y >= renderer.height) return -1;
  193. }
  194. }
  195. return y;
  196. }
  197. int getNextBlackY(int _x, int _y) {
  198. int x = _x;
  199. int y = _y+1;
  200. color c;
  201. if (y < renderer.height) {
  202. while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
  203. y++;
  204. if (y >= renderer.height) return renderer.height-1;
  205. }
  206. }
  207. return y-1;
  208. }
  209. //BRIGHTNESS
  210. int getFirstBrightY(int _x, int _y) {
  211. int x = _x;
  212. int y = _y;
  213. color c;
  214. if (y < renderer.height) {
  215. while (brightness (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
  216. y++;
  217. if (y >= renderer.height) return -1;
  218. }
  219. }
  220. return y;
  221. }
  222. int getNextDarkY(int _x, int _y) {
  223. int x = _x;
  224. int y = _y+1;
  225. color c;
  226. if (y < renderer.height) {
  227. while (brightness (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
  228. y++;
  229. if (y >= renderer.height) return renderer.height-1;
  230. }
  231. }
  232. return y-1;
  233. }
  234. //WHITE
  235. int getFirstNotWhiteY(int _x, int _y) {
  236. int x = _x;
  237. int y = _y;
  238. color c;
  239. if (y < renderer.height) {
  240. while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
  241. y++;
  242. if (y >= renderer.height) return -1;
  243. }
  244. }
  245. return y;
  246. }
  247. int getNextWhiteY(int _x, int _y) {
  248. int x = _x;
  249. int y = _y+1;
  250. color c;
  251. if (y < renderer.height) {
  252. while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
  253. y++;
  254. if (y >= renderer.height) return renderer.height-1;
  255. }
  256. }
  257. return y-1;
  258. }
  259. }
  260. /*
  261. DISTORTER
  262. */
  263. class DISTORTER extends Shader {
  264. PImage buffer;
  265. int[][] distort = new int[2][512];
  266. final static float tick = 1.0/512.0;
  267. final int[] blends = {
  268. ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN
  269. };
  270. // ALL Channels, Nxxx stand for negative (255-value)
  271. // channels to work with
  272. final static int RED = 0;
  273. final static int GREEN = 1;
  274. final static int BLUE = 2;
  275. final static int HUE = 3;
  276. final static int SATURATION = 4;
  277. final static int BRIGHTNESS = 5;
  278. final static int NRED = 6;
  279. final static int NGREEN = 7;
  280. final static int NBLUE = 8;
  281. final static int NHUE = 9;
  282. final static int NSATURATION = 10;
  283. final static int NBRIGHTNESS = 11;
  284. DISTORTER() {
  285. name = "fxDistorter";
  286. /*
  287. //params.add(new Param ("shifthue", 1)); //boolean shift_hue
  288. params.add(new Param("hueshift", 0, 1)); //float shift_amt
  289. params.add(new Param("scalex", 0.01, 1)); //float scalex
  290. params.add(new Param("scaley", 0.01, 1)); //float scaley
  291. //params.add(new Param ("blend", 1)); //boolean do_blend
  292. params.add(new Param ("blendmode", blends.length)); //int blend_mode
  293. params.add(new Param("channel", 12));*/
  294. buffer = createImage(renderer.width, renderer.height, ARGB);
  295. // prepare distortion pattern
  296. for (int i=0; i<512; i++) {
  297. distort[0][i] = (int)random(-128, 128);
  298. distort[1][i] = (int)random(-128, 128);
  299. }
  300. }
  301. void apply() {
  302. buffer = renderer.get();
  303. buffer.resize(renderer.width, renderer.height);
  304. float neww = map(params.get(1).value, 0, 1, 1, buffer.width/4);
  305. float newh = map(params.get(2).value, 0, 1, 1, buffer.height/4);
  306. float totalnum = neww+newh;
  307. float times = (totalnum/floor(totalnum/neww));
  308. float offx = (totalnum%neww)/times;
  309. float ratiox = neww/buffer.width;
  310. renderer.beginDraw();
  311. renderer.noStroke();
  312. for (int y=0; y<buffer.height; y++) {
  313. float yy = y/(float)buffer.height;
  314. for (int x=0; x<buffer.width; x++) {
  315. float xx = x/(float)buffer.width;
  316. float offy = floor(newh*yy);
  317. float fx = xx*ratiox+offx*offy;
  318. float shift = fx%1.0;
  319. float st = shift/tick;
  320. int no1 = floor(st)%512;
  321. int no2 = ceil(st)%512;
  322. float l = st-(float)no1;
  323. float cx = lerp(distort[0][no1], distort[0][no2], l);
  324. float cy = lerp(distort[1][no1], distort[1][no2], l);
  325. float rx =getChannel(buffer.get(x, y), (int)params.get(4).value);
  326. int sx = (int)((buffer.width+x+cx*rx*params.get(1).value*0.1)%buffer.width);
  327. int sy = (int)((buffer.height+y+cy*params.get(0).value)%buffer.height);
  328. color c=buffer.get(sx, sy);
  329. //if (boolean((int)(params.get(0).value))) {
  330. colorMode(HSB, 255);
  331. c = color((hue(c)+params.get(0).value*255*noise(newh+y))%255.0, constrain(saturation(c)*1.2, 0, 255), constrain(brightness(c), 0, 255));
  332. colorMode(RGB, 255);
  333. //}
  334. //renderer.fill(lerpColor(c,buffer.get(x,y),0.2));
  335. renderer.fill(c);
  336. renderer.rect(x, y, 1, 1);
  337. }
  338. }
  339. //if (boolean((int)(params.get(4).value)))
  340. renderer.blend(buffer, 0, 0, buffer.width, buffer.height, 0, 0, renderer.width, renderer.height, (int)params.get(3).value);
  341. colorMode(RGB);
  342. renderer.endDraw();
  343. }
  344. float getChannel(color c, int channel) {
  345. int ch = channel>5?channel-6:channel;
  346. float cc;
  347. switch(ch) {
  348. case RED:
  349. cc = red(c);
  350. break;
  351. case GREEN:
  352. cc = green(c);
  353. break;
  354. case BLUE:
  355. cc = blue(c);
  356. break;
  357. case HUE:
  358. cc = hue(c);
  359. break;
  360. case SATURATION:
  361. cc = saturation(c);
  362. break;
  363. default:
  364. cc= brightness(c);
  365. break;
  366. }
  367. return channel>5?255-cc:cc;
  368. }
  369. }