0
votes

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!

1
Since the error seems to be in your shader, I'd suggest you post that! - Chris
XNA 4 might be using a different version of HLSL which reserves the token VertexShader. If you have a function named VertexShader in PositionColor.fx then try renaming it. - Dustin Kingen
Please, please, stop posting a whole class as a question, it's frustrating to read. - pinckerman
@Chris I will switch the class to the shader when I get home from work tonight, and I will try the renaming thing too. Is there somethign specific I should rename it to? - Nick
@Chris I have updated it with the shader code. - Nick

1 Answers

0
votes

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.