Prigmatego (Voronoi + GlSl + Shaders)

Prigmatego from Armando Rodriguez on Vimeo.

This work shows an environment of creatures called “prigmategos”, which owe their name to their own generative nature extrapolated to phonetics.  These artificial creatures interact in such a way that they create their own movements, color patterns and evolution form.

“Prigmatego” is a work that encompasses different techniques and mathematical concepts. Recently I’ve been experimenting with shaders and GLSL language in Processing to create generative animations and interactive experiences. Every “prigmatego” is initially generated by geometric equations and Voronoi diagrams to give them form and identity. Eventually, these creatures will evolve their characteristics in order to create other complex forms.

//////////////////////////////////////////////SOURCE CODE////////////////////////////////////////////////////

////////////////////////////////// ///////PROCESSING CODE///////////////////////////////////////////////

 

import megamu.mesh.*;
Voronoi myVoronoi;
int sizeX = 1663, diam =600;
float[][] points = new float[sizeX][2];
float[] diametros = new float[sizeX * 2];
float[] noisa= new float[sizeX * 2];
float[] noisaADD= new float[sizeX * 2];

 

float movX =0, movY = 0;
float randAngle = random(TWO_PI);
float saveAngle;

 

////EASING/////////////////////////////////////////////////////
import penner.easing.*;

 

int time= 0;
float beginning= 4.9;
float change = 0.1;
float duration = 600;

 

/////SHADER

PShader Shrtoy;
float y= 0;

 

void setup() {
size(1920, 1080, P3D);
smooth();

Shrtoy = loadShader(“warping.glsl”);
Shrtoy.set(“iResolution”, float(1), float(1));

//guardamos el angulo de creacion de la figura
saveAngle = randAngle;
for (int i = 0; i < sizeX; i++) {
for (int j = 0; j < 2; j++) {
if (j == 0) {
points[i][j] = diam + random(100);
} else {
points[i][j] = diam + random(100);
}
}
}
/////////////////Se almacenan los diametros de cada punto, se asigna el valor ruido y se llena en ceros el aumento

int t = 0;
for (int i = 0; i < sizeX; i++) {
for (int j = 0; j < 2; j++) {
diametros[t] = points[i][j];
noisa[t]=random(10000);
noisaADD[t]= 0;
t++;
}
}

strokeWeight(0.1);
}

void draw() {

Shrtoy.set(“iGlobalTime”, y / 1000.0);
float dato = map(mouseX, width, height, 0, 3);
float dato2 = map(mouseY, width, height, 0, 1);
Shrtoy.set(“mouseX”, dato);
Shrtoy.set(“mouseY”, dato2);
filter(Shrtoy);
y=frameCount*10*dato;

myVoronoi = new Voronoi( points );
float[][] myEdges = myVoronoi.getEdges();
MPolygon[] myRegions = myVoronoi.getRegions();

for (int i=0; i<myEdges.length; i++)
{
float startX = myEdges[i][0];
float startY = myEdges[i][1];
float endX = myEdges[i][2];
float endY = myEdges[i][3];
line( startX, startY, endX, endY );
}

for (int i=0; i< myRegions.length; i++)
{
fill(0, 0, map(i, 0, myRegions.length, 140, 255),132);
if (i%2==0) {
noFill();
}
myRegions[i].draw(this); // draw this shape
}

int t = 0;
for (int i = 0; i < sizeX; i++) {

for (int j = 0; j < 2; j++) {
if (j == 0) {
points[i][j] = ( sin(randAngle) *diametros[t]/1.8 ) + width/2 + noisaADD[t];
}
if (j == 1) {
points[i][j] = ( cos(randAngle * Quad.easeInOut (time, beginning, change, duration)) * diametros[t]/1.8 ) + height/2 + noisaADD[t];
}
randAngle += 0.01;
noisaADD[t] += (noise(noisa[t])-0.5)/28;
noisa[t] += 0.001;
t++;
}
}
randAngle = saveAngle;
if (time < duration) time++;
// saveFrame(“C1-######.png”);
}

 

 

//////////////////////////////////////////////GLSL SOURCE CODE////////////////////////////////////////////

uniform vec2 iResolution;
uniform float iGlobalTime;
uniform float mouseX;
uniform float mouseY;
const mat2 m = mat2( 0.90, 0.70, -0.70, 0.90 );

 

float hash( float n )
{
return fract(sin(n)*43758.5453);
}

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 sin(1.3*x.x)*cos(res)*cos(1.5*x.y)*sin(sin(1.6*x.x));
}

float fbm4( vec2 p )
{
float f = 0.0;
f += 0.5000*noise( p ); p = m*p*mouseX;
f += 0.2500*noise( p ); p = m*p*mouseX;
f += 0.1250*noise( p ); p = m*p*mouseX;
f += 0.0625*noise( p );
return f/0.9375;
}

float fbm6( vec2 p )
{
float f = 0.0;
f += 0.500000*(0.5+0.5*noise( p )); p = m*p*2.32;
f += 0.250000*(0.5+0.5*noise( p )); p = m*p*2.33;
f += 0.125000*(0.5+0.5*noise( p )); p = m*p*2.31;
f += 0.062500*(0.5+0.5*noise( p )); p = m*p*2.34;
f += 0.031250*(0.5+0.5*noise( p )); p = m*p*2.31;
f += 0.015625*(0.5+0.5*noise( p ));
return f/0.96875;
}

float fbm8( vec2 p )
{
float f = 0.0;
f += 0.700000*(0.5+0.5*noise( p )); p = m*p*1.32;
f += 0.556540*(0.5+0.5*noise( p )); p = m*p*1.33;
f += 0.434000*(0.5+0.5*noise( p )); p = m*p*1.31;
f += 0.252500*(0.5+0.5*noise( p )); p = m*p*1.34;
f += 0.134500*(0.5+0.5*noise( p )); p = m*p*1.30;
f += 0.062450*(0.5+0.5*noise( p )); p = m*p*1.33;
f += 0.027550*(0.5+0.5*noise( p )); p = m*p*1.31;
f += 0.016565*(0.5+0.5*noise( p ));
return f/0.98853;
}

float fbm16( vec2 p )
{
float f = 0.0;
f += 0.800000*(0.5+0.5*noise( p )); p = m*p*1.42;
f += 0.756540*(0.5+0.5*noise( p )); p = m*p*1.43;
f += 0.634000*(0.5+0.5*noise( p )); p = m*p*1.41;
f += 0.552500*(0.5+0.5*noise( p )); p = m*p*1.44;
f += 0.434500*(0.5+0.5*noise( p )); p = m*p*1.40;
f += 0.162450*(0.5+0.5*noise( p )); p = m*p*1.43;
f += 0.127550*(0.5+0.5*noise( p )); p = m*p*1.41;
f += 0.10565*(0.5+0.5*noise( p ));
return f/0.98853;
}

 

float func( vec2 q, out vec4 ron )
{
float ql = length( q );
q.x += 0.05*sin(sin(0.27*iGlobalTime+ql*4.1));
q.y += 0.05*cos(0.23*iGlobalTime+ql*4.3)*sin(sin(0.27*iGlobalTime+ql*4.1));
q *= 0.5;

vec2 o = vec2(0.0);
o.x = 0.5 + 0.5*fbm4( vec2(15.0*q +vec2(3.2) ) );
o.y = 0.5 + 0.5*fbm4( vec2(15*q+vec2(5.2)) );

float ol = length( o );
o.x += 0.4*sin((0.12*iGlobalTime+ol))/ol;
o.y += 0.4*cos((0.14*iGlobalTime*2+ol))/ol;

vec2 n;
n.x = fbm6( vec2(4.0*o+vec2(9.2)) );
n.y = fbm6( vec2(4.0*o+vec2(5.7)) );
/////NEW/////////////////////////////////////////////////
float oli = length( n );
n.x += 0.4*sin((0.12*iGlobalTime+oli))/oli;
n.y += 0.4*cos((0.14*iGlobalTime*2+oli))/oli;

vec2 m;
m.x = fbm6( vec2(4.0*n+vec2(3.2)) );
m.y = fbm6( vec2(4.0*n+vec2(6.7)) );

 

/////NEW/////////////////////////////////////////////////
float oli2 = length( m );
m.x += 0.4*sin((0.12*iGlobalTime+oli2))/oli2;
m.y += 0.4*cos((0.14*iGlobalTime*2+oli2))/oli2;

vec2 l;
l.x = fbm16( vec2(0.10*m+vec2(3.2)) );
l.y = fbm16( vec2(0.10*m+vec2(6.7)) );

 

//illuminacion
vec2 p = 8.0*q + 8.0*m + 8.0*n + 0.8*l ;

float f = 0.5 + 0.5*fbm4( p );

f = mix( f, f*f*f*1.5, f*abs(n.y) );

float g = 0.5 + 0.5*sin(sin(4.0*p.x))*sin(cos(4.0*p.y));
f *= 1.0-0.5*pow( g, 28.0 );

ron = vec4( o, n );

return f;
}

vec3 doMagic(vec2 p)
{
vec2 q = p*0.0005;

vec4 on = vec4(0.0);
float f = func(q, on);

vec3 col = vec3(0.0);
////////////////////////////////////DESTELLO////////
col = mix( vec3(mouseY,0.1,0.7), vec3(0.09,0.3,0.02), f );
////////////////COLOR 2 OJO//////////////////////////
col = mix( col, vec3(0.9,0.3,0.2), dot(on.zz,on.zx) );
col = mix( col, vec3(0.1,0.6,0.1), 0.2*on.y*on.y );
//fondo
col = mix( col, vec3(0.9,0.3,0.09), 0.9*smoothstep(1.2,1.3,abs(on.z)+abs(on.w)) );
col = clamp( col*f*2.0, 0.0, 1.0 );

 

vec3 nor = normalize( vec3( dFdx(f)*iResolution.x, 6.0, dFdy(f)*iResolution.y ) );
vec3 lig = normalize( vec3( 0.9, -0.2, -0.4 ) );
float dif = clamp( 0.5+0.7*dot( nor, lig ), 0.0, 1.0 );
vec3 bdrf;
bdrf = vec3(0.70,0.7,0.95)*(nor.y*0.9+0.5);
bdrf += vec3(0.85,0.10,0.5)*dif;
col *= 1.0*bdrf;
col = 1.0-col;
//1.3 brillo
return 1.2*col*col;
}

 

 

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{

vec2 q = fragCoord.xy / iResolution.xy;
vec2 p = -1.0 + 2.0 * q;
p.x *= iResolution.x/(iResolution.y);
p.y *= iResolution.x/(iResolution.y);

fragColor = vec4( doMagic( p ), 0.3 );
}
void main() {
mainImage(gl_FragColor,gl_FragCoord.xy);
}

Anuncios

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión /  Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s