Initial Commit
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Blur Filter
|
||||
*
|
||||
* Change the default shader to apply a simple, custom blur filter.
|
||||
*
|
||||
* Press the mouse to switch between the custom and default shader.
|
||||
*/
|
||||
|
||||
PShader blur;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
blur = loadShader("blur.glsl");
|
||||
stroke(255, 0, 0);
|
||||
rectMode(CENTER);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
filter(blur);
|
||||
rect(mouseX, mouseY, 150, 150);
|
||||
ellipse(mouseX, mouseY, 100, 100);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
#define PROCESSING_TEXTURE_SHADER
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform vec2 texOffset;
|
||||
|
||||
varying vec4 vertColor;
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
void main(void) {
|
||||
// Grouping texcoord variables in order to make it work in the GMA 950. See post #13
|
||||
// in this thread:
|
||||
// http://www.idevgames.com/forums/thread-3467.html
|
||||
vec2 tc0 = vertTexCoord.st + vec2(-texOffset.s, -texOffset.t);
|
||||
vec2 tc1 = vertTexCoord.st + vec2( 0.0, -texOffset.t);
|
||||
vec2 tc2 = vertTexCoord.st + vec2(+texOffset.s, -texOffset.t);
|
||||
vec2 tc3 = vertTexCoord.st + vec2(-texOffset.s, 0.0);
|
||||
vec2 tc4 = vertTexCoord.st + vec2( 0.0, 0.0);
|
||||
vec2 tc5 = vertTexCoord.st + vec2(+texOffset.s, 0.0);
|
||||
vec2 tc6 = vertTexCoord.st + vec2(-texOffset.s, +texOffset.t);
|
||||
vec2 tc7 = vertTexCoord.st + vec2( 0.0, +texOffset.t);
|
||||
vec2 tc8 = vertTexCoord.st + vec2(+texOffset.s, +texOffset.t);
|
||||
|
||||
vec4 col0 = texture2D(texture, tc0);
|
||||
vec4 col1 = texture2D(texture, tc1);
|
||||
vec4 col2 = texture2D(texture, tc2);
|
||||
vec4 col3 = texture2D(texture, tc3);
|
||||
vec4 col4 = texture2D(texture, tc4);
|
||||
vec4 col5 = texture2D(texture, tc5);
|
||||
vec4 col6 = texture2D(texture, tc6);
|
||||
vec4 col7 = texture2D(texture, tc7);
|
||||
vec4 col8 = texture2D(texture, tc8);
|
||||
|
||||
vec4 sum = (1.0 * col0 + 2.0 * col1 + 1.0 * col2 +
|
||||
2.0 * col3 + 4.0 * col4 + 2.0 * col5 +
|
||||
1.0 * col6 + 2.0 * col7 + 1.0 * col8) / 16.0;
|
||||
gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
// GLSL version of Conway's game of life, ported from GLSL sandbox:
|
||||
// http://glsl.heroku.com/e#207.3
|
||||
// Exemplifies the use of the ppixels uniform in the shader, that gives
|
||||
// access to the pixels of the previous frame.
|
||||
PShader conway;
|
||||
PGraphics pg;
|
||||
|
||||
void setup() {
|
||||
size(400, 400, P3D);
|
||||
pg = createGraphics(400, 400, P2D);
|
||||
pg.noSmooth();
|
||||
conway = loadShader("conway.glsl");
|
||||
conway.set("resolution", float(pg.width), float(pg.height));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
conway.set("time", millis()/1000.0);
|
||||
float x = map(mouseX, 0, width, 0, 1);
|
||||
float y = map(mouseY, 0, height, 1, 0);
|
||||
conway.set("mouse", x, y);
|
||||
pg.beginDraw();
|
||||
pg.background(0);
|
||||
pg.shader(conway);
|
||||
pg.rect(0, 0, pg.width, pg.height);
|
||||
pg.endDraw();
|
||||
image(pg, 0, 0, width, height);
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
// Conway's game of life
|
||||
|
||||
#ifdef GL_ES
|
||||
precision highp float;
|
||||
#endif
|
||||
|
||||
#define PROCESSING_COLOR_SHADER
|
||||
|
||||
uniform float time;
|
||||
uniform vec2 mouse;
|
||||
uniform vec2 resolution;
|
||||
uniform sampler2D ppixels;
|
||||
|
||||
vec4 live = vec4(0.5,1.0,0.7,1.);
|
||||
vec4 dead = vec4(0.,0.,0.,1.);
|
||||
vec4 blue = vec4(0.,0.,1.,1.);
|
||||
|
||||
void main( void ) {
|
||||
vec2 position = ( gl_FragCoord.xy / resolution.xy );
|
||||
vec2 pixel = 1./resolution;
|
||||
|
||||
if (length(position-mouse) < 0.01) {
|
||||
float rnd1 = mod(fract(sin(dot(position + time * 0.001, vec2(14.9898,78.233))) * 43758.5453), 1.0);
|
||||
if (rnd1 > 0.5) {
|
||||
gl_FragColor = live;
|
||||
} else {
|
||||
gl_FragColor = blue;
|
||||
}
|
||||
} else {
|
||||
float sum = 0.;
|
||||
sum += texture2D(ppixels, position + pixel * vec2(-1., -1.)).g;
|
||||
sum += texture2D(ppixels, position + pixel * vec2(-1., 0.)).g;
|
||||
sum += texture2D(ppixels, position + pixel * vec2(-1., 1.)).g;
|
||||
sum += texture2D(ppixels, position + pixel * vec2(1., -1.)).g;
|
||||
sum += texture2D(ppixels, position + pixel * vec2(1., 0.)).g;
|
||||
sum += texture2D(ppixels, position + pixel * vec2(1., 1.)).g;
|
||||
sum += texture2D(ppixels, position + pixel * vec2(0., -1.)).g;
|
||||
sum += texture2D(ppixels, position + pixel * vec2(0., 1.)).g;
|
||||
vec4 me = texture2D(ppixels, position);
|
||||
|
||||
if (me.g <= 0.1) {
|
||||
if ((sum >= 2.9) && (sum <= 3.1)) {
|
||||
gl_FragColor = live;
|
||||
} else if (me.b > 0.004) {
|
||||
gl_FragColor = vec4(0., 0., max(me.b - 0.004, 0.25), 0.);
|
||||
} else {
|
||||
gl_FragColor = dead;
|
||||
}
|
||||
} else {
|
||||
if ((sum >= 1.9) && (sum <= 3.1)) {
|
||||
gl_FragColor = live;
|
||||
} else {
|
||||
gl_FragColor = blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* Custom Blend
|
||||
*
|
||||
* The OpenGL-based renderers (P2D and P3D) only support some of the
|
||||
* blending modes available in the default renderer. The reason for this
|
||||
* is that the blend equations in OpenGL allow for combinations of the
|
||||
* form dest_factor * dest_color + src_factor * src_color of the source and
|
||||
* destination colors (see this page http://www.opengl.org/wiki/Blending
|
||||
* for an extensive discussion of blending in OpenGL).
|
||||
* Complex blending modes typically available in photo editing tools,
|
||||
* like hard light or dodge, cannot be modeled with those equations.
|
||||
* However, we can implement virtually any blending math directly in the
|
||||
* fragment shader.
|
||||
*
|
||||
* This example shows how custom blend shaders can be loaded and used in
|
||||
* Processing.
|
||||
* For detailed information on how to implement Photoshop-like blending modes,
|
||||
* check the following pages (a bit old but still useful):
|
||||
* http://www.pegtop.net/delphi/articles/blendmodes/index.htm
|
||||
* http://mouaif.wordpress.com/2009/01/05/photoshop-math-with-glsl-shaders/
|
||||
*
|
||||
*/
|
||||
|
||||
PImage destImage;
|
||||
PImage srcImage;
|
||||
PShader dodge;
|
||||
PShader burn;
|
||||
PShader overlay;
|
||||
PShader difference;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
destImage = loadImage("leaves.jpg");
|
||||
srcImage = loadImage("moonwalk.jpg");
|
||||
|
||||
initShaders();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
shader(dodge);
|
||||
drawOutput(0, 0, width/2, height/2);
|
||||
shader(burn);
|
||||
drawOutput(width/2, 0, width/2, height/2);
|
||||
shader(overlay);
|
||||
drawOutput(0, height/2, width/2, height/2);
|
||||
shader(difference);
|
||||
drawOutput(width/2, height/2, width/2, height/2);
|
||||
|
||||
noLoop();
|
||||
}
|
||||
|
||||
void initShaders() {
|
||||
dodge = loadShader("dodge.glsl");
|
||||
burn = loadShader("burn.glsl");
|
||||
overlay = loadShader("overlay.glsl");
|
||||
difference = loadShader("difference.glsl");
|
||||
|
||||
// The names destination and source come from the OpenGL terminology:
|
||||
// destination from the image already in the framebuffer, or "base layer",
|
||||
// and source for the image that will be blended into the framebuffer, or
|
||||
// "blend layer":
|
||||
dodge.set("destSampler", destImage);
|
||||
dodge.set("srcSampler", srcImage);
|
||||
burn.set("destSampler", destImage);
|
||||
burn.set("srcSampler", srcImage);
|
||||
overlay.set("destSampler", destImage);
|
||||
overlay.set("srcSampler", srcImage);
|
||||
difference.set("destSampler", destImage);
|
||||
difference.set("srcSampler", srcImage);
|
||||
|
||||
// We set the sizes of de st and src images, and the rectangular areas
|
||||
// from the images that we will use for blending:
|
||||
dodge.set("destSize", 640, 360);
|
||||
dodge.set("destRect", 100, 50, 200, 200);
|
||||
burn.set("destSize", 640, 360);
|
||||
burn.set("destRect", 100, 50, 200, 200);
|
||||
overlay.set("destSize", 640, 360);
|
||||
overlay.set("destRect", 100, 50, 200, 200);
|
||||
difference.set("destSize", 640, 360);
|
||||
difference.set("destRect", 100, 50, 200, 200);
|
||||
|
||||
dodge.set("srcSize", 640, 360);
|
||||
dodge.set("srcRect", 0, 0, 640, 360);
|
||||
burn.set("srcSize", 640, 360);
|
||||
burn.set("srcRect", 0, 0, 640, 360);
|
||||
overlay.set("srcSize", 640, 360);
|
||||
overlay.set("srcRect", 0, 0, 640, 360);
|
||||
difference.set("srcSize", 640, 360);
|
||||
difference.set("srcRect", 0, 0, 640, 360);
|
||||
}
|
||||
|
||||
void drawOutput(float x, float y, float w, float h) {
|
||||
pushMatrix();
|
||||
translate(x, y);
|
||||
noStroke();
|
||||
beginShape(QUAD);
|
||||
// Although we are not associating a texture to
|
||||
// this shape, the uv coordinates will be stored
|
||||
// anyways so they can be used in the fragment
|
||||
// shader to access the destination and source
|
||||
// images.
|
||||
vertex(0, 0, 0, 0);
|
||||
vertex(w, 0, 1, 0);
|
||||
vertex(w, h, 1, 1);
|
||||
vertex(0, h, 0, 1);
|
||||
endShape();
|
||||
popMatrix();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
uniform sampler2D destSampler;
|
||||
uniform sampler2D srcSampler;
|
||||
|
||||
uniform ivec2 destSize;
|
||||
uniform ivec4 destRect;
|
||||
|
||||
uniform ivec2 srcSize;
|
||||
uniform ivec4 srcRect;
|
||||
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
void main() {
|
||||
vec2 st = vertTexCoord.st;
|
||||
|
||||
vec2 dest = vec2(destRect.xy) / vec2(destSize) + st * vec2(destRect.zw) / vec2(destSize);
|
||||
vec2 src = vec2(srcRect.xy) / vec2(srcSize) + st * vec2(srcRect.zw) / vec2(srcSize);
|
||||
|
||||
vec3 destColor = texture2D(destSampler, dest).rgb;
|
||||
vec3 srcColor = texture2D(srcSampler, src).rgb;
|
||||
|
||||
gl_FragColor = vec4(1.0 - (1.0 - destColor) / srcColor, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
uniform sampler2D destSampler;
|
||||
uniform sampler2D srcSampler;
|
||||
|
||||
uniform ivec2 destSize;
|
||||
uniform ivec4 destRect;
|
||||
|
||||
uniform ivec2 srcSize;
|
||||
uniform ivec4 srcRect;
|
||||
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
void main() {
|
||||
vec2 st = vertTexCoord.st;
|
||||
|
||||
vec2 dest = vec2(destRect.xy) / vec2(destSize) + st * vec2(destRect.zw) / vec2(destSize);
|
||||
vec2 src = vec2(srcRect.xy) / vec2(srcSize) + st * vec2(srcRect.zw) / vec2(srcSize);
|
||||
|
||||
vec3 destColor = texture2D(destSampler, dest).rgb;
|
||||
vec3 srcColor = texture2D(srcSampler, src).rgb;
|
||||
|
||||
gl_FragColor = vec4(abs(srcColor - destColor), 1.0);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
uniform sampler2D destSampler;
|
||||
uniform sampler2D srcSampler;
|
||||
|
||||
uniform ivec2 destSize;
|
||||
uniform ivec4 destRect;
|
||||
|
||||
uniform ivec2 srcSize;
|
||||
uniform ivec4 srcRect;
|
||||
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
void main() {
|
||||
vec2 st = vertTexCoord.st;
|
||||
|
||||
vec2 dest = vec2(destRect.xy) / vec2(destSize) + st * vec2(destRect.zw) / vec2(destSize);
|
||||
vec2 src = vec2(srcRect.xy) / vec2(srcSize) + st * vec2(srcRect.zw) / vec2(srcSize);
|
||||
|
||||
vec3 destColor = texture2D(destSampler, dest).rgb;
|
||||
vec3 srcColor = texture2D(srcSampler, src).rgb;
|
||||
|
||||
gl_FragColor = vec4(destColor / (1.0 - srcColor), 1.0);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 117 KiB |
@@ -0,0 +1,28 @@
|
||||
uniform sampler2D destSampler;
|
||||
uniform sampler2D srcSampler;
|
||||
|
||||
uniform ivec2 destSize;
|
||||
uniform ivec4 destRect;
|
||||
|
||||
uniform ivec2 srcSize;
|
||||
uniform ivec4 srcRect;
|
||||
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
void main() {
|
||||
vec2 st = vertTexCoord.st;
|
||||
|
||||
vec2 dest = vec2(destRect.xy) / vec2(destSize) + st * vec2(destRect.zw) / vec2(destSize);
|
||||
vec2 src = vec2(srcRect.xy) / vec2(srcSize) + st * vec2(srcRect.zw) / vec2(srcSize);
|
||||
|
||||
vec3 destColor = texture2D(destSampler, dest).rgb;
|
||||
vec3 srcColor = texture2D(srcSampler, src).rgb;
|
||||
|
||||
float luminance = dot(vec3(0.2126, 0.7152, 0.0722), destColor);
|
||||
|
||||
if (luminance < 0.5) {
|
||||
gl_FragColor = vec4(2.0 * destColor * srcColor, 1.0);
|
||||
} else {
|
||||
gl_FragColor = vec4(1.0 - 2.0 * (1.0 - destColor) * (1.0 - srcColor), 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Deform.
|
||||
*
|
||||
* A GLSL version of the oldschool 2D deformation effect, by Inigo Quilez.
|
||||
* Ported from the webGL version available in ShaderToy:
|
||||
* http://www.iquilezles.org/apps/shadertoy/
|
||||
* (Look for Deform under the Plane Deformations Presets)
|
||||
*
|
||||
*/
|
||||
|
||||
PImage tex;
|
||||
PShader deform;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
|
||||
textureWrap(REPEAT);
|
||||
tex = loadImage("tex1.jpg");
|
||||
|
||||
deform = loadShader("deform.glsl");
|
||||
deform.set("resolution", float(width), float(height));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
deform.set("time", millis() / 1000.0);
|
||||
deform.set("mouse", float(mouseX), float(mouseY));
|
||||
shader(deform);
|
||||
image(tex, 0, 0, width, height);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
#define PROCESSING_TEXTURE_SHADER
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
uniform float time;
|
||||
uniform vec2 resolution;
|
||||
uniform vec2 mouse;
|
||||
|
||||
void main(void) {
|
||||
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
|
||||
vec2 m = -1.0 + 2.0 * mouse.xy / resolution.xy;
|
||||
|
||||
float a1 = atan(p.y - m.y, p.x - m.x);
|
||||
float r1 = sqrt(dot(p - m, p - m));
|
||||
float a2 = atan(p.y + m.y, p.x + m.x);
|
||||
float r2 = sqrt(dot(p + m, p + m));
|
||||
|
||||
vec2 uv;
|
||||
uv.x = 0.2 * time + (r1 - r2) * 0.25;
|
||||
uv.y = sin(2.0 * (a1 - a2));
|
||||
|
||||
float w = r1 * r2 * 0.8;
|
||||
vec3 col = texture2D(texture, 0.5 - 0.495 * uv).xyz;
|
||||
|
||||
gl_FragColor = vec4(col / (0.1 + w), 1.0);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
@@ -0,0 +1,98 @@
|
||||
void initCubeMap() {
|
||||
sphereDetail(50);
|
||||
domeSphere = createShape(SPHERE, height/2.0f);
|
||||
domeSphere.rotateX(HALF_PI);
|
||||
domeSphere.setStroke(false);
|
||||
|
||||
PGL pgl = beginPGL();
|
||||
|
||||
envMapTextureID = IntBuffer.allocate(1);
|
||||
pgl.genTextures(1, envMapTextureID);
|
||||
pgl.bindTexture(PGL.TEXTURE_CUBE_MAP, envMapTextureID.get(0));
|
||||
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_WRAP_S, PGL.CLAMP_TO_EDGE);
|
||||
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_WRAP_T, PGL.CLAMP_TO_EDGE);
|
||||
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_WRAP_R, PGL.CLAMP_TO_EDGE);
|
||||
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_MIN_FILTER, PGL.NEAREST);
|
||||
pgl.texParameteri(PGL.TEXTURE_CUBE_MAP, PGL.TEXTURE_MAG_FILTER, PGL.NEAREST);
|
||||
for (int i = PGL.TEXTURE_CUBE_MAP_POSITIVE_X; i < PGL.TEXTURE_CUBE_MAP_POSITIVE_X + 6; i++) {
|
||||
pgl.texImage2D(i, 0, PGL.RGBA8, envMapSize, envMapSize, 0, PGL.RGBA, PGL.UNSIGNED_BYTE, null);
|
||||
}
|
||||
|
||||
// Init fbo, rbo
|
||||
fbo = IntBuffer.allocate(1);
|
||||
rbo = IntBuffer.allocate(1);
|
||||
pgl.genFramebuffers(1, fbo);
|
||||
pgl.bindFramebuffer(PGL.FRAMEBUFFER, fbo.get(0));
|
||||
pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0, PGL.TEXTURE_CUBE_MAP_POSITIVE_X, envMapTextureID.get(0), 0);
|
||||
|
||||
pgl.genRenderbuffers(1, rbo);
|
||||
pgl.bindRenderbuffer(PGL.RENDERBUFFER, rbo.get(0));
|
||||
pgl.renderbufferStorage(PGL.RENDERBUFFER, PGL.DEPTH_COMPONENT24, envMapSize, envMapSize);
|
||||
|
||||
// Attach depth buffer to FBO
|
||||
pgl.framebufferRenderbuffer(PGL.FRAMEBUFFER, PGL.DEPTH_ATTACHMENT, PGL.RENDERBUFFER, rbo.get(0));
|
||||
|
||||
endPGL();
|
||||
|
||||
// Load cubemap shader.
|
||||
cubemapShader = loadShader("cubemapfrag.glsl", "cubemapvert.glsl");
|
||||
cubemapShader.set("cubemap", 1);
|
||||
}
|
||||
|
||||
void drawCubeMap() {
|
||||
PGL pgl = beginPGL();
|
||||
pgl.activeTexture(PGL.TEXTURE1);
|
||||
pgl.enable(PGL.TEXTURE_CUBE_MAP);
|
||||
pgl.bindTexture(PGL.TEXTURE_CUBE_MAP, envMapTextureID.get(0));
|
||||
regenerateEnvMap(pgl);
|
||||
endPGL();
|
||||
|
||||
drawDomeMaster();
|
||||
|
||||
pgl.bindTexture(PGL.TEXTURE_CUBE_MAP, 0);
|
||||
}
|
||||
|
||||
void drawDomeMaster() {
|
||||
camera();
|
||||
ortho();
|
||||
resetMatrix();
|
||||
shader(cubemapShader);
|
||||
shape(domeSphere);
|
||||
resetShader();
|
||||
}
|
||||
|
||||
// Called to regenerate the envmap
|
||||
void regenerateEnvMap(PGL pgl) {
|
||||
// bind fbo
|
||||
pgl.bindFramebuffer(PGL.FRAMEBUFFER, fbo.get(0));
|
||||
|
||||
// generate 6 views from origin(0, 0, 0)
|
||||
pgl.viewport(0, 0, envMapSize, envMapSize);
|
||||
perspective(90.0f * DEG_TO_RAD, 1.0f, 1.0f, 1025.0f);
|
||||
for (int face = PGL.TEXTURE_CUBE_MAP_POSITIVE_X; face <
|
||||
PGL.TEXTURE_CUBE_MAP_NEGATIVE_Z; face++) {
|
||||
resetMatrix();
|
||||
|
||||
if (face == PGL.TEXTURE_CUBE_MAP_POSITIVE_X) {
|
||||
camera(0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f);
|
||||
} else if (face == PGL.TEXTURE_CUBE_MAP_NEGATIVE_X) {
|
||||
camera(0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f);
|
||||
} else if (face == PGL.TEXTURE_CUBE_MAP_POSITIVE_Y) {
|
||||
camera(0.0f, 0.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, -1.0f);
|
||||
} else if (face == PGL.TEXTURE_CUBE_MAP_NEGATIVE_Y) {
|
||||
camera(0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
|
||||
} else if (face == PGL.TEXTURE_CUBE_MAP_POSITIVE_Z) {
|
||||
camera(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f);
|
||||
}
|
||||
|
||||
scale(-1, 1, -1);
|
||||
translate(-width * 0.5f, -height * 0.5f, -500);
|
||||
|
||||
pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0, face, envMapTextureID.get(0), 0);
|
||||
|
||||
drawScene(); // Draw objects in the scene
|
||||
flush(); // Make sure that the geometry in the scene is pushed to the GPU
|
||||
noLights(); // Disabling lights to avoid adding many times
|
||||
pgl.framebufferTexture2D(PGL.FRAMEBUFFER, PGL.COLOR_ATTACHMENT0, face, 0, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* DomeProjection
|
||||
*
|
||||
* This sketch uses use environmental mapping to render the output
|
||||
* on a full spherical dome.
|
||||
*
|
||||
* Based on the FullDomeTemplate code from Christopher Warnow:
|
||||
* https://github.com/mphasize/FullDome
|
||||
*
|
||||
* Note: This example needs desktop-class graphics to function.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
PShader cubemapShader;
|
||||
PShape domeSphere;
|
||||
|
||||
IntBuffer fbo;
|
||||
IntBuffer rbo;
|
||||
IntBuffer envMapTextureID;
|
||||
|
||||
int envMapSize = 1024;
|
||||
|
||||
void setup() {
|
||||
size(640, 640, P3D);
|
||||
initCubeMap();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
drawCubeMap();
|
||||
}
|
||||
|
||||
void drawScene() {
|
||||
background(0);
|
||||
|
||||
stroke(255, 0, 0);
|
||||
strokeWeight(2);
|
||||
for (int i = -width; i < 2 * width; i += 50) {
|
||||
line(i, -height, -100, i, 2 *height, -100);
|
||||
}
|
||||
for (int i = -height; i < 2 * height; i += 50) {
|
||||
line(-width, i, -100, 2 * width, i, -100);
|
||||
}
|
||||
|
||||
lights();
|
||||
noStroke();
|
||||
translate(mouseX, mouseY, 200);
|
||||
rotateX(frameCount * 0.01);
|
||||
rotateY(frameCount * 0.01);
|
||||
box(100);
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
uniform samplerCube cubemap;
|
||||
@@ -0,0 +1 @@
|
||||
uniform mat4 transform;
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Edge Detection
|
||||
*
|
||||
* Change the default shader to apply a simple, custom edge detection filter.
|
||||
*
|
||||
* Press the mouse to switch between the custom and default shader.
|
||||
*/
|
||||
|
||||
PShader edges;
|
||||
PImage img;
|
||||
boolean enabled = true;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
img = loadImage("leaves.jpg");
|
||||
edges = loadShader("edges.glsl");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if (enabled == true) {
|
||||
shader(edges);
|
||||
}
|
||||
image(img, 0, 0);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
enabled = !enabled;
|
||||
if (!enabled == true) {
|
||||
resetShader();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
#define PROCESSING_TEXTURE_SHADER
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform vec2 texOffset;
|
||||
|
||||
varying vec4 vertColor;
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
void main(void) {
|
||||
// Grouping texcoord variables in order to make it work in the GMA 950. See post #13
|
||||
// in this thread:
|
||||
// http://www.idevgames.com/forums/thread-3467.html
|
||||
vec2 tc0 = vertTexCoord.st + vec2(-texOffset.s, -texOffset.t);
|
||||
vec2 tc1 = vertTexCoord.st + vec2( 0.0, -texOffset.t);
|
||||
vec2 tc2 = vertTexCoord.st + vec2(+texOffset.s, -texOffset.t);
|
||||
vec2 tc3 = vertTexCoord.st + vec2(-texOffset.s, 0.0);
|
||||
vec2 tc4 = vertTexCoord.st + vec2( 0.0, 0.0);
|
||||
vec2 tc5 = vertTexCoord.st + vec2(+texOffset.s, 0.0);
|
||||
vec2 tc6 = vertTexCoord.st + vec2(-texOffset.s, +texOffset.t);
|
||||
vec2 tc7 = vertTexCoord.st + vec2( 0.0, +texOffset.t);
|
||||
vec2 tc8 = vertTexCoord.st + vec2(+texOffset.s, +texOffset.t);
|
||||
|
||||
vec4 col0 = texture2D(texture, tc0);
|
||||
vec4 col1 = texture2D(texture, tc1);
|
||||
vec4 col2 = texture2D(texture, tc2);
|
||||
vec4 col3 = texture2D(texture, tc3);
|
||||
vec4 col4 = texture2D(texture, tc4);
|
||||
vec4 col5 = texture2D(texture, tc5);
|
||||
vec4 col6 = texture2D(texture, tc6);
|
||||
vec4 col7 = texture2D(texture, tc7);
|
||||
vec4 col8 = texture2D(texture, tc8);
|
||||
|
||||
vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8);
|
||||
gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 42 KiB |
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Edge Filter
|
||||
*
|
||||
* Apply a custom shader to the filter() function to affect the geometry drawn to the screen.
|
||||
*
|
||||
* Press the mouse to turn the filter on and off.
|
||||
*/
|
||||
|
||||
PShader edges;
|
||||
boolean applyFilter = true;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
edges = loadShader("edges.glsl");
|
||||
noStroke();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
lights();
|
||||
|
||||
translate(width/2, height/2);
|
||||
pushMatrix();
|
||||
rotateX(frameCount * 0.01);
|
||||
rotateY(frameCount * 0.01);
|
||||
box(120);
|
||||
popMatrix();
|
||||
|
||||
if (applyFilter == true) {
|
||||
filter(edges);
|
||||
}
|
||||
|
||||
// The sphere doesn't have the edge detection applied
|
||||
// on it because it is drawn after filter() is called.
|
||||
rotateY(frameCount * 0.02);
|
||||
translate(150, 0);
|
||||
sphere(40);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
applyFilter = !applyFilter;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
#define PROCESSING_TEXTURE_SHADER
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform vec2 texOffset;
|
||||
|
||||
varying vec4 vertColor;
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
void main(void) {
|
||||
// Grouping texcoord variables in order to make it work in the GMA 950. See post #13
|
||||
// in this thread:
|
||||
// http://www.idevgames.com/forums/thread-3467.html
|
||||
vec2 tc0 = vertTexCoord.st + vec2(-texOffset.s, -texOffset.t);
|
||||
vec2 tc1 = vertTexCoord.st + vec2( 0.0, -texOffset.t);
|
||||
vec2 tc2 = vertTexCoord.st + vec2(+texOffset.s, -texOffset.t);
|
||||
vec2 tc3 = vertTexCoord.st + vec2(-texOffset.s, 0.0);
|
||||
vec2 tc4 = vertTexCoord.st + vec2( 0.0, 0.0);
|
||||
vec2 tc5 = vertTexCoord.st + vec2(+texOffset.s, 0.0);
|
||||
vec2 tc6 = vertTexCoord.st + vec2(-texOffset.s, +texOffset.t);
|
||||
vec2 tc7 = vertTexCoord.st + vec2( 0.0, +texOffset.t);
|
||||
vec2 tc8 = vertTexCoord.st + vec2(+texOffset.s, +texOffset.t);
|
||||
|
||||
vec4 col0 = texture2D(texture, tc0);
|
||||
vec4 col1 = texture2D(texture, tc1);
|
||||
vec4 col2 = texture2D(texture, tc2);
|
||||
vec4 col3 = texture2D(texture, tc3);
|
||||
vec4 col4 = texture2D(texture, tc4);
|
||||
vec4 col5 = texture2D(texture, tc5);
|
||||
vec4 col6 = texture2D(texture, tc6);
|
||||
vec4 col7 = texture2D(texture, tc7);
|
||||
vec4 col8 = texture2D(texture, tc8);
|
||||
|
||||
vec4 sum = 8.0 * col4 - (col0 + col1 + col2 + col3 + col5 + col6 + col7 + col8);
|
||||
gl_FragColor = vec4(sum.rgb, 1.0) * vertColor;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* Glossy Fish Eye
|
||||
*
|
||||
* A fish-eye shader is used on the main surface and
|
||||
* a glossy specular reflection shader is used on the
|
||||
* offscreen canvas.
|
||||
*/
|
||||
|
||||
PShader fisheye;
|
||||
PShader glossy;
|
||||
PGraphics canvas;
|
||||
PImage img;
|
||||
PShape ball;
|
||||
|
||||
boolean useFishEye = true;
|
||||
|
||||
void setup() {
|
||||
size(640, 640, P3D);
|
||||
canvas = createGraphics(width, height, P3D);
|
||||
|
||||
fisheye = loadShader("FishEye.glsl");
|
||||
fisheye.set("aperture", 180.0);
|
||||
|
||||
glossy = loadShader("GlossyFrag.glsl", "GlossyVert.glsl");
|
||||
glossy.set("AmbientColour", 0.0, 0.0, 0.0);
|
||||
glossy.set("DiffuseColour", 0.9, 0.2, 0.2);
|
||||
glossy.set("SpecularColour", 1.0, 1.0, 1.0);
|
||||
glossy.set("AmbientIntensity", 1.0);
|
||||
glossy.set("DiffuseIntensity", 1.0);
|
||||
glossy.set("SpecularIntensity", 0.7);
|
||||
glossy.set("Roughness", 0.7);
|
||||
glossy.set("Sharpness", 0.0);
|
||||
|
||||
ball = createShape(SPHERE, 50);
|
||||
ball.setStroke(false);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
canvas.beginDraw();
|
||||
canvas.shader(glossy);
|
||||
canvas.noStroke();
|
||||
canvas.background(0);
|
||||
canvas.pushMatrix();
|
||||
canvas.rotateY(frameCount * 0.01);
|
||||
canvas.pointLight(204, 204, 204, 1000, 1000, 1000);
|
||||
canvas.popMatrix();
|
||||
for (float x = 0; x < canvas.width + 100; x += 100) {
|
||||
for (float y = 0; y < canvas.height + 100; y += 100) {
|
||||
for (float z = 0; z < 400; z += 100) {
|
||||
canvas.pushMatrix();
|
||||
canvas.translate(x, y, -z);
|
||||
canvas.shape(ball);
|
||||
canvas.popMatrix();
|
||||
}
|
||||
}
|
||||
}
|
||||
canvas.endDraw();
|
||||
|
||||
if (useFishEye == true) {
|
||||
shader(fisheye);
|
||||
}
|
||||
image(canvas, 0, 0, width, height);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
if (useFishEye) {
|
||||
useFishEye = false;
|
||||
resetShader();
|
||||
} else {
|
||||
useFishEye = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Inspired by the "Angular Fisheye à la Bourke" sketch from
|
||||
// Jonathan Cremieux, as shown in the OpenProcessing website:
|
||||
// http://openprocessing.org/visuals/?visualID=12140
|
||||
// Using the inverse transform of the angular fisheye as
|
||||
// explained in Paul Bourke's website:
|
||||
// http://paulbourke.net/miscellaneous/domefisheye/fisheye/
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
#define PROCESSING_TEXTURE_SHADER
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform mat4 texMatrix;
|
||||
|
||||
varying vec4 vertColor;
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
uniform float aperture;
|
||||
|
||||
const float PI = 3.1415926535;
|
||||
|
||||
void main(void) {
|
||||
float apertureHalf = 0.5 * aperture * (PI / 180.0);
|
||||
|
||||
// This factor ajusts the coordinates in the case that
|
||||
// the aperture angle is less than 180 degrees, in which
|
||||
// case the area displayed is not the entire half-sphere.
|
||||
float maxFactor = sin(apertureHalf);
|
||||
|
||||
// The st factor takes into account the situation when non-pot
|
||||
// textures are not supported, so that the maximum texture
|
||||
// coordinate to cover the entire image might not be 1.
|
||||
vec2 stFactor = vec2(1.0 / abs(texMatrix[0][0]), 1.0 / abs(texMatrix[1][1]));
|
||||
vec2 pos = (2.0 * vertTexCoord.st * stFactor - 1.0);
|
||||
|
||||
float l = length(pos);
|
||||
if (l > 1.0) {
|
||||
gl_FragColor = vec4(0, 0, 0, 1);
|
||||
} else {
|
||||
float x = maxFactor * pos.x;
|
||||
float y = maxFactor * pos.y;
|
||||
|
||||
float n = length(vec2(x, y));
|
||||
|
||||
float z = sqrt(1.0 - n * n);
|
||||
|
||||
float r = atan(n, z) / PI;
|
||||
|
||||
float phi = atan(y, x);
|
||||
|
||||
float u = r * cos(phi) + 0.5;
|
||||
float v = r * sin(phi) + 0.5;
|
||||
|
||||
gl_FragColor = texture2D(texture, vec2(u, v) / stFactor) * vertColor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright (C) 2007 Dave Griffiths
|
||||
// Copyright (C) 2007 Dave Griffiths
|
||||
// Licence: GPLv2 (see COPYING)
|
||||
// Fluxus Shader Library
|
||||
// ---------------------
|
||||
// Glossy Specular Reflection Shader
|
||||
// A more controllable version of blinn shading,
|
||||
// Useful for ceramic or fluids - from Advanced
|
||||
// Renderman, thanks to Larry Gritz
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
uniform vec3 AmbientColour;
|
||||
uniform vec3 DiffuseColour;
|
||||
uniform vec3 SpecularColour;
|
||||
uniform float AmbientIntensity;
|
||||
uniform float DiffuseIntensity;
|
||||
uniform float SpecularIntensity;
|
||||
uniform float Roughness;
|
||||
uniform float Sharpness;
|
||||
|
||||
varying vec3 N;
|
||||
varying vec3 P;
|
||||
varying vec3 V;
|
||||
varying vec3 L;
|
||||
|
||||
void main() {
|
||||
float w = 0.18*(1.0-Sharpness);
|
||||
|
||||
vec3 l = normalize(L);
|
||||
vec3 n = normalize(N);
|
||||
vec3 v = normalize(V);
|
||||
vec3 h = normalize(l+v);
|
||||
|
||||
float diffuse = dot(l,n);
|
||||
float specular = smoothstep(0.72-w,0.72+w,pow(max(0.0,dot(n,h)),1.0/Roughness));
|
||||
|
||||
gl_FragColor = vec4(AmbientColour*AmbientIntensity +
|
||||
DiffuseColour*diffuse*DiffuseIntensity +
|
||||
SpecularColour*specular*SpecularIntensity,1);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// Copyright (C) 2007 Dave Griffiths
|
||||
// Licence: GPLv2 (see COPYING)
|
||||
// Fluxus Shader Library
|
||||
// ---------------------
|
||||
// Glossy Specular Reflection Shader
|
||||
// A more controllable version of blinn shading,
|
||||
// Useful for ceramic or fluids - from Advanced
|
||||
// Renderman, thanks to Larry Gritz
|
||||
|
||||
#define PROCESSING_LIGHT_SHADER
|
||||
|
||||
uniform mat4 modelview;
|
||||
uniform mat4 transform;
|
||||
uniform mat3 normalMatrix;
|
||||
|
||||
uniform vec4 lightPosition[8];
|
||||
|
||||
attribute vec4 vertex;
|
||||
attribute vec3 normal;
|
||||
|
||||
varying vec3 N;
|
||||
varying vec3 P;
|
||||
varying vec3 V;
|
||||
varying vec3 L;
|
||||
|
||||
void main() {
|
||||
N = normalize(normalMatrix * normal);
|
||||
P = vertex.xyz;
|
||||
V = -vec3(modelview * vertex);
|
||||
L = vec3(modelview * (lightPosition[0] - vertex));
|
||||
gl_Position = transform * vertex;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Image Mask
|
||||
*
|
||||
* Move the mouse to reveal the image through the dynamic mask.
|
||||
*/
|
||||
|
||||
PShader maskShader;
|
||||
PImage srcImage;
|
||||
PGraphics maskImage;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
srcImage = loadImage("leaves.jpg");
|
||||
maskImage = createGraphics(srcImage.width, srcImage.height, P2D);
|
||||
maskImage.noSmooth();
|
||||
maskShader = loadShader("mask.glsl");
|
||||
maskShader.set("mask", maskImage);
|
||||
background(255);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
maskImage.beginDraw();
|
||||
maskImage.background(0);
|
||||
if (mouseX != 0 && mouseY != 0) {
|
||||
maskImage.noStroke();
|
||||
maskImage.fill(255, 0, 0);
|
||||
maskImage.ellipse(mouseX, mouseY, 50, 50);
|
||||
}
|
||||
maskImage.endDraw();
|
||||
|
||||
shader(maskShader);
|
||||
image(srcImage, 0, 0, width, height);
|
||||
}
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 45 KiB |
@@ -0,0 +1,19 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
#define PROCESSING_TEXTURE_SHADER
|
||||
|
||||
uniform sampler2D texture;
|
||||
uniform sampler2D mask;
|
||||
|
||||
uniform vec2 texOffset;
|
||||
varying vec4 vertColor;
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
void main() {
|
||||
vec4 texColor = texture2D(texture, vertTexCoord.st).rgba;
|
||||
vec4 maskColor = texture2D(mask, vec2(vertTexCoord.s, 1.0 - vertTexCoord.t)).rgba;
|
||||
gl_FragColor = mix(texColor, vec4(0, 0, 0, 0), 1.0 - maskColor.r);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//-------------------------------------------------------------
|
||||
// Display endless moving background using a tile texture.
|
||||
// Contributed by martiSteiger
|
||||
//-------------------------------------------------------------
|
||||
|
||||
PImage tileTexture;
|
||||
PShader tileShader;
|
||||
|
||||
void setup() {
|
||||
size(640, 480, P2D);
|
||||
textureWrap(REPEAT);
|
||||
tileTexture = loadImage("penrose.jpg");
|
||||
loadTileShader();
|
||||
}
|
||||
|
||||
void loadTileShader() {
|
||||
tileShader = loadShader("scroller.glsl");
|
||||
tileShader.set("resolution", float(width), float(height));
|
||||
tileShader.set("tileImage", tileTexture);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
tileShader.set("time", millis() / 1000.0);
|
||||
shader(tileShader);
|
||||
rect(0, 0, width, height);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 88 KiB |
@@ -0,0 +1,17 @@
|
||||
//---------------------------------------------------------
|
||||
// Display endless moving background using a tile texture.
|
||||
// Contributed by martiSteiger
|
||||
//---------------------------------------------------------
|
||||
|
||||
uniform float time;
|
||||
uniform vec2 resolution;
|
||||
uniform sampler2D tileImage;
|
||||
|
||||
#define TILES_COUNT_X 4.0
|
||||
|
||||
void main() {
|
||||
vec2 pos = gl_FragCoord.xy - vec2(4.0 * time);
|
||||
vec2 p = (resolution - TILES_COUNT_X * pos) / resolution.x;
|
||||
vec3 col = texture2D (tileImage, p).xyz;
|
||||
gl_FragColor = vec4 (col, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Elevated
|
||||
* https://www.shadertoy.com/view/MdX3Rr by inigo quilez
|
||||
* Created by inigo quilez - iq/2013
|
||||
* License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
||||
* Processing port by Raphaël de Courville.
|
||||
*/
|
||||
|
||||
PShader landscape;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
noStroke();
|
||||
|
||||
// This GLSL code shows how to use shaders from
|
||||
// shadertoy in Processing with minimal changes.
|
||||
landscape = loadShader("landscape.glsl");
|
||||
landscape.set("resolution", float(width), float(height));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
|
||||
landscape.set("time", millis() / 1000.0);
|
||||
shader(landscape);
|
||||
rect(0, 0, width, height);
|
||||
|
||||
if (frameCount % 10 == 0) { // every 10th frame
|
||||
println("frame: " + frameCount + " - fps: " + frameRate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,352 @@
|
||||
// Elevated shader
|
||||
// https://www.shadertoy.com/view/MdX3Rr by inigo quilez
|
||||
|
||||
// Created by inigo quilez - iq/2013
|
||||
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
||||
|
||||
// Processing port by Raphaël de Courville.
|
||||
|
||||
#ifdef GL_ES
|
||||
precision highp float;
|
||||
#endif
|
||||
|
||||
// Type of shader expected by Processing
|
||||
#define PROCESSING_COLOR_SHADER
|
||||
|
||||
// Processing specific input
|
||||
uniform float time;
|
||||
uniform vec2 resolution;
|
||||
uniform vec2 mouse;
|
||||
|
||||
// Layer between Processing and Shadertoy uniforms
|
||||
vec3 iResolution = vec3(resolution,0.0);
|
||||
float iGlobalTime = time;
|
||||
vec4 iMouse = vec4(mouse,0.0,0.0); // zw would normally be the click status
|
||||
|
||||
// ------- Below is the unmodified Shadertoy code ----------
|
||||
// Created by inigo quilez - iq/2013
|
||||
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
||||
|
||||
//stereo thanks to Croqueteer
|
||||
//#define STEREO
|
||||
|
||||
mat3 m = mat3( 0.00, 0.80, 0.60,
|
||||
-0.80, 0.36, -0.48,
|
||||
-0.60, -0.48, 0.64 );
|
||||
|
||||
float hash( float n )
|
||||
{
|
||||
return fract(sin(n)*43758.5453123);
|
||||
}
|
||||
|
||||
|
||||
float noise( in vec3 x )
|
||||
{
|
||||
vec3 p = floor(x);
|
||||
vec3 f = fract(x);
|
||||
|
||||
f = f*f*(3.0-2.0*f);
|
||||
|
||||
float n = p.x + p.y*57.0 + 113.0*p.z;
|
||||
|
||||
float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
|
||||
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y),
|
||||
mix(mix( hash(n+113.0), hash(n+114.0),f.x),
|
||||
mix( hash(n+170.0), hash(n+171.0),f.x),f.y),f.z);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
vec3 noised( in vec2 x )
|
||||
{
|
||||
vec2 p = floor(x);
|
||||
vec2 f = fract(x);
|
||||
|
||||
vec2 u = f*f*(3.0-2.0*f);
|
||||
|
||||
float n = p.x + p.y*57.0;
|
||||
|
||||
float a = hash(n+ 0.0);
|
||||
float b = hash(n+ 1.0);
|
||||
float c = hash(n+ 57.0);
|
||||
float d = hash(n+ 58.0);
|
||||
return vec3(a+(b-a)*u.x+(c-a)*u.y+(a-b-c+d)*u.x*u.y,
|
||||
30.0*f*f*(f*(f-2.0)+1.0)*(vec2(b-a,c-a)+(a-b-c+d)*u.yx));
|
||||
|
||||
}
|
||||
|
||||
float noise( in vec2 x )
|
||||
{
|
||||
vec2 p = floor(x);
|
||||
vec2 f = fract(x);
|
||||
|
||||
f = f*f*(3.0-2.0*f);
|
||||
|
||||
float n = p.x + p.y*57.0;
|
||||
|
||||
float res = mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),
|
||||
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
float fbm( vec3 p )
|
||||
{
|
||||
float f = 0.0;
|
||||
|
||||
f += 0.5000*noise( p ); p = m*p*2.02;
|
||||
f += 0.2500*noise( p ); p = m*p*2.03;
|
||||
f += 0.1250*noise( p ); p = m*p*2.01;
|
||||
f += 0.0625*noise( p );
|
||||
|
||||
return f/0.9375;
|
||||
}
|
||||
|
||||
mat2 m2 = mat2(1.6,-1.2,1.2,1.6);
|
||||
|
||||
float fbm( vec2 p )
|
||||
{
|
||||
float f = 0.0;
|
||||
|
||||
f += 0.5000*noise( p ); p = m2*p*2.02;
|
||||
f += 0.2500*noise( p ); p = m2*p*2.03;
|
||||
f += 0.1250*noise( p ); p = m2*p*2.01;
|
||||
f += 0.0625*noise( p );
|
||||
|
||||
return f/0.9375;
|
||||
}
|
||||
|
||||
float terrain( in vec2 x )
|
||||
{
|
||||
vec2 p = x*0.003;
|
||||
float a = 0.0;
|
||||
float b = 1.0;
|
||||
vec2 d = vec2(0.0);
|
||||
for(int i=0;i<5; i++)
|
||||
{
|
||||
vec3 n = noised(p);
|
||||
d += n.yz;
|
||||
a += b*n.x/(1.0+dot(d,d));
|
||||
b *= 0.5;
|
||||
p=mat2(1.6,-1.2,1.2,1.6)*p;
|
||||
}
|
||||
|
||||
return 140.0*a;
|
||||
}
|
||||
|
||||
float terrain2( in vec2 x )
|
||||
{
|
||||
vec2 p = x*0.003;
|
||||
float a = 0.0;
|
||||
float b = 1.0;
|
||||
vec2 d = vec2(0.0);
|
||||
for(int i=0;i<14; i++)
|
||||
{
|
||||
vec3 n = noised(p);
|
||||
d += n.yz;
|
||||
a += b*n.x/(1.0+dot(d,d));
|
||||
b *= 0.5;
|
||||
p=m2*p;
|
||||
}
|
||||
|
||||
return 140.0*a;
|
||||
}
|
||||
|
||||
|
||||
float map( in vec3 p )
|
||||
{
|
||||
float h = terrain(p.xz);
|
||||
|
||||
float ss = 0.03;
|
||||
float hh = h*ss;
|
||||
float fh = fract(hh);
|
||||
float ih = floor(hh);
|
||||
fh = mix( sqrt(fh), fh, smoothstep(50.0,140.0,h) );
|
||||
h = (ih+fh)/ss;
|
||||
|
||||
return p.y - h;
|
||||
}
|
||||
|
||||
float map2( in vec3 p )
|
||||
{
|
||||
float h = terrain2(p.xz);
|
||||
|
||||
|
||||
float ss = 0.03;
|
||||
float hh = h*ss;
|
||||
float fh = fract(hh);
|
||||
float ih = floor(hh);
|
||||
fh = mix( sqrt(fh), fh, smoothstep(50.0,140.0,h) );
|
||||
h = (ih+fh)/ss;
|
||||
|
||||
return p.y - h;
|
||||
}
|
||||
|
||||
bool jinteresct(in vec3 rO, in vec3 rD, out float resT )
|
||||
{
|
||||
float h = 0.0;
|
||||
float t = 0.0;
|
||||
for( int j=0; j<120; j++ )
|
||||
{
|
||||
//if( t>2000.0 ) break;
|
||||
|
||||
vec3 p = rO + t*rD;
|
||||
if( p.y>300.0 ) break;
|
||||
h = map( p );
|
||||
|
||||
if( h<0.1 )
|
||||
{
|
||||
resT = t;
|
||||
return true;
|
||||
}
|
||||
t += max(0.1,0.5*h);
|
||||
|
||||
}
|
||||
|
||||
if( h<5.0 )
|
||||
{
|
||||
resT = t;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
float sinteresct(in vec3 rO, in vec3 rD )
|
||||
{
|
||||
float res = 1.0;
|
||||
float t = 0.0;
|
||||
for( int j=0; j<50; j++ )
|
||||
{
|
||||
//if( t>1000.0 ) break;
|
||||
vec3 p = rO + t*rD;
|
||||
|
||||
float h = map( p );
|
||||
|
||||
if( h<0.1 )
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
res = min( res, 16.0*h/t );
|
||||
t += h;
|
||||
|
||||
}
|
||||
|
||||
return clamp( res, 0.0, 1.0 );
|
||||
}
|
||||
|
||||
vec3 calcNormal( in vec3 pos, float t )
|
||||
{
|
||||
float e = 0.001;
|
||||
e = 0.001*t;
|
||||
vec3 eps = vec3(e,0.0,0.0);
|
||||
vec3 nor;
|
||||
nor.x = map2(pos+eps.xyy) - map2(pos-eps.xyy);
|
||||
nor.y = map2(pos+eps.yxy) - map2(pos-eps.yxy);
|
||||
nor.z = map2(pos+eps.yyx) - map2(pos-eps.yyx);
|
||||
return normalize(nor);
|
||||
}
|
||||
|
||||
vec3 camPath( float time )
|
||||
{
|
||||
vec2 p = 600.0*vec2( cos(1.4+0.37*time),
|
||||
cos(3.2+0.31*time) );
|
||||
|
||||
return vec3( p.x, 0.0, p.y );
|
||||
}
|
||||
|
||||
void main(void)
|
||||
{
|
||||
vec2 xy = -1.0 + 2.0*gl_FragCoord.xy / iResolution.xy;
|
||||
|
||||
vec2 s = xy*vec2(1.75,1.0);
|
||||
|
||||
#ifdef STEREO
|
||||
float isCyan = mod(gl_FragCoord.x + mod(gl_FragCoord.y,2.0),2.0);
|
||||
#endif
|
||||
|
||||
float time = iGlobalTime*.15;
|
||||
|
||||
vec3 light1 = normalize( vec3( 0.4, 0.22, 0.6 ) );
|
||||
vec3 light2 = vec3( -0.707, 0.000, -0.707 );
|
||||
|
||||
|
||||
vec3 campos = camPath( time );
|
||||
vec3 camtar = camPath( time + 3.0 );
|
||||
campos.y = terrain( campos.xz ) + 15.0;
|
||||
camtar.y = campos.y*0.5;
|
||||
|
||||
float roll = 0.1*cos(0.1*time);
|
||||
vec3 cw = normalize(camtar-campos);
|
||||
vec3 cp = vec3(sin(roll), cos(roll),0.0);
|
||||
vec3 cu = normalize(cross(cw,cp));
|
||||
vec3 cv = normalize(cross(cu,cw));
|
||||
vec3 rd = normalize( s.x*cu + s.y*cv + 1.6*cw );
|
||||
|
||||
#ifdef STEREO
|
||||
campos += 2.0*cu*isCyan; // move camera to the right - the rd vector is still good
|
||||
#endif
|
||||
|
||||
float sundot = clamp(dot(rd,light1),0.0,1.0);
|
||||
vec3 col;
|
||||
float t;
|
||||
if( !jinteresct(campos,rd,t) )
|
||||
{
|
||||
col = 0.9*vec3(0.97,.99,1.0)*(1.0-0.3*rd.y);
|
||||
col += 0.2*vec3(0.8,0.7,0.5)*pow( sundot, 4.0 );
|
||||
}
|
||||
else
|
||||
{
|
||||
vec3 pos = campos + t*rd;
|
||||
|
||||
vec3 nor = calcNormal( pos, t );
|
||||
|
||||
float dif1 = clamp( dot( light1, nor ), 0.0, 1.0 );
|
||||
float dif2 = clamp( 0.2 + 0.8*dot( light2, nor ), 0.0, 1.0 );
|
||||
float sh = 1.0;
|
||||
if( dif1>0.001 )
|
||||
sh = sinteresct(pos+light1*20.0,light1);
|
||||
|
||||
vec3 dif1v = vec3(dif1);
|
||||
dif1v *= vec3( sh, sh*sh*0.5+0.5*sh, sh*sh );
|
||||
|
||||
float r = noise( 7.0*pos.xz );
|
||||
|
||||
col = (r*0.25+0.75)*0.9*mix( vec3(0.10,0.05,0.03), vec3(0.13,0.10,0.08), clamp(terrain2( vec2(pos.x,pos.y*48.0))/200.0,0.0,1.0) );
|
||||
col = mix( col, 0.17*vec3(0.5,.23,0.04)*(0.50+0.50*r),smoothstep(0.70,0.9,nor.y) );
|
||||
col = mix( col, 0.10*vec3(0.2,.30,0.00)*(0.25+0.75*r),smoothstep(0.95,1.0,nor.y) );
|
||||
col *= 0.75;
|
||||
// snow
|
||||
#if 1
|
||||
float h = smoothstep(55.0,80.0,pos.y + 25.0*fbm(0.01*pos.xz) );
|
||||
float e = smoothstep(1.0-0.5*h,1.0-0.1*h,nor.y);
|
||||
float o = 0.3 + 0.7*smoothstep(0.0,0.1,nor.x+h*h);
|
||||
float s = h*e*o;
|
||||
s = smoothstep( 0.1, 0.9, s );
|
||||
col = mix( col, 0.4*vec3(0.6,0.65,0.7), s );
|
||||
#endif
|
||||
|
||||
|
||||
vec3 brdf = 2.0*vec3(0.17,0.19,0.20)*clamp(nor.y,0.0,1.0);
|
||||
brdf += 6.0*vec3(1.00,0.95,0.80)*dif1v;
|
||||
brdf += 2.0*vec3(0.20,0.20,0.20)*dif2;
|
||||
|
||||
col *= brdf;
|
||||
|
||||
float fo = 1.0-exp(-pow(0.0015*t,1.5));
|
||||
vec3 fco = vec3(0.7) + 0.6*vec3(0.8,0.7,0.5)*pow( sundot, 4.0 );
|
||||
col = mix( col, fco, fo );
|
||||
}
|
||||
|
||||
col = sqrt(col);
|
||||
|
||||
vec2 uv = xy*0.5+0.5;
|
||||
col *= 0.7 + 0.3*pow(16.0*uv.x*uv.y*(1.0-uv.x)*(1.0-uv.y),0.1);
|
||||
|
||||
#ifdef STEREO
|
||||
col *= vec3( isCyan, 1.0-isCyan, 1.0-isCyan );
|
||||
#endif
|
||||
|
||||
gl_FragColor=vec4(col,1.0);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* Monjori.
|
||||
*
|
||||
* GLSL version of the 1k intro Monjori from the demoscene
|
||||
* (http://www.pouet.net/prod.php?which=52761)
|
||||
* Ported from the webGL version available in ShaderToy:
|
||||
* http://www.iquilezles.org/apps/shadertoy/
|
||||
* (Look for Monjori under the Plane Deformations Presets)
|
||||
*/
|
||||
|
||||
PShader monjori;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
noStroke();
|
||||
|
||||
monjori = loadShader("monjori.glsl");
|
||||
monjori.set("resolution", float(width), float(height));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
monjori.set("time", millis() / 1000.0);
|
||||
|
||||
shader(monjori);
|
||||
// This kind of effects are entirely implemented in the
|
||||
// fragment shader, they only need a quad covering the
|
||||
// entire view area so every pixel is pushed through the
|
||||
// shader.
|
||||
rect(0, 0, width, height);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
#define PROCESSING_COLOR_SHADER
|
||||
|
||||
uniform vec2 resolution;
|
||||
uniform float time;
|
||||
|
||||
void main(void) {
|
||||
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
|
||||
float a = time*40.0;
|
||||
float d,e,f,g=1.0/40.0,h,i,r,q;
|
||||
e=400.0*(p.x*0.5+0.5);
|
||||
f=400.0*(p.y*0.5+0.5);
|
||||
i=200.0+sin(e*g+a/150.0)*20.0;
|
||||
d=200.0+cos(f*g/2.0)*18.0+cos(e*g)*7.0;
|
||||
r=sqrt(pow(i-e,2.0)+pow(d-f,2.0));
|
||||
q=f/r;
|
||||
e=(r*cos(q))-a/2.0;f=(r*sin(q))-a/2.0;
|
||||
d=sin(e*g)*176.0+sin(e*g)*164.0+r;
|
||||
h=((f+d)+a/2.0)*g;
|
||||
i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.0)*(r+h/3.0);
|
||||
h=sin(f*g)*144.0-sin(e*g)*212.0*p.x;
|
||||
h=(h+(f-e)*q+sin(r-(a+h)/7.0)*10.0+i/4.0)*g;
|
||||
i+=cos(h*2.3*sin(a/350.0-q))*184.0*sin(q-(r*4.3+a/12.0)*g)+tan(r*g+h)*184.0*cos(r*g+h);
|
||||
i=mod(i/5.6,256.0)/64.0;
|
||||
if(i<0.0) i+=4.0;
|
||||
if(i>=2.0) i=4.0-i;
|
||||
d=r/350.0;
|
||||
d+=sin(d*d*8.0)*0.52;
|
||||
f=(sin(a*g)+1.0)/2.0;
|
||||
gl_FragColor=vec4(vec3(f*i/1.6,i/2.0+d/13.0,i)*d*p.x+vec3(i/1.3+d/8.0,i/2.0+d/18.0,i)*d*(1.0-p.x),1.0);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Nebula.
|
||||
*
|
||||
* From CoffeeBreakStudios.com (CBS)
|
||||
* Ported from the webGL version in GLSL Sandbox:
|
||||
* http://glsl.heroku.com/e#3265.2
|
||||
*/
|
||||
|
||||
PShader nebula;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
noStroke();
|
||||
|
||||
nebula = loadShader("nebula.glsl");
|
||||
nebula.set("resolution", float(width), float(height));
|
||||
}
|
||||
|
||||
void draw() {
|
||||
nebula.set("time", millis() / 500.0);
|
||||
shader(nebula);
|
||||
// This kind of raymarching effects are entirely implemented in the
|
||||
// fragment shader, they only need a quad covering the entire view
|
||||
// area so every pixel is pushed through the shader.
|
||||
rect(0, 0, width, height);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
#define PROCESSING_COLOR_SHADER
|
||||
|
||||
uniform float time;
|
||||
uniform vec2 resolution;
|
||||
|
||||
// NEBULA - CoffeeBreakStudios.com (CBS)
|
||||
// Work in progress...
|
||||
//
|
||||
// 3148.26: Switched from classic to simplex noise
|
||||
// 3148.27: Reduced number of stars
|
||||
// 3249.0: Switched to fast computed 3D noise. Less quality but ~ 2x faster
|
||||
// 3249.5: Removed use of random number generator to gain performance
|
||||
// 3265.0: Added rotation: glsl.heroku.com/e#3005.1
|
||||
|
||||
//Utility functions
|
||||
|
||||
vec3 fade(vec3 t) {
|
||||
return vec3(1.0,1.0,1.0);//t*t*t*(t*(t*6.0-15.0)+10.0);
|
||||
}
|
||||
|
||||
vec2 rotate(vec2 point, float rads) {
|
||||
float cs = cos(rads);
|
||||
float sn = sin(rads);
|
||||
return point * mat2(cs, -sn, sn, cs);
|
||||
}
|
||||
|
||||
vec4 randomizer4(const vec4 x)
|
||||
{
|
||||
vec4 z = mod(x, vec4(5612.0));
|
||||
z = mod(z, vec4(3.1415927 * 2.0));
|
||||
return(fract(cos(z) * vec4(56812.5453)));
|
||||
}
|
||||
|
||||
// Fast computed noise
|
||||
// http://www.gamedev.net/topic/502913-fast-computed-noise/
|
||||
|
||||
const float A = 1.0;
|
||||
const float B = 57.0;
|
||||
const float C = 113.0;
|
||||
const vec3 ABC = vec3(A, B, C);
|
||||
const vec4 A3 = vec4(0, B, C, C+B);
|
||||
const vec4 A4 = vec4(A, A+B, C+A, C+A+B);
|
||||
|
||||
float cnoise4(const in vec3 xx)
|
||||
{
|
||||
vec3 x = mod(xx + 32768.0, 65536.0);
|
||||
vec3 ix = floor(x);
|
||||
vec3 fx = fract(x);
|
||||
vec3 wx = fx*fx*(3.0-2.0*fx);
|
||||
float nn = dot(ix, ABC);
|
||||
|
||||
vec4 N1 = nn + A3;
|
||||
vec4 N2 = nn + A4;
|
||||
vec4 R1 = randomizer4(N1);
|
||||
vec4 R2 = randomizer4(N2);
|
||||
vec4 R = mix(R1, R2, wx.x);
|
||||
float re = mix(mix(R.x, R.y, wx.y), mix(R.z, R.w, wx.y), wx.z);
|
||||
|
||||
return 1.0 - 2.0 * re;
|
||||
}
|
||||
float surface3 ( vec3 coord, float frequency ) {
|
||||
|
||||
float n = 0.0;
|
||||
|
||||
n += 1.0 * abs( cnoise4( coord * frequency ) );
|
||||
n += 0.5 * abs( cnoise4( coord * frequency * 2.0 ) );
|
||||
n += 0.25 * abs( cnoise4( coord * frequency * 4.0 ) );
|
||||
n += 0.125 * abs( cnoise4( coord * frequency * 8.0 ) );
|
||||
n += 0.0625 * abs( cnoise4( coord * frequency * 16.0 ) );
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
void main( void ) {
|
||||
float rads = radians(time*3.15);
|
||||
vec2 position = gl_FragCoord.xy / resolution.xy;
|
||||
position += rotate(position, rads);
|
||||
float n = surface3(vec3(position*sin(time*0.1), time * 0.05)*mat3(1,0,0,0,.8,.6,0,-.6,.8),0.9);
|
||||
float n2 = surface3(vec3(position*cos(time*0.1), time * 0.04)*mat3(1,0,0,0,.8,.6,0,-.6,.8),0.8);
|
||||
float lum = length(n);
|
||||
float lum2 = length(n2);
|
||||
|
||||
vec3 tc = pow(vec3(1.0-lum),vec3(sin(position.x)+cos(time)+4.0,8.0+sin(time)+4.0,8.0));
|
||||
vec3 tc2 = pow(vec3(1.1-lum2),vec3(5.0,position.y+cos(time)+7.0,sin(position.x)+sin(time)+2.0));
|
||||
vec3 curr_color = (tc*0.8) + (tc2*0.5);
|
||||
|
||||
|
||||
//Let's draw some stars
|
||||
|
||||
float scale = sin(0.3 * time) + 5.0;
|
||||
vec2 position2 = (((gl_FragCoord.xy / resolution) - 0.5) * scale);
|
||||
float gradient = 0.0;
|
||||
vec3 color = vec3(0.0);
|
||||
float fade = 0.0;
|
||||
float z = 0.0;
|
||||
vec2 centered_coord = position2 - vec2(sin(time*0.1),sin(time*0.1));
|
||||
centered_coord = rotate(centered_coord, rads);
|
||||
|
||||
for (float i=1.0; i<=60.0; i++)
|
||||
{
|
||||
vec2 star_pos = vec2(sin(i) * 250.0, sin(i*i*i) * 250.0);
|
||||
float z = mod(i*i - 10.0*time, 256.0);
|
||||
float fade = (256.0 - z) /256.0;
|
||||
vec2 blob_coord = star_pos / z;
|
||||
gradient += ((fade / 384.0) / pow(length(centered_coord - blob_coord), 1.5)) * ( fade);
|
||||
}
|
||||
|
||||
curr_color += gradient;
|
||||
|
||||
gl_FragColor = vec4(curr_color, 1.0);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
* Separate Blur Shader
|
||||
*
|
||||
* This blur shader works by applying two successive passes, one horizontal
|
||||
* and the other vertical.
|
||||
*
|
||||
* Press the mouse to switch between the custom and default shader.
|
||||
*/
|
||||
|
||||
PShader blur;
|
||||
PGraphics src;
|
||||
PGraphics pass1, pass2;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P2D);
|
||||
|
||||
blur = loadShader("blur.glsl");
|
||||
blur.set("blurSize", 9);
|
||||
blur.set("sigma", 5.0f);
|
||||
|
||||
src = createGraphics(width, height, P2D);
|
||||
|
||||
pass1 = createGraphics(width, height, P2D);
|
||||
pass1.noSmooth();
|
||||
|
||||
pass2 = createGraphics(width, height, P2D);
|
||||
pass2.noSmooth();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
src.beginDraw();
|
||||
src.background(0);
|
||||
src.fill(255);
|
||||
src.ellipse(width/2, height/2, 100, 100);
|
||||
src.endDraw();
|
||||
|
||||
// Applying the blur shader along the vertical direction
|
||||
blur.set("horizontalPass", 0);
|
||||
pass1.beginDraw();
|
||||
pass1.shader(blur);
|
||||
pass1.image(src, 0, 0);
|
||||
pass1.endDraw();
|
||||
|
||||
// Applying the blur shader along the horizontal direction
|
||||
blur.set("horizontalPass", 1);
|
||||
pass2.beginDraw();
|
||||
pass2.shader(blur);
|
||||
pass2.image(pass1, 0, 0);
|
||||
pass2.endDraw();
|
||||
|
||||
image(pass2, 0, 0);
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (key == '9') {
|
||||
blur.set("blurSize", 9);
|
||||
blur.set("sigma", 5.0);
|
||||
} else if (key == '7') {
|
||||
blur.set("blurSize", 7);
|
||||
blur.set("sigma", 3.0);
|
||||
} else if (key == '5') {
|
||||
blur.set("blurSize", 5);
|
||||
blur.set("sigma", 2.0);
|
||||
} else if (key == '3') {
|
||||
blur.set("blurSize", 5);
|
||||
blur.set("sigma", 1.0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
// Adapted from:
|
||||
// http://callumhay.blogspot.com/2010/09/gaussian-blur-shader-glsl.html
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
#define PROCESSING_TEXTURE_SHADER
|
||||
|
||||
uniform sampler2D texture;
|
||||
|
||||
// The inverse of the texture dimensions along X and Y
|
||||
uniform vec2 texOffset;
|
||||
|
||||
varying vec4 vertColor;
|
||||
varying vec4 vertTexCoord;
|
||||
|
||||
uniform int blurSize;
|
||||
uniform int horizontalPass; // 0 or 1 to indicate vertical or horizontal pass
|
||||
uniform float sigma; // The sigma value for the gaussian function: higher value means more blur
|
||||
// A good value for 9x9 is around 3 to 5
|
||||
// A good value for 7x7 is around 2.5 to 4
|
||||
// A good value for 5x5 is around 2 to 3.5
|
||||
// ... play around with this based on what you need :)
|
||||
|
||||
const float pi = 3.14159265;
|
||||
|
||||
void main() {
|
||||
float numBlurPixelsPerSide = float(blurSize / 2);
|
||||
|
||||
vec2 blurMultiplyVec = 0 < horizontalPass ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
|
||||
|
||||
// Incremental Gaussian Coefficent Calculation (See GPU Gems 3 pp. 877 - 889)
|
||||
vec3 incrementalGaussian;
|
||||
incrementalGaussian.x = 1.0 / (sqrt(2.0 * pi) * sigma);
|
||||
incrementalGaussian.y = exp(-0.5 / (sigma * sigma));
|
||||
incrementalGaussian.z = incrementalGaussian.y * incrementalGaussian.y;
|
||||
|
||||
vec4 avgValue = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
float coefficientSum = 0.0;
|
||||
|
||||
// Take the central sample first...
|
||||
avgValue += texture2D(texture, vertTexCoord.st) * incrementalGaussian.x;
|
||||
coefficientSum += incrementalGaussian.x;
|
||||
incrementalGaussian.xy *= incrementalGaussian.yz;
|
||||
|
||||
// Go through the remaining 8 vertical samples (4 on each side of the center)
|
||||
for (float i = 1.0; i <= numBlurPixelsPerSide; i++) {
|
||||
avgValue += texture2D(texture, vertTexCoord.st - i * texOffset *
|
||||
blurMultiplyVec) * incrementalGaussian.x;
|
||||
avgValue += texture2D(texture, vertTexCoord.st + i * texOffset *
|
||||
blurMultiplyVec) * incrementalGaussian.x;
|
||||
coefficientSum += 2.0 * incrementalGaussian.x;
|
||||
incrementalGaussian.xy *= incrementalGaussian.yz;
|
||||
}
|
||||
|
||||
gl_FragColor = avgValue / coefficientSum;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Toon Shading.
|
||||
*
|
||||
* Example showing the use of a custom lighting shader in order
|
||||
* to apply a "toon" effect on the scene. Based on the glsl tutorial
|
||||
* from lighthouse 3D:
|
||||
* http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/
|
||||
*/
|
||||
|
||||
PShader toon;
|
||||
boolean shaderEnabled = true;
|
||||
|
||||
void setup() {
|
||||
size(640, 360, P3D);
|
||||
noStroke();
|
||||
fill(204);
|
||||
toon = loadShader("ToonFrag.glsl", "ToonVert.glsl");
|
||||
}
|
||||
|
||||
void draw() {
|
||||
if (shaderEnabled == true) {
|
||||
shader(toon);
|
||||
}
|
||||
|
||||
noStroke();
|
||||
background(0);
|
||||
float dirY = (mouseY / float(height) - 0.5) * 2;
|
||||
float dirX = (mouseX / float(width) - 0.5) * 2;
|
||||
directionalLight(204, 204, 204, -dirX, -dirY, -1);
|
||||
translate(width/2, height/2);
|
||||
sphere(120);
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
if (shaderEnabled) {
|
||||
shaderEnabled = false;
|
||||
resetShader();
|
||||
}
|
||||
else {
|
||||
shaderEnabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
precision mediump int;
|
||||
#endif
|
||||
|
||||
varying vec3 vertNormal;
|
||||
varying vec3 vertLightDir;
|
||||
|
||||
void main() {
|
||||
float intensity;
|
||||
vec4 color;
|
||||
intensity = max(0.0, dot(vertLightDir, vertNormal));
|
||||
|
||||
if (intensity > 0.95) {
|
||||
color = vec4(1.0, 0.5, 0.5, 1.0);
|
||||
} else if (intensity > 0.5) {
|
||||
color = vec4(0.6, 0.3, 0.3, 1.0);
|
||||
} else if (intensity > 0.25) {
|
||||
color = vec4(0.4, 0.2, 0.2, 1.0);
|
||||
} else {
|
||||
color = vec4(0.2, 0.1, 0.1, 1.0);
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
// Toon shader using per-pixel lighting. Based on the glsl
|
||||
// tutorial from lighthouse 3D:
|
||||
// http://www.lighthouse3d.com/tutorials/glsl-tutorial/toon-shader-version-ii/
|
||||
|
||||
#define PROCESSING_LIGHT_SHADER
|
||||
|
||||
uniform mat4 modelview;
|
||||
uniform mat4 transform;
|
||||
uniform mat3 normalMatrix;
|
||||
|
||||
uniform vec3 lightNormal[8];
|
||||
|
||||
attribute vec4 vertex;
|
||||
attribute vec3 normal;
|
||||
|
||||
varying vec3 vertNormal;
|
||||
varying vec3 vertLightDir;
|
||||
|
||||
void main() {
|
||||
// Vertex in clip coordinates
|
||||
gl_Position = transform * vertex;
|
||||
|
||||
// Normal vector in eye coordinates is passed
|
||||
// to the fragment shader
|
||||
vertNormal = normalize(normalMatrix * normal);
|
||||
|
||||
// Assuming that there is only one directional light.
|
||||
// Its normal vector is passed to the fragment shader
|
||||
// in order to perform per-pixel lighting calculation.
|
||||
vertLightDir = -lightNormal[0];
|
||||
}
|
||||
Reference in New Issue
Block a user