LYGIA Shader Library

axis (lygia/draw/axis)

Draw the three axis (X,Y,Z) of a 3D object projected in 2D. The thickness of the axis can be adjusted.

Dependencies:

Use:

<vec4> axis(<vec2> st, <mat4> M, <vec3> pos, <float> thickness)

Check it on Github




#ifndef FNC_AXIS
#define FNC_AXIS

vec4 axis(in vec2 st, mat4 M, vec3 pos, float thickness) {
    vec4 rta = vec4(0.0);

    vec4 center = M * vec4(pos, 1.0);
    center.xy /= center.w;
    center.xy = (center.xy * 0.5 + 0.5);

    vec4 axis[3];
    axis[0] = vec4(1.0, 0.0, 0.0, 1.0);
    axis[1] = vec4(0.0, 1.0, 0.0, 1.0);
    axis[2] = vec4(0.0, 0.0, 1.0, 1.0);

    for (int i = 0; i < 3; i++) {
        #ifdef DEBUG_FLIPPED_SPACE
        vec4 a = M * (vec4(pos - axis[i].xyz, 1.0));
        #else
        vec4 a = M * (vec4(pos + axis[i].xyz, 1.0));
        #endif
        a.xy /= a.w;
        a.xy = (a.xy * 0.5 + 0.5);
        rta += axis[i] * line(st, center.xy, a.xy, thickness);
    } 

    return rta;
}

#endif

Dependencies:

Use:

<float4> axis(<float2> st, <float4x4> M, <float3> pos, <float> thickness)

Check it on Github




#ifndef FNC_AXIS
#define FNC_AXIS

float4 axis(in float2 st, float4x4 M, float3 pos, float thickness) {
    float4 rta = float4(0.0);

    float4 center = mult(M, float4(pos, 1.0));
    center.xy /= center.w;
    center.xy = (center.xy * 0.5 + 0.5);

    float4 axis[3];
    axis[0] = float4(1.0, 0.0, 0.0, 1.0);
    axis[1] = float4(0.0, 1.0, 0.0, 1.0);
    axis[2] = float4(0.0, 0.0, 1.0, 1.0);

    for (int i = 0; i < 3; i++) {
        #ifdef DEBUG_FLIPPED_SPACE
        float4 a = M * (float4(pos - axis[i].xyz, 1.0));
        #else
        float4 a = M * (float4(pos + axis[i].xyz, 1.0));
        #endif
        a.xy /= a.w;
        a.xy = (a.xy * 0.5 + 0.5);
        rta += axis[i] * line(st, center.xy, a.xy, thickness);
    } 

    return rta;
}

#endif

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