Last active
January 12, 2017 20:02
-
-
Save ayamflow/8e82f5a15543b6f16c20217e8bb7e913 to your computer and use it in GitHub Desktop.
Basic glsl lightning
This file contains hidden or 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
// 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