Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiling simple shader for iOS on Windows - runtime error on iPhone Simulator "Shader Compilation Failed" #5147

Open
neildanson opened this issue Sep 1, 2016 · 2 comments
Labels
iOS OpenGL OpenGL graphics backend

Comments

@neildanson
Copy link

neildanson commented Sep 1, 2016

I've been playing with a simple shader, and wanted to move the code to run on iOS:

The Effect file looks like this

# if OPENGL

#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0

# else


#define VS_SHADERMODEL vs_4_0_level_9_1
#define PS_SHADERMODEL ps_4_0_level_9_1

# endif

matrix WorldViewProjection;

struct VertexShaderInput
{
    float4 Position : SV_POSITION;
    float3 Normal : NORMAL0;
    float3 Color : COLOR0;
};

struct VertexShaderOutput
{
    float4 Position : SV_POSITION;
    float3 Normal : NORMAL;
    float4 Color : COLOR0;
};

VertexShaderOutput MainVS(in VertexShaderInput input)
{
    VertexShaderOutput output = (VertexShaderOutput)0;

    output.Position = mul(input.Position, WorldViewProjection);
    output.Color = float4(input.Color,1);
    output.Normal = input.Normal; 
    return output;
}

float4 MainPS(VertexShaderOutput input) : COLOR
{
    return input.Color \* saturate(dot(float3(-0.5,0.3,-0.5), input.Normal));
}

technique BasicColorDrawing
{
    pass P0
    {
        VertexShader = compile VS_SHADERMODEL MainVS();
        PixelShader = compile PS_SHADERMODEL MainPS();
    }
};

And when run through the MonoGame Content Pipeline on Win10 (selecting build iOS) the xnb looks like this

XNBi
precision mediump float;
precision mediump int;
# endif

const vec4 ps_c0 = vec4(-0.5, 0.3, 0.0, 0.0);
vec4 ps_r0;
# define ps_oC0 gl_FragColor

varying vec4 vFrontColor;
# define ps_v1 vFrontColor

void main()
{
    ps_r0.x = clamp(dot(ps_c0.xyx, ps_v0.xyz), 0.0, 1.0);
    ps_oC0 = ps_r0.xxxx \* ps_v1;
}

precision highp float;
precision mediump int;
# endif

uniform vec4 vs_uniforms_vec4[4];
uniform vec4 posFixup;
const vec4 vs_c4 = vec4(1.0, 0.0, 0.0, 0.0);
# define vs_c0 vs_uniforms_vec4[0]
# define vs_c1 vs_uniforms_vec4[1]
# define vs_c2 vs_uniforms_vec4[2]
# define vs_c3 vs_uniforms_vec4[3]

attribute vec4 vs_v0;
# define vs_o0 gl_Position

attribute vec4 vs_v1;
vec4 vs_o1;
attribute vec4 vs_v2;
varying vec4 vFrontColor;
# define vs_o2 vFrontColor

void main()
{
    vs_o0.x = dot(vs_v0, vs_c0);
    vs_o0.y = dot(vs_v0, vs_c1);
    vs_o0.z = dot(vs_v0, vs_c2);
    vs_o0.w = dot(vs_v0, vs_c3);
    vs_o1.xyz = vs_v1.xyz;
    vs_o2 = (vs_v2.xyzx \* vs_c4.xxxy) + vs_c4.yyyx;
    gl_Position.y = gl_Position.y \* posFixup.y;
    gl_Position.xy += posFixup.zw \* gl_Position.ww;
    gl_Position.z = gl_Position.z \* 2.0 - gl_Position.w;
}

The XNB loads fine, but on calling DrawIndexedPrimitive I get an exception stating the "Shader Compilation Failed"

Monogame 3.5.1.1679 on both OSes.

If there is anything extra you need me to add, please let me know.

@neildanson
Copy link
Author

Attached source and XNB file in a zip

Effect.zip

@neildanson
Copy link
Author

Update:

I fixed the issue by changing the effect to do all the lighting in the vertex shader.

While my specific issue is fixed, I still think the behaviour is wrong - I'd expect either the compile step to fail in the pipeline, or to fail to load, rather failing at the point of trying to use the shader.

@Jjagg Jjagg added iOS OpenGL OpenGL graphics backend labels Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS OpenGL OpenGL graphics backend
Projects
None yet
Development

No branches or pull requests

2 participants