I'm just revisiting my very simple font shader and I noticed something odd.
For my text, I draw a line of text in one go, e.g. 128 x 16 quad. I pass the indexes of the letters to the shaders in an array and I gauge where the current pixel is in the text line, pick out the correct letter then calculate that letter's uv coordinates in my font texture (256 x 128).
It had been working ok but I'd noticed some strange aliasing artifacts in my font characters, so I went back to basics and to find the 'x' texture coordinate for the current letter that I'm rendering the pixel for, I do this in my pixel shader:
float xPosOfCurrentCharacter = ((In.texC.x * lineWidth) % 16.0f) / 16.0f;
Where In.texC.x is the texture coordinate coming from the vertex shader (in this example, it's a standard 2-tri quad with texture coordinates at 0-1 as per normal, of size 128 x 16) and lineWidth is 128. I use the modulo at 16 to get the x position of the current character.
Just for testing, I decided to quickly return a float4 of this value to see what it looked like (I was expecting a line of white - black gradients at each set of 16 pixels). What I got was almost that, but after each block of 16, the gradient seems to shift a bit, some gradients are 16 pixels but some are 15.
Is there something I should be doing with regard to precision here? Is there a better way of working out the texture coordinates of my font lookup texture?
I've attached an image. The black staggered lines above are all 16 pixels in length so you can see the areas which are out of sync as it were...
Edited by RobMaddison, 09 October 2013 - 04:02 PM.