// Reflections as well!
#version 450

struct lightingInput_t
{
    vec3 albedo;
    vec3 colorMask;
    vec3 specular;
    float smoothness;
    float maskSSS;
    float thickness;
    vec3 normal;
    vec3 normalTS;
    vec3 normalSSS;
    vec3 lightmap;
    vec3 emissive;
    float alpha;
    float ssdoDiffuseMul;
    vec3 view;
    vec3 position;
    vec4 texCoords;
    vec4 fragCoord;
    mat3 invTS;
    vec3 ambient_lighting;
    vec3 diffuse_lighting;
    vec3 specular_lighting;
    vec3 output_lighting;
    uint albedo_packed;
    uint specular_packed;
    uint diffuse_lighting_packed;
    uint specular_lighting_packed;
    uint normal_packed;
    uvec4 ticksDecals;
    uvec4 ticksProbes;
    uvec4 ticksLights;
};

struct clusternumlights_t
{
    int offset;
    int numItems;
};

struct light_t
{
    vec3 pos;
    uint lightParms;
    vec4 posShadow;
    vec4 falloffR;
    vec4 projS;
    vec4 projT;
    vec4 projQ;
    uvec4 scaleBias;
    vec4 boxMin;
    vec4 boxMax;
    vec4 areaPlane;
    uint lightParms2;
    uint colorPacked;
    float specMultiplier;
    float shadowBleedReduce;
};


// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
layout(set = 0, binding = 30, std140) uniform Vk3DParams
{
    vec4 stereo;
    vec4 custom_params;
} vk3d_params;

layout(set = 0, binding = 0, std140) uniform freqHigh_fragmentUniforms_ubo
{
    vec4 renderpositiontoviewtexture;
    vec4 staticmodel;
    vec4 positiontoviewtexture;
} freqHigh_fragmentUniforms;

layout(set = 0, binding = 1, std140) uniform freqLow_fragmentUniforms_ubo
{
    vec4 frustumvectl;
    vec4 frustumvectr;
    vec4 resolutionscale;
    vec4 frustumvecbl;
    vec4 frustumvecbr;
    vec4 projectionmatrixz;
    vec4 globalvieworigin;
    vec4 clusteredlighting;
    vec4 pbrdebugparms;
} freqLow_fragmentUniforms;

layout(set = 0, binding = 9, std430) restrict readonly buffer clusternumlights_b
{
    clusternumlights_t clusternumlights[];
} _839;

layout(set = 0, binding = 10, std430) restrict readonly buffer clusterlightsid_b
{
    uint clusterlightsid[];
} _941;

layout(set = 0, binding = 2, std140) uniform lightparms1_ubo
{
    vec4 lightparms1[4096];
} _970;

layout(set = 0, binding = 3, std140) uniform lightparms2_ubo
{
    vec4 lightparms2[4096];
} _1009;

layout(set = 0, binding = 4, std140) uniform lightparms3_ubo
{
    vec4 lightparms3[4096];
} _1077;

layout(set = 0, binding = 5) uniform sampler2D samp_tex2;
layout(set = 0, binding = 6) uniform sampler2D samp_tex0;
layout(set = 0, binding = 7) uniform sampler2D samp_tex1;
layout(set = 0, binding = 8) uniform samplerCubeArray samp_envprobesmaparray;

layout(location = 0) out vec4 out_FragColor0;

vec2 screenPosToTexcoord(vec2 pos, vec4 bias_scale)
{
    return (pos * bias_scale.zw) + bias_scale.xy;
}

vec4 tex2Dlod(sampler2D image, vec4 texcoord)
{
    return textureLod(image, texcoord.xy, texcoord.w);
}

float sqr(float x)
{
    return x * x;
}

vec2 SmoothnessDecode(float s)
{
    float expanded_s = (s * 2.0) - 1.0;
    float param = expanded_s;
    float _536;
    if (expanded_s > 0.0)
    {
        _536 = 1.0;
    }
    else
    {
        _536 = 0.0;
    }
    return vec2(sqr(param), _536);
}

float GetLinearDepth(float ndcZ, vec4 projectionMatrixZ, float rcpFarZ, bool bFirstPersonArmsRescale)
{
    float linearZ = projectionMatrixZ.w / (ndcZ + projectionMatrixZ.z);
    if (bFirstPersonArmsRescale)
    {
        float _451;
        if (linearZ < 1.0)
        {
            _451 = 10.0;
        }
        else
        {
            _451 = 1.0;
        }
        linearZ *= _451;
    }
    return linearZ * rcpFarZ;
}

vec2 OctWrap(vec2 v)
{
    float _471;
    if (v.x >= 0.0)
    {
        _471 = 1.0;
    }
    else
    {
        _471 = -1.0;
    }
    float _480;
    if (v.y >= 0.0)
    {
        _480 = 1.0;
    }
    else
    {
        _480 = -1.0;
    }
    return (vec2(1.0) - abs(v.yx)) * vec2(_471, _480);
}

vec3 NormalOctDecode(inout vec2 encN, bool expand_range)
{
    if (expand_range)
    {
        encN = (encN * 2.0) - vec2(1.0);
    }
    vec3 n;
    n.z = (1.0 - abs(encN.x)) - abs(encN.y);
    vec2 _510;
    if (n.z >= 0.0)
    {
        _510 = encN;
    }
    else
    {
        vec2 param = encN;
        _510 = OctWrap(param);
    }
    n = vec3(_510.x, _510.y, n.z);
    n = normalize(n);
    return n;
}

vec3 saturate(vec3 v)
{
    return clamp(v, vec3(0.0), vec3(1.0));
}

uint packR10G10B10(inout vec3 value)
{
    vec3 param = value;
    value = saturate(param);
    return ((uint(value.x * 1023.0) << uint(20)) | (uint(value.y * 1023.0) << uint(10))) | uint(value.z * 1023.0);
}

float GetLuma(vec3 c)
{
    return dot(c, vec3(0.2125999927520751953125, 0.715200006961822509765625, 0.072200000286102294921875));
}

uint asuint(float x)
{
    return floatBitsToUint(x);
}

float ApproxLog2(float f)
{
    float param = f;
    return (float(asuint(param)) / 8388608.0) - 127.0;
}

float asfloat(uint x)
{
    return uintBitsToFloat(x);
}

float ApproxExp2(float f)
{
    uint param = uint((f + 127.0) * 8388608.0);
    return asfloat(param);
}

vec4 saturate(vec4 v)
{
    return clamp(v, vec4(0.0), vec4(1.0));
}

uint packR8G8B8A8(inout vec4 value)
{
    vec4 param = value;
    value = saturate(param);
    return (((uint(value.x * 255.0) << uint(24)) | (uint(value.y * 255.0) << uint(16))) | (uint(value.z * 255.0) << uint(8))) | uint(value.w * 255.0);
}

uint packRGBE(vec3 value)
{
    float param = max(max(value.x, value.y), value.z);
    float sharedExp = ceil(ApproxLog2(param));
    float param_1 = sharedExp;
    vec4 param_2 = vec4(value / vec3(ApproxExp2(param_1)), (sharedExp + 128.0) / 255.0);
    vec4 param_3 = saturate(param_2);
    uint _357 = packR8G8B8A8(param_3);
    return _357;
}

float fmin3(float f1, float f2, float f3)
{
    return min(f1, min(f2, f3));
}

float fmax3(float f1, float f2, float f3)
{
    return max(f1, max(f2, f3));
}

vec4 unpackR8G8B8A8(uint value)
{
    return vec4(float((value >> uint(24)) & 255u), float((value >> uint(16)) & 255u), float((value >> uint(8)) & 255u), float(value & 255u)) / vec4(255.0);
}

vec3 unpackRGBE(uint value)
{
    uint param = value;
    vec4 rgbe = unpackR8G8B8A8(param);
    float param_1 = (rgbe.w * 255.0) - 128.0;
    return rgbe.xyz * ApproxExp2(param_1);
}

float saturate(float v)
{
    return clamp(v, 0.0, 1.0);
}

vec4 unpackUintR8G8B8A8(uint value)
{
    return vec4(float((value >> uint(24)) & 255u), float((value >> uint(16)) & 255u), float((value >> uint(8)) & 255u), float(value & 255u));
}

vec4 texCUBEARRAYlod(samplerCubeArray image, vec4 texcoord, float lod)
{
    return textureLod(image, texcoord, lod);
}

vec3 unpackR10G10B10(uint value)
{
    return vec3(float((value >> uint(20)) & 1023u), float((value >> uint(10)) & 1023u), float(value & 1023u)) / vec3(1023.0);
}

vec3 environmentBRDF(float NdotV, float smoothness, vec3 f0)
{
    float t1 = 0.0949999988079071044921875 + (smoothness * (0.60000002384185791015625 + (4.190000057220458984375 * smoothness)));
    float t2 = NdotV + 0.02500000037252902984619140625;
    float t3 = (9.5 * smoothness) * NdotV;
    float param = 1.0 - (14.0 * NdotV);
    float a0 = (t1 * t2) * ApproxExp2(param);
    float param_1 = -t3;
    float a1 = 0.4000000059604644775390625 + (0.60000002384185791015625 * (1.0 - ApproxExp2(param_1)));
    return mix(vec3(a0), vec3(a1), f0);
}

void main()
{
    vec2 param = gl_FragCoord.xy;
    vec4 param_1 = freqHigh_fragmentUniforms.renderpositiontoviewtexture;
    vec2 tc = screenPosToTexcoord(param, param_1);
    vec4 param_2 = vec4(tc, 0.0, 0.0);
    vec4 spec = tex2Dlod(samp_tex2, param_2);
    float param_3 = spec.w;
    float smoothness = SmoothnessDecode(param_3).x;
    vec4 param_4 = vec4(tc, 0.0, 0.0);
    float depth = tex2Dlod(samp_tex0, param_4).x;
    out_FragColor0 = vec4(0.0);
    if ((dot(spec.xyz, vec3(1.0)) > 0.0) && (depth < 1.0))
    {
        lightingInput_t inputs = lightingInput_t(vec3(0.0), vec3(0.0), vec3(0.0), 0.0, 0.0, 0.0, vec3(0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, 1.0), vec3(0.0), vec3(0.0), 1.0, 1.0, vec3(0.0), vec3(0.0), vec4(0.0), vec4(0.0), mat3(vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 0.0, 1.0)), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), 0u, 0u, 0u, 0u, 0u, uvec4(0u), uvec4(0u), uvec4(0u));
        vec3 frustumVecX0 = mix(freqLow_fragmentUniforms.frustumvectl.xyz, freqLow_fragmentUniforms.frustumvectr.xyz, vec3(tc.x * freqLow_fragmentUniforms.resolutionscale.z));
        vec3 frustumVecX1 = mix(freqLow_fragmentUniforms.frustumvecbl.xyz, freqLow_fragmentUniforms.frustumvecbr.xyz, vec3(tc.x * freqLow_fragmentUniforms.resolutionscale.z));
        vec3 frustumVec = mix(frustumVecX1, frustumVecX0, vec3(1.0 - (tc.y * freqLow_fragmentUniforms.resolutionscale.w)));
        inputs.albedo = vec3(1.0);
        vec2 _661 = vec2(gl_FragCoord.xy);
        inputs.fragCoord = vec4(_661.x, _661.y, inputs.fragCoord.z, inputs.fragCoord.w);
        vec4 wPosM = vec4(tc, depth, 1.0);
        float param_5 = depth;
        vec4 param_6 = freqLow_fragmentUniforms.projectionmatrixz;
        float param_7 = 1.0;
        bool param_8 = false;
        float zLinear = GetLinearDepth(param_5, param_6, param_7, param_8);
        vec3 world_pos = freqLow_fragmentUniforms.globalvieworigin.xyz + (frustumVec * zLinear);
        
        
        // Frustum corners appear to be in _fa_freqLow[0,1,3,4], let's use 0 & 1 as the top two corners:
        vec3 camera_horizontal_world = freqLow_fragmentUniforms.frustumvectr.xyz - freqLow_fragmentUniforms.frustumvectl.xyz;

        // In this case I think that the frustum is already a unit distance from the
        // camera, otherwise it would need to be rescaled.

        // Find the width of the frustum using Pythagorus:
        float frustum_width = sqrt(dot(camera_horizontal_world.xyz, camera_horizontal_world.xyz));

        // Calculate the horizontal unit vector:
        vec3 camera_horizontal_world_normalized = camera_horizontal_world / frustum_width;

        // Calculate the stereo adjustment magnitude, using frustum_width/2 in place of
        // tan(fov_horizontal / 2) normally obtained from the inverse projection matrix:
        float adjustment_magnitude = vk3d_params.stereo.x * (zLinear - vk3d_params.stereo.x) * frustum_width / 2;

        // World space adjustment is just the magitude * horizontal:
        world_pos.xyz -= adjustment_magnitude * camera_horizontal_world_normalized;
        
        
        
        
        inputs.fragCoord.z = depth;
        inputs.position = world_pos;
        inputs.view = normalize(freqLow_fragmentUniforms.globalvieworigin.xyz - world_pos);
        vec4 param_9 = vec4(tc, 0.0, 0.0);
        vec2 param_10 = tex2Dlod(samp_tex1, param_9).xy;
        bool param_11 = false;
        vec3 _714 = NormalOctDecode(param_10, param_11);
        inputs.normal = _714;
        inputs.specular = spec.xyz * spec.xyz;
        inputs.smoothness = smoothness;
        int _726;
        if (freqHigh_fragmentUniforms.staticmodel.x > 0.0)
        {
            _726 = 8;
        }
        else
        {
            _726 = 0;
        }
        uint skipStaticModel = uint(_726);
        float NUM_CLUSTERS_X = 16.0;
        float NUM_CLUSTERS_Y = 8.0;
        float NUM_CLUSTERS_Z = 24.0;
        vec2 param_12 = inputs.fragCoord.xy;
        vec4 param_13 = freqHigh_fragmentUniforms.positiontoviewtexture;
        vec2 _753 = screenPosToTexcoord(param_12, param_13) * freqLow_fragmentUniforms.resolutionscale.zw;
        vec3 clusterCoordinate;
        clusterCoordinate = vec3(_753.x, _753.y, clusterCoordinate.z);
        clusterCoordinate.y = 1.0 - clusterCoordinate.y;

// Vk3DVision (http://3dsurroundgaming.com/) - Stereo Injection
clusterCoordinate.x -= vk3d_params.stereo.x * 0.5; 
        vec2 _766 = floor(clusterCoordinate.xy * vec2(NUM_CLUSTERS_X, NUM_CLUSTERS_Y));
        clusterCoordinate = vec3(_766.x, _766.y, clusterCoordinate.z);
        float param_14 = inputs.fragCoord.z;
        vec4 param_15 = freqLow_fragmentUniforms.projectionmatrixz;
        float param_16 = 1.0;
        bool param_17 = false;
        float curr_z = GetLinearDepth(param_14, param_15, param_16, param_17);
        float slice = log2(max(1.0, curr_z / freqLow_fragmentUniforms.clusteredlighting.z)) * freqLow_fragmentUniforms.clusteredlighting.w;
        clusterCoordinate.z = min(NUM_CLUSTERS_Z - 1.0, floor(slice));
        uint clusterOffset = uint((clusterCoordinate.x + (clusterCoordinate.y * NUM_CLUSTERS_X)) + ((clusterCoordinate.z * NUM_CLUSTERS_X) * NUM_CLUSTERS_Y));
        vec3 param_18 = inputs.albedo;
        uint _816 = packR10G10B10(param_18);
        inputs.albedo_packed = _816;
        vec3 param_19 = inputs.specular;
        uint _822 = packR10G10B10(param_19);
        inputs.specular_packed = _822;
        uint lightsMin = 0u;
        uint lightsMax = 0u;
        uint decalsMin = 0u;
        uint decalsMax = 0u;
        uint probesMin = 0u;
        uint probesMax = 0u;
        int MAX_LIGHTS_PER_CLUSTER = 256;
        clusternumlights_t cluster;
        cluster.offset = _839.clusternumlights[clusterOffset].offset;
        cluster.numItems = _839.clusternumlights[clusterOffset].numItems;
        int dataOffset = cluster.offset & (~(cluster.offset >> 31));
        int numItems = cluster.numItems & (~(cluster.numItems >> 31));
        lightsMin = uint((dataOffset >> 16) * MAX_LIGHTS_PER_CLUSTER);
        lightsMax = lightsMin + uint(numItems & 255);
        decalsMin = lightsMin;
        decalsMax = decalsMin + uint((numItems >> 8) & 255);
        probesMin = lightsMin;
        probesMax = probesMin + uint((numItems >> 16) & 255);
        vec3 ambient = vec3(0.0);
        ambient += inputs.emissive;
        float _895;
        if (dot(inputs.emissive, vec3(1.0)) > 0.0)
        {
            _895 = -inputs.smoothness;
        }
        else
        {
            _895 = inputs.smoothness;
        }
        inputs.smoothness = _895;
        vec3 param_20 = ambient;
        ambient = mix(vec3(GetLuma(param_20)), ambient, freqLow_fragmentUniforms.pbrdebugparms.www);
        inputs.ambient_lighting = ambient;
        vec3 param_21 = ambient;
        inputs.diffuse_lighting_packed = packRGBE(param_21);
        float probes_dst_alpha = 1.0;
        uint probeIdx = probesMin;
        light_t lightParms;
        while (probeIdx < probesMax)
        {
            uint temp = _941.clusterlightsid[probeIdx];
            uint divergentProbeId = (temp >> uint(24)) & 4095u;
            uint probe_id = divergentProbeId;
            if (probe_id >= divergentProbeId)
            {
                probeIdx++;
            }
            int lightParms1Size = 4;
            int lightParms2Size = 4;
            int lightParms3Size = 3;
            lightParms.pos = _970.lightparms1[(uint(lightParms1Size) * probe_id) + 0u].xyz;
            
            //lightParms.pos.x += 1;
            
            
            float param_22 = _970.lightparms1[(uint(lightParms1Size) * probe_id) + 0u].w;
            lightParms.lightParms = asuint(param_22);
            lightParms.posShadow = _970.lightparms1[(uint(lightParms1Size) * probe_id) + 1u];
            lightParms.falloffR = _970.lightparms1[(uint(lightParms1Size) * probe_id) + 2u];
            lightParms.projS = _1009.lightparms2[(uint(lightParms2Size) * probe_id) + 0u];
            lightParms.projT = _1009.lightparms2[(uint(lightParms2Size) * probe_id) + 1u];
            lightParms.projQ = _1009.lightparms2[(uint(lightParms2Size) * probe_id) + 2u];
            float param_23 = _970.lightparms1[(uint(lightParms1Size) * probe_id) + 3u].x;
            lightParms.scaleBias.x = asuint(param_23);
            float param_24 = _970.lightparms1[(uint(lightParms1Size) * probe_id) + 3u].y;
            lightParms.scaleBias.y = asuint(param_24);
            float param_25 = _970.lightparms1[(uint(lightParms1Size) * probe_id) + 3u].z;
            lightParms.scaleBias.z = asuint(param_25);
            float param_26 = _970.lightparms1[(uint(lightParms1Size) * probe_id) + 3u].w;
            lightParms.scaleBias.w = asuint(param_26);
            
            
            
            lightParms.boxMin = _1077.lightparms3[(uint(lightParms3Size) * probe_id) + 0u];
            lightParms.boxMax = _1077.lightparms3[(uint(lightParms3Size) * probe_id) + 1u];
            lightParms.areaPlane = _1077.lightparms3[(uint(lightParms3Size) * probe_id) + 2u];
            
            float param_27 = _1009.lightparms2[(uint(lightParms2Size) * probe_id) + 3u].x;
            lightParms.lightParms2 = asuint(param_27);
            float param_28 = _1009.lightparms2[(uint(lightParms2Size) * probe_id) + 3u].y;
            
            lightParms.colorPacked = asuint(param_28);
            lightParms.specMultiplier = _1009.lightparms2[(uint(lightParms2Size) * probe_id) + 3u].z;
            lightParms.shadowBleedReduce = _1009.lightparms2[(uint(lightParms2Size) * probe_id) + 3u].w;
            
            //inputs.position.x += vk3d_params.stereo.x;
            
            vec3 projTC = vec3((inputs.position.x * lightParms.projS.x) + ((inputs.position.y * lightParms.projS.y) + ((inputs.position.z * lightParms.projS.z) + lightParms.projS.w)), (inputs.position.x * lightParms.projT.x) + ((inputs.position.y * lightParms.projT.y) + ((inputs.position.z * lightParms.projT.z) + lightParms.projT.w)), (inputs.position.x * lightParms.projQ.x) + ((inputs.position.y * lightParms.projQ.y) + ((inputs.position.z * lightParms.projQ.z) + lightParms.projQ.w)));
            vec2 _1208 = projTC.xy / vec2(projTC.z);
            projTC = vec3(_1208.x, _1208.y, projTC.z);
            
            //projTC.x += 0.5;
            
            
            projTC.z = (inputs.position.x * lightParms.falloffR.x) + ((inputs.position.y * lightParms.falloffR.y) + ((inputs.position.z * lightParms.falloffR.z) + lightParms.falloffR.w));
            
            
            float clip_min = 0.0039215688593685626983642578125;
            float param_29 = projTC.x;
            float param_30 = projTC.y;
            float param_31 = projTC.z;
            bool _1245 = fmin3(param_29, param_30, param_31) <= clip_min;
            bool _1262;
            if (!_1245)
            {
                float param_32 = projTC.x;
                float param_33 = projTC.y;
                float param_34 = projTC.z;
                _1262 = fmax3(param_32, param_33, param_34) >= (1.0 - clip_min);
            }
            else
            {
                _1262 = _1245;
            }
            if (_1262)
            {
                continue;
            }
            uint light_parms = lightParms.lightParms;
            uint param_35 = lightParms.colorPacked;
            vec3 light_color = unpackRGBE(param_35);
            float light_spec_multiplier = lightParms.specMultiplier;
            vec3 light_position = lightParms.pos;
            uint param_36 = light_parms;
            float light_probe_innerfalloff = unpackR8G8B8A8(param_36).y;
            vec3 norm_pos_cube = (projTC * 2.0) - vec3(1.0);
            vec3 norm_pos_sphere = norm_pos_cube * sqrt(((vec3(1.0) - ((norm_pos_cube.yzx * norm_pos_cube.yzx) * 0.5)) - ((norm_pos_cube.zxy * norm_pos_cube.zxy) * 0.5)) + ((((norm_pos_cube.yzx * norm_pos_cube.yzx) * norm_pos_cube.zxy) * norm_pos_cube.zxy) / vec3(3.0)));
            float param_37 = 1.0 - ((length(norm_pos_sphere) - light_probe_innerfalloff) / ((1.0 - light_probe_innerfalloff) + 9.9999999747524270787835121154785e-07));
            float light_attenuation = saturate(param_37);
            light_attenuation *= light_attenuation;
            light_attenuation *= (lightParms.boxMin.w * probes_dst_alpha);
            probes_dst_alpha *= (1.0 - light_attenuation);
            if (light_attenuation <= (clip_min * 4.0))
            {
                continue;
            }
            vec3 light_color_final = light_color;
            vec3 param_38 = light_color_final;
            light_color_final = mix(vec3(GetLuma(param_38)), light_color_final, freqLow_fragmentUniforms.pbrdebugparms.www);
            uint param_39 = light_parms;
            float light_probe_id = unpackUintR8G8B8A8(param_39).z;
            vec3 diffEnvProbe = vec3(0.0);
            vec3 specEnvProbe = vec3(0.0);
            vec3 normal = inputs.normal;
            normal.x = dot(lightParms.posShadow.xy, inputs.normal.xy);
            normal.y = dot(lightParms.posShadow.zw, inputs.normal.xy);
            vec3 R = reflect(-inputs.view, inputs.normal);
            vec3 bmax = (lightParms.boxMax.xyz - inputs.position) / R;
            vec3 bmin = (lightParms.boxMin.xyz - inputs.position) / R;
            vec3 bminmax = max(bmax, bmin);
            float param_40 = bminmax.x;
            float param_41 = bminmax.y;
            float param_42 = bminmax.z;
            float intersection_dist = fmin3(param_40, param_41, param_42);
            vec3 intersection_pos = inputs.position + (R * intersection_dist);
            vec3 LRtmp = normalize(intersection_pos - light_position);
            vec3 LR = LRtmp;
            LR.x = dot(lightParms.posShadow.xy, LRtmp.xy);
            LR.y = dot(lightParms.posShadow.zw, LRtmp.xy);
            float num_mips = 6.0;
            float mip_level = num_mips - (num_mips * abs(inputs.smoothness));
            vec4 param_43 = vec4(LR, light_probe_id);
            float param_44 = mip_level;
            specEnvProbe = texCUBEARRAYlod(samp_envprobesmaparray, param_43, param_44).xyz;
            float param_45 = dot(inputs.view, inputs.normal);
            float NdotV = saturate(param_45);
            uint param_46 = inputs.specular_packed;
            float param_47 = NdotV;
            float param_48 = abs(inputs.smoothness);
            vec3 param_49 = unpackR10G10B10(param_46);
            vec3 envBRDF = environmentBRDF(param_47, param_48, param_49);
            specEnvProbe *= (envBRDF * light_spec_multiplier);
            vec3 param_50 = diffEnvProbe;
            diffEnvProbe = mix(vec3(GetLuma(param_50)), diffEnvProbe, freqLow_fragmentUniforms.pbrdebugparms.www);
            vec3 param_51 = specEnvProbe;
            specEnvProbe = mix(vec3(GetLuma(param_51)), specEnvProbe, freqLow_fragmentUniforms.pbrdebugparms.www);
            float param_52 = light_attenuation;
            uint param_53 = inputs.specular_lighting_packed;
            vec3 param_54 = ((specEnvProbe * light_color_final) * saturate(param_52)) + unpackRGBE(param_53);
            inputs.specular_lighting_packed = packRGBE(param_54);
            if (probes_dst_alpha <= (clip_min * 4.0))
            {
                break;
            }
        }
        uint param_55 = inputs.diffuse_lighting_packed;
        uint param_56 = inputs.albedo_packed;
        inputs.diffuse_lighting = unpackRGBE(param_55) * unpackR10G10B10(param_56);
        uint param_57 = inputs.specular_lighting_packed;
        inputs.specular_lighting = unpackRGBE(param_57);
        inputs.output_lighting = inputs.diffuse_lighting + inputs.specular_lighting;
        out_FragColor0 = vec4(inputs.specular_lighting.x, inputs.specular_lighting.y, inputs.specular_lighting.z, out_FragColor0.w);
    }
}



