Textured Cube - a newbie question

Hi there,

The question is very simple: I want to draw a cube with 6 different textures on 6 surfaces of the cube, what is the “proper” way to design the fragment shader?

My initial thought is that: using a flag in the fragment shader, for example,

uniform int surface;

main () {

if (surface == 0) // front surface, for example
{ 
     vec4 texColor0 = texture(frontTexture, TexCoord);
     .............
}
if (surfac == 1) // back surface

{…
}

}

and when draw the cube, the 6 surfaces will be drawn separately with proper value of “surface” passed to fragment shader.

However, I do not like this idea, and wondering any other proper ways to do this??

Thanks.

I think that it is better to assemble the 6 maps into a common texture and to use texels coordinates for to select the good portion of each face.

This make 6x less of texture binding, cf. only one texture binding for the entire cube instead one texture binding for each face = 6 textures bindings
(but ok, only 3 if you only draw front facing faces)

Note that you can too use a 3D texture if you want to handle a more volumetric texturing
(for example, you can varying texture coordinates associated with the 8 vertices of the cube for to have the posibility to explore the interior of the 3D texture)

Thanks for your reply. I think you are talking about cube map, but that is not what I want. I am thinking to do textures in more general way, for example, rather then a cube, we have a polygon with 12 faces, how to texture the 12 faces with 12 different textures?

I don’t think Little Body is talking about cubemapping. Google for “texture atlas” - i think that’s what is meant. It is basically putting all needed textures in one bigger texture.

many thanks, that solved my problem.

another quick question, is texture atlas a standard practice for rendering textures to geometries? thanks

I would not say there is a “THE” standard for this, but i think it is pretty common. However the needs change wether you just implement a quick app maybe using not even as many textures as you have texturing units or developing large scale games or the like.
Everything has its downside … texture atlases are fast becaus they minimize texture switching, but you have to do extra work in advance to compile it. Furthermore at polygons edges adjacent textures may bleed through if you are not careful, especially when using mipmapping (of course e.g. for whole character model textures this may not be a problem because the texture continues seamlessly). Requirements may change again if there is not enough memory to keep all textures for the whole app at once.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.