error X3000: Illegal character in shader file

给你一囗甜甜゛ 提交于 2019-12-19 18:17:29

问题


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

  • I removed the tainted line of code.

  • I've re-written the shader multiple times from scratch using VS, Notepad and Notepad++ as suggested on the Unity forums.

  • I've used the hex editor view in Notepad++ to rule out the first two bytes aren't 0xFE 0xFF as suggested on this gamedev question.

I really can't figure this one out. I'm grateful for any suggestions you might 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;
}


回答1:


It was an encoding problem. When I pasted the line of code it somehow made my compiler treat every text file as UNICODE instead of ASCII. This caused the problem.
The solution was opening 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.



来源:https://stackoverflow.com/questions/44067027/error-x3000-illegal-character-in-shader-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!