Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

[C#] [HLSL] How can I align textures to an axis?

This topic is 2860 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a textured quadrangle with a normal of (0,0,-1) (facing "left").

How can I align the texture on that quadrangle to the "up" axis (0,1,0)?

This way when looking at the quadrangle (with the camera "up" = (0,1,0)) the texture would have the same orientation as when viewing it in software such as Paint. It shouldn't be rotated.

Share this post


Link to post
Share on other sites
Advertisement
Just a question of getting the texture coordinates correct. Assuming 0, 0 (u, v) is the top left of the texture, and you are looking directly at the quad.


0,0 1,0
-------------
| |
| |
| |
| |
| |
-------------
0,1 1,1





You did mention HLSL... are you trying to generate the texcoords in the shader from the vertex position? If so, you can take the dot product of the local space positions of each vertex with the y axis (to find v) and the z axis (to find u).

Share this post


Link to post
Share on other sites
Quote:

You did mention HLSL... are you trying to generate the texcoords in the shader from the vertex position? If so, you can take the dot product of the local space positions of each vertex with the y axis (to find v) and the z axis (to find u).


That is correct. I am using this formula:


float3 v0 = input.Position.xyz - centre;
float widthInverse = 1.0f / width;
float heightInverse = 1.0f / height;

Output.TextureCoordinates.x = dot(v0, normalize(float3(right))) * widthInverse + 0.5f;
Output.TextureCoordinates.y = dot(v0, normalize(float3(up))) * heightInverse + 0.5f;



but it doesn't work and produces non axis aligned results.

I've also tried:


float3 v0 = input.Position.xyz - centre;
float widthInverse = 1.0f / width;
float heightInverse = 1.0f / height;

Output.TextureCoordinates.x = dot(v0, float3(1,0,0)) * widthInverse + 0.5f;
Output.TextureCoordinates.y = dot(v0, float3((0,1,0)) * heightInverse + 0.5f;



but that doesn't work either. Any ideas as to why?

Share this post


Link to post
Share on other sites
Second one looks good since you need to take the dot product with the world axis.

However, if you are still testing using the left facing quad, you need to take the dot product with the z axis for the u texture coordinate. If the quad is front facing, and your coordinate system is y up, x left to right, what you have there should work fine.

[Edited by - 1863 on August 26, 2010 11:40:43 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!