Android Build fail | shader error: 'nointerpolation' : syntax error

Hello,

I am getting this error: Shader error in ‘shader’: ‘nointerpolation’ : syntax error syntax error at line (on gles)

When building for Android, it is a flat shader and it works fine in the editor, is it platform related?

     {
           float4 pos    : SV_POSITION;
           nointerpolation float2 cap    : TEXCOORD0;  // error here
           float3 model_normal : TEXCOORD1;
           float3 world_normal : TEXCOORD2;
           float3 view_normal : TEXCOORD3;
           float4 vertColors : Color;
    };

GLES doesn’t support vertex interpolation modifiers pretty sure. Possible solution here though:

GLES 2.0 doesn’t support nointerpolation (which is normally translated to the varying identifier flat in OpenGL). The alternative of using derivatives in the fragment shader can work, but derivative support is optional for OpenGL ES 2.0, so there’s no guarantee that’ll work either.

It your intent is to support OpenGLES 2.0 android devices, you have to modify the meshes to be actually flat shaded with duplicated vertices.

Thank you, i am trying to use the derivatives method but had no luck with it, do you have a simple on how to do that?

Unfortunately i can not go with doubling the vertices because the mesh gets constantly manipulated over time so doubling them and setting them back would eat too much performance, i think i will limit this shader to just OpenGLES 3.0, to detect it i can use SystemInfo.graphicsShaderLevel >= 35 right?

You don’t have to handle the shader switching on the C# side, you can just use one of the multi-compile directives in the shader to avoid using the nointerpolation if shader level is too low.

#if SHADER_TARGET < 30
    float2 cap : TEXCOORD0;
#else
    nointerpolation float2 cap : TEXCOORD0
#endif

or

#if SHADER_API_GLES
    float2 cap : TEXCOORD0;
#else
    nointerpolation float2 cap : TEXCOORD0
#endif

might even be good enough.

Yes thank you, i did it in both, in the shader so i can build it and in c# because switching to the shader is the user’s choice so i have to hide that option in the interface as well.