Skip to main content

Truncated

Code Example

#define PHI (1.618033988749895)
#define _0 vec3(1, 0, 0)
#define _1 vec3(0, 1, 0)
#define _2 vec3(0, 0, 1)
#define _3 normalize(vec3(1, 1, 1))
#define _4 normalize(vec3(-1, 1, 1))
#define _5 normalize(vec3(1, -1, 1))
#define _6 normalize(vec3(1, 1, -1))
#define _7 normalize(vec3(0, 1, PHI + 1.))
#define _8 normalize(vec3(0, -1, PHI + 1.))
#define _9 normalize(vec3(PHI + 1., 0, 1))
#define _10 normalize(vec3(-PHI - 1., 0, 1))
#define _11 normalize(vec3(1, PHI + 1., 0))
#define _12 normalize(vec3(-1, PHI + 1., 0))
#define _13 normalize(vec3(0, PHI, 1))
#define _14 normalize(vec3(0, -PHI, 1))
#define _15 normalize(vec3(1, 0, PHI))
#define _16 normalize(vec3(-1, 0, PHI))
#define _17 normalize(vec3(PHI, 1, 0))
#define _18 normalize(vec3(-PHI, 1, 0))
#define _(v) d = max(d, abs(dot(p, v)));
float truncatedSDF(vec3 p, float r) {
        float d = 0.;
        _(_0) _(_1) _(_2)
        _(_3) _(_4) _(_5) _(_6)
        _(_7) _(_8) _(_9) _(_10)
        _(_11) _(_12) _(_13) _(_14)
        _(_15) _(_16) _(_17) _(_18)
        return d - r;
}

More