## Aduki shader

Got this toying with a GLSL Sandbox.

It's my first shader ever!! :D

Here's the code:

``````
#ifdef GL_ES
precision highp float;
#endif

uniform float time;
uniform vec2 resolution;

void main( void ) {

vec2 position = gl_FragCoord.xy / resolution.xy;

float color = 0.0;
float t = time / 8.0;

float r = 0.7 + 0.35 * (sin(position.x + t) + sin(position.x + t * 5.0));
float g = 1.0 + 0.5 * sin(t);
float b = 0.7 + 0.35 * (sin(position.y + t * 1.7) + sin(position.y + t*0.5) );

gl_FragColor = vec4( vec3( r, g, b ), 1.0 );

}
``````

I actually wanted to replicate the crappy plasma effect I did for "Killotrona", but the original code is an scary, terrible mess:

``````
// [...]
this->colorList[x][y].x=0.7+0.5*(sin(vertexList[x][y].x+t + vertexList[x][y].z)+sin(vertexList[x][y].x+t*5 + vertexList[x][y].z));//+0.5*sin(vertexList[x][y].x+t);
this->colorList[x][y].y=2+sin(t);//1+0.5*(sin(vertexList[x][y].x+t*0.1 + vertexList[x][y].z)+sin(vertexList[x][y].y+t*2 + vertexList[x][y].z));
this->colorList[x][y].z=0.7+0.5*(sin(vertexList[x][y].y+t*1.7 + vertexList[x][y].z)+sin(vertexList[x][y].y+t*0.5 + vertexList[x][y].z)) +this->colorList[x][y].x;

this->colorList[x][y].x=fmod(this->colorList[x][y].x + this->colorList[x][y].y,1.1+cos(t));
this->colorList[x][y].z=fmod(this->colorList[x][y].z + this->colorList[x][y].y,1.1+sin(t));

aux=this->colorList[x][y].y;
this->colorList[x][y].y=this->colorList[x][y].x;
this->colorList[x][y].x=aux;

this->vertexList[x][y].z=10*(sin(t*0.1)+cos(t*0.5));
// [...]
``````

Although it's a bit hard to follow, that code updates a list of colours on each iteration, and these colours are then used for the next iteration. I have no idea how to do this with shaders... I have the notion that you need a texture of sorts to store that kind of values but I'm not sure.

Also, it's not shown in the above fragment but the code also scales the entire output cyclically:

``````
float sx=1.5+0.5*(sin(t_elapsed*0.1)+cos(t_elapsed*0.2));
float sy=1.5+0.5*cos(t_elapsed*0.1);
glScalef(sx,sy,1);
``````

I guess this could be emulated by multiplying the values we send to the various sin() functions with the output of another sin which is function of time, so that the scaling is cyclical, but again, I'm quite unsure...

It's nice to see how clean GLSL code is, though. I might even finally learn it after five years promising to do so! But I have an excuse: having to include glew and all that is just so cumbersome...!