LYGIA Shader Library

fisheye2xyz (lygia/space/fisheye2xyz)

fisheye 2D projection to 3D vector

Dependencies:

Use:

<vec3> fisheye2xyz(<vec2> uv)

Check it on Github



#ifndef FNC_FISHEYE2XYZ
#define FNC_FISHEYE2XYZ
vec3 fisheye2xyz(vec2 uv) {
    vec2 ndc = uv * 2.0 - 1.0;
    float R = sqrt(ndc.x * ndc.x + ndc.y * ndc.y);
    vec3 dir = vec3(ndc.x / R, 0.0, ndc.y / R);
    float Phi = (R) * PI * 0.52;
    dir.y   = cos(Phi);//clamp(, MinCos, 1.0);
    dir.xz *= sqrt(1.0 - dir.y * dir.y);
    return dir;
}
#endif

Dependencies:

Use:

<float3> fisheye2xyz(<float2> uv)

Check it on Github



#ifndef FNC_FISHEYE2XYZ
#define FNC_FISHEYE2XYZ
float3 fisheye2xyz(float2 uv) {
    float2 ndc = uv * 2.0 - 1.0;
    float R = sqrt(ndc.x * ndc.x + ndc.y * ndc.y);
    float3 dir = float3(ndc.x / R, 0.0, ndc.y / R);
    float Phi = (R) * PI * 0.52;
    dir.y   = cos(Phi);//clamp(, MinCos, 1.0);
    dir.xz *= sqrt(1.0 - dir.y * dir.y);
    return dir;
}
#endif

Dependencies:

Use:

<float3> fisheye2xyz(<float2> uv)

Check it on Github



#ifndef FNC_FISHEYE2XYZ
#define FNC_FISHEYE2XYZ
float3 fisheye2xyz(float2 uv) {
    float2 ndc = uv * 2.0 - 1.0;
    float R = sqrt(ndc.x * ndc.x + ndc.y * ndc.y);
    float3 dir = float3(ndc.x / R, 0.0, ndc.y / R);
    float Phi = (R) * PI * 0.52;
    dir.y   = cos(Phi);//clamp(, MinCos, 1.0);
    dir.xz *= sqrt(1.0 - dir.y * dir.y);
    return dir;
}
#endif

Dependencies:

Check it on Github




fn fisheye2xyz(uv: vec2f) -> vec3f {
    let ndc = uv * 2.0 - 1.0;
    let R = sqrt(ndc.x * ndc.x + ndc.y * ndc.y);
    var dir = vec3(ndc.x / R, 0.0, ndc.y / R);
    let Phi = (R) * PI * 0.52;
    dir.y   = cos(Phi);
    let s = sqrt(1.0 - dir.y * dir.y);
    dir.x *= s;
    dir.z *= s;
    return dir;
}

Licenses

LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository