0
votes

What am I Doing Wrong ? if I Compile This Get an Error

cbuffer MatrixBuffer
{
    matrix worldM;
    matrix viewM;
    matrix projectionM;
};

struct VertexInput
{
    float4 position : POSITION;
    float4 color : COLOR;
};

struct PixelInput
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
}

PixelInput ColorVertexShader(VertexInput input)
{
    PixelInputType output;

    input.position.w = 1.0f;

    output.position = mul(input.position, worldM);
    output.position = mul(output.position, viewM);
    output.position = mul(output.position, projectionM);

    output.color = input.color;

    return output;
}

i get a syntax error at line 2 at the " { "

and if i do This

    matrix worldM;
    matrix viewM;
    matrix projectionM;


struct VertexInput
{
    float4 position : POSITION;
    float4 color : COLOR;
};

struct PixelInput
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
}

PixelInput ColorVertexShader(VertexInput input)
{
    PixelInputType output;

    input.position.w = 1.0f;

    output.position = mul(input.position, worldM);
    output.position = mul(output.position, viewM);
    output.position = mul(output.position, projectionM);

    output.color = input.color;

    return output;
}

i get an unexpected token 'output '

I Got No Idea What Wrong Im Still a Noob in Writing Shaders in HLSL

2

2 Answers

0
votes

I'm not sure if this will help, but maybe try defining your cbuffer lik this:

cbuffer cbPerObject: register(b0)
{
    matrix WorldM:      packoffset(c0);
    matrix ViewM:       packoffset(c4);
    matrix ProjectionM: packoffset(c8);
};
0
votes

You have defined

struct PixelInput
{
    float4 position : SV_POSITION;
    float4 color : COLOR;
}

but then later you use

 PixelInputType output;

Obviously, that won't work. Use the same name.