Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
GLSL Bumped Specular
// Final for now...
// iPhone 3Gs: 5.9ms
#ifdef VERTEX
attribute vec4 a_position;
attribute vec2 a_uv;
attribute vec3 a_normal;
attribute vec4 a_tangent;
uniform mat4 u_mvp;
uniform mat4 u_world2object;
uniform vec4 u_worldlightdir;
uniform vec4 u_worldcampos;
varying vec2 v_uv;
varying vec3 v_lightdir;
varying vec3 v_halfdir;
void main()
gl_Position = u_mvp * a_position;
v_uv = a_uv;
vec3 bitan = cross (, * a_tangent.w;
mat3 tsprotation = mat3 (
a_tangent.x, bitan.x, a_normal.x,
a_tangent.y, bitan.y, a_normal.y,
a_tangent.z, bitan.z, a_normal.z);
vec3 objLightDir = (u_world2object * u_worldlightdir).xyz;
vec3 objCamPos = (u_world2object * u_worldcampos).xyz;
vec3 objViewDir = objCamPos -;
v_lightdir = tsprotation * objLightDir;
vec3 viewdir = normalize(tsprotation * objViewDir);
v_halfdir = normalize (v_lightdir + viewdir);
uniform lowp vec4 u_lightcolor;
uniform lowp vec4 u_matcolor;
uniform mediump float u_spec;
varying mediump vec2 v_uv;
varying lowp vec3 v_lightdir;
varying lowp vec3 v_halfdir;
uniform sampler2D u_texcolor;
uniform sampler2D u_texnormal;
uniform sampler2D u_texLUT;
void main()
lowp vec4 albedo = texture2D (u_texcolor, v_uv);
lowp vec3 normal = texture2D (u_texnormal, v_uv).rgb * 2.0 - 1.0;
lowp float diff = dot (normal, v_lightdir);
lowp float nh = dot (normal, v_halfdir);
lowp vec2 luv = vec2(diff,nh);
lowp vec4 l = texture2D (u_texLUT, luv);
lowp vec4 c = albedo * l + l.a;
gl_FragColor = c;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment