Math problem for texture coords

Started by
8 comments, last by MARS_999 18 years, 7 months ago
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
Advertisement

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

gives 1.25, 1.5, 1.75...
Quote:Original post by Anonymous Poster

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

gives 1.25, 1.5, 1.75...


Close but 1 + .25 * 2 = 2.5 :(
multiplication occurs before addition.

1 + (2 * 0.25) = 1.5
Quote:Original post by Anonymous Poster
multiplication occurs before addition.

1 + (2 * 0.25) = 1.5


Whoops you are correct I wasn't looking at it like that. :)
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
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);

enum Bool { True, False, FileNotFound };
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
Quote:Original post by hplus0603
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);


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));
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... :(

This topic is closed to new replies.

Advertisement