Dynamicaly changing textures.

Started by
1 comment, last by Wilhelm van Huyssteen 12 years, 9 months ago
Hi

I have a cube. It consists of 12 triangles wich make up its 6 sides. I want each side to use a different texture but i want to decide wich textures to use before drawing the cube and i dont want to make 6 seperate draw calls. I can pass 6 textures to the my shader but how can my shader know wich texture to apply to wich faces.

I came up with 2 possible solutions.

1. Check the normal of the face (in modelspace). And depending wich way it faces i will know wich texture to apply to it

2. Create another vertex attribute for the cube that would store a 0-5 for every vertex wich would indicate wich side of the cube its on and let my sader use that.

Is either of these two methods a good way to go about it? (with good i mean fast! I need to render alot of cubes!) if not what would you suggest

Thnx in Advance!
Advertisement

1. Check the normal of the face (in modelspace). And depending wich way it faces i will know wich texture to apply to it

When you can determine the right texture this way, you should do it in the vertex shader. When you don't need to use tileable textures, I would sugguest to put all texture on a single texture (=>texture atlas) and calculate only the right texture coords in the vertex shader. If you need to support tileable textures, I would take a look at texture arrays and change the z coord depending on the texture you have choosen.
good idea with the atlas :D unfortenetley they do need to be tilable and in total the amount of textures im going to use will be way to big for a single atlas. I will try a texture array. Im guessing i should stil determine the z index in the vertex shader and just pass it through with a varaying vec instead of doing it in the fragment shader since it would be faster.<BR><BR>Im also guessing youre saying texture arrays would be faster for this? but if thats the case when would you ever not use a texture array. I havent used texture arrays yet so im just trying to figure out the pros/cons.

This topic is closed to new replies.

Advertisement