2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2017-09-28 14:15:21 +02:00
|
|
|
[vertex]
|
|
|
|
|
2018-12-15 22:47:47 +01:00
|
|
|
#ifdef USE_GLES_OVER_GL
|
2018-12-21 15:14:55 +01:00
|
|
|
#define lowp
|
2018-12-15 22:47:47 +01:00
|
|
|
#define mediump
|
|
|
|
#define highp
|
|
|
|
#else
|
|
|
|
precision highp float;
|
|
|
|
precision highp int;
|
|
|
|
#endif
|
|
|
|
|
2018-09-30 22:51:50 +02:00
|
|
|
attribute highp vec2 vertex; // attrib:0
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2017-09-28 14:15:21 +02:00
|
|
|
|
2018-09-30 22:51:50 +02:00
|
|
|
uniform vec2 offset;
|
|
|
|
uniform vec2 scale;
|
2017-09-28 14:15:21 +02:00
|
|
|
|
2018-09-30 22:51:50 +02:00
|
|
|
varying vec2 uv_interp;
|
2017-09-28 14:15:21 +02:00
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
2018-09-30 22:51:50 +02:00
|
|
|
uv_interp = vertex.xy * 2.0 - 1.0;
|
|
|
|
|
|
|
|
vec2 v = vertex.xy * scale + offset;
|
|
|
|
gl_Position = vec4(v, 0.0, 1.0);
|
2017-09-28 14:15:21 +02:00
|
|
|
}
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2017-09-28 14:15:21 +02:00
|
|
|
[fragment]
|
|
|
|
|
2018-12-15 22:47:47 +01:00
|
|
|
#ifdef USE_GLES_OVER_GL
|
2018-12-21 15:14:55 +01:00
|
|
|
#define lowp
|
2018-12-15 22:47:47 +01:00
|
|
|
#define mediump
|
|
|
|
#define highp
|
|
|
|
#else
|
|
|
|
precision mediump float;
|
|
|
|
precision highp int;
|
|
|
|
#endif
|
|
|
|
|
2017-09-28 14:15:21 +02:00
|
|
|
uniform sampler2D source; //texunit:0
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2017-09-28 14:15:21 +02:00
|
|
|
|
|
|
|
uniform vec2 eye_center;
|
|
|
|
uniform float k1;
|
|
|
|
uniform float k2;
|
|
|
|
uniform float upscale;
|
|
|
|
uniform float aspect_ratio;
|
|
|
|
|
2018-09-30 22:51:50 +02:00
|
|
|
varying vec2 uv_interp;
|
2017-09-28 14:15:21 +02:00
|
|
|
|
|
|
|
void main() {
|
2018-08-27 07:31:48 +02:00
|
|
|
vec2 coords = uv_interp;
|
|
|
|
vec2 offset = coords - eye_center;
|
|
|
|
|
|
|
|
// take aspect ratio into account
|
|
|
|
offset.y /= aspect_ratio;
|
|
|
|
|
|
|
|
// distort
|
|
|
|
vec2 offset_sq = offset * offset;
|
|
|
|
float radius_sq = offset_sq.x + offset_sq.y;
|
|
|
|
float radius_s4 = radius_sq * radius_sq;
|
|
|
|
float distortion_scale = 1.0 + (k1 * radius_sq) + (k2 * radius_s4);
|
|
|
|
offset *= distortion_scale;
|
|
|
|
|
|
|
|
// reapply aspect ratio
|
|
|
|
offset.y *= aspect_ratio;
|
|
|
|
|
|
|
|
// add our eye center back in
|
|
|
|
coords = offset + eye_center;
|
|
|
|
coords /= upscale;
|
|
|
|
|
|
|
|
// and check our color
|
|
|
|
if (coords.x < -1.0 || coords.y < -1.0 || coords.x > 1.0 || coords.y > 1.0) {
|
2018-09-30 22:51:50 +02:00
|
|
|
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
2018-08-27 07:31:48 +02:00
|
|
|
} else {
|
|
|
|
coords = (coords + vec2(1.0)) / vec2(2.0);
|
2018-09-30 22:51:50 +02:00
|
|
|
gl_FragColor = texture2D(source, coords);
|
2018-08-27 07:31:48 +02:00
|
|
|
}
|
2017-09-28 14:15:21 +02:00
|
|
|
}
|