0
\$\begingroup\$

I am rendering a fullscreen quad using XNA. I am having an issue where the top pixel line and left pixel line are not rendered. It should be black in the picture. Can anyone tell me why this might be happening?

FullScreenQuadRendered

The effect's intent is to fade the screen out or in by adjusting the alpha of the pixel.

HLSL

float3 c;
float a;

float4 ShadeVertex(float3 pos : POSITION0) : POSITION0
{
    return float4(pos, 1);
}

float4 ShadePixel(float2 p : VPOS) : COLOR0
{
    return float4(c, a);
}

technique Simple  
{
    pass FirstPass  
    {
        VertexShader = compile vs_3_0 ShadeVertex();  
        PixelShader = compile ps_3_0 ShadePixel();  
    }
} 

QuadRenderer.cs

internal sealed class QuadRenderer : GameComponent
{

    #region fields

    private VertexPositionTexture[] triangles;
    private short[] indexData = new short[] { 0, 1, 2, 2, 3, 0 };
    private GraphicsDevice gfx;

    #endregion

    #region constructors

    public QuadRenderer(IGameEngine engine)
        : base(engine)
    {
        this.gfx = engine.Device.Graphics;

        // texture coordinates semantic not used or needed
        this.triangles = new VertexPositionTexture[] 
                     { 
                       new VertexPositionTexture(new Vector3(1, -1, 0), 
                                                 Vector2.Zero),
                       new VertexPositionTexture(new Vector3(-1, -1, 0), 
                                                 Vector2.Zero),
                       new VertexPositionTexture(new Vector3(-1, 1, 0), 
                                                 Vector2.Zero),
                       new VertexPositionTexture(new Vector3(1, 1, 0), 
                                                 Vector2.Zero) 
                     };
    }

    #endregion

    #region methods

    public void Render(Effect effect)
    {
        foreach (EffectPass p in effect.CurrentTechnique.Passes)
            p.Apply();

        this.Render();
    }

    private void Render()
    {
        this.gfx.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, 
                                           this.triangles, 0, 4, 
                                           this.indexData, 0, 2);
    }

    #endregion

}
\$\endgroup\$
3
  • \$\begingroup\$ Off the top of my head, your code seems fine, so I suspect it is an aliasing artifact? If you tile the effect across the screen a few times does it show up there? If so, then whatever temporary texture is being used is getting aliased by compression most likely (or mip-maps). Its been a while since I did XNA, so I am not sure how it is actually handling your texture. \$\endgroup\$ – user54892 Nov 12 '14 at 2:58
  • \$\begingroup\$ have you overwriten the default game border in xna? form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; In order to do this you must have a using statement with the windows.forms dll. This might help see if it has anything to do with that ugly border:P \$\endgroup\$ – Shroeder Nov 12 '14 at 4:27
  • \$\begingroup\$ It depends on your camera as well. we don't see the projection matrix and the viewport setup you use. \$\endgroup\$ – v.oddou Dec 16 '14 at 5:13
2
\$\begingroup\$

Sorry for the late reply, but saw an answer (by GameDevSE's own Josh Petrie) to another question here that reminded me of this one, and it seemed like it could also apply here. Don't know if its truly relevant, but it could be worth a look.

It basically discusses the half-pixel offset problem, in which a pixel can end up being misaligned by 0.5 units due to the differences in placement of the pixel occupying the center of its cell, and the placement of co-ordinates in the standard co-ordinate system. This can result in the actual pixel being offset from the specified point by 0.5 units in the X and Y direction.

In regards to your FSQ, I am also using a FSQ, and I have not noticed this issue with my engine. However, your FSQ does differ from mine slightly, so I'm not too sure if that might also be a problem as well. My FSQ is basically the one described in this guide (pages 5-6), so it also might be worth trying out as well to see if it fixes your problem.

One thing I did notice was your vertices assembly, and how each corner has a TextureCoord of Vector2.Zero. Mine looks something like this:

VertexPositionTexture[] vertices =
{
    new VertexPositionTexture(new Vector3(1, -1, 0), Vector2.One),
    new VertexPositionTexture(new Vector3(-1, -1, 0), Vector2.UnitY),
    new VertexPositionTexture(new Vector3(-1, 1, 0), Vector2.Zero),
    new VertexPositionTexture(new Vector3(1, 1, 0), Vector2.UnitX)
};

Another minor part to consider (Especially if your effect has multiple passes) is your Render function. IMO, it should look like this:

public void Render(Effect effect)
{
    foreach (EffectPass p in effect.CurrentTechnique.Passes)
    {
        p.Apply();
        this.Render();
    }
}

This will ensure that the FSQ is drawn once per pass, as you code will currently only apply the last pass in your effects technique. Its a minor thing, but if you have PPC's (Post Processing Chains) built into the shader file (pass 1 draws the scene, pass 2 applies a Post Processing Effect/Filter) then you can get some odd stuff happening.

Hopefully some of this helps. If I come up with or find anything else, I'll include it here.

\$\endgroup\$
1
  • \$\begingroup\$ Try to summarize the main content of these links, please. If the links go offline, your answer will be lost. \$\endgroup\$ – Emir Lima Dec 16 '14 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.