0
\$\begingroup\$

Alright, so I've tried everything I can think of. I've put in over 10 hours into this crap, but nothing seems to work (tried multiple online tutorials as well). Always purple screen.

Here is the simple .fx code:

float4x4 matrixTransform;

struct VShader
{
    float2 Coords : TEXCOORD0;
    float4 Position : POSITION;
};
struct PShader
{
    float2 Coords : TEXCOORD0;
};

VShader VertexShaderFunction(VShader input)
{
    VShader output;

    output.Position = mul(input.Position, matrixTransform);
    output.Coords = input.Coords;

    return output;
}

float4 PixelShaderFunction(PShader input) : COLOR0
{

    return tex2D(textureSampler, input.Coords);
}

technique Technique1
{
    pass Pass1
    {
        VertexShader = compile vs_3_0 VertexShaderFunction();
        PixelShader = compile ps_3_0 PixelShaderFunction();
    }
}

Here is how I'm assigning MatrixTransform:

Matrix Projection = Matrix.CreateOrthographic(GameSettings.VectorResolution.X, GameSettings.VectorResolution.Y, -1, 1);

Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0);
Projection = halfPixelOffset * Projection;

x.Parameters["matrixTransform"].SetValue(camera.Projection);

Note: the above code works just fine when the vertex shader is disabled. Everything displays like normal.

I'd appreciate it if someone could point out what I'm doing wrong.

Thanks.

EDIT:

I'm currently using multiple shaders in my code that do not use a vertex shader (pixel shaders). I am also making use of render targets. This leads me to believe there is something wrong with the vertex shader code, not the render targets.

EDIT 2:

public Matrix World { get; protected set; }
public Matrix Projection { get; protected set; }
public Matrix View(Vector2 parallax)
{
    return Matrix.CreateTranslation(new Vector3(-Position * parallax, 0.0f)) *
        Matrix.CreateTranslation(new Vector3(-Origin, 0.0f)) *
        Matrix.CreateRotationZ(Rotation) *
        Matrix.CreateScale(Zoom, Zoom, 1) *
        Matrix.CreateTranslation(new Vector3(Origin, 0.0f));
}

public void ReloadMatrices()
{
    World = Matrix.Invert(View(Vector2.One));
    Projection = Matrix.CreateOrthographic(GameSettings.VectorResolution.X, GameSettings.VectorResolution.Y, -1, 1);
    Matrix halfPixelOffset = Matrix.CreateTranslation(-0f, -0f, 0);
    Projection *= halfPixelOffset;
}

Zoom is 1f, Rotation always remains unchanged, and Origin is center of screen.

\$\endgroup\$
  • \$\begingroup\$ You should described what you're trying to achieve. \$\endgroup\$ – Vaillancourt Mar 29 '16 at 2:17
  • \$\begingroup\$ No purple screen? I don't know how can be much more clear than this. When ever I use a vertex shader, purple screen (e.g, nothing draws on screen when in use). I want to be able to make use of the vertex shader, not be restricted to pixel shaders only. \$\endgroup\$ – Shyy Guy Mar 29 '16 at 2:19
  • \$\begingroup\$ You're getting the purple screen, even while clearing the backbuffer with- for example Cornflowerblue? \$\endgroup\$ – Felsir Mar 29 '16 at 5:21
  • 1
    \$\begingroup\$ This was a big topic years ago on the XNA forums. See these search results: xboxforums.create.msdn.com/search/… Also, it was fixed often by this answer: xboxforums.create.msdn.com/forums/p/95682/571781.aspx#571781 \$\endgroup\$ – Steve H Mar 29 '16 at 11:39
  • 2
    \$\begingroup\$ I'm not on my usual machine so I can't confirm, but I'm reasonably sure that the output of the vertex shader has to align with the input of the pixel shader. Maybe try using VShader input instead of PShader input? I know this has worked on all the shaders I've written previously. Also might pay to check that you've calculated the view/projection matrix correctly. \$\endgroup\$ – Seta Mar 29 '16 at 21:31

Your Answer

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

Browse other questions tagged or ask your own question.