Android Game Maker does not compile shader (only on Android)

Discussion in 'GameMaker Studio 2 Community Tech Support' started by Mert, Jun 24, 2019.

  1. Mert

    Mert Member

    Joined:
    Jul 20, 2016
    Posts:
    357
    Here's the shader I'm using (From SMF system of TheSnidr) (GLSLES)

    The shader works on Html5 and on Windows perfectly. shader_is_compiled returns false only on Android.
    (Creating a simple passthru shader works, but it doesnt). Any ideas/suggestions?
    Vertex
    Code:
    /*////////////////////////////////////////////////////////////
    This is a per-fragment shader for the SMF format.
    It draws an animated and shaded model. Shading is done
    per fragment, giving it optimal aesthetics at the cost
    of performance.
    ////////////////////////////////////////////////////////////*/
    attribute vec3 in_Position;                // (x,y,z)
    attribute vec3 in_Normal;                  // (x,y,z)  
    attribute vec2 in_TextureCoord;            // (u,v)
    attribute vec4 in_Colour;                  // (r, g, b, a) tangent
    attribute vec4 in_Colour2;                 // (bone1, bone2, bone3, bone4)
    attribute vec4 in_Colour3;                 // (weight1, weight2, weight3, weight4)
    
    varying vec2 v_vTexcoord;
    varying vec3 v_vEyeVec;
    varying vec3 v_vNormal;
    varying vec3 v_vPos;
    varying float v_vOutline;
    
    const int maxBones = 64;
    uniform vec4 boneDQ[2*maxBones];
    uniform int animate;
    //Outline
    uniform float outlineThickness;
    //Texture UVs
    uniform vec4 texUVs;
    
    vec3 WorldCameraPos = - (gm_Matrices[MATRIX_VIEW][3] * gm_Matrices[MATRIX_VIEW]).xyz;
    void main()
    {
        vec3 newPosition = in_Position;
        vec3 newNormal = in_Normal;
        vec3 hardNormal = in_Colour.xyz * 2.0 - 1.0;
       
        if (animate == 1)
        {
            //Blend bones
            ivec4 bone = ivec4(in_Colour2 * 510.0);
            vec4 weight = in_Colour3;
            vec4 blendReal = boneDQ[bone[0]] * weight[0] + boneDQ[bone[1]] * weight[1] + boneDQ[bone[2]] * weight[2] + boneDQ[bone[3]] * weight[3];
            vec4 blendDual = boneDQ[bone[0]+1] * weight[0] + boneDQ[bone[1]+1] * weight[1] + boneDQ[bone[2]+1] * weight[2] + boneDQ[bone[3]+1] * weight[3];
            //Normalize resulting dual quaternion
            float blendNormReal = 1.0 / length(blendReal);
            blendReal *= blendNormReal;
            blendDual = (blendDual - blendReal * dot(blendReal, blendDual)) * blendNormReal;
    
            //Transform vertex
            /*Rotation*/    newPosition += 2.0 * cross(blendReal.xyz, cross(blendReal.xyz, newPosition) + blendReal.w * newPosition);
            /*Translation*/    newPosition += 2.0 * (blendReal.w * blendDual.xyz - blendDual.w * blendReal.xyz + cross(blendReal.xyz, blendDual.xyz));
            /*Normal*/        newNormal += 2.0 * cross(blendReal.xyz, cross(blendReal.xyz, newNormal) + blendReal.w * newNormal);
            /*Normal*/        hardNormal += 2.0 * cross(blendReal.xyz, cross(blendReal.xyz, hardNormal) + blendReal.w * hardNormal);
        }
       
        vec4 objectSpacePos = vec4(newPosition, 1.0);
       
        //Varying variables
        v_vNormal = mat3(gm_Matrices[MATRIX_WORLD]) * newNormal;
        v_vTexcoord = texUVs.xy + vec2(texUVs.z, texUVs.w) * in_TextureCoord;
        v_vPos = vec3(gm_Matrices[MATRIX_WORLD] * objectSpacePos);
        v_vEyeVec = WorldCameraPos - v_vPos;
       
        v_vOutline = 0.0;
        vec3 WorldHardNormal = normalize((gm_Matrices[MATRIX_WORLD] * vec4(hardNormal, 0.0)).xyz);
        if (dot(WorldHardNormal, v_vEyeVec) < 0.0)
        {
            vec4 tempPos = gm_Matrices[MATRIX_WORLD_VIEW] * objectSpacePos;
            objectSpacePos.xyz += 2.0 * newNormal * tempPos.z * outlineThickness;
            v_vOutline = 1.0;
        }
        gl_Position = gm_Matrices[MATRIX_WORLD_VIEW_PROJECTION] * objectSpacePos;
    }
    
    Fragment
    Code:
    //
    // Simple passthrough fragment shader
    //
    varying vec2 v_vTexcoord;
    varying vec3 v_vEyeVec;
    varying vec3 v_vNormal;
    varying vec3 v_vPos;
    varying float v_vOutline;
    
    //Lights
    const int MAXLIGHTS = 16;
    uniform vec4 lightArray[MAXLIGHTS];
    uniform int lightNum;
    uniform vec3 ambientColor;
    //Specular lighting
    uniform float reflectivity;
    uniform float damping;
    //Cel shading
    uniform float celSteps;
    //Rim lighting
    uniform float rimPower;
    uniform float rimFactor;
    //Outline
    uniform vec3 outlineColour;
    
    void main()
    {
        if (v_vOutline != 0.0)
        {
            gl_FragColor = vec4(outlineColour, 1.0);
        }
        else
        {
            vec2 TexCoord = v_vTexcoord;
            vec3 eyeVec = normalize(v_vEyeVec);
            vec3 NewNormal = normalize(v_vNormal);
            vec3 Specular = vec3(0.0);
            vec3 Shade = vec3(0.0);
            for (int i = 0; i < MAXLIGHTS; i ++)
            {
                if (i >= lightNum){break;}
                vec3 lightDir;
                float att = 1.0;
                vec3 lightCol = vec3(1.0, 1.0, 1.0);
                //Point light
                if (lightArray[i*2].w > 0.0)
                {
                    vec3 lightPos = lightArray[i*2].xyz;
                    lightDir = v_vPos - lightPos;
                    float dist = length(lightDir);
                    lightDir /= dist;
                    att = clamp((1.0 - dist*dist / (lightArray[i*2].w * lightArray[i*2].w)), 0.0, 1.0);
                    att *= att;
                    lightCol = lightArray[i*2+1].w * lightArray[i*2+1].rgb;
                }
                //Directional light
                else if (lightArray[i*2].w == 0.0)
                {
                    lightDir = lightArray[i*2].xyz;
                    lightCol = lightArray[i*2+1].w * lightArray[i*2+1].rgb;
                }
                //Cone light
                else
                {
                    vec3 lightPos = lightArray[i*2].xyz;
                    lightDir = v_vPos - lightPos;
                    att = 0.0;
                    float dist = length(lightDir);
                    lightDir /= dist;
                    if (dot(lightDir, lightArray[i*2+1].xyz) > lightArray[i*2+1].w)
                    {
                        att = clamp((1.0 - dist*dist / (lightArray[i*2].w * lightArray[i*2].w)), 0.0, 1.0);
                        att *= clamp(0.0, 1.0, 4.0 * (dot(lightDir, lightArray[i*2+1].xyz) - lightArray[i*2+1].w) / (1.0-lightArray[i*2+1].w));
                    }
                    else
                    {
                        lightCol = vec3(0.0);
                    }
                }
           
                //Diffuse
                Shade += lightCol * max(- dot(NewNormal, lightDir), 0.0) * att;
           
                //Specular lighting
                if (damping > 0.0 && reflectivity > 0.0)
                {
                    vec3 reflectedLight = reflect(lightDir, NewNormal);
                    float specFactor = max(dot(reflectedLight, eyeVec), 0.0);
                    float dampFactor = pow(specFactor, damping);
                    Specular += lightCol * dampFactor * reflectivity * att;
                }
            }
       
            //Cel shading
            if (celSteps > 0.0)
            {
                Specular = floor(max(Specular, 0.0) * celSteps) / celSteps;
                Shade = ceil(max(Shade, 0.0) * celSteps - 0.5) / celSteps;
            }
       
            //Rim lighting
            float RimLight = 0.0;
            if (rimPower > 0.0 && rimFactor > 0.0)
            {
                RimLight = rimFactor * pow(1.0 - max(dot(eyeVec, NewNormal), 0.0), rimPower);
            }
       
            vec4 baseCol = texture2D(gm_BaseTexture, TexCoord);
            if (baseCol.a < 0.01){discard;}
            gl_FragColor = vec4(Specular + RimLight, 0.0) + vec4(ambientColor + Shade, 1.0) * baseCol;
        }
    }
    
     
  2. chirpy

    chirpy Member

    Joined:
    Oct 6, 2016
    Posts:
    111
    Superstition alert:
    I had once experienced a nonsensical issue that none of my shaders worked because a single one of them did not compile. Deleting it and/or rearranging the shaders in the resource tree made others come back. It was in html5 target though (running in android browser).
     
  3. Mert

    Mert Member

    Joined:
    Jul 20, 2016
    Posts:
    357
    I have the exact same feeling, because I remember seeing them worked before on my mobile.
     
  4. TheSnidr

    TheSnidr Heavy metal viking dentist GMC Elder

    Joined:
    Jun 21, 2016
    Posts:
    462
    Try reducing the max number of bones to, say, 20, and see if it compiles then! :)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice