gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Texture Coordinates

#145933 - Peter - Sun Nov 25, 2007 11:05 pm

Hello all,

I have a few questions regarding texture-coordinates.

When I wrote my displaylist converter and mesh viewer code, my goal was to use texture coordinates between 0..1, then use the texture matrix to scale them to the actual texture size. I though this makes sense, because it enables me to use textures with different sizes without changing the displaylist that contains the tex-coords.

However, since the precision of the TEXCOORD command has only 4 bit fractional part, unfortunalety it runs out of precision rather soon and this makes it useless for me.

My current idea is to multiply the texture-coordinates in a displaylist by 256*16 during the displaylist creation. The 256 would be a hardcoded texture-size of 256x256 pixels and the 16 is for the tex-coord command's 4bit fraction.

Since I know the hardcoded 256 in the displaylists, I can calculate the ration between the 256 and the real texture size I want to use, then use the texture matrix again to scale it to the correct size. But I still have a bad feeling about this, it just seems wrong to me.

However, I don't like the idea to store the exact texture-size in the displaylist and more or less bound it to exactly this size. What if I want to use the same displaylist with two different textures with different sizes (e.g. LOD, not the best example but you get what I mean).

What is your approach to handle this? I'm kinda confused.
_________________
Kind Regards,
Peter

#145935 - DekuTree64 - Sun Nov 25, 2007 11:18 pm

Personally I would just avoid using different texture sizes on the same model. A good artist will tweak the UV coordinates so it looks good with a specific resolution, depending on how large the model will generally be on screen. And for LOD, you'll generally want a different model with more polygons anyway, or use the high resolution textures all the time (because if you're planning to swap models in-game, you probably won't have time to load high-res textures).

That said, if you do have a legitimate reason to switch sizes, then yes, I would generate the coordinates for the largest size you plan to use, and then scale them down with a texture matrix.

And for what it's worth, you can modify display list data on the fly too.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#145940 - nce - Mon Nov 26, 2007 12:45 am

Peter wrote:
But I still have a bad feeling about this, it just seems wrong to me.


Don't worry, it's working :) that's the way I did it.
_________________
-jerome-

#145966 - M3d10n - Mon Nov 26, 2007 6:23 pm

I generate UV coordinates assuming a fixed texture size (32x32, I think) and scale the texture matrix depending on the texture size. However, I don't store texture change commands in my display lists (I split my meshes in display lists for each material).

#145974 - kusma - Mon Nov 26, 2007 11:46 pm

wouldn't the "best" method be to normalize the texture coordinate so you utilize the full range and thus get maximum precision on each model, and then scale everything to match the texture using the texture-matrix?

edit: this technique does of course not limit itself to texture coordinates. use it at your vertices as well.

#145976 - nce - Tue Nov 27, 2007 12:54 am

kusma wrote:
wouldn't the "best" method be to normalize the texture coordinate so you utilize the full range and thus get maximum precision on each model.


you can of course, use the full range if you want, but you have to think also at your tilling.

Imagine that you know from the beginning that you 'll never make a texture bigger than 256*256 you don't need the extra precision to put a uv between 2 pixel ( no bilinear filtering on the DS ). So it's better to assume all your texture as 256*256 that left you room to make them tile ( if you are doing environment )

- I use the same configuration : max texture 256*256 but all are assumed to be 128*128 so I can tile easily textures and when I have a 256 256 I just make sure that my uvs match the precision of a 128*128


and yes I scale also environment with a factor of 16 compared to the characters :)
_________________
-jerome-

#145978 - kusma - Tue Nov 27, 2007 1:03 am

nce wrote:
you can of course, use the full range if you want, but you have to think also at your tilling.

Normalizing to the full range still gives you tiling. What I'm talking about is basically taking all your texture coordinates (in floating point), finding the minimum and the maximum of each component, and scale them to occupy the entire 16bit range of the texture coordinates. Then you can scale back however you want to texture-space using the texture matrix. Of course, if you have a lot of tiling over a single polygon, you might have to do something different, but that's a completely different matter, as no single scaling-method will give you high range and high precision at the same time.

#145981 - M3d10n - Tue Nov 27, 2007 2:57 am

Oh, that's a really good idea, Kusma. I already normalize vertex coordinates and store the correcting scale in the display list itself, to use the maximum precision, but I never thought of using it for textures. It might even improve minification and magnification quality a bit.

It also allows the artists to be more free when creating their UVs. Right now I have to ask them to keep all UVs as close as possible to the origin and avoid offsetting UV coords too much to avoid overflows, but if they are normalized, it doesn't matter.

#145987 - nce - Tue Nov 27, 2007 4:58 am

Hi Kusma, Yes it's a good idea,

But I'm not sure to understand why trying to get the best resolution possible ? there is no bilinear filtering on the ds so when you are doing your uvs is better to try to set them just between your texel.

as if you have a texture size 2 * 2, you can only have 0 , 0.5 and 1 as value for you uv. no realy need to get able to set a uv at 0.02 or 0.3, because that will just result in flickering, sometimes piking one pixel sometimes piking the other...

>> that's why if you know that your texture is max 256*256, the concern about having full precision is not needed, I think.
_________________
-jerome-

#145991 - kusma - Tue Nov 27, 2007 8:53 am

nce wrote:

But I'm not sure to understand why trying to get the best resolution possible ? there is no bilinear filtering on the ds so when you are doing your uvs is better to try to set them just between your texel.

Sure, there's no bilinear filtering, but there IS sub-texel precision. Being able to choose exactly where inside the texel a vertex is positioned makes it easier to improve the quality of the sampling. However, I believe that the biggest gain is that you get a somewhat "dynamic" range / precision trade-off from mesh to mesh.

By the way (quite unrelated, I know), I played around a bit with some kind of temporal filtering yesterday - alternating the texture matrix at full frame rate to get something slightly better than normal point sampling. It wasn't exactly a great success in 2d (1d worked great) due to all the flickering you get, but it might be usable for something. Perhaps, if one already does normal motion trail post processing, the flickering artifacts will disappear? :)