2013-11-30 16:33:06 -05:00
|
|
|
uniform sampler2D ntex;
|
2014-01-27 14:08:59 -05:00
|
|
|
uniform sampler2D dtex;
|
2014-01-21 17:44:23 -05:00
|
|
|
//uniform sampler2D cloudtex;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-01-21 17:44:23 -05:00
|
|
|
uniform vec3 direction;
|
2013-11-30 16:33:06 -05:00
|
|
|
uniform vec3 col;
|
2013-12-18 19:13:17 -05:00
|
|
|
uniform mat4 invproj;
|
2014-01-21 17:44:23 -05:00
|
|
|
//uniform int hasclouds;
|
|
|
|
//uniform vec2 wind;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-05-02 12:11:34 -04:00
|
|
|
#ifdef UBO_DISABLED
|
|
|
|
uniform mat4 ViewMatrix;
|
|
|
|
uniform mat4 ProjectionMatrix;
|
|
|
|
uniform mat4 InverseViewMatrix;
|
|
|
|
uniform mat4 InverseProjectionMatrix;
|
|
|
|
#else
|
|
|
|
layout (std140) uniform MatrixesData
|
|
|
|
{
|
|
|
|
mat4 ViewMatrix;
|
|
|
|
mat4 ProjectionMatrix;
|
|
|
|
mat4 InverseViewMatrix;
|
|
|
|
mat4 InverseProjectionMatrix;
|
|
|
|
mat4 ShadowViewProjMatrixes[4];
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2014-02-28 11:29:05 -05:00
|
|
|
#if __VERSION__ >= 130
|
2014-01-21 17:44:23 -05:00
|
|
|
in vec2 uv;
|
2014-01-19 13:31:00 -05:00
|
|
|
out vec4 Diff;
|
|
|
|
out vec4 Spec;
|
2014-02-28 11:29:05 -05:00
|
|
|
#else
|
|
|
|
varying vec2 uv;
|
|
|
|
#define Diff gl_FragData[0]
|
|
|
|
#define Spec gl_FragData[1]
|
|
|
|
#endif
|
|
|
|
|
2014-01-19 13:31:00 -05:00
|
|
|
|
2014-03-21 13:17:21 -04:00
|
|
|
vec3 DecodeNormal(vec2 n);
|
2014-04-06 17:57:54 -04:00
|
|
|
vec3 getSpecular(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float roughness);
|
2014-05-02 12:11:34 -04:00
|
|
|
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
|
2014-01-27 17:29:46 -05:00
|
|
|
|
2013-11-30 16:33:06 -05:00
|
|
|
void main() {
|
2014-01-27 14:08:59 -05:00
|
|
|
float z = texture(dtex, uv).x;
|
2014-05-02 12:11:34 -04:00
|
|
|
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
|
2013-11-30 16:33:06 -05:00
|
|
|
|
|
|
|
if (z < 0.03)
|
|
|
|
{
|
|
|
|
// Skyboxes are fully lit
|
2014-01-19 13:31:00 -05:00
|
|
|
Diff = vec4(1.0);
|
|
|
|
Spec = vec4(1.0);
|
2013-11-30 16:33:06 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-27 17:29:46 -05:00
|
|
|
vec3 norm = normalize(DecodeNormal(2. * texture(ntex, uv).xy - 1.));
|
2014-04-06 16:19:10 -04:00
|
|
|
float roughness = texture(ntex, uv).z;
|
2014-04-06 15:23:09 -04:00
|
|
|
vec3 eyedir = -normalize(xpos.xyz);
|
2013-11-30 16:33:06 -05:00
|
|
|
|
|
|
|
// Normalized on the cpu
|
2014-04-06 15:23:09 -04:00
|
|
|
vec3 L = direction;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-04-06 15:23:09 -04:00
|
|
|
float NdotL = max(0., dot(norm, L));
|
|
|
|
|
2014-04-06 17:57:54 -04:00
|
|
|
vec3 Specular = getSpecular(norm, eyedir, L, col, roughness) * NdotL;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
|
|
|
vec3 outcol = NdotL * col;
|
|
|
|
|
2014-01-21 17:44:23 -05:00
|
|
|
/* if (hasclouds == 1)
|
2013-11-30 16:33:06 -05:00
|
|
|
{
|
|
|
|
vec2 cloudcoord = (xpos.xz * 0.00833333) + wind;
|
2014-01-19 12:53:35 -05:00
|
|
|
float cloud = texture(cloudtex, cloudcoord).x;
|
2013-11-30 16:33:06 -05:00
|
|
|
//float cloud = step(0.5, cloudcoord.x) * step(0.5, cloudcoord.y);
|
|
|
|
|
|
|
|
outcol *= cloud;
|
2014-01-21 17:44:23 -05:00
|
|
|
}*/
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-01-19 13:31:00 -05:00
|
|
|
Diff = vec4(NdotL * col, 1.);
|
2014-04-06 17:57:54 -04:00
|
|
|
Spec = vec4(Specular, 1.);
|
2013-11-30 16:33:06 -05:00
|
|
|
}
|