39 lines
1.3 KiB
Plaintext
39 lines
1.3 KiB
Plaintext
|
// RozK
|
||
|
// Fisheye removal for GoPro 11+, 4:3 ratio, Max SuperView, 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
|
||
|
|
||
|
uniform sampler2DRect myTextureY;
|
||
|
uniform sampler2DRect myTextureU;
|
||
|
uniform sampler2DRect myTextureV;
|
||
|
uniform vec2 myResolution;
|
||
|
uniform float pts;
|
||
|
|
||
|
const vec2 half_pixel = vec2(0.5, 0.5);
|
||
|
|
||
|
const vec2 input_scale = vec2(0.602294, 1.0);
|
||
|
const float input_fov = 169.0;
|
||
|
const float output_fov = 122.604854;
|
||
|
|
||
|
vec2 unfish(vec2 coord) {
|
||
|
float diameter = sqrt(dot(myResolution, myResolution));
|
||
|
vec2 center = myResolution * 0.5;
|
||
|
vec2 input_position = (coord - center) * input_scale;
|
||
|
float input_distance = length(input_position);
|
||
|
float input_len = diameter / radians(input_fov);
|
||
|
float output_len = diameter / (2.0 * tan(radians(output_fov) * 0.5));
|
||
|
float unfish_ratio = input_len * atan(input_distance / output_len) / input_distance;
|
||
|
return center + input_position * unfish_ratio;
|
||
|
}
|
||
|
|
||
|
void main() {
|
||
|
vec2 y_coord = unfish(gl_TexCoord[0].xy + half_pixel);
|
||
|
vec2 uv_coord = y_coord * 0.5;
|
||
|
vec4 y = texture2DRect(myTextureY, y_coord);
|
||
|
vec4 u = texture2DRect(myTextureU, uv_coord);
|
||
|
vec4 v = texture2DRect(myTextureV, uv_coord);
|
||
|
gl_FragColor = vec4(y.r, u.r, v.r, 1.0);
|
||
|
}
|