Hi everyone!
I'm implementing image-based lighting in a demo program and I ran into a problem with sampling an environment map. For the map I use a free HDR sample from CGSkies, loaded with stb_image. I create the texture with DXGI_FORMAT_R32G32B32A32_FLOAT and call GenerateMips on it (I do intend to implement proper environment map filtering later). Here is fragment shader code that samples the map:
float3 reflectionDir = reflect(-dirToViewer, normal);
float theta = acos(reflectionDir.z); // lat, 0..PI
float phi = atan2(reflectionDir.y, reflectionDir.x); // lon, 0..2PI
float emx = phi / (PI*2);
float emy = theta / PI;
float3 emsample = textureEnv.Sample(samplerDiffuse, float2(emx, emy));
return float4(emsample, 1.0f);
The reflection on the sphere has a seam that passes through the sun (envmap01). Notice however, that the sun is in the middle of the texture, nowhere near any border. Also, if a add an offset to the x coordinate, the reflection moves, but not the seam (envmap02). If I move the camera, the seam moves with the reflection.
float emx = phi / (PI*2) + 0.2f;
Finally, the seam disappears if I do any of the following (envmap03):
1) Set sampler's MaxLOD to 0,
2) Create a Texture with only a single mip level,
3) Sample the texture with SampleLevel, even with a fractional LOD level.
And that's where I'm at right now. Looks like it has something to do with mip mapping, since first two methods effectively disable it, but I don't see how SampleLevel is different from regular Sample with a hardware-calculated level. Will greatly appreciate any pointers!