简体   繁体   中英

When to transform tangent space to world space except using normal map?

I am learning OpenGL from https://learnopengl.com/ . I know how to transform normal(sampled from normal map) from tangent space to world space and why it is necessary in Normal Mapping tutorial .

But in Diffuse irradiance tutorial , it transform a vector from tangent space to world space again!

float sampleDelta = 0.025;
float nrSamples = 0.0; 
for(float phi = 0.0; phi < 2.0 * PI; phi += sampleDelta)
{
    for(float theta = 0.0; theta < 0.5 * PI; theta += sampleDelta)
    {
        // spherical to cartesian (in tangent space)
        vec3 tangentSample = vec3(sin(theta) * cos(phi),  sin(theta) * sin(phi), cos(theta));
        // tangent space to world
        vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * N; 

        irradiance += texture(environmentMap, sampleVec).rgb * cos(theta) * sin(theta);
        nrSamples++;
    }
}

At this time I don't know why we need to transform the tangentSample vector .

Besides, in the Specular IBL tutorial , it transform the sampleVector from tangent space to world space in ImportanceSampleGGX too !

It seems we need to transform a vector from tangent space to world space when we get it from spherical coordinates to cartesian coordinates ?

  • Initially, we start with a vector using the spherical coordinate system representing a direction pointing away from the surface
  • The texture you want to sample is an environment map, which is a cartesian vector in world coordinates (since the image in the cubemap is arranged so that up/forward/left/etc. correspond to the equivalent directions in the world)
  • There's no meaningful way to compare a spherical coordinate vector with a cartesian vector, so you need to convert it to cartesian coordinates, which leaves you with a vector in tangent space
  • This 3D vector still isn't in the same space as the cubemap (which means sampling with it will likely return pixels from completely the wrong direction) so we need to convert it one more time to finally get it into world space so we can sample from the map

The basic answer to your question is that tangent space and world space can't be compared and produce a meaningful result, so if you have a vector in tangent space you have to convert it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM