1
0
Files
avidemux_shaders/gopro_8:7/unfish_gopro_8:7.glsl

66 lines
1.8 KiB
Plaintext
Raw Normal View History

2025-06-15 10:57:43 +02:00
// RozK
2025-06-15 16:49:25 +02:00
// Fisheye removal for GoPro 11+, 8:7 ratio, without hypersmooth
// Adapted from https://github.com/duducosmos/defisheye
2025-06-15 10:57:43 +02:00
// itself based on http://www.fmwconcepts.com/imagemagick/defisheye/index.php
#extension GL_ARB_texture_rectangle: enable
2025-09-10 13:56:31 +02:00
// TODO: investigate
// precision highp float;
// uniforms
uniform sampler2DRect myTextureY;
uniform sampler2DRect myTextureU;
uniform sampler2DRect myTextureV;
uniform vec2 myResolution;
uniform float pts;
2025-09-10 13:56:31 +02:00
// parameters
2025-06-15 10:57:43 +02:00
const float input_fov = 156.0;
2025-09-10 13:56:31 +02:00
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 * pixel_scale) * ((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() {
2025-09-10 13:56:31 +02:00
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));
}
}
gl_FragColor = pixel * subscale;
}