|
| 1 | +filters4ruby-processing |
| 2 | +================== |
| 3 | +A port of [Filters4Processing][] to ruby-processing |
| 4 | +A growing collection of pixel shaders ported to Processing to be used with the `filter()` function. Most of these shaders come from the excellent [Shadertoy](https://www.shadertoy.com) by Iñigo Quilez. |
| 5 | + |
| 6 | +### To run shader sketches |
| 7 | +```bash |
| 8 | +rp5 --nojruby run/watch sketch.rb # Need to use jruby-complete |
| 9 | +``` |
| 10 | +or in `.rp5rc` add following (if pure yaml) |
| 11 | +```yaml |
| 12 | +JRUBY: 'false' |
| 13 | +``` |
| 14 | +or if you used our configRP5.pde tool (emits json) |
| 15 | +```json |
| 16 | +{ |
| 17 | +"JRUBY": "false", |
| 18 | +.... |
| 19 | +} |
| 20 | +``` |
| 21 | +to avoid need for `--nojruby` flag, NB: delete line, or change back to 'true' when you need to use gems.... |
| 22 | + |
| 23 | +This is a java/jruby permission thing, and beyond our control |
| 24 | +## Filters |
| 25 | + |
| 26 | +### Barrel Blur Chroma |
| 27 | + |
| 28 | + |
| 29 | +### Barrel & Pincushion |
| 30 | + |
| 31 | + |
| 32 | +### Bicubic Filter |
| 33 | + |
| 34 | + |
| 35 | +### Bilateral Filter (denoise) |
| 36 | + |
| 37 | + |
| 38 | +### Contrast, Saturation, Brightness |
| 39 | + |
| 40 | + |
| 41 | +### Dithering |
| 42 | + |
| 43 | + |
| 44 | +### Edge filter |
| 45 | + |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +This is a minimal example showing how to import shader file in ruby-processing and use it as a filter. |
| 50 | + |
| 51 | +*Note: Some shaders require additional uniforms. For details, refer to the example sketches included.* |
| 52 | + |
| 53 | +```ruby |
| 54 | +attr_reader :my_filter, :my_image |
| 55 | + |
| 56 | +def setup |
| 57 | + size(512, 512, P2D) |
| 58 | + # import an image object |
| 59 | + @my_image = load_image('texture.jpg') |
| 60 | + # load a shader object |
| 61 | + @my_filter = load_shader('shader.glsl') |
| 62 | + # pass the window size to the shader |
| 63 | + my_filter.set('sketchSize', width.to_f, height.to_f) |
| 64 | +end |
| 65 | + |
| 66 | +def draw |
| 67 | + background(0) |
| 68 | + # Draw the image on the scene |
| 69 | + image(my_image, 0, 0) |
| 70 | + # Applies the shader to everything that has already been drawn |
| 71 | + return if mouse_pressed? |
| 72 | + filter(my_filter) |
| 73 | +end |
| 74 | +``` |
| 75 | + |
| 76 | +## Notes about porting filters from Shadertoy |
| 77 | + |
| 78 | +Shadertoy and Processing both have their own quirks when it comes to shader programming. We need to make some changes in order to make Shadertoy code work with Processing/ruby-processing. |
| 79 | + |
| 80 | +Replace: |
| 81 | +`void mainImage( out vec4 fragColor, in vec2 fragCoord )` -> `void main( void )` |
| 82 | + |
| 83 | +Replace all: |
| 84 | +* `iChannel0` -> `texture` |
| 85 | +* `fragCoord` -> `gl_FragCoord` |
| 86 | +* `fragColor` -> `gl_FragColor` |
| 87 | + |
| 88 | +There is more to it than this but these tips should cover most basic filters. |
| 89 | + |
| 90 | +Now go dig for some [shaders](https://www.shadertoy.com/results?query=filter) and help us extend the library of filters available for Processing/ruby-processing! |
| 91 | + |
| 92 | +*Note: It is possible to port other types of shaders, but this repository focuses on filters.* |
| 93 | + |
| 94 | +## Acknowledgments |
| 95 | +Port to processing by Raphaël de Courville. |
| 96 | +Thanks to all the Shadertoy contributors for their hard work. This collection wouldn't exist without them. Thanks to Andres Colubri for his work on the Processing Shader API. |
| 97 | + |
| 98 | +## License |
| 99 | +All shaders from Shadertoy belong to there respective authors. Unless otherwise specified in the shader file, they are licensed under Creative Commons ([CC BY-NC-SA 3.0](http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_US)) |
| 100 | + |
| 101 | +[Filters4Processing]:https://github.com/SableRaf/Filters4Processing |
0 commit comments