Skip to content

Instantly share code, notes, and snippets.

@Robadob
Last active March 13, 2016 16:50
Show Gist options
  • Save Robadob/de2d1cedbe3f0ebf16ee to your computer and use it in GitHub Desktop.
Save Robadob/de2d1cedbe3f0ebf16ee to your computer and use it in GitHub Desktop.
Simple flat shading pair
#version 120
varying vec3 u_normal;
void main()
{
//Calculate face normal
vec3 N = normalize(cross(dFdx(u_normal), dFdy(u_normal)));//Face Normal
//This sets the Light source to be the camera
vec3 L = normalize(vec3(0,0,0)-u_normal);
vec3 diffuse = gl_Color.xyz * max(dot(L, N), 0.0);
gl_FragColor = vec4(diffuse.xyz,1);
}
#version 120
varying vec3 u_normal;
void main()
{
//pass gl_Vertex to frag shader to calculate face normal
u_normal = (gl_ModelViewMatrix * gl_Vertex).rgb;
//apply model view proj
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
//Pass gl_Color to frag shader
gl_FrontColor = gl_Color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment