Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Anti-Aliased Lines from ShaderX7 not working

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 FromShadow   Members   


Posted 02 January 2013 - 06:03 PM

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:


    [...] // 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;

    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?

Attached Thumbnails

  • PerspectiveError.jpg
  • Perspective ErrorWireframe.jpg

#2 NewDisplayName   Members   


Posted 02 January 2013 - 10:44 PM

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.

#3 FromShadow   Members   


Posted 03 January 2013 - 05:10 AM

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.

Attached Files

Edited by FromShadow, 03 January 2013 - 05:13 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.