Skip to content

Instantly share code, notes, and snippets.

@ykob
Last active January 19, 2017 08:06
Show Gist options
  • Save ykob/38a48bd2752e13f3e2c1d8bcf173d6da to your computer and use it in GitHub Desktop.
Save ykob/38a48bd2752e13f3e2c1d8bcf173d6da to your computer and use it in GitHub Desktop.
uniform vec3 light_direction;
varying vec3 vPosition;
varying vec3 vColor;
varying mat4 vInvertMatrix;
void main() {
vec3 normal = normalize(cross(dFdx(vPosition), dFdy(vPosition)));
vec3 inv_light = normalize(vInvertMatrix * vec4(light_direction, 1.0)).xyz;
float diff = clamp(dot(normal, inv_light), 0.0, 1.0);
gl_FragColor = vec4(vColor * diff, 1.0);
}
attribute vec3 position;
attribute vec3 color;
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
varying vec3 vPosition;
varying vec3 vColor;
varying mat4 vInvertMatrix;
#pragma glslify: inverse = require(glsl-inverse);
void main() {
vPosition = position;
vPosition = color;
vInvertMatrix = inverse(modelMatrix);
gl_Position = projectionMatrix * modelViewMatrix * position;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment