LYGIA Shader Library

render (lygia/lighting/raymarch/render)

default raymarching renderer

Dependencies:

Use:

<vec4> raymarchDefaultRender( in <vec3> ro, in <vec3> rd )

Check it on Github



#ifndef RAYMARCH_MAP_DISTANCE
#define RAYMARCH_MAP_DISTANCE a
#endif

#ifndef RAYMARCH_MAP_MATERIAL
#define RAYMARCH_MAP_MATERIAL rgb
#endif

#ifndef RAYMARCH_MAP_MATERIAL_TYPE
#define RAYMARCH_MAP_MATERIAL_TYPE vec3
#endif

#ifndef RAYMARCHCAST_TYPE
#define RAYMARCHCAST_TYPE vec4
#endif

#ifndef FNC_RAYMARCHDEFAULT
#define FNC_RAYMARCHDEFAULT

vec4 raymarchDefaultRender( in vec3 ray_origin, in vec3 ray_direction ) { 
    vec3 col = vec3(0.0);

    RAYMARCHCAST_TYPE res = raymarchCast(ray_origin, ray_direction);
    float t = res.RAYMARCH_MAP_DISTANCE;

    vec3 pos = ray_origin + t * ray_direction;
    vec3 nor = raymarchNormal( pos );
    col = raymarchMaterial(ray_direction, pos, nor, res.RAYMARCH_MAP_MATERIAL);

    return vec4( saturate(col), t );
}

#endif

Dependencies:

Use:

<float4> raymarchDefaultRender( in <float3> ro, in <float3> rd )

Check it on Github



#ifndef RAYMARCH_MAP_DISTANCE
#define RAYMARCH_MAP_DISTANCE a
#endif

#ifndef RAYMARCH_MAP_MATERIAL
#define RAYMARCH_MAP_MATERIAL rgb
#endif

#ifndef RAYMARCH_MAP_MATERIAL_TYPE
#define RAYMARCH_MAP_MATERIAL_TYPE float3
#endif

#ifndef RAYMARCHCAST_TYPE
#define RAYMARCHCAST_TYPE float4
#endif

#ifndef FNC_RAYMARCHDEFAULT
#define FNC_RAYMARCHDEFAULT

float4 raymarchDefaultRender( in float3 ray_origin, in float3 ray_direction ) { 
    float3 col = float3(0.0, 0.0, 0.0);

    RAYMARCHCAST_TYPE res = raymarchCast(ray_origin, ray_direction);
    float t = res.RAYMARCH_MAP_DISTANCE;

    float3 pos = ray_origin + t * ray_direction;
    float3 nor = raymarchNormal( pos );
    col = raymarchMaterial(ray_direction, pos, nor, res.RAYMARCH_MAP_MATERIAL);

    return float4( saturate(col), t );
}

#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