PDA

View Full Version : Multitexuring questions



cbadboy9
03-04-2010, 01:34 AM
Hi..I'm fairly new to OpenGL so I have some questions...

I actually play arround with texture mapping and the multitexture extension (also GLSL shading). Simple multitextureing is working fine.

I've try to implement a simple plane with a base texture in background and a logo, which i would place somewhere on this plane and scaling/rotating the texture ...

A friend of mine told me that i could only archive this using more geometry informations. Is this right?

I thought multitextureing might be a solution to approach my aim, using multiple texture coordinates at the different units. What is the sense of using differend texture coordinates?

All tutorials i've found using only the same texture coordinates from Unit 0 at the other Units ... And all examples using textures of the same size?

I've actually trouble to understand this. Could me anyone point me in the right direction?

ZbuffeR
03-04-2010, 02:10 AM
In compatibility profile, you have some built-ins for this :
http://www.lighthouse3d.com/opengl/glsl/index.php?texture

For core GL 3.2, you have to provide your own attributes to vertex/fragment shaders.

cbadboy9
03-04-2010, 03:23 AM
I know this tutorial and I've implemented it successfully. But this tutorial also uses the same texture coordinates on each texture unit...

At the multitextureing part of this tutorial they add a 2nd texture with a text at the middle of each face using multitexturing. But the 2nd texture is from same size, using the same coords, the visible area is predefined using alpha values so the placement of the texture is fixed ...

Regarding to this tutorial how you would add a 2nd texture (i.e. a logo) and place it somewhere on the crate where you want without using a static predefined texture position at the image?

What is the advantage of additionally texture coords at multitextureing?

dorbie
03-04-2010, 03:23 AM
You have a choice, you can use the same texture coordinate in your shader or a different one. Clearly whether you need to is a matter of choice.

It used to be that you needed separate texture coordinates for each texture unit (although an early SGI multi-texture extension could multi-case coordinates).

So your friend is wrong, or rather his answer is out of date for modern shader based rendering.

cbadboy9
03-04-2010, 05:22 AM
Ok, but how i should use different coordinates? I.e. i've to create a simple box (this box is modelled by a friend in 3ds max using multiple materials):

[IMG=http://www.image-share.com/upload/188/136m.bmp] (http://www.image-share.com/ibmp-188-136.html)
[IMG=http://www.image-share.com/upload/188/137.jpg] (http://www.image-share.com/ijpg-188-137.html)
[IMG=http://www.image-share.com/upload/188/138m.jpg] (http://www.image-share.com/ijpg-188-138.html)

As you can see, the biohazard logo has been placed several times at different positions in different scales on the faces of the box.

To make it easier, talk for a single face. Here I've implemented:

Vertex lower left:
Pos -5, -5, 0 Texture 1 0,0

Vertex lower right:
Pos 5, -5, 0 Texture 1 1,0

Vertex upper right:
Pos 5, 5, 0 Texture 1 1,1

Vertex upper left:
Pos -5, 5, 0 Texture 1 0,1

Now i twist my mind how i could add a second texture, i. e. in the middle of that plane or any other position or scale using another texture without an alpha range using same coordinates for fix placing.

dorbie
03-04-2010, 06:17 AM
Use 2D coordinates not 3D. This may be the cause of your confusion. Just map the texture to the surface using these coordinates.

In a shader your sampler call takes the interpolated vertex values as input.

Now if you have a cubemap then 3D coordinates would be appropriate but that's kinda nuts, even if you are drawing a cube, it's not what cubemaps are really for :-).

Pierre Boudier
03-04-2010, 06:27 AM
what you are asking is to create a decal texture:
- to avoid the alpha trick, you should use a border color with an alpha of 0, and use the wrap mode clamp_to_border
- to place the texture correctly in the shader, you should translate/rotate your texture coordinate in your shader, or use texture matrix in fixed function
- in your shader or in fixed function, you just modulate the two textures

cbadboy9
03-04-2010, 06:48 AM
It's all Greek to me, could you please give me more explanatory notes?
In my example i use only 2D textures for the plane, the first number is the ID for the texture Nr. 1 ...

Vertex lower left:
Pos (-5, -5, 0) Texture_1 (0,0) Texture_2 (? ?)

Vertex lower right:
Pos (5, -5, 0) Texture_1 (1,0) Texture_2 (? ?)

Vertex upper right:
Pos (5, 5, 0) Texture_1 (1,1) Texture_2 (? ?)

Vertex upper left:
Pos (-5, 5, 0) Texture_1 (0,1) Texture_2 (? ?)

I still missing a hint how i use the second texture coordinates ...
If i use the same texture coords for texture unit 2 i got a logo mapped on the plane having the same size as texture 1 ...

How could i add a 2nd texture i.e. to the left lower corner of that plane expanding half width and height from left bottom corner? Could you give me a hint following my example?

Note:
I've searched checked the ASE file format of the box and I've figured out that they use UV-Tiling and UV-Offset informations on Material definitions. Might it be a solution by regard this value on texture coord definition? I.e use 0,5 instead of 1.0 will scale up the texture, or 1.5 scale it down.

Y-tension
03-04-2010, 07:45 AM
Nothing peculiar about Greek, I speak it all the time ;)

Use the same texture coordinates as texture 1 for your texture 2. But then you can use a rotation/scale matrix to rotate/scale the texture.

In shaders you simply define your matrix and multiply your texture coordinates with it in the shader.

In fixed function, you must do something like:



glActiveTexture(GL_TEXTURE1);
glMatrixMode(GL_TEXTURE);
glRotatef(....);
//or
glScalef(....);

cbadboy9
03-04-2010, 08:27 AM
Ok this sounds better scaling and rotation is no matter anymore :D But when i use the same coords I've not moved or translated the texture ...

rats_ogl
03-04-2010, 11:52 AM
3 textures in first plane, 2 tex in second plane
http://imgurl.filetac.com/img/77286790.jpg

cbadboy9
03-04-2010, 12:05 PM
Great, this is what i would archieve, but how? Using differend texture units and different texture coordinates for the render stage.

Ok, but how i define the second texture coordinates? For the first unit i got in the left lower corner 0,0 and in the right lower corner 0,1 ...

Y-tension
03-09-2010, 06:00 AM
Ok this sounds better scaling and rotation is no matter anymore :D But when i use the same coords I've not moved or translated the texture ...

When you use a texture matrix, your coordinates, even if they are the same initially, get transformed by the texture matrix first before they are used. So if you downscale your coordinates with a texture matrix (glScale(0.5, 0.5, 0.5); for example)the image gets bigger on your object(Yeah, it's bizarre, I know).

Remember to reset (load identity to) your texture matrix after using it for something like that.