Advertisement

How to sample a random sprite texture?

Started by October 24, 2018 03:41 PM
7 comments, last by babaliaris 5 years, 10 months ago

Let's say you have a random sprite sheet like this:

latest?cb=20120324233027

How can you sample from it?

I want to create a sprite system which you give it a sprite texture sheet and automatically samples from it and creates different textures. I really don't have a clue how to do this. The only think i can do now, is to manually try different texture coordinates for each figure i see on the texture (somehow to guess the texture coordinates for each figure) and then try them to see if I'm getting the correct part from the sprite sheet and if not depending on the output, i adjust the texture coordinates (a little to the left, or right or bottom or top) in order to get the part of the texture i want. This is cumbersome and does not allow me to create an automatic system for that.

If only I knew the texture coordinates for each figure that would be easy. So am I missing something? Just downloading images from google is not enough? Do i need to find a special sprite sheet format or something which the creator already includes the texture coordinates too?

 

Thank you.


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

Quote

How can you sample from it?

Can you clarify what you mean by sample from it? Usually sampling with respect to textures means deriving a color value using a texture coordinate and various filtering rules, but I'm thinking that's not what you mean here.

Quote

I want to create a sprite system which you give it a sprite texture sheet and automatically samples from it and creates different textures.

When you say create different textures, do you actually want to create a separate texture object for each sprite? Or do you just want to determine appropriate texture coordinates for each sprite?

Quote

If only I knew the texture coordinates for each figure that would be easy. So am I missing something? Just downloading images from google is not enough? Do i need to find a special sprite sheet format or something which the creator already includes the texture coordinates too?

I would think that most sprite sheets would have an associated file specifying the parameters (e.g. texture coordinates) for each sprite.

As for trying to derive this information automatically, I saw a post here a while back where someone was using flood fills to generate sprite UV rectangles automatically. This might not be sufficient by itself though, because you'd likely still need 'hot spot' information in order to position the sprites correctly with respect to one another (especially with animation sequences).

Apologies if I misunderstood anything here.

Advertisement
58 minutes ago, Zakwayda said:

Can you clarify what you mean by sample from it? Usually sampling with respect to textures means deriving a color value using a texture coordinate and various filtering rules, but I'm thinking that's not what you mean here.

When you say create different textures, do you actually want to create a separate texture object for each sprite? Or do you just want to determine appropriate texture coordinates for each sprite?

I would think that most sprite sheets would have an associated file specifying the parameters (e.g. texture coordinates) for each sprite.

As for trying to derive this information automatically, I saw a post here a while back where someone was using flood fills to generate sprite UV rectangles automatically. This might not be sufficient by itself though, because you'd likely still need 'hot spot' information in order to position the sprites correctly with respect to one another (especially with animation sequences).

Apologies if I misunderstood anything here.

Only one texture will be loaded into the GPU (the sprite sheet texture). Then inside the fragment shader i want to use the appropriate texture coordinates to take only the part of the texture (some figure) which I'm interesting in.

Actually the system will display each figure separately and let you decide which goes to which sprite object. 

To not confuse you more, If I know the texture coordinates for each figure into the sprite sheet then i have enough information to know what to do next.

So is there a way to know these coordinates?


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

If you don't have the original metadata available, then it seems like the options available are to figure out the UV coordinates manually (possibly tedious and difficult) or to automate it. (This is assuming I understand the question correctly.)

Just in case it might be helpful, here is a recent thread where automatic generation of texture atlas UVs was discussed.

With respect to automating, it may be that there are existing tools that can help with that. Here are a couple threads I found that might be useful to you:

https://stackoverflow.com/questions/25945930/generating-uv-coordinates-for-texture-atlas

https://gamedev.stackexchange.com/questions/35868/how-to-decompose-sprite-sheet

8 minutes ago, Zakwayda said:

If you don't have the original metadata available, then it seems like the options available are to figure out the UV coordinates manually (possibly tedious and difficult) or to automate it. (This is assuming I understand the question correctly.)

Just in case it might be helpful, here is a recent thread where automatic generation of texture atlas UVs was discussed.

With respect to automating, it may be that there are existing tools that can help with that. Here are a couple threads I found that might be useful to you:

https://stackoverflow.com/questions/25945930/generating-uv-coordinates-for-texture-atlas

https://gamedev.stackexchange.com/questions/35868/how-to-decompose-sprite-sheet

So there are places on the web where you can find textures with the meta data too?

If I understood correctly, your way of automating them is somehow to have an algorithm that finds the texture coordinates using pixel calculations? This sounds difficult


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

For thisnkind of texture you need additional file that stores the information about each row, since each row is different sprite you need to store jnformation about sprite height, width and sprite number (num of frames per sprite) along this will require the speed of the animation which you should store too

Then you do some fancy computing to determine from which x you start

So the spec file contains

Number of sprites

Sprite no1 width, height, number of frames(sprites per row), animation speed

Sprite no2 width, height, number of frames(sprites per row), animation speed

Advertisement
Quote

So there are places on the web where you can find textures with the meta data too?

It does seem like a lot of the sprite sheets available online are image-only and don't include metadata. I think if you do some digging though you could probably find some that do. Just as an example, I looked around a bit online and found this, which appears to include metadata. There also appear to be quite a few sprite sets available that use a uniform grid, obviating the need for metadata.

Whether you can find something that meets your particular needs is of course a different question.

Quote

If I understood correctly, your way of automating them is somehow to have an algorithm that finds the texture coordinates using pixel calculations? This sounds difficult

Yes, it could be non-trivial. However, the GDNet thread I linked earlier includes some example code, and the other threads I linked mention some tools that might do automatic sprite sheet decomposition. If you're interested in pursuing an automated approach, I'd suggest investigating existing tools first, as that might offer a fairly straightforward solution.

Thank you guys! This is more complicated than I thought. I will stick with existing tools first to understand how they work and I'll see what's next.


void life()
{
  while (!succeed())
    try_again();

  die_happily();
}

 

This topic is closed to new replies.

Advertisement