compositor for 2d shader
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DISTORTER.pde 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. class DISTORTER extends Shader {
  2. PImage buffer;
  3. int[][] distort = new int[2][512];
  4. final static float tick = 1.0/512.0;
  5. final int[] blends = {
  6. ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN
  7. };
  8. // ALL Channels, Nxxx stand for negative (255-value)
  9. // channels to work with
  10. final static int RED = 0;
  11. final static int GREEN = 1;
  12. final static int BLUE = 2;
  13. final static int HUE = 3;
  14. final static int SATURATION = 4;
  15. final static int BRIGHTNESS = 5;
  16. final static int NRED = 6;
  17. final static int NGREEN = 7;
  18. final static int NBLUE = 8;
  19. final static int NHUE = 9;
  20. final static int NSATURATION = 10;
  21. final static int NBRIGHTNESS = 11;
  22. DISTORTER() {
  23. name = "fxDistorter";
  24. /*
  25. //params.add(new Param ("shifthue", 1)); //boolean shift_hue
  26. params.add(new Param("hueshift", 0, 1)); //float shift_amt
  27. params.add(new Param("scalex", 0.01, 1)); //float scalex
  28. params.add(new Param("scaley", 0.01, 1)); //float scaley
  29. //params.add(new Param ("blend", 1)); //boolean do_blend
  30. params.add(new Param ("blendmode", blends.length)); //int blend_mode
  31. params.add(new Param("channel", 12));*/
  32. buffer = createImage(renderer.width, renderer.height, ARGB);
  33. // prepare distortion pattern
  34. for (int i=0; i<512; i++) {
  35. distort[0][i] = (int)random(-128, 128);
  36. distort[1][i] = (int)random(-128, 128);
  37. }
  38. }
  39. float inc1, inc2;
  40. void animate() {
  41. inc1+=.03;
  42. inc2+=.04;
  43. params.get(1).setValue((sin(inc1)+1)/2);
  44. params.get(2).setValue((sin(inc2)+1)/2);
  45. if (random(1) > .99) {
  46. for (int i = 0; i < params.size(); i++)
  47. params.get(i).randomize();
  48. }
  49. }
  50. void apply() {
  51. buffer = renderer.get();
  52. buffer.resize(renderer.width, renderer.height);
  53. float neww = map(params.get(1).value, 0, 1, 1, buffer.width/4);
  54. float newh = map(params.get(2).value, 0, 1, 1, buffer.height/4);
  55. float totalnum = neww+newh;
  56. float times = (totalnum/floor(totalnum/neww));
  57. float offx = (totalnum%neww)/times;
  58. float ratiox = neww/buffer.width;
  59. renderer.beginDraw();
  60. renderer.noStroke();
  61. for (int y=0; y<buffer.height; y++) {
  62. float yy = y/(float)buffer.height;
  63. for (int x=0; x<buffer.width; x++) {
  64. float xx = x/(float)buffer.width;
  65. float offy = floor(newh*yy);
  66. float fx = xx*ratiox+offx*offy;
  67. float shift = fx%1.0;
  68. float st = shift/tick;
  69. int no1 = floor(st)%512;
  70. int no2 = ceil(st)%512;
  71. float l = st-(float)no1;
  72. float cx = lerp(distort[0][no1], distort[0][no2], l);
  73. float cy = lerp(distort[1][no1], distort[1][no2], l);
  74. float rx =getChannel(buffer.get(x, y), (int)params.get(4).value);
  75. int sx = (int)((buffer.width+x+cx*rx*params.get(1).value*0.1)%buffer.width);
  76. int sy = (int)((buffer.height+y+cy*params.get(0).value)%buffer.height);
  77. color c=buffer.get(sx, sy);
  78. //if (boolean((int)(params.get(0).value))) {
  79. colorMode(HSB, 255);
  80. 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));
  81. colorMode(RGB, 255);
  82. //}
  83. //renderer.fill(lerpColor(c,buffer.get(x,y),0.2));
  84. renderer.fill(c);
  85. renderer.rect(x, y, 1, 1);
  86. }
  87. }
  88. //if (boolean((int)(params.get(4).value)))
  89. renderer.blend(buffer, 0, 0, buffer.width, buffer.height, 0, 0, renderer.width, renderer.height, (int)params.get(3).value);
  90. colorMode(RGB);
  91. renderer.endDraw();
  92. }
  93. float getChannel(color c, int channel) {
  94. int ch = channel>5?channel-6:channel;
  95. float cc;
  96. switch(ch) {
  97. case RED:
  98. cc = red(c);
  99. break;
  100. case GREEN:
  101. cc = green(c);
  102. break;
  103. case BLUE:
  104. cc = blue(c);
  105. break;
  106. case HUE:
  107. cc = hue(c);
  108. break;
  109. case SATURATION:
  110. cc = saturation(c);
  111. break;
  112. default:
  113. cc= brightness(c);
  114. break;
  115. }
  116. return channel>5?255-cc:cc;
  117. }
  118. }