Error X3000: Invalid character in shader file

I pasted a line of shader code from SO and now my project refuses to work.

  • I removed the broken line of code.

  • I rewrote the shader several times from scratch using VS, Notepad and Notepad ++ as suggested on the Unity forums .

  • I used the hex editor representation in Notepad ++ to exclude the first two bytes, not 0xFE 0xFF

    as suggested in this question by gamedev .

I really can't figure it out. I am grateful for any suggestions you may have.

cbuffer CB_PER_FRAME : register(b0)
{
    column_major float4x4 view;
    column_major float4x4 proj;
    float4 eyePosition;
};

struct VertexInput
{
    float3 position : POSITION;
    float3 normal   : NORMAL;
    float2 texCoord : TEXCOORD;

    row_major float4x4 world : WORLD;
    float4 color : COLOR;
    uint instanceID : SV_InstanceID;
};

struct PixelInput
{
    float4 position : SV_POSITION;
    float3 normal   : NORMAL;
    float2 texCoord : TEXCOORD;
    float4 color    : COLOR;
};

PixelInput VertexShaderMain( VertexInput vertexInput )
{
    PixelInput pixelInput (PixelInput)0;

    pixelInput.position = mul( float4( pixelInput.position, 1.0f ), vertexInput.world );
    pixelInput.position = mul( pixelInput.position, view );
    pixelInput.position = mul( pixelInput.position, proj );

    pixelInput.normal = normalize( mul( pixelInput.normal, (float3x3)vertexInput.world ) );
    pixelInput.texCoord = vertexInput.color;
    pixelInput.color = vertexInput.color;

    return pixelInput;
}

float4 PixelShaderMain( PixelInput pixelInput ) : SV_Target
{
    return pixelInput.color;
}

      

enter image description here

+3


source to share


1 answer


It was an encoding issue. When I pasted in the line of code, it somehow made my compiler treat each text file as UNICODE instead of ASCII. This caused the problem.
The solution was to open the shader file in Visual Studio and go to File-> Save As-> Save with Encoding and then choose the correct format and rebuild the solution.

enter image description here enter image description here



+3


source







All Articles