Skip to content

Instantly share code, notes, and snippets.

@mmj-the-fighter
Last active October 25, 2015 10:42
Show Gist options
  • Save mmj-the-fighter/c294504f58a7e9870dfd to your computer and use it in GitHub Desktop.
Save mmj-the-fighter/c294504f58a7e9870dfd to your computer and use it in GitHub Desktop.
Shader for painting cube faces with respect to the direction of the vertex normal . ( March 2012 )
//Copyright © 2015 Manoj M J
//All Rights Reserved
//Why I do copyright the code that I provide at gist.github.com
//( https://gist.github.com/mmj-the-fighter/bccd0a7ff57c638beee8 )
//Development History:
//Authored on : Monday, July 04, 2011 using ShaderDesigner
//Posted to my blog on, July 05, 2011 http://www.gamedev1001.blogspot.in/2011/07/gpu-programming.html
//Posted to gamedev.net on March 25, 2012 http://www.gamedev.net/topic/622385-a-free-shader/
//Updated the blog later: http://www.gamedev1001.blogspot.in/2011/07/gpu-programming.html
varying vec4 color;
void main()
{
gl_FragColor = color;
}
//Copyright © 2015 Manoj M J
//All Rights Reserved
//Why I do copyright the code that I provide at gist.github.com
//( https://gist.github.com/mmj-the-fighter/bccd0a7ff57c638beee8 )
//Development History:
//Authored on : Monday, July 04, 2011 using ShaderDesigner
//Posted to my blog on, July 05, 2011 http://www.gamedev1001.blogspot.in/2011/07/gpu-programming.html
//Posted to gamedev.net on March 25, 2012 http://www.gamedev.net/topic/622385-a-free-shader/
//Updated the blog later: http://www.gamedev1001.blogspot.in/2011/07/gpu-programming.html
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();
gl_Position = ftransform();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment