fisheyeFragmentShader top-level property
Implementation
final ShaderObject fisheyeFragmentShader = ShaderObject("FisheyePassF")
..AddUniformVars([uTexture])
..SetBody([
"""
float fisheye_radius = 1.0;
void main() {
vec2 dim = vec2(textureSize(${uTexture}, 0));
vec2 pixel = gl_FragCoord.xy / dim;
float y = (pixel.y-0.5) * 2.0; // [0,1] => [-1, 1]
float angle = asin(y/fisheye_radius); // [-pi/2, pi/2]
float arc_length = angle * fisheye_radius;
float max_arc_length = asin(1.0 / fisheye_radius) * fisheye_radius;
float normalized_arc_length = (arc_length + max_arc_length) /
(max_arc_length * 2.0);
// set arc_length as y
vec2 uv = vec2(pixel.x, normalized_arc_length);
${oFragColor} = texelFetch(${uTexture}, ivec2(dim *uv), 0);
}
"""
]);