1.0.0 • Published 8 years ago

glsl-cos-palette v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

cos-palette

cosPalette is a simple shader function that is defined as

vec3 cosPalette(  float t,  vec3 a,  vec3 b,  vec3 c, vec3 d ){
    return a + b*cos( 6.28318*(c*t+d) );
}

where a,b,c,d are RGB-colors. This function can be used to make very compact color palettes. A simple editor for making such palettes is provided here.

If you set t to be the value of some noise function(say, Perlin noise), you can use this palette to make simple procedural textures. In the fragment shader, we can easily procedurally generate a texture by doing something like

    float t = noise(vPosition);
    vec3 tex = cosPalette(t, uAColor, uBColor, uCColor, uDColor );

Credit goes to Inigo Quilez for coming up with this technique.

Examples

Below are some examples of palettes

cosPalette(t,vec3(0.2,0.7,0.4),vec3(0.6,0.9,0.2),vec3(0.6,0.8,0.7),vec3(0.5,0.1,0.0))

cosPalette(t,vec3(0.2,0.5,0.3),vec3(0.0,0.5,0.7),vec3(1.0,1.0,1.0),vec3(0.0,0.3,0.7))

cosPalette(t,vec3(0.6,0.0,0.0),vec3(1.0,0.0,0.0),vec3(1.0,0.0,0.0),vec3(1.0,0.0,0.0))

cosPalette(t,vec3(1.0,0.4,0.0),vec3(0.4,0.8,0.0),vec3(0.5,0.3,0.9),vec3(0.9,0.6,0.9))

cosPalette(t,vec3(0.4,0.3,0.1),vec3(0.1,0.1,0.1),vec3(0.4,0.4,0.4),vec3(0.0,0.0,0.0))