Created
January 18, 2011 00:31
-
-
Save aras-p/783784 to your computer and use it in GitHub Desktop.
GLSL Bumped Specular Initial
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
#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_viewdir; | |
void main() | |
{ | |
gl_Position = u_mvp * a_position; | |
v_uv = a_uv; | |
vec3 bitan = cross (a_normal.xyz, a_tangent.xyz) * 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 - a_position.xyz; | |
v_lightdir = tsprotation * objLightDir; | |
v_viewdir = tsprotation * objViewDir; | |
} | |
#endif | |
#ifdef FRAGMENT | |
precision highp float; | |
uniform vec4 u_lightcolor; | |
uniform vec4 u_matcolor; | |
uniform float u_spec; | |
varying vec2 v_uv; | |
varying vec3 v_lightdir; | |
varying vec3 v_viewdir; | |
uniform sampler2D u_texcolor; | |
uniform sampler2D u_texnormal; | |
void main() | |
{ | |
vec4 albedo = texture2D (u_texcolor, v_uv) * u_matcolor; | |
vec3 normal = texture2D (u_texnormal, v_uv).rgb * 2.0 - 1.0; | |
vec3 halfdir = normalize (normalize(v_lightdir) + normalize(v_viewdir)); | |
float diff = max (0.0, dot (normal, v_lightdir)); | |
float nh = max (0.0, dot (normal, halfdir)); | |
float spec = pow (nh, u_spec); | |
vec4 c = albedo * u_lightcolor * diff + u_lightcolor * spec; | |
gl_FragColor = c; | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment