Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Textured Cube - a newbie question

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12

    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.
    Last edited by Power2012; 12-03-2012 at 05:30 PM.

  2. #2
    Member Regular Contributor
    Join Date
    Jan 2011
    Location
    Paris, France
    Posts
    250
    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)
    @+
    Yannoo

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12
    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?

  4. #4
    Intern Contributor
    Join Date
    Aug 2009
    Posts
    77
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12
    many thanks, that solved my problem.

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2012
    Posts
    12
    another quick question, is texture atlas a standard practice for rendering textures to geometries? thanks

  7. #7
    Intern Contributor
    Join Date
    Aug 2009
    Posts
    77
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •