Question

So my professor gave our class code to look over to help us learn about Vector3D drawing, positioning, and movement. The code was originally written in XNA 3.1, and our lab here at school is still in XNA 3.1, however, I do everything on my laptop. My laptop has Visual Studio 2012 (I have 2013 but haven't moved XNA over yet). I have figured out and fixed all but one of the errors. I keep getting this error whenever I debug and run the game:

Error 1 Errors compiling C:\Users\Nicholas\Documents\Visual Studio 2013\Projects\MGH05_PrimitiveObjects\MGH05_PrimitiveObjects\Content\Shaders\PositionColor.fx:
C:\Users\Nicholas\Documents\Visual Studio  2013\Projects\MGH05_PrimitiveObjects\MGH05_PrimitiveObjects\Content\Shaders\PositionColor.fx(27,6): error X3000: syntax error: unexpected token 'VertexShader'   C:\Users\Nicholas\Documents\Visual Studio 2013\Projects\MGH05_PrimitiveObjects\MGH05_PrimitiveObjects\Content\Content\Shaders\PositionColor.fx  27  6   MGH05_Win_PrimitiveObjects

My professor has been of no help, and neither has google. Anyone have any idea how to fix this? Here is the shader (PositionColor.fx) code:

float4x4 wvpMatrix  : WORLDVIEWPROJ;

struct VSinput
{
    float4 position : POSITION0;
    float4 color    : COLOR0;
};

struct VStoPS
{
    float4 position : POSITION0;
    float4 color    : COLOR0;
};

struct PSoutput
{
    float4 color    : COLOR0;
};

// alter vertex inputs
void VertexShader(in VSinput IN, out VStoPS OUT)
{
    // transform vertex
    OUT.position = mul(IN.position, wvpMatrix);
    OUT.color = IN.color;
}

// alter vs color output
void PixelShader(in VStoPS IN, out PSoutput OUT)
{
    float4 color = IN.color;
    OUT.color    = clamp(color, 0, 1); // range between 0 and 1
}

// the shader starts here
technique BasicShader
{
    pass p0
    { 
            // declare & initialize ps & vs
            vertexshader = compile vs_1_1 VertexShader();
            pixelshader  = compile ps_1_1 PixelShader();
    }
}

When I rename VertexShader I still get the error, but now with PixelShader. When I rename them both it still gives me the VertexShader error.

If anyone has any thoughts let me know! Also, I apologize if this was asked on the wrong stack website. I'd think this one would be the proper place. If you need any extra info, let me know!

Thanks in advance!

Was it helpful?

Solution

As Romoku suggested, it would appear that XNA 4 uses a newer/different shader version, in which some new keywords have been added. This includes PixelShader and VertexShader, so those may no longer be used as identifiers.

The solution would be to give them some other name (any will do). Also remember to update the names in the technique.

void FancyVertexShader(in VSinput IN, out VStoPS OUT)
{
    // transform vertex
    OUT.position = mul(IN.position, wvpMatrix);
    OUT.color = IN.color;
}

// alter vs color output
void AwesomePixelShader(in VStoPS IN, out PSoutput OUT)
{
    float4 color = IN.color;
    OUT.color    = clamp(color, 0, 1); // range between 0 and 1
}

// the shader starts here
technique BasicShader
{
    pass p0
    { 
            // declare & initialize ps & vs
            vertexshader = compile vs_2_0 FancyVertexShader();
            pixelshader  = compile ps_2_0 AwesomePixelShader();
    }
}

Edit: and as you pointed out yourself, XNA 4 uses version 2.0 for both the vertex and the pixel shader.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top