Jump to content


Photo

texture coordinates problems


  • Please log in to reply
20 replies to this topic

#1 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 16 May 2012 - 06:14 PM

Hey in my terrain, to use different textures while creating the model, i set the texture coordinates to show only the wanted texture from a single 320x320 image.
Every single texture is 32x32 so the 10% of the image that in 0-1 is 0.1 .
The textures comes perfect but have a problem: around every terrain's square there's a border (a piece of the previous and next image on all the sides, like if it wasnt set to 0.1 but to 0.11)
Spoiler

To show the problem even resizing the screenshot (for uploading reasons), i had to set texture_set_interpolation to true, but this problem occur even with it set to false.
I dont get what im doing wrong because everything looks fine.
[FIXED]




Another problem about the coords. is that the terrain's squares are not always squares, sometimes they are rectangles (it depends on the z) and i get the texture stretched and i dont know how to make it repeat accordingly to the z height.

Can someone please help me?

Edited by RevenantGhost, 12 June 2012 - 09:28 PM.

  • 0

#2 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1590 posts
  • Version:GM8.1

Posted 16 May 2012 - 09:28 PM

First:
320x320 is a bad size. (Non-power-of-2 textures are not supported by all graphics cards)
Split into 256x256, 256x128, and 64x64 (Or a single 256x512)

Second:
The texture artifact shown in the screenshot is caused by the way texture coordinates are handled when interpolated. When texture interpolation is off, you probably only see some small slivers of bad texturing. This can be solved in both cases by shrinking the coordinates used so that there is a half-pixel buffer between the edge of the texture and the uv coordinates of the triangles that use it.

Best solution: Instead of using the (scaled) texture coordinate range [0, 32], use the range [0.5,31.5]. This will fix all problems, with or without interpolation, at the expense of reducing your actual tile size to 31x31 (Still fit into a 32x32 space). Use the extra space to aid tiling (interpolated or not) by copying the leftmost and topmost rows.

Edited by Gamer3D, 16 May 2012 - 09:32 PM.

  • 1

#3 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 17 May 2012 - 01:05 PM

First:
320x320 is a bad size. (Non-power-of-2 textures are not supported by all graphics cards)
Split into 256x256, 256x128, and 64x64 (Or a single 256x512)

with 320x320 is easier to scale the texture coords than other sizes, also people with a graphic card from a gameboy color won't be able to run the game anyway because is pretty heavy (talking about graphics) so i dont think that is a big problem...

Second:
The texture artifact shown in the screenshot is caused by the way texture coordinates are handled when interpolated. When texture interpolation is off, you probably only see some small slivers of bad texturing. This can be solved in both cases by shrinking the coordinates used so that there is a half-pixel buffer between the edge of the texture and the uv coordinates of the triangles that use it.

Best solution: Instead of using the (scaled) texture coordinate range [0, 32], use the range [0.5,31.5]. This will fix all problems, with or without interpolation, at the expense of reducing your actual tile size to 31x31 (Still fit into a 32x32 space). Use the extra space to aid tiling (interpolated or not) by copying the leftmost and topmost rows.

It works! It works! Thank you!! Can you please help me with the texture repeating too? :D
  • 0

#4 TheSnidr

TheSnidr

    That guy

  • Global Moderators
  • 2440 posts
  • Version:GM:Studio

Posted 17 May 2012 - 01:15 PM


First:
320x320 is a bad size. (Non-power-of-2 textures are not supported by all graphics cards)
Split into 256x256, 256x128, and 64x64 (Or a single 256x512)

with 320x320 is easier to scale the texture coords than other sizes, also people with a graphic card from a gameboy color won't be able to run the game anyway because is pretty heavy (talking about graphics) so i dont think that is a big problem...

He didn't say only weak graphics cards draw non-power-of-2 differently, many newer ones too will scale the texture differently when it's not a power of 2. That's just something you'll have to live with; if you'd rather use 320*320, it will look really bad when played on many computers
  • 1

#5 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 17 May 2012 - 01:38 PM

He didn't say only weak graphics cards draw non-power-of-2 differently, many newer ones too will scale the texture differently when it's not a power of 2. That's just something you'll have to live with; if you'd rather use 320*320, it will look really bad when played on many computers

But if i dont make it 320x320 is a problem to choose different textures because im making a script to do the calculations to set the texture coords. without setting evry texture start pos and end pos in an array (doing it manually if there's 100 textures will take a lot of time) if for example i make it 256x256 evry single texture cant be 25.6x25.6 pixels, can be 25 or 26 and that will be so hard to make automated :S
  • 0

#6 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1590 posts
  • Version:GM8.1

Posted 17 May 2012 - 08:28 PM

But if i dont make it 320x320 is a problem to choose different textures because im making a script to do the calculations to set the texture coords. without setting evry texture start pos and end pos in an array (doing it manually if there's 100 textures will take a lot of time) if for example i make it 256x256 evry single texture cant be 25.6x25.6 pixels, can be 25 or 26 and that will be so hard to make automated :S

  • A subtexture doesn't have to be 0.1 of the texture width.
  • You don't have to fill the entire space.
  • The texture doesn't have to be square. If it'll be more space-efficient, use rectangular textures, as long as both sides are powers of 2.
With that in mind, let's create a system to AUTOMATICALLY generate coordinates:
var tex_w, tex_h, off_u, off_v;
tex_w = texture_get_width(in_tex) / subtexture_count_horizontal;
tex_h = texture_get_height(in_tex) / subtexture_count_vertical;
off_u = 0.5 * tex_w / (subtexture_width + 1);
off_v = 0.5 * tex_h / (subtexture_height + 1);
out_u = off_u * (1 - 2 * in_u) + (subtex_x + in_u) * tex_w;
out_v = off_v * (1 - 2 * in_v) + (subtex_y + in_v) * tex_h;
subtexture_count_horizontal is the number of subtextures along the width of the main texture. subtexture_count_vertical is the number of subtextures along the height of the main texture.
subtexture_width and subtexture_height are the width and height (in pixels) of every subtexture, not including the repeated "buffer" pixels.
subtex_x and subtex_y are integers indicating which subtexture to choose.
in_u and in_v permit you to choose any u,v pair on the subtexture. In your case, 0,0 1,0 1,1 and 0,1 will be used.

Note: The script I gave above (untested) should work even for non-power-of-2 textures (because of texture_get_width/texture_get_height). Despite this, GET OUT OF THE HABIT; at some point, it'll ruin the game on some card.


As for the repeating, you could potentially write a program to automate it for you (using surface_getpixel), but it may be faster and easier to do it manually.

Edited by Gamer3D, 17 May 2012 - 08:32 PM.

  • 1

#7 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 18 May 2012 - 02:33 PM


But if i dont make it 320x320 is a problem to choose different textures because im making a script to do the calculations to set the texture coords. without setting evry texture start pos and end pos in an array (doing it manually if there's 100 textures will take a lot of time) if for example i make it 256x256 evry single texture cant be 25.6x25.6 pixels, can be 25 or 26 and that will be so hard to make automated :S

  • A subtexture doesn't have to be 0.1 of the texture width.
  • You don't have to fill the entire space.
  • The texture doesn't have to be square. If it'll be more space-efficient, use rectangular textures, as long as both sides are powers of 2.
With that in mind, let's create a system to AUTOMATICALLY generate coordinates:
var tex_w, tex_h, off_u, off_v;
tex_w = texture_get_width(in_tex) / subtexture_count_horizontal;
tex_h = texture_get_height(in_tex) / subtexture_count_vertical;
off_u = 0.5 * tex_w / (subtexture_width + 1);
off_v = 0.5 * tex_h / (subtexture_height + 1);
out_u = off_u * (1 - 2 * in_u) + (subtex_x + in_u) * tex_w;
out_v = off_v * (1 - 2 * in_v) + (subtex_y + in_v) * tex_h;
subtexture_count_horizontal is the number of subtextures along the width of the main texture. subtexture_count_vertical is the number of subtextures along the height of the main texture.
subtexture_width and subtexture_height are the width and height (in pixels) of every subtexture, not including the repeated "buffer" pixels.
subtex_x and subtex_y are integers indicating which subtexture to choose.
in_u and in_v permit you to choose any u,v pair on the subtexture. In your case, 0,0 1,0 1,1 and 0,1 will be used.

Note: The script I gave above (untested) should work even for non-power-of-2 textures (because of texture_get_width/texture_get_height). Despite this, GET OUT OF THE HABIT; at some point, it'll ruin the game on some card.


As for the repeating, you could potentially write a program to automate it for you (using surface_getpixel), but it may be faster and easier to do it manually.

Thanks for the script :) By the way about the texture repeat i dont even know how to do it manually D:
  • 0

#8 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 20 May 2012 - 12:45 PM

BUMP

Please i need to know how to repeat the texture..
  • 0

#9 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1590 posts
  • Version:GM8.1

Posted 20 May 2012 - 09:26 PM

Please i need to know how to repeat the texture..


Same thing you're doing in first image (draw each tile separately).

For the texture itself, select the topmost row of each tile. Press copy. Press paste. Move that row to the bottom of the tile. Same for the leftmost column of each tile.

Alternately, use separate backgrounds for each tile type so you can use texture_set_repeat(true) and UV coordinates outside of the [0,1] range.
  • 1

#10 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 21 May 2012 - 09:21 AM

Alternately, use separate backgrounds for each tile type so you can use texture_set_repeat(true) and UV coordinates outside of the [0,1] range.

If only was so easy... The terrain is a model, i can use only 1 texture for it, this is why im using a single background and UV coords. And i have no idea on how to repeat the texture of a triangle using UV coords...
  • 0

#11 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 30 May 2012 - 07:20 PM

bump
  • 0

#12 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 05 June 2012 - 02:26 PM

bump
  • 0

#13 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 12 June 2012 - 09:28 PM

bump
  • 0

#14 Phantom107

Phantom107

    Engineer

  • GMC Member
  • 2599 posts
  • Version:GM:Studio

Posted 13 June 2012 - 02:47 PM

Yes, it actually is that easy.

Just try drawing a single textured triangle on screen. Then play with the settings and see what happens.
  • 0

#15 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 13 June 2012 - 05:09 PM

Yes, it actually is that easy.

Just try drawing a single textured triangle on screen. Then play with the settings and see what happens.

You dont get my point, that is a model, i can use only a single texture for the entire model (entire terrain), this is why im using texture coordinates, but using them as far as i know there's no way to make it repeat the texture, or is there any way?
  • 0

#16 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1590 posts
  • Version:GM8.1

Posted 13 June 2012 - 08:15 PM

You dont get my point, that is a model, i can use only a single texture for the entire model (entire terrain), this is why im using texture coordinates, but using them as far as i know there's no way to make it repeat the texture, or is there any way?

For what you're doing, to repeat a texture, you'll need to draw multiple triangles, each mapped to the same patch of texture. There are some things you can do to increase efficiency, but since you couldn't figure this problem out on your own over the course of... about 24 days, I doubt you'd be able to use them.
  • 0

#17 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 15 June 2012 - 09:24 AM


You dont get my point, that is a model, i can use only a single texture for the entire model (entire terrain), this is why im using texture coordinates, but using them as far as i know there's no way to make it repeat the texture, or is there any way?

For what you're doing, to repeat a texture, you'll need to draw multiple triangles, each mapped to the same patch of texture. There are some things you can do to increase efficiency, but since you couldn't figure this problem out on your own over the course of... about 24 days, I doubt you'd be able to use them.

Drawing miltiple triangles is EXACTLY what i want to avoid, i wondered if there was any way to repeat a (subtexture?) without drawing multiple triangles.
I did many tests in my game and i figured out the maximum map size with my triangle's size without having fps drops, believe me it is really at the limit GM or my graphic card can handle, a bit more triangles and the frame rate drops like a bass in a dubstep song, what if i make 10 or 100 times those triangles to repeat the texture? 1fpm (frame per minute) LOL
The map is insanely big and that's the whole point of the game, i tried making a kind of voxels but with a horrible result in fps, the only way is to keep it like this but looks pretty bad if textures cant be stretched!
Yes, evrything is efficient, the map is divided in some parts with different models by detail and are choosen a less detail by as far as it is to keep the less triangle number as possible, no execute_code, no other slow functions, evrything is ok, i reached the top my pc or GM can handle, so adding triangles is no way the fix for this problem..
The question was, is there any direct way to repeat the subtextures without adding triangles or using surfaces or doing anything else that slows down a game?
  • 0

#18 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1590 posts
  • Version:GM8.1

Posted 15 June 2012 - 10:03 PM

Drawing miltiple triangles is EXACTLY what i want to avoid, i wondered if there was any way to repeat a (subtexture?) without drawing multiple triangles.
I did many tests in my game and i figured out the maximum map size with my triangle's size without having fps drops, believe me it is really at the limit GM or my graphic card can handle, a bit more triangles and the frame rate drops like a bass in a dubstep song, what if i make 10 or 100 times those triangles to repeat the texture? 1fpm (frame per minute) LOL

You can repeat subtextures along strips (Pick one direction, not two) by ensuring that each subtexture occupies an entire dimension of the texture. For example, 32x32 textures could be placed on a 512x32 texture. You could then repeat vertically (but not horizontally) by using v coordinates outside the [0,1) range.

Yes, evrything is efficient, the map is divided in some parts with different models by detail and are choosen a less detail by as far as it is to keep the less triangle number as possible, no execute_code, no other slow functions, evrything is ok, i reached the top my pc or GM can handle, so adding triangles is no way the fix for this problem..

Might be time to start culling (Find an efficient way to determine which segments to render and which to ignore). I'm rather surprised that you're having trouble. I had no trouble with 132000 triangles at 60FPS.

You should also make sure you're using triangle strips instead of triangle lists.
  • 1

#19 RevenantGhost

RevenantGhost

    GMC Member

  • GMC Member
  • 106 posts
  • Version:GM8

Posted 16 June 2012 - 11:50 AM

You can repeat subtextures along strips (Pick one direction, not two) by ensuring that each subtexture occupies an entire dimension of the texture. For example, 32x32 textures could be placed on a 512x32 texture. You could then repeat vertically (but not horizontally) by using v coordinates outside the [0,1) range.

This is so a nice idea, but here comes another problem with it: because the triangles could be long on a side or on another, making it able to stretch on a single direction would make impossible to stretch the texture on a certain direction, if i invert h and v for the stretched ones to make always possible to stretch it, i will have some traingles with inverted texture, so looking even worse than now without the texture repeating... Plus what if the triangle isnt straight and needs both h and v to repeat? The idea is nice and i never tought about it, but seems like it has some lacks...
  • 0

#20 Gamer3D

Gamer3D

    Human* me = this;

  • GMC Member
  • 1590 posts
  • Version:GM8.1

Posted 16 June 2012 - 06:16 PM

This is so a nice idea, but here comes another problem with it: because the triangles could be long on a side or on another, making it able to stretch on a single direction would make impossible to stretch the texture on a certain direction, if i invert h and v for the stretched ones to make always possible to stretch it, i will have some traingles with inverted texture, so looking even worse than now without the texture repeating... Plus what if the triangle isnt straight and needs both h and v to repeat? The idea is nice and i never tought about it, but seems like it has some lacks...

So work around the problems. Use texture repetition if you can and split up triangles if you can't. This isn't a difficult concept.

Also, this is probably as good as (pure) GM texture atlassing is going to get. You're going to need to make some compromises now.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users