Jump to content

  • Log In with Google      Sign In   
  • Create Account

faster equirectangular sampling


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1   Members   -  Reputation: 1527

Like
0Likes
Like

Posted 29 March 2014 - 04:15 PM

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

 

 



#2   Members   -  Reputation: 3018

Like
0Likes
Like

Posted 29 March 2014 - 06:06 PM


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

 

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



#3   Members   -  Reputation: 1527

Like
0Likes
Like

Posted 30 March 2014 - 03:10 AM

 


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, 30 March 2014 - 03:11 AM.


#4   Members   -  Reputation: 3018

Like
0Likes
Like

Posted 30 March 2014 - 03:30 AM

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



#5   Members   -  Reputation: 1527

Like
0Likes
Like

Posted 30 March 2014 - 04:40 AM

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


Edited by Yours3!f, 30 March 2014 - 04:44 AM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS