lygia
/v1.1.4
/lighting
/raymarch
/ao
)calculare Ambient Occlusion
Dependencies:
Use:
<float> raymarchAO( in <vec3> pos, in <vec3> nor )
#ifndef RAYMARCH_SAMPLES_AO
#define RAYMARCH_SAMPLES_AO 5
#endif
#ifndef RAYMARCH_MAP_FNC
#define RAYMARCH_MAP_FNC(POS) raymarchMap(POS)
#endif
#ifndef RAYMARCH_MAP_DISTANCE
#define RAYMARCH_MAP_DISTANCE a
#endif
#ifndef FNC_RAYMARCHAO
#define FNC_RAYMARCHAO
float raymarchAO( in vec3 pos, in vec3 nor ) {
float occ = 0.0;
float sca = 1.0;
for( int i = 0; i < RAYMARCH_SAMPLES_AO; i++ ) {
float hr = 0.01 + 0.12 * float(i) * 0.2;
float dd = RAYMARCH_MAP_FNC( hr * nor + pos ).RAYMARCH_MAP_DISTANCE;
occ += (hr-dd)*sca;
sca *= 0.9;
if( occ > 0.35 )
break;
}
return saturate( 1.0 - 3.0 * occ ) * (0.5+0.5*nor.y);
}
#endif
Dependencies:
Use:
<float> raymarchAO( in <float3> pos, in <float3> nor )
#ifndef RAYMARCH_SAMPLES_AO
#define RAYMARCH_SAMPLES_AO 5
#endif
#ifndef RAYMARCH_MAP_FNC
#define RAYMARCH_MAP_FNC(POS) raymarchMap(POS)
#endif
#ifndef RAYMARCH_MAP_DISTANCE
#define RAYMARCH_MAP_DISTANCE a
#endif
#ifndef FNC_RAYMARCHAO
#define FNC_RAYMARCHAO
float raymarchAO( in float3 pos, in float3 nor ) {
float occ = 0.0;
float sca = 1.0;
for( int i = 0; i < RAYMARCH_SAMPLES_AO; i++ ) {
float hr = 0.01 + 0.12 * float(i) * 0.2;
float dd = RAYMARCH_MAP_FNC( hr * nor + pos ).RAYMARCH_MAP_DISTANCE;
occ += (hr-dd)*sca;
sca *= 0.9;
if( occ > 0.35 )
break;
}
return saturate( 1.0 - 3.0 * occ ) * (0.5+0.5*nor.y);
}
#endif
Dependencies:
Use:
<float> raymarchAO( in <float3> pos, in <float3> nor )
#ifndef RAYMARCH_SAMPLES_AO
#define RAYMARCH_SAMPLES_AO 5
#endif
#ifndef RAYMARCH_MAP_FNC
#define RAYMARCH_MAP_FNC(POS) raymarchMap(POS)
#endif
#ifndef RAYMARCH_MAP_DISTANCE
#define RAYMARCH_MAP_DISTANCE w
#endif
#ifndef FNC_RAYMARCHAO
#define FNC_RAYMARCHAO
inline __host__ __device__ float raymarchAO(const float3& pos, const float3& nor ) {
float occ = 0.0f;
float sca = 1.0f;
for( int i = 0; i < RAYMARCH_SAMPLES_AO; i++ ) {
float hr = 0.01f + 0.12f * float(i) * 0.2f;
float dd = RAYMARCH_MAP_FNC( hr * nor + pos ).RAYMARCH_MAP_DISTANCE;
occ += (hr - dd) * sca;
sca *= 0.9f;
if( occ > 0.35f )
break;
}
return clamp( 1.0f - 3.0f * occ, 0.0f, 1.0f) * (0.5f + 0.5f * nor.y);
}
#endif
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.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository