faster equirectangular sampling

Started by
3 comments, last by Yours3!f 10 years ago

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

Advertisement


dir.x = normalize( dir.xz ).x * 0.5;

You are normalizing a vec2, this is not the same as the OGLSB example.



dir.x = normalize( dir.xz ).x * 0.5;

You are normalizing a vec2, this is not the same as the OGLSB example.

well x / sqrt( x^2 + z^2 ) should be equal to x / sqrt( x^2 + 0^2 + z^2 )

so it's essentially the same

In that case can you elaborate on what you mean by "it didn't really work"?

In that case can you elaborate on what you mean by "it didn't really work"?

diffuse:

should be: http://i.imgur.com/3Epr2Sf.png
it is instead: http://i.imgur.com/F1cxU3g.png

EDIT: it's a bit more evident using the reflection texture
should be: http://i.imgur.com/3uPHQLG.jpg

it is instead: http://i.imgur.com/01tbFMN.jpg

This topic is closed to new replies.

Advertisement