Advertisement Jump to content
Sign in to follow this  
Yours3!f

OpenGL faster equirectangular sampling

This topic is 1758 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

 

 

Share this post


Link to post
Share on other sites
Advertisement


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

 

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

Share this post


Link to post
Share on other sites

 


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

Edited by Yours3!f

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!