uv-coordinates HELP?

Started by LRFLEW, March 15, 2012, 09:10:24 PM

Previous topic - Next topic

LRFLEW

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?

EgonOlsen

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...

LRFLEW

#2
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>

Marlon

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

LRFLEW

Quote from: Marlon 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
The image is 256x256, so that can't be the problem...

EgonOlsen

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.

LRFLEW

#6
Quote from: EgonOlsen 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.
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.

Hrolf

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.

LRFLEW

Quote from: Hrolf on March 18, 2012, 03:19: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 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

Hrolf

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.

LRFLEW

Quote from: Hrolf 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.
Yeah, and from what I tried, not even a full solution :P

Quote from: Hrolf on March 18, 2012, 04:02:18 AMUnless 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...

EgonOlsen

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.

LRFLEW

#12
Quote from: EgonOlsen 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).
*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...

Quote from: EgonOlsen on March 18, 2012, 08:24:41 AM
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.