66 lines
1.8 KiB
GLSL
66 lines
1.8 KiB
GLSL
// RozK
|
|
// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
|
|
// Adapted from https://github.com/duducosmos/defisheye
|
|
// itself based on http://www.fmwconcepts.com/imagemagick/defisheye/index.php
|
|
|
|
#extension GL_ARB_texture_rectangle: enable
|
|
|
|
// TODO: investigate
|
|
// precision highp float;
|
|
|
|
// uniforms
|
|
uniform sampler2DRect myTextureY;
|
|
uniform sampler2DRect myTextureU;
|
|
uniform sampler2DRect myTextureV;
|
|
uniform vec2 myResolution;
|
|
uniform float pts;
|
|
|
|
// parameters
|
|
const float input_fov = 156.0;
|
|
const float output_fov = 124.45;
|
|
const vec2 pixel_scale = vec2(0.652485, 1.0);
|
|
const int subsampling = 4;
|
|
|
|
// subsampling constants
|
|
const float substep = 1.0 / float(subsampling);
|
|
const float substart = substep * 0.5 - 0.5;
|
|
const float subscale = 1.0 / float(subsampling * subsampling);
|
|
|
|
// variables
|
|
vec2 center;
|
|
float diameter;
|
|
float input_len;
|
|
float inv_output_len;
|
|
|
|
vec4 unfish(const in vec2 coord) {
|
|
float len = max(0.001, length(coord));
|
|
vec2 y_coord = center + coord * ((input_len / len) * atan(len * inv_output_len));
|
|
vec2 uv_coord = y_coord * 0.5;
|
|
return vec4(
|
|
texture2DRect(myTextureY, y_coord).r,
|
|
texture2DRect(myTextureU, uv_coord).r,
|
|
texture2DRect(myTextureV, uv_coord).r,
|
|
1.0
|
|
);
|
|
}
|
|
|
|
void main() {
|
|
center = myResolution * 0.5;
|
|
diameter = length(myResolution);
|
|
input_len = diameter / radians(input_fov);
|
|
inv_output_len = (2.0 * tan(radians(output_fov * 0.5))) / diameter;
|
|
|
|
vec2 coord = gl_TexCoord[0].xy - center;
|
|
vec4 pixel = vec4(0.0, 0.0, 0.0, 0.0);
|
|
|
|
float x, y = substart;
|
|
for (int column = 0; column < subsampling; column++, y += substep) {
|
|
x = substart;
|
|
for (int row = 0; row < subsampling; row++, x += substep) {
|
|
pixel += unfish((coord + vec2(x, y)) * pixel_scale);
|
|
}
|
|
}
|
|
|
|
gl_FragColor = pixel * subscale;
|
|
}
|