Advertisement

Sample Equirectangular map into a Cube

Started by April 30, 2021 05:11 PM
2 comments, last by そら 3 years, 5 months ago

Hi,

In this tutorial (https://learnopengl.com/PBR/IBL/Diffuse-irradiance)​ the author uses the following code snipet to sample from an Equirectangular map and draw it into a Cube (or convert it to a Cubemap later on):

const vec2 invAtan = vec2(0.1591, 0.3183);
vec2 SampleSphericalMap(vec3 v)
{
    vec2 uv = vec2(atan(v.z, v.x), asin(v.y));
    uv *= invAtan;
    uv += 0.5;
    return uv;
}

However, all the explanation it gives is that he's using some trigonomertic magic (spherical to cartesian), but doesn't give any reference beyond that, and haven't been able to find something useful in google that could explain the code above.

Anyone has a good reference that could explain what's going on here?

Thanks!

"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"

https://en.wikipedia.org/wiki/Equirectangular_projection

Maybe this helps?

For this kind of mapping an image to the sphere there are two singularities (north and south pole), where the top and bottom edges of the image collapse to a single point. Left and right edge both map to the same arc connecting those poles.

To understand the math, you could work out the mapping form direction unit vector → spherical coordinate → uv in image space. Then after some optimizing you should get that same code snippet.

Advertisement

Thanks JoeJ,

Definitely that will help!…

"lots of shoulddas, coulddas, woulddas in the air, thinking about things they shouldda couldda wouldda donne, however all those shoulddas coulddas woulddas ran away when they saw the little did to come"

This topic is closed to new replies.

Advertisement