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
|
|
|
uniform float spec;
|
2013-12-18 19:13:17 -05:00
|
|
|
uniform mat4 invproj;
|
2014-03-10 18:29:37 -04:00
|
|
|
uniform mat4 ViewMatrix;
|
|
|
|
uniform vec2 screen;
|
|
|
|
|
|
|
|
flat in vec3 center;
|
|
|
|
flat in float energy;
|
|
|
|
flat in vec3 col;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-01-19 13:31:00 -05:00
|
|
|
out vec4 Diffuse;
|
|
|
|
out vec4 Specular;
|
2014-01-13 20:24:28 -05:00
|
|
|
|
2014-03-21 13:17:21 -04:00
|
|
|
vec3 DecodeNormal(vec2 n);
|
2014-01-27 17:29:46 -05:00
|
|
|
|
2014-04-06 15:23:09 -04:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec2 texc = gl_FragCoord.xy / screen;
|
|
|
|
float z = texture(dtex, texc).x;
|
|
|
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
|
2014-04-06 16:19:10 -04:00
|
|
|
float roughness = texture(ntex, texc).z;
|
2014-04-06 15:23:09 -04:00
|
|
|
|
|
|
|
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
|
|
|
|
xpos = invproj * xpos;
|
|
|
|
xpos /= xpos.w;
|
|
|
|
vec3 eyedir = -normalize(xpos.xyz);
|
|
|
|
|
|
|
|
vec4 pseudocenter = ViewMatrix * vec4(center.xyz, 1.0);
|
|
|
|
pseudocenter /= pseudocenter.w;
|
|
|
|
vec3 light_pos = pseudocenter.xyz;
|
|
|
|
vec3 light_col = col.xyz;
|
|
|
|
float d = distance(light_pos, xpos.xyz);
|
|
|
|
float att = energy * 200. / (4. * 3.14 * d * d);
|
|
|
|
float spec_att = (energy + 10.) * 200. / (4. * 3.14 * d * d);
|
|
|
|
|
|
|
|
// Light Direction
|
|
|
|
vec3 L = -normalize(xpos.xyz - light_pos);
|
|
|
|
// Half Light View direction
|
|
|
|
vec3 H = normalize(eyedir + L);
|
|
|
|
|
|
|
|
float NdotL = max(0., dot(norm, L));
|
|
|
|
float NdotH = max(0., dot(norm, H));
|
2014-04-06 16:19:10 -04:00
|
|
|
float normalisationFactor = (roughness + 2.) / 8.;
|
2014-04-06 15:23:09 -04:00
|
|
|
|
|
|
|
Diffuse = vec4(NdotL * light_col * att, 1.);
|
2014-04-06 16:19:10 -04:00
|
|
|
Specular = vec4(pow(NdotH, roughness) * light_col * NdotL * spec_att * normalisationFactor, 1.);
|
2013-11-30 16:33:06 -05:00
|
|
|
}
|