2014-01-04 19:08:00 -05:00
|
|
|
#version 130
|
2013-11-30 16:33:06 -05:00
|
|
|
uniform sampler2D ntex;
|
2014-01-27 13:10:34 -05:00
|
|
|
uniform sampler2D dtex;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2013-12-26 19:34:41 -05:00
|
|
|
uniform vec4 center[16];
|
|
|
|
uniform vec4 col[16];
|
|
|
|
uniform float energy[16];
|
2013-11-30 16:33:06 -05:00
|
|
|
uniform float spec;
|
2013-12-18 19:13:17 -05:00
|
|
|
uniform mat4 invproj;
|
2013-12-26 17:55:15 -05:00
|
|
|
uniform mat4 viewm;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-01-13 20:24:28 -05:00
|
|
|
in vec2 uv;
|
2014-01-19 13:31:00 -05:00
|
|
|
out vec4 Diffuse;
|
|
|
|
out vec4 Specular;
|
2014-01-13 20:24:28 -05:00
|
|
|
|
2013-11-30 16:33:06 -05:00
|
|
|
void main() {
|
2014-01-13 20:24:28 -05:00
|
|
|
vec2 texc = uv;
|
2014-01-27 13:10:34 -05:00
|
|
|
float z = texture(dtex, texc).x;
|
2014-01-27 16:21:16 -05:00
|
|
|
vec3 norm = normalize(2. * texture(ntex, texc).xyz - 1.);
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2013-12-18 19:13:17 -05:00
|
|
|
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
|
|
|
|
xpos = invproj * xpos;
|
|
|
|
xpos /= xpos.w;
|
2014-01-22 16:22:54 -05:00
|
|
|
vec3 eyedir = normalize(xpos.xyz);
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2013-12-26 17:55:15 -05:00
|
|
|
vec3 diffuse = vec3(0.), specular = vec3(0.);
|
|
|
|
|
2013-12-29 13:37:45 -05:00
|
|
|
for (int i = 0; i < 16; ++i) {
|
2013-12-26 17:55:15 -05:00
|
|
|
vec4 pseudocenter = viewm * vec4(center[i].xyz, 1.0);
|
|
|
|
pseudocenter /= pseudocenter.w;
|
|
|
|
vec3 light_pos = pseudocenter.xyz;
|
|
|
|
vec3 light_col = col[i].xyz;
|
|
|
|
float d = distance(light_pos, xpos.xyz);
|
|
|
|
float att = energy[i] * 200. / (4. * 3.14 * d * d);
|
2013-12-27 12:03:02 -05:00
|
|
|
float spec_att = (energy[i] + 10.) * 200. / (4. * 3.14 * d * d);
|
2013-12-26 17:55:15 -05:00
|
|
|
|
|
|
|
// Light Direction
|
|
|
|
vec3 L = normalize(xpos.xyz - light_pos);
|
|
|
|
|
|
|
|
float NdotL = max(0.0, dot(norm, -L));
|
|
|
|
diffuse += NdotL * light_col * att;
|
|
|
|
// Reflected light dir
|
|
|
|
vec3 R = reflect(-L, norm);
|
2014-01-22 16:22:54 -05:00
|
|
|
float RdotE = max(0.0, dot(R, eyedir));
|
2013-12-26 17:55:15 -05:00
|
|
|
float Specular = pow(RdotE, spec);
|
2013-12-26 21:41:58 -05:00
|
|
|
specular += Specular * light_col * spec_att;
|
2013-12-26 17:55:15 -05:00
|
|
|
}
|
|
|
|
|
2014-01-19 13:31:00 -05:00
|
|
|
Diffuse = vec4(diffuse, 1.);
|
|
|
|
Specular = vec4(specular , 1.);
|
2013-11-30 16:33:06 -05:00
|
|
|
}
|