• Advertisement
Sign in to follow this  

A free shader

This topic is 2156 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,
The following is a shader I wrote for rubix cube.
I can see it has some educational value.
Feel free, this is in public domain.

//FragmentProgram

varying vec4 color;
void main()
{
gl_FragColor = color;
}


//VertexProgram

varying vec4 color;
const mat4 pal0 =
mat4(1,0.55,0,1,0,0.9,0,1,1,0,0,1,0,0,0.8,1);
const mat4 pal1 =
mat4(1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0);

void colorRubix()
{
if( abs(gl_Normal.x) > 0.5 )
{
if(sign(gl_Normal.x) > 0.0)
{
color = pal0[0]; //orange;
}
else
{
color = pal0[1]; //green
}
}
else if( abs(gl_Normal.y) > 0.5 )
{
if(sign(gl_Normal.y) > 0.0)
{
color = pal0[2]; //red
}
else
{
color = pal0[3];//blue;
}
}
else if(abs(gl_Normal.z) > 0.5 )
{
if(sign(gl_Normal.z) > 0.0)
{
color = pal1[0];//white
}
else
{
color = pal1[1];//yellow
}
}
}
void colorNormalDebug()
{
color = vec4( clamp(abs( (gl_Normal + 1.0) * 0.5),0.0,1.0), 1.0 );
}
void colorHashed()
{
//Note:under construction, experimental
vec3 n = (gl_Normal + 1.0);
float k = 4.0 * n.y + n.z;
k += 2.0*n.x;
k += 5.0;
k = clamp(k,0.0, 6.0);
//use k as an index to fetch a color;
}
void main()
{
color = vec4(1,1,1,1);
colorRubix();
///colorNormalDebug(); //fallback option
gl_Position = ftransform();
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement