Reply
Recognized Member
Ciaran Laval
Posts: 3,621
0 Kudos

Formula for calculating offsets

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?

Advisor
Kwakkelde Kwak
Posts: 863
0 Kudos

Re: Formula for calculating offsets

Reply to Ciaran Laval - view message

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...

"The superior man understands what is right; the inferior man understands what will sell."
Confucius

Recognized Member
Ciaran Laval
Posts: 3,621
0 Kudos

Re: Formula for calculating offsets

Reply to Kwakkelde Kwak - view message

Thanks a lot :smileyhappy: I'll try again tomorrow as it's getting late for me too.

Honored Resident
namssab1nad Piers
Posts: 94
0 Kudos

Re: Formula for calculating offsets

Reply to Ciaran Laval - view message

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.

Advisor
Kwakkelde Kwak
Posts: 863
0 Kudos

Re: Formula for calculating offsets

Reply to namssab1nad Piers - view message

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.

"The superior man understands what is right; the inferior man understands what will sell."
Confucius

Advisor
Kwakkelde Kwak
Posts: 863
0 Kudos

Re: Formula for calculating offsets

[ Edited ]

Reply to Ciaran Laval - view message


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.)

"The superior man understands what is right; the inferior man understands what will sell."
Confucius

Recognized Member
Ciaran Laval
Posts: 3,621
0 Kudos

Re: Formula for calculating offsets

Reply to namssab1nad Piers - view message


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.

 

Recognized Member
Ciaran Laval
Posts: 3,621
0 Kudos

Re: Formula for calculating offsets

Reply to Kwakkelde Kwak - view message


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 :smileyhappy:

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.

Advisor
Kwakkelde Kwak
Posts: 863
0 Kudos

Re: Formula for calculating offsets

Reply to Ciaran Laval - view message


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.... :smileyhappy:

"The superior man understands what is right; the inferior man understands what will sell."
Confucius

Recognized Member
Ciaran Laval
Posts: 3,621
0 Kudos

Re: Formula for calculating offsets

Reply to Kwakkelde Kwak - view message


Kwakkelde Kwak wrote:

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


Haha! I think the number of textures part threw me, it all works anyway thank you very much :smileyhappy: