lygia
/lighting
/sphereMap
)Given a Spherical Map texture and a normal direction returns the right pixel
Dependencies:
Use:
spheremap(<SAMPLER_TYPE> texture, <vec3> normal)
#ifndef SPHEREMAP_TYPE
#define SPHEREMAP_TYPE vec4
#endif
#ifndef SPHEREMAP_SAMPLER_FNC
#define SPHEREMAP_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#ifndef FNC_SPHEREMAP
#define FNC_SPHEREMAP
vec2 sphereMap(const in vec3 normal, const in vec3 eye) {
vec3 r = reflect(-eye, normal);
r.z += 1.0;
float m = 2.0 * length(r);
return r.xy / m + 0.5;
}
SPHEREMAP_TYPE sphereMap(in SAMPLER_TYPE tex, const in vec3 normal, const in vec3 eye) {
return SPHEREMAP_SAMPLER_FNC(tex, sphereMap(normal, eye) );
}
#endif
Dependencies:
Use:
spheremap(<SAMPLER_TYPE> texture, <float3> normal)
#ifndef SPHEREMAP_TYPE
#define SPHEREMAP_TYPE float4
#endif
#ifndef SPHEREMAP_SAMPLER_FNC
#define SPHEREMAP_SAMPLER_FNC(TEX, UV) SAMPLER_FNC(TEX, UV)
#endif
#ifndef FNC_SPHEREMAP
#define FNC_SPHEREMAP
float2 sphereMap(float3 normal, float3 eye) {
float3 r = reflect(-eye, normal);
r.z += 1.;
float m = 2. * length(r);
return r.xy / m + 0.5;
}
SPHEREMAP_TYPE sphereMap (in SAMPLER_TYPE tex, in float3 normal, in float3 eye) {
return SPHEREMAP_SAMPLER_FNC(tex, sphereMap(normal, eye) );
}
#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