Jump to content
  • Advertisement
Sign in to follow this  
Bakura

Drawing cubemap face with GLSL

This topic is 3648 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 everyone, I want to draw my cubemaps faces (one at the time) for debugging purpose. All the faces were generated with a FBO, but I don't really know how to access them in the shader. I thought that, for instance, if I use vec3 = 1.0, 0.5, 0.5, the shader would select the face with the biggest magnitude (so here it would select the positive X face), and then do a normal texturing selecting the pixel at the center of that face, but it doesn't seem to be the case, as the coords aren't the good ones. The fragment shader : uniform samplerCube text; void main() { vec3 coordinates = vec3 (1.0, gl_TexCoord[0].st); gl_FragColor = textureCube (text, coordinates); } And the draw quad function :
[source="cpp"]void DrawQuad ()
{
	glViewport(0,0,512,512);  
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity(); 
	glFrustum(-1,1,-1,1,1,1000); 
 
 
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity(); 
	gluLookAt(0,0,0,   0,0,-1,  0,1,0);
 
	glBegin(GL_QUADS); 
		glTexCoord2f (0.0f, 0.0f);
		glVertex3f(-1,-1,-1);
		glTexCoord2f (0.0f, 1.0f);
		glVertex3f(-1,1,-1);
		glTexCoord2f (1.0f, 1.0f);
		glVertex3f(1,1,-1);
		glTexCoord2f (1.0f, 0.0f);
		glVertex3f (1, -1, -1);
	glEnd();
}
Thanks for your help

Share this post


Link to post
Share on other sites
Advertisement
Texture coordinates into cubemaps are 3 dimensional, you're mapping faces like vertices in unit cube ;-)

So for first face (POSITIVE Z) the texture coordinates shall be (I'm writing this like quad and you're beginning onto left bottom corner, then you're moving in counter-clockwise direction through other vertices (Fig.01)):
vertex1 U = 0 V = 0 W = 0
vertex2 U = 1 V = 0 W = 0
vertex3 U = 1 V = 1 W = 0
vertex4 U = 0 V = 1 W = 0

Fig.01:
vertex4--------vertex3
|............................|
|............................|
|............................|
|............................|
|............................|
|............................|
|............................|
vertex1--------vertex2

Share this post


Link to post
Share on other sites
Thanks for the asnwer ;).

But while I was waiting for the answer I have moved to simple texture 2D (so I'm using 6 2D textures instead of one cube map), and it's faster :/. I will move on to cubemaps later, but thanks for the help !

Share this post


Link to post
Share on other sites
If you are on GF8 or newer hardware you could use a texture array and only use one texture unit and just index the levels you want vs. binding 6 textures and should be faster.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!