# Math problem for texture coords

This topic is 4829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am not finding a good solution to my math problem with texture coordinates. I have my texture coodinates repeating 16x. So the values are figured out as so texCoord = (x / 128) * 16 //x = 1,2,3... texCoord is repeated 128 to fill out my mesh. Now the problem is in my shader I would like to call texture coordinates at every .25 on a whole number. e.g. 1.25, 1.5, 1.75, ect... I have to map to those exact 1/4 of a whole number. Problem is my texcoords I have end up as above .125 the next one will be .25, the next .375 and so on... Any ideas on how I can remap the texture coodinates into those fixed numbers. Thanks for any help

##### Share on other sites

texCoord = 1 + 0.25 * x //x = 1,2,3...

gives 1.25, 1.5, 1.75...

##### Share on other sites
Quote:
 Original post by Anonymous PostertexCoord = 1 + 0.25 * x //x = 1,2,3...gives 1.25, 1.5, 1.75...

Close but 1 + .25 * 2 = 2.5 :(

##### Share on other sites
multiplication occurs before addition.

1 + (2 * 0.25) = 1.5

##### Share on other sites
Quote:
 Original post by Anonymous Postermultiplication occurs before addition.1 + (2 * 0.25) = 1.5

Whoops you are correct I wasn't looking at it like that. :)

##### Share on other sites
Ok, not 100% what I am looking for, I need to keep the range 0-16 but I am iterating 128 for x and need to keep my values spread over 128 time 0-16 at .25 increments?? I hope that clears up what I am trying to do better now. Thanks for the help so far anonymous

##### Share on other sites
There aren't enough values in that interval to achieve what you want.
If you include 0 and 16, you get 65 possible values (0, 0.25, 0.5, ... 16 means 65 different values)

You have to first figure out how you want your data to deal with this. Do you want to have neighboring vertices share the value? Then shift x right by 1 before you divide by (64/16):

  float y = ((x>>1) / ((128>>1)/16);

##### Share on other sites
Ok, not 100% what I am looking for, I need to keep the range 0-16 but I am iterating 128 for x and need to keep my values spread over 128 time 0-16 at .25 increments?? I hope that clears up what I am trying to do better now. Thanks for the help so far anonymous

if i understand what you're trying to do, you want to go from 0-16 in 128 steps.

if this is the case, you can't do it in .25 increments because 16 / 128 = 1/8 = 0.125

so what you had originally was correct: 0.125, 0.25, 0.375 = x / 8

##### Share on other sites
Quote:
 Original post by hplus0603There aren't enough values in that interval to achieve what you want.If you include 0 and 16, you get 65 possible values (0, 0.25, 0.5, ... 16 means 65 different values)You have to first figure out how you want your data to deal with this. Do you want to have neighboring vertices share the value? Then shift x right by 1 before you divide by (64/16): float y = ((x>>1) / ((128>>1)/16);

Ok, here is what I am using and I get 0's for the first 7 or so elements in the debugger?

terrain[z][x].ttx = float((x>>1) / ((128>>1) / TILE_FACTOR));
terrain[z][x].tty = float((z>>1) / ((128>>1) / TILE_FACTOR));

##### Share on other sites
What looks to be the problem and I dont' care so much as of now what the tile amount is but the values need to map to 0-1 range but over a tiled amount. I don't want the texture stretched but tiled. I am texture mosaicing... if I have 16 textures in one texture each texture coord needs to map to .25 to get to the next texture. This is all fine when you have 0-1, but I want the texture to repeat x amount of times. This is where the problem shows up. I have to get some sleep I am drained... :(

1. 1
Rutin
27
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 9
• 9
• 14
• ### Forum Statistics

• Total Topics
633311
• Total Posts
3011313
• ### Who's Online (See full list)

There are no registered users currently online

×