ES2.0 Fragment shader compile failed without any errors or warnings

This topic contains 3 replies, has 2 voices, and was last updated by  Joe Davis 3 years, 11 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #31584

    Can you help me with that shader.
    It perfectly compiles and runs on snapdragon, but SGX compiler fails. Not actully fails, but stuck in infinite compiling (right now i’ve been wating for 10 minutes, 1 core is fully loaded with GLSLESCompiler_Series5XT.exe)
    I’m using PVRShaderEditor 2.2 and SDK verision 3.2


    precision mediump float;
    #ifdef ALPHA_BLEND
    #if ALPHA_BLEND == 1
    //ALPHA_HALF:
    #pragma profilepragma blendoperation(gl_FragColor, GL_FUNC_ADD, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    #elif ALPHA_BLEND == 2
    //ALPHA_ADD:
    #pragma profilepragma blendoperation(gl_FragColor, GL_FUNC_ADD, GL_SRC_ALPHA, GL_ONE)
    #elif ALPHA_BLEND == 3
    //ALPHA_SUB
    #pragma profilepragma blendoperation(gl_FragColor, GL_FUNC_ADD, GL_ZERO, GL_ONE_MINUS_SRC_COLOR)
    #elif ALPHA_BLEND == 4
    //ALPHA_BLEND
    #pragma profilepragma blendoperation(gl_FragColor, GL_FUNC_ADD, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
    #endif
    #endif
    // COMMON fragment params
    uniform sampler2D inSampler0;
    uniform mediump vec4 inMaterialSpecular;
    const mediump mat4 HomoToUV = mat4(0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0);
    // COMMON varyings
    varying mediump vec3 varPos;
    varying mediump vec3 varNormal;
    varying mediump vec3 varToEye;
    varying mediump vec2 varTexCoord;
    // LIGHT fragment params
    uniform lowp int shadowRendering;
    #define SHADOWS_PER_TEXTURE 4
    #define LIGHT_TYPE_NOLIGHT 0
    #define LIGHT_TYPE_DIRECTIONAL 1
    #define LIGHT_TYPE_POINT 2
    #define LIGHT_TYPE_SPOT 3
    #define POINT_LIGHT_NEARZ 2.0
    #define DIFFUSE_FACTOR 0.5
    #define MAX_LIGHTS 3
    #define MAX_DIRECTIONAL_AND_SPOT_LIGHTS 2
    #define MAX_POINT_LIGHTS 1
    #define AMBIENT_PART_OF_LIGHT 0.1
    #define DIFFUSE_PART_OF_LIGHT 0.9
    const mediump mat4 PointLightFaceXPosViewMat = mat4(0.0, 0.0, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    const mediump mat4 PointLightFaceXNegViewMat = mat4(0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    const mediump mat4 PointLightFaceYPosViewMat = mat4(1.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    const mediump mat4 PointLightFaceYNegViewMat = mat4(-1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    const mediump mat4 PointLightFaceZPosViewMat = mat4(-1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    const mediump mat4 PointLightFaceZNegViewMat = mat4(1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0);
    uniform lowp vec3 lightAmbient;
    uniform lowp int lightInfo[MAX_LIGHTS];
    uniform lowp vec4 lightColor[MAX_LIGHTS];
    uniform mediump vec3 lightDirection[MAX_DIRECTIONAL_AND_SPOT_LIGHTS];
    uniform mediump vec3 lightPosition[MAX_LIGHTS];
    uniform lowp vec3 lightAtt[MAX_LIGHTS];
    uniform highp mat4 lightMat2;
    #define SHADOWMAP_DIMENSION 512.0
    #define SHADOW_CALCULATION_TRESHOLD 0.008
    uniform sampler2D inSampler1;
    uniform sampler2D inSampler2;
    // LIGHT varyings
    varying mediump vec3 varShadowCoord[MAX_DIRECTIONAL_AND_SPOT_LIGHTS];

    int Mod(int x, int y) {
    return x - y * (x / y);
    }
    vec2 GetCoordForPacked4Textures(vec2 coord, int index) {
    index = Mod(index, 4);
    return (index == 0) ? coord / 2.0 :
    (index == 1) ? coord / 2.0 + vec2(0.5, 0.0) :
    (index == 2) ? coord / 2.0 + vec2(0.0, 0.5) :
    (index == 3) ? coord / 2.0 + vec2(0.5, 0.5) :
    vec2(0.0, 0.0);
    }

    vec2 SmootherEdgesForTexture(vec2 coord, float textureDimension) {
    float texel = 1.0 / textureDimension;
    coord.x = abs(1.0 - coord.x) < texel ? 1.0 - texel : abs(coord.x) < texel ? texel : coord.x;
    coord.y = abs(1.0 - coord.y) < texel ? 1.0 - texel : abs(coord.y) < texel ? texel : coord.y;
    return coord;
    }

    float UnpackFloat8bitRGB(vec3 pack) {
    return dot(pack, vec3(1.0, 1.0 / 255.0, 1.0 / 65025.0));
    }

    float UnpackFloat8bitRG(vec2 pack) {
    return dot(pack, vec2(1.0, 1.0 / 255.0));
    }

    vec2 UnpackFloatAndSquare8bitRGBA(vec4 pack) {
    return vec2(UnpackFloat8bitRG(pack.rg), UnpackFloat8bitRG(pack.ba));
    }
    lowp int ExtractType(lowp int info) {
    return Mod(info, 4);
    }
    //
    // lowp int ExtractInTextureIndex(lowp int info) {
    // return Mod(info / 64, 4);
    // }

    // lowp int ExtractTextureIndex(lowp int info) {
    // return Mod(info / 32, 2);
    // }

    bool isAttenuated(lowp int info) {
    return Mod(info, 8) >= 4;
    }

    bool isCastingShadow(lowp int info) {
    return Mod(info, 16) >= 8;
    }

    float DiffuseIntensity(vec3 lightDirection, vec3 normal) {
    vec3 l = normalize(lightDirection);
    vec3 n = normalize(normal);
    return max(dot(n, l) + DIFFUSE_FACTOR, 0.0) / (1.0 + DIFFUSE_FACTOR);
    }
    vec4 CalculateDiffuseLight(lowp vec4 lightColor, vec3 lightDirection, vec3 normal) {
    return lightColor * DiffuseIntensity(lightDirection, normal);
    }

    float SpecularIntensity(vec3 lightDirection, vec3 normal, vec3 toEyeDirection, lowp float specularPower) {
    vec3 l = normalize(lightDirection);
    vec3 n = normalize(normal);
    vec3 v = normalize(toEyeDirection);
    vec3 r = 2.0 * n * dot(n, v) - v;
    return pow(max(dot(l, r), 0.0), specularPower);
    }

    vec4 CalculateSpecularLight(lowp vec4 lightColor, lowp float specularAlpha, vec3 lightDirection, vec3 normal, vec3 toEyeDirection, lowp float specularPower) {
    lowp float specIntensity = SpecularIntensity(lightDirection, normal, toEyeDirection, specularPower);
    return vec4(lightColor.rgb * specIntensity, specularAlpha * specIntensity);
    }

    float Attenuate(vec3 lightPosition, vec3 position, vec3 attenuation) {
    float distance = length(lightPosition - position);
    return clamp(1.0 / (attenuation.x + attenuation.y * distance + attenuation.z * distance * distance), 0.0, 1.0);
    }

    lowp float SlopeBias(lowp float maxBias, vec3 lightDirection, vec3 normal) {
    return clamp(maxBias / 2.0 * tan(acos(clamp(dot(normal, lightDirection), 0.0, 1.0))), 0.0, maxBias);
    }

    bool InTexture(vec2 coord) {
    return all(greaterThanEqual(coord, vec2(0.0))) && all(lessThan(coord, vec2(1.0)));
    }

    bool In4PackedTexture(vec2 coord, int index) {
    return (index == 0) ? InTexture(coord * 2.0) :
    (index == 1) ? InTexture((coord - vec2(0.5, 0.0)) * 2.0) :
    (index == 2) ? InTexture((coord - vec2(0.0, 0.5)) * 2.0) :
    (index == 3) ? InTexture((coord - vec2(0.5, 0.5)) * 2.0) :
    false;
    }

    // hard shadows
    float InShadow(float depth, sampler2D shade, vec2 shadeCoord) {
    return step(depth, UnpackFloat8bitRGB(texture2D(shade, shadeCoord).rgb));
    }

    ////soft shadows with linear interpolation
    // float InShadowLerp(highp float depth, sampler2D shade, vec2 shadeCoord) {
    // vec2 texel = vec2(1.0) / SHADOWMAP_DIMENSION;
    // vec2 coeff = fract(shadeCoord * SHADOWMAP_DIMENSION + 0.5);
    // vec2 centr = floor(shadeCoord * SHADOWMAP_DIMENSION + 0.5) / SHADOWMAP_DIMENSION;

    // float sample1 = InShadow(depth, shade, centr + texel * vec2(0.0, 0.0));
    // float sample2 = InShadow(depth, shade, centr + texel * vec2(0.0, 1.0));
    // float sample3 = InShadow(depth, shade, centr + texel * vec2(1.0, 0.0));
    // float sample4 = InShadow(depth, shade, centr + texel * vec2(1.0, 1.0));

    // return mix(mix(sample1, sample2, coeff.y), mix(sample3, sample4, coeff.y), coeff.x);
    // }
    ////soft shadows with PCF and linear interpolation
    // float InShadowPCFLerp(highp float depth, sampler2D shade, vec2 shadeCoord) {
    // float result = 0.0;
    // for(int x = -1; x < = 1; x++){
    // for(int y = -1; y < = 1; y++){
    // vec2 off = vec2(x,y)/SHADOWMAP_DIMENSION;
    // result += InShadowLerp(depth, shade, shadeCoord + off);
    // }
    // }
    // return result / 9.0;
    // }
    // VSM shadows
    #define MIN_VARIANCE 0.0003
    #define LIGHT_BLEEDING_DROPPER 0.70
    float InShadowVSM(float depth, sampler2D shade, vec2 shadeCoord) {
    vec2 occluder = UnpackFloatAndSquare8bitRGBA(texture2D(shade, shadeCoord));
    float sigma = max(occluder.y - occluder.x * occluder.x, MIN_VARIANCE);
    float pmax = sigma / (sigma + (depth - occluder.x) * (depth - occluder.x));
    pmax = clamp((pmax - LIGHT_BLEEDING_DROPPER) / (1.0 - LIGHT_BLEEDING_DROPPER), 0.0, 1.0);
    return ((depth < = occluder.x) ? 1.0 : pmax);
    }

    void main(void) {
    vec3 n = normalize(varNormal);
    vec3 v = normalize(varToEye);
    vec3 r = 2.0 * n * dot(n, v) - v;
    vec4 texColor = texture2D(inSampler0, varTexCoord);

    vec4 ambient = vec4(lightAmbient, 0.0);
    vec4 diff = vec4(0.0);
    vec4 spec = vec4(0.0);

    for(int i = 0; i < MAX_DIRECTIONAL_AND_SPOT_LIGHTS; i++) {
    if(ExtractType(lightInfo) == LIGHT_TYPE_NOLIGHT) {
    continue;
    }
    vec3 l = normalize(-lightDirection
    );
    float depth = varShadowCoord
    .z;
    vec2 shadowCoord = GetCoordForPacked4Textures(SmootherEdgesForTexture(varShadowCoord
    .xy, SHADOWMAP_DIMENSION), i);

    float attenuation = isAttenuated(lightInfo) ? Attenuate(lightPosition, varPos, lightAtt) : 1.0;

    ambient += attenuation * lightColor * AMBIENT_PART_OF_LIGHT;
    vec4 _diff = CalculateDiffuseLight(lightColor
    , l, n) * DIFFUSE_PART_OF_LIGHT;
    vec4 _spec = CalculateSpecularLight(lightColor
    , lightColor.a, l, n, v, inMaterialSpecular.a);
    float visibility = (shadowRendering == 0 || attenuation * length(_diff + _spec) < SHADOW_CALCULATION_TRESHOLD) ? 1.0 :
    isCastingShadow(lightInfo
    ) && In4PackedTexture(shadowCoord, i) ? (
    (shadowRendering == 1) ? InShadow(clamp(depth - SlopeBias(0.006, l, n), 0.0, 1.0), inSampler1, shadowCoord) :
    //(shadowRendering == 2) ? InShadowLerp(clamp(depth - SlopeBias(0.008, l, n), 0.0, 1.0), inSampler1, shadowCoord) :
    //(shadowRendering == 3) ? InShadowPCFLerp(clamp(depth - SlopeBias(0.013, l, n), 0.0, 1.0), inSampler1, shadowCoord) :
    (shadowRendering == 4 || shadowRendering == 5) ? InShadowVSM(clamp(depth, 0.0, 1.0), inSampler1, shadowCoord) : 1.0
    ) : 1.0;
    diff += visibility * attenuation * _diff;
    spec += visibility * attenuation * _spec;
    }

    for(int i = MAX_DIRECTIONAL_AND_SPOT_LIGHTS; i < MAX_DIRECTIONAL_AND_SPOT_LIGHTS + MAX_POINT_LIGHTS; i++) {
    if(ExtractType(lightInfo
    ) == LIGHT_TYPE_NOLIGHT) {
    continue;
    }

    vec3 l = normalize(lightPosition - varPos);
    float depth = length(varPos - lightPosition
    ) / (POINT_LIGHT_NEARZ * (1.0 + 2.0 / (lightMat2[2].z - 1.0)));
    int inTextureIndex;
    int textureIndex;

    mat4 viewMat;
    if(abs(l.x) > abs(l.y) && abs(l.x) > abs(l.z) && l.x < 0.0) {
    viewMat = PointLightFaceXPosViewMat;
    viewMat[3] = viewMat * vec4(-lightPosition
    , 1.0);
    inTextureIndex = 2;
    textureIndex = 0;
    } else if(abs(l.x) > abs(l.y) && abs(l.x) > abs(l.z) && l.x > 0.0) {
    viewMat = PointLightFaceXNegViewMat;
    viewMat[3] = viewMat * vec4(-lightPosition
    , 1.0);
    inTextureIndex = 3;
    textureIndex = 0;
    } else if(abs(l.y) > abs(l.x) && abs(l.y) >= abs(l.z) && l.y > 0.0) {
    viewMat = PointLightFaceYPosViewMat;
    viewMat[3] = viewMat * vec4(-lightPosition
    , 1.0);
    inTextureIndex = 0;
    textureIndex = 1;
    } else if(abs(l.y) > abs(l.x) && abs(l.y) > abs(l.z) && l.y < 0.0) {
    viewMat = PointLightFaceYNegViewMat;
    viewMat[3] = viewMat * vec4(-lightPosition
    , 1.0);
    inTextureIndex = 1;
    textureIndex = 1;
    } else if(abs(l.z) > abs(l.x) && abs(l.z) > abs(l.y) && l.z < 0.0) {
    viewMat = PointLightFaceZPosViewMat;
    viewMat[3] = viewMat * vec4(-lightPosition
    , 1.0);
    inTextureIndex = 2;
    textureIndex = 1;
    } else if(abs(l.z) > abs(l.x) && abs(l.z) > abs(l.y) && l.z > 0.0) {
    viewMat = PointLightFaceZNegViewMat;
    viewMat[3] = viewMat * vec4(-lightPosition
    , 1.0);
    inTextureIndex = 3;
    textureIndex = 1;
    }

    vec4 tmp = (HomoToUV * lightMat2 * viewMat * vec4(varPos, 1.0));
    vec2 shadowCoord = GetCoordForPacked4Textures(SmootherEdgesForTexture(tmp.xy / tmp.w, SHADOWMAP_DIMENSION), inTextureIndex);

    float attenuation = isAttenuated(lightInfo) ? Attenuate(lightPosition, varPos, lightAtt) : 1.0;

    ambient += attenuation * lightColor * AMBIENT_PART_OF_LIGHT;
    vec4 _diff = CalculateDiffuseLight(lightColor
    , l, n) * DIFFUSE_PART_OF_LIGHT;
    vec4 _spec = CalculateSpecularLight(lightColor
    , lightColor.a, l, n, v, inMaterialSpecular.a);
    float visibility = (shadowRendering == 0 || attenuation * length(_diff + _spec) < SHADOW_CALCULATION_TRESHOLD) ? 1.0 :
    isCastingShadow(lightInfo
    ) && In4PackedTexture(shadowCoord, inTextureIndex) ? (
    (textureIndex == 0) ? (
    (shadowRendering == 1) ? InShadow(clamp(depth - SlopeBias(0.006, l, n), 0.0, 1.0), inSampler1, shadowCoord) :
    //(shadowRendering == 2) ? InShadowLerp(clamp(depth - SlopeBias(0.008, l, n), 0.0, 1.0), inSampler1, shadowCoord) :
    //(shadowRendering == 3) ? InShadowPCFLerp(clamp(depth - SlopeBias(0.013, l, n), 0.0, 1.0), inSampler1, shadowCoord) :
    (shadowRendering == 4 || shadowRendering == 5) ? InShadowVSM(clamp(depth, 0.0, 1.0), inSampler1, shadowCoord) : 1.0
    ) : (
    (shadowRendering == 1) ? InShadow(clamp(depth - SlopeBias(0.006, l, n), 0.0, 1.0), inSampler2, shadowCoord) :
    //(shadowRendering == 2) ? InShadowLerp(clamp(depth - SlopeBias(0.008, l, n), 0.0, 1.0), inSampler2, shadowCoord) :
    //(shadowRendering == 3) ? InShadowPCFLerp(clamp(depth - SlopeBias(0.013, l, n), 0.0, 1.0), inSampler2, shadowCoord) :
    (shadowRendering == 4 || shadowRendering == 5) ? InShadowVSM(clamp(depth, 0.0, 1.0), inSampler2, shadowCoord) : 1.0
    )
    ) : 1.0;
    diff += visibility * attenuation * _diff;
    spec += visibility * attenuation * _spec;
    }

    gl_FragColor = texColor * clamp(vec4((ambient + diff).rgb * (ambient + diff).a, 1.0), vec4(0.0), vec4(1.0)) +
    vec4(inMaterialSpecular.rgb * clamp(spec.rgb, vec3(0.0), vec3(1.0)), spec.a);
    }

    Can you point me in what direction should i look?

    #38312

    Joe Davis
    Member

    Hi,

    Apologies for the delay. Have you made any progress with this issue?

    Thanks,
    Joe

    #38313

    Hi,

    Apologies for the delay. Have you made any progress with this issue?

    Thanks,
    Joe

    Hi.
    I will post later simplified version of that shader which compiles.

    #38314

    Joe Davis
    Member

    Hi,

    Does that mean you’ve been able to work around the issue, or just that a version of the shader with reduced functionality doesn’t hit the problem?

    Thanks,
    Joe

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.