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.
[C#] [HLSL] How can I align textures to an axis?
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.
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).
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).
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?
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement