Last active
March 13, 2016 16:50
-
-
Save Robadob/de2d1cedbe3f0ebf16ee to your computer and use it in GitHub Desktop.
Simple flat shading pair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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