# Anti-Aliased Lines from ShaderX7 not working

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

## Recommended Posts

Hello everyone,

I followed the Chapter "2.3: Simplified High-Quality Anti-Aliased Lines" from the ShaderX7 book. I copy-pasted the shader file from the CD and carefully ported the managing class to XNA. I cannot guarantee that the buffers are correctly filled but I am pretty sure.

Have a look at the first screenshot. The perspective is not correct. I chose my Line texture to be a square to enhance the effect. Looking at the wireframe (second screenshot), you can see that the vertex positions are in fact correct. The error is in the texture lookup.

I assume I cannot upload the whole shader since it's from the CD, but here are the lines that set the texture coordinates:

VS_OUTPUT VS(...)
{
[...] // Calculate Vertex Positions (works)

VS_OUTPUT output;
output.textureUV.x = weights.z;
output.textureUV.y = weights.w;
output.textureUV.z = 0.0f;
output.textureUV.w = 1.0f;
return output;
}

PS_OUTPUT PS(VS_OUTPUT input)
{
return g_Color * tex2Dproj( FilterTextureSampler, input.textureUV );
}

where weights contains the texture coordinates in z and w. g_Color is the Line's Color and FilterTextureSampler contains the square texture.

I understand that tex2Dproj divides the coordinates by the w-component. But w = 1.0f everywhere! Can somebody explain what this is supposed to do? Changing "tex2Dproj" to "tex2D" makes no difference. Why can't I just take the usual texture coordinates?

##### Share on other sites

Going on several assumptions at my end (because I can't see your VS_OUTPUT structure and several other pieces of interest), I would say that don't assign textureUV values the way you're doing now.

Change your VS method's signature to pass this parameter "float2 vTexCoord0 : TEXCOORD0"

and then do an assignment to textureUV in below fashion :

output.textureUV = vTexCoord;

After doing this, see if something changes.

##### Share on other sites
I'm afraid to post the whole shader code due to copyright issues. If you have the book, it is printed in chapter 2.3. I wanted to use the original shader to prevent error infusion.

What I can do is post my own adaptation of that code. It uses the original math/shader, but I added hardware instancing, so it should be ok. I also attached the class that manages the buffers.
My main change is that the texture coordinates are now in input.Position.xy instead of weights.zw

I applied your change to both versions, i.e. use float2 instead of float4 for the texture coordinates und tex2D instead of tex2Dproj. The output is the same every time. Edited by FromShadow