2013-11-30 21:33:06 +00:00
|
|
|
uniform sampler2D ntex;
|
2014-01-27 19:10:34 +01:00
|
|
|
uniform sampler2D dtex;
|
2014-03-10 23:29:37 +01:00
|
|
|
|
|
|
|
flat in vec3 center;
|
|
|
|
flat in float energy;
|
|
|
|
flat in vec3 col;
|
2014-05-12 19:36:45 +02:00
|
|
|
flat in float radius;
|
2013-11-30 21:33:06 +00:00
|
|
|
|
2016-09-12 21:39:52 +02:00
|
|
|
#ifdef GL_ES
|
|
|
|
layout (location = 0) out vec4 Diff;
|
|
|
|
layout (location = 1) out vec4 Spec;
|
|
|
|
#else
|
2014-12-14 21:39:18 +01:00
|
|
|
out vec4 Diff;
|
|
|
|
out vec4 Spec;
|
2016-09-12 21:39:52 +02:00
|
|
|
#endif
|
2014-01-14 01:24:28 +00:00
|
|
|
|
2016-06-27 13:11:27 +02:00
|
|
|
#stk_include "utils/decodeNormal.frag"
|
|
|
|
#stk_include "utils/SpecularBRDF.frag"
|
|
|
|
#stk_include "utils/DiffuseBRDF.frag"
|
|
|
|
#stk_include "utils/getPosFromUVDepth.frag"
|
2014-01-27 23:29:46 +01:00
|
|
|
|
2014-04-06 21:23:09 +02:00
|
|
|
void main()
|
|
|
|
{
|
2017-12-25 14:00:10 +08:00
|
|
|
vec2 texc = gl_FragCoord.xy / u_screen;
|
2014-04-06 21:23:09 +02:00
|
|
|
float z = texture(dtex, texc).x;
|
|
|
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, texc).xy - 1.));
|
2014-04-06 22:19:10 +02:00
|
|
|
float roughness = texture(ntex, texc).z;
|
2014-04-06 21:23:09 +02:00
|
|
|
|
2017-12-25 14:00:10 +08:00
|
|
|
vec4 xpos = getPosFromUVDepth(vec3(texc, z), u_inverse_projection_matrix);
|
2014-04-06 21:23:09 +02:00
|
|
|
vec3 eyedir = -normalize(xpos.xyz);
|
|
|
|
|
2017-12-25 14:00:10 +08:00
|
|
|
vec4 pseudocenter = u_view_matrix * vec4(center.xyz, 1.0);
|
2014-04-06 21:23:09 +02:00
|
|
|
pseudocenter /= pseudocenter.w;
|
|
|
|
vec3 light_pos = pseudocenter.xyz;
|
|
|
|
vec3 light_col = col.xyz;
|
|
|
|
float d = distance(light_pos, xpos.xyz);
|
2014-05-05 01:46:57 +02:00
|
|
|
float att = energy * 20. / (1. + d * d);
|
2014-05-12 19:36:45 +02:00
|
|
|
att *= (radius - d) / radius;
|
2014-05-03 23:44:27 +02:00
|
|
|
if (att <= 0.) discard;
|
2014-04-06 21:23:09 +02:00
|
|
|
|
|
|
|
// Light Direction
|
|
|
|
vec3 L = -normalize(xpos.xyz - light_pos);
|
|
|
|
|
2014-12-05 17:48:56 +01:00
|
|
|
float NdotL = clamp(dot(norm, L), 0., 1.);
|
2014-12-14 21:39:18 +01:00
|
|
|
vec3 Specular = SpecularBRDF(norm, eyedir, L, vec3(1.), roughness);
|
|
|
|
vec3 Diffuse = DiffuseBRDF(norm, eyedir, L, vec3(1.), roughness);
|
2014-04-06 21:23:09 +02:00
|
|
|
|
2014-12-14 21:39:18 +01:00
|
|
|
Diff = vec4(Diffuse * NdotL * light_col * att, 1.);
|
|
|
|
Spec = vec4(Specular * NdotL * light_col * att, 1.);
|
2013-11-30 21:33:06 +00:00
|
|
|
}
|