Sign in to follow this  
giugio

texture atlas and tiled textures

Recommended Posts

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 .

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1307354610' post='4820024']
U1. float2 vNewTexCoord = float2(0.5f, 0.5f) + (float2(0.0625f, 0.0625f) * frac(vTexCoord)); // Note that 1024/2048 == 0.5
[/quote]

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[quote name='Adam_42' timestamp='1307354610' post='4820024']
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.
[/quote]

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this