LYGIA Shader Library

3DSdf (lygia/sample/3DSdf)

Use a 2D texture as to encode a 3D SDF (Signed Distance Field) function

Dependencies:

Use:

<vecSAMPLE3DSDF_TYPE4> sample3DSdf(in <SAMPLER_TYPE> lut, in <vec3> xyz)

Check it on Github



#ifndef SAMPLE3DSDF_TYPE
#define SAMPLE3DSDF_TYPE float
#endif

#ifndef SAMPLE3DSDF_FNC
#define SAMPLE3DSDF_FNC(TEX, POS) sample2DCube(TEX, POS).r
#endif

#ifndef FNC_SAMPLE3DSDF
#define FNC_SAMPLE3DSDF
SAMPLE3DSDF_TYPE sample3DSdf(SAMPLER_TYPE tex, vec3 pos) {
    pos += 0.5;
    pos = scale(pos, 0.5);
    SAMPLE3DSDF_TYPE sdf = (SAMPLE3DSDF_FNC(tex, pos) * 2.0 - 1.0) * 1.5;
    return opIntersection( boxSDF(pos - 0.5, vec3(0.5)), sdf);
}
#endif

Dependencies:

Check it on Github


#ifndef FNC_SAMPLE3DSDF
#define FNC_SAMPLE3DSDF
float sample3DSdf(SAMPLER_TYPE tex, float3 pos) {
    pos += .5;
    pos = scale(pos, .5);
    float sdf = (sample2DCube(tex, pos).r * 2.0 - 1.0) * 1.5;
    return opIntersection( boxSDF(pos - 0.5, float3(.5, .5, .5)), sdf);
}
#endif

Examples

License

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