Jump to content

Formula for calculating offsets


You are about to reply to a thread that has been inactive for 4479 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I've been trying to calculate the formula for calculating offsets, and can't grasp it.

The situation is I have three prims, the two edges are 0.210 and the main centre piece is 13.580, so overall it's 14M wide.

I have my horizontal texture repeats set to 0.030 for the two edges and 1.940 for the centre piece, so the texture repeats twice.

I currently have my offsets set (from left to right) at -0.500, -0.508 and 0.492.

This comes out very very close to being ideal, well it's close enough to get away with it. The same settings pretty much work for a 12.8 prim set of 0.192 for the edges and 12.416 for the centre piece.

However I can't work this backwards to give me a formula for working it out, it doesn't help that I can't remember how I ended up with the offsets I currently have, this whole thing got delayed, I think it may have been simply trial and error.

Anyone got any clues?

Link to comment
Share on other sites

No time to do the math right now as it's bedtime here..I can give some pointers, it's not very hard to calculate...

1) it's a linear formula...

2) start out with a single repeat, not two, that makes it a lot easier

2) compare the % of the texture width with the offset per face

3) use numbers that make a bit more sense mathematically, like 1, 2 and 1 (25%, 50%, 25%) and 1,6,1 (12.5%,75%,12.5%)

4) calculate the formula for the left face first, the right is the same, but negative

I hope that helps, if not, I might have a moment tomorrow...

Link to comment
Share on other sites

Your math would simply immensley if your prims were not such odd sizes.  Always try to keep your prim sizes as close to round numbers as possible.  If that is not possible, since we are dealing with metrics,is to keep your prims last digit ending in an even number.  This will make virtually all of your calculations end within the number of decimal digits supported by SL.  It also means a simple calculator will give you exact results.  Try it, you will be suprised at how starting out with that small change will help.

Link to comment
Share on other sites

pfff, that was for some reason more confusing than I suspected...anyway...

 

I went with 3 prims side by side and made a formula for the left prim.

The result is this:

Repeat = [number of textures side by side] * [width of left prim] / [width of all three prims combined]

Offset = 0.5 * [number of textures side by side] * [width of the left prim] / [width of all three prims combined] - 0.5

or Offset = 0,5 * Repeat - 0.5

The result can be less than -1.000 or more than 1.000. In that case keep adding or subtracting 1.000 until you have a number that fits the offset range.

If the prim on the right is the same size as the one on the left, you can multiply by -1 for the correct offset.

Note..there can be some rounding off.

In that case this might work slightly better:

Calculate the repeat for the center prim:

Repeat(center) = [number of textures side by side] * [width of center prim] / [width of all prims combined]

round off the result to an even number and use this for the center prim.

Repeat(left) = [number of textures side by side] - Repeat(center) / 2

the result will be 100% seamless, there might be some very very minor texture stretch, absolutely not noticable.

Link to comment
Share on other sites


Ciaran Laval wrote:

 

I have my horizontal texture repeats set to 0.030 for the two edges and 1.940 for the centre piece, so the texture repeats twice.

I currently have my offsets set (from left to right) at -0.500, -0.508 and 0.492.

Your repeats match the formula exactly, the offsets should be -0.485 , 0.500 , 0.485

There is no rounding off and no texture stretch or seams....

(The center prim always has an offset of 0 when the number of textures is odd and 0.500 when even, if you want to move the texture so it's not centered, add the same number to all offsets.)

Link to comment
Share on other sites


namssab1nad Piers wrote:

Your math would simply immensley if your prims were not such odd sizes.  Always try to keep your prim sizes as close to round numbers as possible.  If that is not possible, since we are dealing with metrics,is to keep your prims last digit ending in an even number.  This will make virtually all of your calculations end within the number of decimal digits supported by SL.  It also means a simple calculator will give you exact results.  Try it, you will be suprised at how starting out with that small change will help.

The number crunching worked well for those prim sizes, it meant I could get my repeats to be no more than three decimal places, that won't work if for example I had my starting edge walls at .200 instead of ,210.

 

Link to comment
Share on other sites


Kwakkelde Kwak wrote:

pfff, that was for some reason more confusing than I suspected...anyway...

 

I went with 3 prims side by side and made a formula for the left prim.

The result is this:

Repeat = [number of textures side by side] * [width of left prim] / [width of all three prims combined]

Offset = 0.5 * [number of textures side by side] * [width of the left prim] / [width of all three prims combined] - 0.5

or
Offset = 0,5 * Repeat - 0.5

The result can be less than -1.000 or more than 1.000. In that case keep adding or subtracting 1.000 until you have a number that fits the offset range.

If the prim on the right is the same size as the one on the left, you can multiply by -1 for the correct offset.

Note..there can be some rounding off.

In that case this might work slightly better:

Calculate the repeat for the center prim:

Repeat(center) = [number of textures side by side] * [width of center prim] / [width of all prims combined]

round off the result to an even number and use this for the center prim.

Repeat(left) = [number of textures side by side] - Repeat(center) / 2

the result will be 100% seamless, there might be some very very minor texture stretch, absolutely not noticable.

Ah that starts to make sense! Thank you. The offsets you suggested in your later post do indeed work perfectly :)

The only thing I'd add here is that I find the repeats by:

repeats = size of prim / total width of side

So in my case for my edges it's:

repeats = .210/14

Which comes out at .015, which I then doubled as I wanted the texture to repeat twice.

Link to comment
Share on other sites


Ciaran Laval wrote:

The only thing I'd add here is that I find the repeats by:

repeats = size of prim / total width of side

So in my case for my edges it's:

repeats = .210/14

Which comes out at .015, which I then doubled as I wanted the texture to repeat twice.

Eh yes that's exactly what I put in my post.... :)

Link to comment
Share on other sites


Kwakkelde Kwak wrote:

You're very welcome, the "number of textures side by side" part can be replaced with "2" in your case, so then it's exactly what you did. It however also works for any other amount. You asked for a formula afterall, not just the right digits for your specific case:)

ah penny drops, because I wanted the full texture to repeat twice across the full width. I was doubling it at the end of my formula. I was getting confused because I thought number of textures meant how many faces I was texturing but now I understand what you mean.

Yes I wanted the formula, otherwise I'd have been here again with another question with different sizes, long term the formula is very useful, so again, thank you very much for your help :)

Link to comment
Share on other sites

I think this does it for a general case....

If you have a series of sid-by-side boxes, where the total width is W and the texture is repeated R times across the whole lot, then the texture offset for each prim can be calculated by adding the texture offset of the prim on its left to

(w1+w2)*R/(2*W)  

where w1 and w2 are the widths of the prim and the prim on its left.

If the answer is greater than 1, subtract 1 enough times to end up with something less than 1 (i.e. express the answer modulo 1). The offset of the texture on the first (leftmost) prim can be anything you like.

Example: boxes with widths 1,2,3,4; W=8. Texture repeated twice across the assembly. Choose 0 for left prim offset...

Second offset = 0        + (1+2)*2/(2*8) =                  6/16 = 0.375
Third offset     = 0.375 + (2+3)*2/(2*8) = 0.375 + 10/16 = 0.375 + 0.625 = 1
Fourth offset   = 1        + (3+2)*2/(2*8)  = 1         + 10/16 = 1.625; modulo 1 = 0.625

As Kwak said, widths have to be chosen carefully if you want to avoid rounding errors from the fact that you only have three digit precision in the offsets. All values of (R*w)/(2*W) should be expressible precisely with just three digits.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4479 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...