Skip to content

Instantly share code, notes, and snippets.

@ayamflow
Last active January 12, 2017 20:02
Show Gist options
  • Save ayamflow/8e82f5a15543b6f16c20217e8bb7e913 to your computer and use it in GitHub Desktop.
Save ayamflow/8e82f5a15543b6f16c20217e8bb7e913 to your computer and use it in GitHub Desktop.
Basic glsl lightning
// Vertex
varying vec3 vNormal;
void main() {
vNormal = normal;
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(position, 1.0);
}
// Fragment
uniform vec3 lightPosition;
uniform vec3 lightColor;
uniform vec3 objectColor;
uniform vec3 ambient;
varying vec3 vNormal;
varying vec2 resolution;
void main() {
// diffuse
vec3 norm = normalize(vNormal);
float brightness = max(0.0, dot(norm, lightPosition));
vec3 diffuse = brightness * lightColor;
gl_FragColor = vec4((ambient + diffuse) * objectColor, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment