FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Put shader toy and GLSL sandbox examples back with proper credits and… · ranlevinstein/processing@054ef25 · GitHub

Repository navigation

Commit 054ef25

Browse files
committed
Put shader toy and GLSL sandbox examples back with proper credits and comments
1 parent cc8c857 commit 054ef25

9 files changed

Lines changed: 505 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Deform
3+
* A GLSL version of the oldschool 2D deformation effect, by Inigo Quilez.
4+
* Ported from the webGL version available in ShaderToy:
5+
* http://www.iquilezles.org/apps/shadertoy/
6+
* (look for Deform under the Plane Deformations Presets)
7+
*
8+
*/
9+
10+
PImage tex;
11+
PShader deform;
12+
13+
void setup() {
14+
size(640, 360, P2D);
15+
16+
textureWrap(REPEAT);
17+
tex = loadImage("tex1.jpg");
18+
19+
deform = loadShader("deform.glsl");
20+
deform.set("resolution", float(width), float(height));
21+
}
22+
23+
void draw() {
24+
deform.set("time", millis() / 1000.0);
25+
deform.set("mouse", float(mouseX), float(mouseY));
26+
shader(deform);
27+
image(tex, 0, 0, width, height);
28+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
uniform sampler2D textureSampler;
2+
3+
uniform float time;
4+
uniform vec2 resolution;
5+
uniform vec2 mouse;
6+
7+
void main(void) {
8+
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
9+
vec2 m = -1.0 + 2.0 * mouse.xy / resolution.xy;
10+
11+
float a1 = atan(p.y - m.y, p.x - m.x);
12+
float r1 = sqrt(dot(p - m, p - m));
13+
float a2 = atan(p.y + m.y, p.x + m.x);
14+
float r2 = sqrt(dot(p + m, p + m));
15+
16+
vec2 uv;
17+
uv.x = 0.2 * time + (r1 - r2) * 0.25;
18+
uv.y = sin(2.0 * (a1 - a2));
19+
20+
float w = r1 * r2 * 0.8;
21+
vec3 col = texture2D(textureSampler, 0.5 - 0.495 * uv).xyz;
22+
23+
gl_FragColor = vec4(col / (0.1 + w), 1.0);
24+
}
31.9 KB
LoadingViewer requires iframe.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Landscape
3+
* Simple raymarching shader with camera, originally by Paulo Falcão
4+
* Ported from the webGL version in GLSL Sandbox:
5+
* http://glsl.heroku.com/e#3213.0
6+
*
7+
*/
8+
9+
PShader landscape;
10+
PGraphics pg;
11+
12+
void setup() {
13+
size(640, 360, P2D);
14+
15+
// This effect can be too demanding on older GPUs,
16+
// so we render it on a smaller res offscreen surface
17+
pg = createGraphics(320, 180, P2D);
18+
pg.noStroke();
19+
20+
landscape = loadShader("landscape.glsl");
21+
landscape.set("resolution", float(width), float(height));
22+
}
23+
24+
void draw() {
25+
landscape.set("time", millis() / 1000.0);
26+
landscape.set("mouse", float(mouseX), height - float(mouseY));
27+
28+
// This kind of raymarching effects are entirely implemented in the
29+
// fragment shader, they only need a quad covering the entire view
30+
// area so every pixel is pushed through the shader.
31+
pg.beginDraw();
32+
pg.shader(landscape);
33+
pg.rect(0, 0, width, height);
34+
pg.endDraw();
35+
36+
// Scaling up offscreen surface to cover entire screen.
37+
image(pg, 0, 0, width, height);
38+
}
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
// Some hills...
2+
// rotwang: @mod* lowered cam for better flight feeling
3+
// @mod+ mouse y controls flight height
4+
// @mod* some color tests
5+
// @mod+ Canyon
6+
// @emackey: Simple sky blue (no clouds...)
7+
// @rotwang: mod* sky gradient, different terrain front and backcolor
8+
// @mod* stripes texture
9+
// @mod* terrain variation
10+
// @psonice flyover adjusted so height depends on terrain. WOuld be better with spline interpolation, if you have the time go do it :)
11+
#ifdef GL_ES
12+
precision highp float;
13+
#endif
14+
15+
16+
uniform vec2 resolution;
17+
uniform float time;
18+
uniform vec2 mouse;
19+
//Simple raymarching sandbox with camera
20+
21+
//Raymarching Distance Fields
22+
//About http://www.iquilezles.org/www/articles/raymarchingdf/raymarchingdf.htm
23+
//Also known as Sphere Tracing
24+
//Original seen here: http://twitter.com/#!/paulofalcao/statuses/134807547860353024
25+
26+
//Util Start
27+
28+
mat2 m = mat2( 0.80, 0.60, -0.60, 0.80 );
29+
30+
float hash( float n )
31+
{
32+
return fract(sin(n)*43758.5453);
33+
}
34+
35+
float noise( in vec2 x )
36+
{
37+
vec2 p = floor(x);
38+
vec2 f = fract(x);
39+
f = f*f*(3.0-2.0*f);
40+
float n = p.x + p.y*57.0;
41+
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);
42+
return res;
43+
}
44+
45+
float fbm_5oct( vec2 p )
46+
{
47+
float f = 0.0;
48+
f += 0.50000*noise( p ); p = m*p*2.02;
49+
f += 0.25000*noise( p ); p = m*p*2.03;
50+
f += 0.12500*noise( p ); p = m*p*2.01;
51+
f += 0.06250*noise( p ); p = m*p*2.04;
52+
f += 0.03125*noise( p );
53+
return f/0.984375;
54+
}
55+
56+
float fbm_3oct( vec2 p )
57+
{
58+
float f = 0.0;
59+
f += 0.50000*noise( p ); p = m*p*2.02;
60+
f += 0.25000*noise( p ); p = m*p*2.03;
61+
f += 0.12500*noise( p ); p = m*p*2.01;
62+
63+
return f/0.875;
64+
}
65+
66+
vec2 ObjUnion(in vec2 obj_floor,in vec2 obj_roundBox){
67+
if (obj_floor.x<obj_roundBox.x)
68+
return obj_floor;
69+
else
70+
return obj_roundBox;
71+
}
72+
//Util End
73+
74+
//Scene Start
75+
76+
//Torus
77+
float torus(in vec3 p, in vec2 t){
78+
vec2 q = vec2(length(vec2(p.x,p.z))-t.x, p.y);
79+
return length(q) - t.y;
80+
}
81+
82+
//Sphere
83+
float sphere(in vec3 p, float radius){
84+
float length = sqrt(p.x*p.x + p.y*p.y + p.z*p.z);
85+
return length-radius;
86+
}
87+
88+
89+
vec2 terrain(in vec3 p){
90+
91+
92+
float da = sin(0.9*p.y)*fbm_3oct(p.xz);
93+
vec2 vd = vec2(p.y+fbm_3oct(p.xz / 9.0) * 9.33 ,0);
94+
vd.x += da;
95+
96+
return vd;
97+
}
98+
99+
vec3 hsv2rgb(float h,float s,float v) {
100+
return mix(vec3(1.),clamp((abs(fract(h+vec3(3.,2.,1.)/3.)*6.-3.)-1.),0.,1.),s)*v;
101+
}
102+
103+
/**
104+
@rotwang:
105+
smoothes between 2 vectors a and b (eg colors)
106+
using a source value and a smooth amount
107+
about the base as center.
108+
*/
109+
vec3 smoothmix(vec3 a, vec3 b, float base, float smooth, float source)
110+
{
111+
float f = smoothstep(base-smooth, base+smooth, source );
112+
vec3 vec = mix(a, b, f);
113+
return vec;
114+
}
115+
116+
117+
//Terrain Color
118+
vec3 terrain_clr(in vec3 p){
119+
120+
121+
vec3 clr_a = vec3(0.4, 0.5, 0.2);
122+
vec3 clr_b = vec3(0.3, 0.3, 0.3);
123+
float m = fract(p.y*4.0);
124+
float g = fbm_3oct(p.xz * 28.0);
125+
clr_b += g;
126+
vec3 clr = smoothmix(clr_a, clr_b,0.76, 0.3, m );
127+
clr = mix( clr, g*clr, 0.6);
128+
129+
130+
return clr;
131+
}
132+
133+
//IQs RoundBox (try other objects http://www.iquilezles.org/www/articles/distfunctions/distfunctions.htm)
134+
vec2 obj_roundBox(in vec3 p){
135+
return vec2(length(max(abs(p)-vec3(1,1,1),0.0))-0.25,1);
136+
}
137+
138+
vec2 obj_sphere(in vec3 p){
139+
return vec2(length(p)-2.0);
140+
}
141+
142+
//RoundBox with simple solid color
143+
vec3 obj_roundBox_c(in vec3 p){
144+
return vec3(1.0,0.5,0.2);
145+
}
146+
147+
//Objects union
148+
vec2 inObj(in vec3 p){
149+
return terrain(p);
150+
}
151+
152+
//Scene End
153+
154+
void main(void){
155+
//Camera animation
156+
vec3 U=vec3(0,1,0);//Camera Up Vector
157+
158+
float speed = time*2.0;
159+
float my = sin(time/8.0); // mouse.y*4.0;
160+
float camy = -1.0+my;
161+
float tary = -1.0+my;
162+
vec3 E=vec3(0., camy, speed);//vec3(-sin(time/4.0)*8.0,4,cos(time/4.0)*8.0); //Camera location; Change camera path position here
163+
E.y += .2;
164+
vec3 viewDir=vec3(E.x-sin(mouse.x*0.0),tary,E.z+cos(mouse.x*0.0)); //Change camere view vector here
165+
//vec3 E=vec3(mouse.x*0.0, 4, mouse.y*4.0); //Camera location; Change camera path position here
166+
167+
//Camera setup
168+
vec3 C=normalize(viewDir-E);
169+
vec3 A=cross(C, U);
170+
vec3 B=cross(A, C);
171+
vec3 M=(E+C);
172+
173+
vec2 vPos=2.0*gl_FragCoord.xy/resolution.xy - 1.0; // (2*Sx-1) where Sx = x in screen space (between 0 and 1)
174+
vec3 scrCoord=M + vPos.x*A*resolution.x/resolution.y + vPos.y*B; //normalize resolution in either x or y direction (ie resolution.x/resolution.y)
175+
vec3 scp=normalize(scrCoord-E);
176+
// scp.z += 1.;
177+
scp.y -=0.25;
178+
E.y -= (terrain(E).x + terrain(E + vec3(0., 0., 0.1)).x + terrain(E + vec3(0., 0., -0.1)).x) / 3.;
179+
E.y += 2.;
180+
//Raymarching
181+
const vec3 e=vec3(0.1,0,0);
182+
const float MAX_DEPTH=60.0; //Max depth0.
183+
184+
vec2 s=vec2(0.1,0.0);
185+
vec3 c,p,n;
186+
187+
float f=1.0;
188+
for(int i=0;i<100;i++){
189+
if (abs(s.x)<.01||f>MAX_DEPTH) break;
190+
f+=s.x;
191+
p=E+scp*f;
192+
s=inObj(p);
193+
}
194+
195+
if (f<MAX_DEPTH){
196+
if (s.y==0.0)
197+
c=terrain_clr(p);
198+
vec3 cc = vec3(0.7, c.g, c.b);
199+
200+
float m = smoothstep(3.0, 20.0, f);
201+
c = mix(c,cc, 1.0-m);
202+
203+
204+
n=normalize(
205+
vec3(s.x-inObj(p-e.xyy).x,
206+
s.x-inObj(p-e.yxy).x,
207+
s.x-inObj(p-e.yyx).x));
208+
float b=dot(n,normalize(E-p));
209+
210+
gl_FragColor=vec4(b*c*(2.0-f*.01),1.0);//simple phong LightPosition=CameraPosition
211+
}
212+
else {
213+
float invy = 1.0-vPos.y;
214+
float r = invy*0.8;
215+
float g = 0.2 + invy*0.7;
216+
vec3 sky_clr = vec3(r,g,0.9);
217+
gl_FragColor=vec4( sky_clr,1.0); //background color
218+
}
219+
220+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Monjori
3+
* GLSL version of the 1k intro Monjori from the demoscene
4+
* (http://www.pouet.net/prod.php?which=52761)
5+
* Ported from the webGL version available in ShaderToy:
6+
* http://www.iquilezles.org/apps/shadertoy/
7+
* (look for Monjori under the Plane Deformations Presets)
8+
*/
9+
10+
PShader monjori;
11+
12+
void setup() {
13+
size(640, 360, P2D);
14+
noStroke();
15+
16+
monjori = loadShader("monjori.glsl");
17+
monjori.set("resolution", float(width), float(height));
18+
}
19+
20+
void draw() {
21+
monjori.set("time", millis() / 1000.0);
22+
23+
shader(monjori);
24+
// This kind of effects are entirely implemented in the
25+
// fragment shader, they only need a quad covering the
26+
// entire view area so every pixel is pushed through the
27+
// shader.
28+
rect(0, 0, width, height);
29+
}
30+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
uniform vec2 resolution;
2+
uniform float time;
3+
4+
void main(void)
5+
{
6+
vec2 p = -1.0 + 2.0 * gl_FragCoord.xy / resolution.xy;
7+
float a = time*40.0;
8+
float d,e,f,g=1.0/40.0,h,i,r,q;
9+
e=400.0*(p.x*0.5+0.5);
10+
f=400.0*(p.y*0.5+0.5);
11+
i=200.0+sin(e*g+a/150.0)*20.0;
12+
d=200.0+cos(f*g/2.0)*18.0+cos(e*g)*7.0;
13+
r=sqrt(pow(i-e,2.0)+pow(d-f,2.0));
14+
q=f/r;
15+
e=(r*cos(q))-a/2.0;f=(r*sin(q))-a/2.0;
16+
d=sin(e*g)*176.0+sin(e*g)*164.0+r;
17+
h=((f+d)+a/2.0)*g;
18+
i=cos(h+r*p.x/1.3)*(e+e+a)+cos(q*g*6.0)*(r+h/3.0);
19+
h=sin(f*g)*144.0-sin(e*g)*212.0*p.x;
20+
h=(h+(f-e)*q+sin(r-(a+h)/7.0)*10.0+i/4.0)*g;
21+
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);
22+
i=mod(i/5.6,256.0)/64.0;
23+
if(i<0.0) i+=4.0;
24+
if(i>=2.0) i=4.0-i;
25+
d=r/350.0;
26+
d+=sin(d*d*8.0)*0.52;
27+
f=(sin(a*g)+1.0)/2.0;
28+
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);
29+
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL