2014-03-03 17:58:01 -05:00
|
|
|
uniform sampler2D displacement_tex;
|
|
|
|
uniform sampler2D mask_tex;
|
|
|
|
uniform sampler2D color_tex;
|
2013-11-30 16:33:06 -05:00
|
|
|
uniform vec2 dir;
|
|
|
|
uniform vec2 dir2;
|
|
|
|
|
2014-05-16 20:39:55 -04:00
|
|
|
layout (std140) uniform MatrixesData
|
|
|
|
{
|
|
|
|
mat4 ViewMatrix;
|
|
|
|
mat4 ProjectionMatrix;
|
|
|
|
mat4 InverseViewMatrix;
|
|
|
|
mat4 InverseProjectionMatrix;
|
|
|
|
mat4 ShadowViewProjMatrixes[4];
|
|
|
|
vec2 screen;
|
|
|
|
};
|
|
|
|
|
2014-02-28 11:29:05 -05:00
|
|
|
#if __VERSION__ >= 130
|
2014-01-08 19:17:28 -05:00
|
|
|
in vec2 uv;
|
2014-01-20 19:18:26 -05:00
|
|
|
in vec2 uv_bis;
|
2014-01-08 19:17:28 -05:00
|
|
|
in float camdist;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-01-19 13:31:00 -05:00
|
|
|
out vec4 FragColor;
|
2014-02-28 11:29:05 -05:00
|
|
|
#else
|
|
|
|
varying vec2 uv;
|
|
|
|
varying vec2 uv_bis;
|
|
|
|
varying float camdist;
|
|
|
|
#define FragColor gl_FragColor
|
|
|
|
#endif
|
|
|
|
|
2014-01-20 19:18:26 -05:00
|
|
|
const float maxlen = 0.02;
|
2014-01-19 13:31:00 -05:00
|
|
|
|
2013-11-30 16:33:06 -05:00
|
|
|
void main()
|
|
|
|
{
|
2014-03-03 17:58:01 -05:00
|
|
|
float horiz = texture(displacement_tex, uv + dir).x;
|
|
|
|
float vert = texture(displacement_tex, (uv.yx + dir2) * vec2(0.9)).x;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
|
|
|
vec2 offset = vec2(horiz, vert);
|
|
|
|
offset *= 2.0;
|
|
|
|
offset -= 1.0;
|
|
|
|
|
|
|
|
// Fade according to distance to cam
|
2013-12-25 20:01:12 -05:00
|
|
|
float fade = 1.0 - smoothstep(1.0, 100.0, camdist);
|
2013-11-30 16:33:06 -05:00
|
|
|
|
|
|
|
// Fade according to distance from the edges
|
|
|
|
const float mindist = 0.1;
|
2014-01-20 19:18:26 -05:00
|
|
|
fade *= smoothstep(0.0, mindist, uv_bis.x) * smoothstep(0.0, mindist, uv_bis.y) *
|
|
|
|
(1.0 - smoothstep(1.0 - mindist, 1.0, uv_bis.x)) *
|
|
|
|
(1.0 - smoothstep(1.0 - mindist, 1.0, uv_bis.y));
|
2013-11-30 16:33:06 -05:00
|
|
|
|
|
|
|
offset *= 50.0 * fade * maxlen;
|
|
|
|
|
2014-03-03 17:58:01 -05:00
|
|
|
vec4 shiftval;
|
|
|
|
shiftval.r = step(offset.x, 0.0) * -offset.x;
|
|
|
|
shiftval.g = step(0.0, offset.x) * offset.x;
|
|
|
|
shiftval.b = step(offset.y, 0.0) * -offset.y;
|
|
|
|
shiftval.a = step(0.0, offset.y) * offset.y;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-03-03 17:58:01 -05:00
|
|
|
vec2 shift;
|
|
|
|
shift.x = -shiftval.x + shiftval.y;
|
|
|
|
shift.y = -shiftval.z + shiftval.w;
|
|
|
|
shift /= 50.;
|
|
|
|
|
|
|
|
vec2 tc = gl_FragCoord.xy / screen;
|
|
|
|
float mask = texture(mask_tex, tc + shift).x;
|
|
|
|
tc += (mask < 1.) ? vec2(0.) : shift;
|
|
|
|
|
|
|
|
FragColor = texture(color_tex, tc);
|
2013-11-30 16:33:06 -05:00
|
|
|
}
|