lygia
/v1.1.4
/sample
/equirect
)sample an equirect texture as it was a cubemap
Dependencies:
lygia
/v1.1.4
/space
/xyz2equirect
.glsl
lygia
/v1.1.4
/generative
/random
.glsl
lygia
/v1.1.4
/generative
/srandom
.glsl
lygia
/v1.1.4
/sample
.glsl
Use:
sampleEquirect(<sampler2D> texture, <vec3> dir)
#ifndef FNC_SAMPLEEQUIRECT
#define FNC_SAMPLEEQUIRECT
vec4 sampleEquirect(sampler2D tex, vec3 dir) {
vec2 st = xyz2equirect(dir);
#ifdef SAMPLEEQUIRECT_FLIP_Y
st.y = 1.0-st.y;
#endif
return SAMPLER_FNC(tex, st);
}
vec4 sampleEquirect(sampler2D tex, vec3 dir, float lod) {
#if defined(SAMPLEEQUIRET_ITERATIONS)
vec4 acc = vec4(0.0);
vec2 st = xyz2equirect(dir);
#ifdef SAMPLEEQUIRECT_FLIP_Y
st.y = 1.0-st.y;
#endif
mat2 rot = mat2(cos(GOLDEN_ANGLE), sin(GOLDEN_ANGLE), -sin(GOLDEN_ANGLE), cos(GOLDEN_ANGLE));
float r = 1.;
vec2 vangle = vec2(0.0, lod * 0.01);
for (int i = 0; i < SAMPLEEQUIRET_ITERATIONS; i++) {
vangle = rot * vangle;
r++;
vec4 col = SAMPLER_FNC(tex, st + random( vec3(st, r) ) * vangle );
acc += col * col;
}
return vec4(acc.rgb/acc.a, 1.0);
#else
dir += srandom3( dir ) * 0.01 * lod;
vec2 st = xyz2equirect(dir);
#ifdef SAMPLEEQUIRECT_FLIP_Y
st.y = 1.0-st.y;
#endif
return SAMPLER_FNC(tex, st);
#endif
}
#endif
Dependencies:
lygia
/v1.1.4
/space
/xyz2equirect
.glsl
lygia
/v1.1.4
/generative
/random
.glsl
lygia
/v1.1.4
/generative
/srandom
.glsl
lygia
/v1.1.4
/sample
.glsl
Use:
sampleEquirect(<sampler2D> texture, <float3> dir)
#ifndef FNC_SAMPLEEQUIRECT
#define FNC_SAMPLEEQUIRECT
float4 sampleEquirect(sampler2D tex, float3 dir) {
float2 st = xyz2equirect(dir);
#ifdef SAMPLEEQUIRECT_FLIP_Y
st.y = 1.0-st.y;
#endif
return SAMPLER_FNC(tex, st);
}
float4 sampleEquirect(sampler2D tex, float3 dir, float lod) {
#if defined(SAMPLEEQUIRET_ITERATIONS)
float4 acc = float4(0.0, 0.0, 0.0, 0.0);
float2 st = xyz2equirect(dir);
#ifdef SAMPLEEQUIRECT_FLIP_Y
st.y = 1.0-st.y;
#endif
float2x2 rot = float2x2(cos(GOLDEN_ANGLE), sin(GOLDEN_ANGLE), -sin(GOLDEN_ANGLE), cos(GOLDEN_ANGLE));
float r = 1.;
float2 vangle = float2(0.0, lod * 0.01);
for (int i = 0; i < SAMPLEEQUIRET_ITERATIONS; i++) {
vangle = mul(rot, vangle);
r++;
float4 col = SAMPLER_FNC(tex, st + random( float3(st, r) ) * vangle );
acc += col * col;
}
return float4(acc.rgb/acc.a, 1.0);
#else
dir += srandom3( dir ) * 0.01 * lod;
float2 st = xyz2equirect(dir);
#ifdef SAMPLEEQUIRECT_FLIP_Y
st.y = 1.0-st.y;
#endif
return SAMPLER_FNC(tex, st);
#endif
}
#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