Skip to main content
GameDev.net gamedev.net
🔒 Locked

D3D9: Texture offsetting?

Started by Koobazaur Feb 19, 2007 at 6:47 PM 3 replies 1.1k views
Original Post
Koobazaur
Koobazaur
Hey, I was wondering if there is any way to set an offset for the U/V texture coordinates in DX9. The problem I am having is, I have a big grid of vertexes (100 x 100) which have UV cords so that a single texture covers the whole surface. Now, I want to move the texture accross the surface. Is there a way to set an offset somehow for the UV coords, or do I need to go in and modify them for each single vertex?
Comrade, Listen! The Glorious Commonwealth's first Airship has been compromised! Who is the saboteur? Who can be saved? Uncover what the passengers are hiding and write the grisly conclusion of its final hours in an open-ended, player-driven adventure. Dziekujemy! -- Karaski: What Goes Up...
Mindowindow
Mindowindow
If you're using the the programmable pipeline then just do it in the vertex or pixel shader using a shader constant that you set when the offset changes.

float2 UVOffset;VS_OUTPUT UVOffsetVertexShader(VS_INPUT input){    VS_OUTPUT output;    ...transformations etc...    output.uv = input.uv + UVOffset;    return output;}or (less efficient but still would work)float4 OffsetPixelShader(float2 uv: TEXCOORD0) : COLOR0{    return tex2D(TextureSampler, uv+UVOffset);}


If you're using the fixed-function pipeline then...well...start using the programmable pipeline, cases like this are why its flexibility is so useful.
Namethatnobodyelsetook
Namethatnobodyelsetook
For the fixed pipeline.

Set D3DTSS_TEXTURETRANSFORMFLAGS to D3DTTFF_COUNT2 (ie: 2D transform) on whichever texture stage you want to transform.
ie:
pDev->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);

Set the tranform for the appropriate stage
ie:
D3DXMATRIX mat;
D3DXMatrixIdentity(&mat);
mat.31 = translationu;
mat.32 = translationv;
pDev->SetTransform(D3DTS_TEXTURE0, &mat);

if you don't know how to setup 2D transforms on your own, you can use the recently added D3DXMatrixTransformation2D instead of the code I posted above.

Be sure to disable the transform after drawing so as to not affect any subsequent draws.
Koobazaur
Koobazaur
Thanks for the tip!

Also, about the fixed vs. programmable pipeline... I only started learning DX9 recently and don't exactly know what you are talking about. Do elaborate, please?
Comrade, Listen! The Glorious Commonwealth's first Airship has been compromised! Who is the saboteur? Who can be saved? Uncover what the passengers are hiding and write the grisly conclusion of its final hours in an open-ended, player-driven adventure. Dziekujemy! -- Karaski: What Goes Up...
Namethatnobodyelsetook
Namethatnobodyelsetook
Fixed-pipeline is when use you D3D's lights, texture stages, transforms (world, view, projection), etc. You can control what the hardware does to some extent, but there are definately limits you'll hit.

programmable pipeline is using shaders. You must perform more work yourself, but you can control exactly what calculations are performed. In DirectX8 shader model 1 was introduced, which itself is fairly restrictive, though still a step up from the fixed pipeline. In DirectX9 shader models 2 and 3 were introduced, adding more functionality, longer shaders, and more storage. In DirectX 10, for Vista only, shader model 4 is introduced, and the fixed pipeline is dropped.

The programmable pipeline is the way forward. I'm not sure which method is the easiest for learning. Fixed pipeline will get you up and running quicker, but you'll need to take a step back at some point and learn the math behind everything to implement it yourself in a shader. It's sometimes easier to see how/why things work in a shader than a magic black box.

Pick one and run with it. Or learn something in the fixed pipe and then work out how it works in a shader. Whatever works for you.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.