texture atlas and tiled textures

Started by
4 comments, last by giugio 12 years, 10 months ago
hello.
I must understand the tiled textures.
I'm ending a sketchup importer , and in this importer i use texture atlas.
Each texture have a width , height , U offset and V offset.
The problem is that i have some UV coordinates that go from 0 to 47 or 0 to 23 , are this used for tiled textures?

the questions are:
1)what is the math procedure for add U offset and V offset to my texture in the atlas?
For example i have a texture atlas widht of 2048 and height of 2048 and a texture in the atlas at offset 1024 ,1024 of width 128x128

2)how I behave with the tiled textures?
for a tiled in the x component and y component.
On this forum I was told of build a custom shader, how?
I have also read about change the texture border, but i'm not understand .
Advertisement
UV coordinates outside the 0-1 range are usually designed to work with the 'wrap' texturing mode. In general it's not simple to make that work well with a texture atlas - it's much easier just to use an individual texture for anything that's wrapped because the hardware can then do the wrapping for you. Doing the wrapping in the shader is difficult to get looking right (you'll get seams where it wraps) and the extra frac() will make it slower.

1. float2 vNewTexCoord = float2(0.5f, 0.5f) + (float2(0.0625f, 0.0625f) * frac(vTexCoord)); // Note that 1024/2048 == 0.5

2. You can create 4 versions of #1 which implement wrap / clamp on each texture coordinate. You just need to split the calculations into separate ones for x and y instead of calculating both together. Use saturate() instead of frac() to clamp.

U1. float2 vNewTexCoord = float2(0.5f, 0.5f) + (float2(0.0625f, 0.0625f) * frac(vTexCoord)); // Note that 1024/2048 == 0.5


this is calculated in c++ , is possible pre processing it in c++?
I think that fract is related to "floor" , but i'm not sure.
What is the formula in c++?
thanks.
That is hlsl, to be executed in the pixel shader that reads the texture from the atlas. You can't do it in C++, unless you plan on using software rendering.

frac(x) is roughly equivalent to fmod(x, 1.0f). See http://msdn.microsoft.com/en-us/library/bb509603%28v=vs.85%29.aspx

UV coordinates outside the 0-1 range are usually designed to work with the 'wrap' texturing mode. In general it's not simple to make that work well with a texture atlas - it's much easier just to use an individual texture for anything that's wrapped because the hardware can then do the wrapping for you. Doing the wrapping in the shader is difficult to get looking right (you'll get seams where it wraps) and the extra frac() will make it slower.

1. float2 vNewTexCoord = float2(0.5f, 0.5f) + (float2(0.0625f, 0.0625f) * frac(vTexCoord)); // Note that 1024/2048 == 0.5

2. You can create 4 versions of #1 which implement wrap / clamp on each texture coordinate. You just need to split the calculations into separate ones for x and y instead of calculating both together. Use saturate() instead of frac() to clamp.


However you would rather preprocess this and add some meta data to the texture which you load along side it, seeing you are building an importer you have control over what you output. If you do it offline all your resources can use texture coordinates from 0..1 and then you only pass the offset data along to the shader. Recalculating on the GPU would only involve basic math operations which should be faster than that frac statement. The meta data should be the fractional position in the atlas map and the size of the atlas image, the only drawback to this is that your texture needs to know it is an atlas map.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion

I'm not understand .
I have all the uv texture in a vector.
Why is not possible transform all the uv in the vector for work with the atlas?
Now i separate the meshes with uv > 1 (tiled) and processed apart.
Now i have only texture from 0 to 1 .
I cant transform all the UV coord in the vector for work with atlas IN c++before send all to the shader via vertex buffer?
thanks.

This topic is closed to new replies.

Advertisement