Hi there,
I'm doing image based lighting, and I need to sample a texture that has an equirectangular projection layout.
I've got this function to sample it:
vec4 sample_equirectangular_map(vec3 dir, sampler2D sampler, float lod)
{
vec2 uv;
uv.x = atan( dir.z, dir.x );
uv.y = acos( dir.y );
uv /= vec2( 2 * pi, pi );
return textureLod( sampler, uv, lod );
}
where dir is the normalized world-space normal.
The texture wrapping is set to GL_REPEAT, so negative values don't hurt.
This works well, but I kinda have the feeling that the atan and acos aren't really needed there...
so I found this from oglsuperbible 6, but when I put that in, it didn't really work:
https://github.com/openglsuperbible/sb6code/blob/master/bin/media/shaders/equirectangular/render.fs.glsl
vec4 sample_equirectangular_map(vec3 dir, sampler2D sampler, float lod)
{
vec2 uv;
uv.y = dir.y;
dir.x = normalize( dir.xz ).x * 0.5;
float s = sign( dir.z ) * 0.5;
uv.x = 0.75 - s * (0.5 - uv.x);
uv.y = 0.5 + 0.5 * uv.y;
return textureLod( sampler, uv, lod );
}
Any ideas how to remove the atan/acos from there?
the ibl maps I sampled are from here:
http://www.hdrlabs.com/sibl/archive.html
Best regards,
Yours3!f