Jump to content



Is it possible to multi-texture without extra uv coordinates?

  • You cannot reply to this topic
2 replies to this topic

#1 JohnnyLightwave   Members   -  Reputation: 103

Like
0Likes
Like

Posted 21 February 2012 - 07:40 AM

Hi all,
Okay, everyone knows something like this, right?

typedef struct Vertex2D
{
public:
    float            mX;
    float            mY;
    float            mZ;
    
    long            mDiffuse;

    float            mTextureU;
    float            mTextureV;
} Vertex2D;

I want to multitexture... but I'm doing something weird. I want texture stage 1 to basically be multiplied by a single pixel in texture stage 2. Okay, easy enough... I add mTextureU2 and mTextureV2 to my vertex up there, and just set all the U2/V2 coordinates to my single pixel.

So here's my question:

Is there any way I can do this without adding two more floats to my vertex type?

I am not changing those UV's often. They stay the same a long time. There's no good reason for me to send them to the card with every single vertex, when I might have 10,000 vertices, all using mTextureU2=.1,mTextureV2=.37

So... is there any way I could not send them-- but clamp stage 2 to a certain texture coordinate, via stage sets or whatnot?

Thanks!

Ad:

#2 yckx   Members   -  Reputation: 517

Like
0Likes
Like

Posted 21 February 2012 - 08:27 AM

In DirectX I'd use a cbuffer for that. I'm sure OpenGL has an analogous method, but I don't know what it would be called.

#3 mhagain   Members   -  Reputation: 701

Like
0Likes
Like

Posted 21 February 2012 - 03:30 PM

As stated, in D3D10 or 11 you'd use a cbuffer. In D3D9 or OpenGL you can just set them as regular shader uniforms (or use a UBO in OpenGL 3.x). Texture coords don't necessarily have to come from the vertex structure - they're just a pair of numbers so you can take them from anywhere.

If you're using the fixed pipeline in old OpenGL (with immediate mode) you can set your glMultiTexCoord (GL_TEXTURE1, ...) once every time they change and forget about it after that. This will transfer the extra coords with each glVertex call, because that's how glVertex works, but you won't need to worry about them in your program.

Another option might be to use some texgen/texture matrix tricks to get the right coords coming out. You'd want this if you're using the fixed pipeline with vertex arrays/VBOs in OpenGL or in D3D9. I haven't fully worked it out, but it seems like setting up a texgen (any one should do), followed by a texture matrix scale to bring the generated coords as close to 0 as possible, then a translate to set them to your desired values would work.






We are working on generating results for this topic
PARTNERS