   [HLSL]  Tangent, Bitangent, Normal.  How can I make sure the texture scales exactly?
  I am trying to get my quadrangles textured correctly no matter what their orientation is.  HLSL accepts vertex points so I am calculating the uv coordinate based off each of the quadrangle vertices.Currently the following works for quadrangles of any orientation and of equal width and height: // Current position of quadrangle vertex - quadrangle centre (average of all 4 vertices) float3 v0 = input.Position.xyz - centre; // (u, v) texture coordinates texCoord.X = dot(v0, tangent) * width_Inverse + 0.5f; texCoord.Y = dot(v0, bitangent) * height_Inverse + 0.5f;Why does it not work for all sizes of quadrangles?For example in this picture:each quadrangle texture is supposed to have a green border but the texture coordinates don't always fit the size of the quadrangle, and therefore the green outline is not shown.Is there a way of calculating the T,B,N so that it is orientated correctly and fits the quadrangle exactly?By orientated correctly I wish to have (0,0) to the upper left of the quadrangles rotational "Up" vector, (1,1) to the lower right.EDIT:I can't simply have:Output.TextureCoordinates = input.TextureCoordinates;because the texture coordinates need to be rotated correctly.  For example if I have a quadrangle which has a normal of (1,0,0) I would like the texture's bitangent to be (0,1,0) or vertically aligned.  The same goes for the following quadrangle normals (-1,0,0), (0,0,1) and (0,0,-1).[Edited by - Spa8nky on May 6, 2010 4:55:52 PM]
  Your code looks ok.Well, there could be a few issues.1. Try to use linear texturing instead of nearest neighbour.2. Try to use mipmaps.3. In what space are your calculations ? Tangent, camera or world space ? There could be precision issues. Do you really need a 100% border mapping ?  Well, I would sugguest to activate linear texturing and mipmapping. Then make the border a little bit broader.   ;Quote:Original post by Ashaman731. Try to use linear texturing instead of nearest neighbour.This makes no difference to final result, except the blurring of the texture.Quote:Original post by Ashaman733. In what space are your calculations ? Tangent, camera or world space ? There could be precision issues. VertexShaderOutput VertexShaderFunction(VertexShaderInput input){    VertexShaderOutput Output = (VertexShaderOutput)0;// [Rotation, Scale]World._11 = input.IData0.w * input.IData3.x;// * Scale XWorld._12 = input.IData1.x * input.IData3.x;World._13 = input.IData1.y * input.IData3.x;World._21 = input.IData1.z * input.IData3.y;// * Scale YWorld._22 = input.IData1.w * input.IData3.y;World._23 = input.IData2.x * input.IData3.y;World._31 = input.IData2.y;World._32 = input.IData2.z;World._33 = input.IData2.w;// [Translation]World._41 = input.IData0.x;World._42 = input.IData0.y;World._43 = input.IData0.z;// [Transformation]input.Position = mul(input.Position, World);Output.Position = mul(input.Position, ViewProjection);    // [Create uv coordinates]    float3 v0 = input.Position.xyz - float3(input.IData0.x, input.IData0.y, input.IData0.z);    float widthInverse = 1.0f / input.IData3.x;    float heightInverse = 1.0f / input.IData3.y;    Output.TextureCoordinates.x = dot(v0, float3(input.IData0.w, input.IData1.x, input.IData1.y)) * widthInverse + 0.5f;    Output.TextureCoordinates.y = dot(v0, float3(input.IData1.z, input.IData1.w, input.IData2.x)) * heightInverse + 0.5f;  return Output;}v0 is calculated from vertex world position - world translation (centre)u is calculated from world rotation ("right")v is calculated from world rotation ("up")Everything is calculated in world space, can precision errors creep in here?   ;Quote:Original post by Spa8nkyQuote:Original post by Ashaman731. Try to use linear texturing instead of nearest neighbour.This makes no difference to final result, except the blurring of the texture.This makes a difference !Lets say your texture contains a green border of 1 pixel. When your texture has a size of 128x128 and your quad will be displayed with a screensize of 127x127 pixels, one row and one column of your texture will not be displayed ! This could be the border. Making the displayed size of the quad even smaller (quad is farther away), the propability of getting the border displayed is even smaller.Quote:*** Source Snippet Removed ***v0 is calculated from vertex world position - world translation (centre)u is calculated from world rotation ("right")v is calculated from world rotation ("up")Everything is calculated in world space, can precision errors creep in here?You could get problems with positions in world space if you have large worlds ( far away from the center (0,0,0)). Try to normalize the tanget/bitangent in the shader and see if it has an effect.Looking at your screenshot, the missing border is most probably a nearest neighbour issue. But some quads cut off a major part of the green arrow and E, this is most probably a calcuation issue.For debugging:Turn on linear mapping and auto-mipmapping and add some kind of pattern (chessboard) to your texture.   ;  I've discovered that the texture coordinates are only incorrect when the quad is rotated around an axis.The following rotations (quad normal's):(1,0,0)(-1,0,0)(0,1,0)(0,-1,0)(0,0,1)(0,0,-1)all produce correct results:If I were to use a normal of (0.1f,1,0) then the texture coordinates will be incorrect.What could be the cause of this?