Author Topic: uv-coordinates HELP?  (Read 5788 times)

Offline LRFLEW

  • byte
  • *
  • Posts: 17
    • View Profile
uv-coordinates HELP?
« on: March 15, 2012, 09:10:24 pm »
Ok, I have a basic understanding of how uv-coordinates work to put an image on a 3D object, but I don't get how jPCT is using it, or with what unit's it does it. 

Specifically, this is what I'm trying to do: I have a texture file which is 256 pixels square.  The image is designed as four 128 pixel square textures (but put in the same image file so I can load it all at once).  In order of first left to right, then up to down, the textures are the floor, all four walls (they share one texture), and the ceiling.  The fourth sub-image is blank and currently holds my secrets to world domination, but it shouldn't be shown in the cube at all. 

How might I go about setting up the uv-coordinates to get this to work?
« Last Edit: March 17, 2012, 05:19:46 am by LRFLEW »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: uv-coordinates help?
« Reply #1 on: March 15, 2012, 09:52:09 pm »
u/v coordinates are normalized, i.e. to map something with the complete texture, you would do 0,0-1,1. If you want to use only a quarter of the texture...0,0-0.5,0.5 pr 0.5,0,5-1,1 etc...

Offline LRFLEW

  • byte
  • *
  • Posts: 17
    • View Profile
Re: uv-coordinates help?
« Reply #2 on: March 15, 2012, 10:27:07 pm »
Ok, I tried doing that, and I'm getting a weird outcome.  I have no clue what's going on, so I've uploaded the files to see if anybody else can figure it out before me.  Please tell me what's wrong

EDIT: Where is the origin in the image? Upper-Left?

<Links removed because the files are no longer hosted>
« Last Edit: March 18, 2012, 03:48:41 am by LRFLEW »

Offline Marlon

  • int
  • **
  • Posts: 74
    • View Profile
    • Forgotten Elements Action MMORPG
Re: uv-coordinates HELP?
« Reply #3 on: March 17, 2012, 08:45:37 pm »
Keep in mind that the resolution of the texture should be a power of 2.
E.g:
64X64, 128x128,256x256 or 512x512
www.forgottenelements.com
Free Action JAVA MMORPG

Offline LRFLEW

  • byte
  • *
  • Posts: 17
    • View Profile
Re: uv-coordinates HELP?
« Reply #4 on: March 17, 2012, 08:58:02 pm »
Keep in mind that the resolution of the texture should be a power of 2.
E.g:
64X64, 128x128,256x256 or 512x512
The image is 256x256, so that can't be the problem...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: uv-coordinates HELP?
« Reply #5 on: March 17, 2012, 09:51:33 pm »
I can't try the code right now...do you have a screen shot that actually shows this in a clearer way!? I've no idea what i'm looking at nor how it is supposed to look.

Offline LRFLEW

  • byte
  • *
  • Posts: 17
    • View Profile
Re: uv-coordinates HELP?
« Reply #6 on: March 17, 2012, 10:10:45 pm »
I can't try the code right now...do you have a screen shot that actually shows this in a clearer way!? I've no idea what i'm looking at nor how it is supposed to look.
This is actually quite hard to explain what's going on.  The room is a cube, but viewed from the inside.  It appears that the texture is centering on one wall, warping around the other walls, and converging again on the other side.  It's really hard to explain exactly what's happening because I'm not sure entirely what the problem is. 
To see what it's suppose to look like, the walls.png shows the three textures. The dark green/brown one should span the bottom face of the cube, the light face covers the upper face, and the texture on the upper-right of the image file spans the remaining four sides. 

Hope this clarifies somewhat.
« Last Edit: March 17, 2012, 10:32:32 pm by LRFLEW »

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: uv-coordinates HELP?
« Reply #7 on: March 18, 2012, 03:19:29 am »
I think you need to do a test case: remove all the walls except the back wall and set the uv co-ords to 0,0 - 1,1. This will show you the texture orientation for just that wall. Get that right then adjust the uv co-ords so that wall looks like you want it to. Rinse and repeat for the other walls.
A trick I've used before is to put temporary marks on the texture ('up', 'left', etc) so I can understand what's actually happening.

Offline LRFLEW

  • byte
  • *
  • Posts: 17
    • View Profile
Re: uv-coordinates HELP?
« Reply #8 on: March 18, 2012, 03:47:29 am »
...

That was an excellent idea Hrolf, thanks, but it only confused me at first.  When I isolated a single wall, weird things started to happen.  Wondering what could be causing such strange actions, I went ahead and looked in the launcher class, and found the problem.  I accidentally left in the line
Code: [Select]
room.setEnvmapped(Object3D.ENVMAP_ENABLED);and that was screwing it up :P.  Thanks though to everybody that has helped. 

I still have one more problem, however it's kind of minor.  Because the textures are right next to each other in the image file, sometimes little seams appear where one texture tries to grab a column or row from the next texture.  Is there an easy way to prevent that without clipping the texture I'm trying to place?

Screenshots:
Shot 1
Shot 2

Offline Hrolf

  • int
  • **
  • Posts: 84
    • View Profile
Re: uv-coordinates HELP?
« Reply #9 on: March 18, 2012, 04:02:18 am »
Texture bleed. The best answer I've found is to tweak the uv coords from say 0,0 - 0.5,0.5 to 0.05,0.05 - 0.495,0.495 - not so pretty.
Unless memory or latency are really important issues it would be much better to simply use one texture per surface.
On a PC you can easily have 10s or even 100s of 256x256 textures without a problem, Android - maybe just 10s.

Offline LRFLEW

  • byte
  • *
  • Posts: 17
    • View Profile
Re: uv-coordinates HELP?
« Reply #10 on: March 18, 2012, 04:21:08 am »
Texture bleed. The best answer I've found is to tweak the uv coords from say 0,0 - 0.5,0.5 to 0.05,0.05 - 0.495,0.495 - not so pretty.
Yeah, and from what I tried, not even a full solution :P

Unless memory or latency are really important issues it would be much better to simply use one texture per surface.
although memory and latency are not issues *yet*, I had thought (from what research I tried to do) that using multiple textures on a 3D model was a pain, especially using software render.  I don't really know why I'm using a software render and would probably switch over to OpenGL if I had a reason to...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: uv-coordinates HELP?
« Reply #11 on: March 18, 2012, 08:24:41 am »
You'll run into the same issues with hardware rendering as long as you are using anything but pick nearest filtering (which looks ugly). IMHO, doing this is premature optimization. I would go for separate textures instead.

Offline LRFLEW

  • byte
  • *
  • Posts: 17
    • View Profile
Re: uv-coordinates HELP?
« Reply #12 on: March 18, 2012, 07:35:18 pm »
You'll run into the same issues with hardware rendering as long as you are using anything but pick nearest filtering (which looks ugly).
*googles 'pick nearest filtering'* oh, so like minecraft rendering :).  Just out of curiosity, how would i tell jPCT to use that?

EDIT: Found it :).  Texture.setFiltering(boolean filter);  Feels kind of weird, though, having trilinear filtering set in another place...

I would go for separate textures instead.
1) can I do this with software render, or should I just go over to OpenGL, which I will probably do inevitably?

EDIT: Forget the software render.  It's ugly and I would have needed to ditched it before any sort of release anyways.  I have already converted to full OpenGL :)

2) how exactly do I go about multi-texturing?  Do I need to make multiple Object3D instances to get it to work??

EDIT: I figured it out :P.  Now I feel stupid.  Now it looks a little weird without anti-aliasing, but whatever.
« Last Edit: March 20, 2012, 12:24:11 am by LRFLEW »