Sign in to follow this  
EternityZA

Dynamicaly changing textures.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
[quote name='Wilhelm van Huyssteen' timestamp='1310718276' post='4835602']
1. Check the normal of the face (in modelspace). And depending wich way it faces i will know wich texture to apply to it
[/quote]
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this