├── processingShaderHelloWorld ├── data │ ├── screenshot.png │ └── myShader.frag └── processingShaderHelloWorld.pde └── README.md /processingShaderHelloWorld/data/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golanlevin/ProcessingShader/HEAD/processingShaderHelloWorld/data/screenshot.png -------------------------------------------------------------------------------- /processingShaderHelloWorld/data/myShader.frag: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | #define PROCESSING_COLOR_SHADER 6 | 7 | uniform vec2 u_resolution; 8 | uniform vec2 u_mouse; 9 | uniform bool u_button; 10 | uniform float u_time; 11 | 12 | void main() { 13 | vec2 uv = gl_FragCoord.st/u_resolution; 14 | 15 | float r = (u_button) ? uv.x : 1.0-uv.x; 16 | float g = u_mouse.x / u_resolution.x; 17 | float b = 0.5 + 0.5 * sin(u_time + 30.0*uv.y); 18 | 19 | gl_FragColor = vec4(r,g,b, 1.0); 20 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | "Hello World" example for GLSL shaders in Processing v.3.4. 2 | 3 | Golan Levin, October 2018 4 | 5 | -- 6 | 7 | More resources for programming GLSL shaders in Processing: 8 | * [The Book of Shaders, by Patricio Gonzalez Vivo and Jen Lowe](https://thebookofshaders.com/) 9 | * [Processing Shader Tutorial, by Andres Colubri](https://processing.org/tutorials/pshader/) 10 | * [Gene Kogan, Processing Shader Examples](https://github.com/genekogan/Processing-Shader-Examples/) 11 | * [Florian Bruggisser, Processing PostFX shaders](https://github.com/cansik/processing-postfx) 12 | 13 | ![screenshot](processingShaderHelloWorld/data/screenshot.png) 14 | -------------------------------------------------------------------------------- /processingShaderHelloWorld/processingShaderHelloWorld.pde: -------------------------------------------------------------------------------- 1 | // Simple "Hello World" example for shaders in Processing v.3.4. 2 | // Golan Levin, October 2018 3 | 4 | PShader myShader; 5 | 6 | void setup() { 7 | size(540, 720, OPENGL); 8 | myShader = loadShader("myShader.frag"); 9 | } 10 | 11 | void draw() { 12 | background(0); 13 | 14 | myShader.set("u_resolution", float(width), float(height)); 15 | myShader.set("u_mouse", float(mouseX), float(mouseY)); 16 | myShader.set("u_time", ((float)millis()/1000.0)); 17 | myShader.set("u_button", mousePressed); 18 | 19 | noStroke(); 20 | shader(myShader); 21 | rect(0, 0, width, height); 22 | } 23 | 24 | 25 | /* 26 | // Here's what the shader code should look like. 27 | // It should be stored in the file: data/myShader.frag 28 | 29 | #ifdef GL_ES 30 | precision mediump float; 31 | #endif 32 | 33 | #define PROCESSING_COLOR_SHADER 34 | 35 | uniform vec2 u_resolution; 36 | uniform vec2 u_mouse; 37 | uniform bool u_button; 38 | uniform float u_time; 39 | 40 | void main() { 41 | vec2 uv = gl_FragCoord.st/u_resolution; 42 | 43 | float r = (u_button) ? uv.x : 1.0-uv.x; 44 | float g = u_mouse.x / u_resolution.x; 45 | float b = 0.5 + 0.5 * sin(u_time + 30.0*uv.y); 46 | 47 | gl_FragColor = vec4(r,g,b, 1.0); 48 | } 49 | */ 50 | 51 | 52 | // More resources for programming GLSL shaders in Processing: 53 | // The Book of Shaders, by Patricio Gonzalez Vivo and Jen Lowe 54 | // https://thebookofshaders.com/ 55 | // Shaders (Processing Shader Tutorial), by Andres Colubri 56 | // https://processing.org/tutorials/pshader/ 57 | // Gene Kogan, Processing Shader Examples: 58 | // https://github.com/genekogan/Processing-Shader-Examples/ 59 | // Florian Bruggisser, Processing PostFX shaders 60 | // https://github.com/cansik/processing-postfx 61 | --------------------------------------------------------------------------------