// FIX FOR DECALS CLIPPING & Shadows?
#version 450
layout(early_fragment_tests) in;

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

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 decal_t
{
    vec4 projS;
    vec4 projT;
    vec4 projR;
    uvec2 albedoScaleBias;
    uvec2 specScaleBias;
    uvec2 normalScaleBias;
    uint opacity;
    uint decalParms;
    uint albedo;
    uint emissive;
    uint specOverride;
    uint decalParms2;
};

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;
};

struct shadowparms_t
{
    vec4 shadowLightS;
    vec4 shadowLightT;
    vec4 shadowLightR;
    vec4 shadowLightQ;
    vec4 shadowAtlasScaleBias;
};

layout(set = 0, binding = 3, std140) uniform freqLow_fragmentUniforms_ubo
{
    vec4 globalvieworigin;
    vec4 vmtrfeedbackfloat;
    vec4 virtualtextureoptions;
    vec4 vmtrphysicalpagesaspectratio;
    vec4 physicalpagesaspectratio;
    vec4 vmtrlightmapfeedback;
    vec4 resolutionscale;
    vec4 projectionmatrixz;
    vec4 clusteredlighting;
    vec4 lightmapscale;
    vec4 envlightmapscale;
    vec4 pbrdebugparms;
    vec4 parallellightslicescale;
    vec4 shadowatlasresolution;
    vec4 highlightcolor;
} freqLow_fragmentUniforms;

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

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

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

layout(set = 0, binding = 4, std140) uniform decalparms1_ubo
{
    vec4 decalparms1[4096];
} _2367;

layout(set = 0, binding = 5, std140) uniform decalparms2_ubo
{
    vec4 decalparms2[4096];
} _2387;

layout(set = 0, binding = 6, std140) uniform decalparms3_ubo
{
    vec4 decalparms3[4096];
} _2439;

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

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

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

layout(set = 0, binding = 10, std140) uniform shadowsparmsubo_ubo
{
    vec4 shadowsparmsubo[4095];
} _3682;

layout(set = 0, binding = 11) uniform sampler2D samp_vmtrpagetablemap;
layout(set = 0, binding = 12) uniform sampler2D samp_vmtrphysicalmappingsmap;
layout(set = 0, binding = 13) uniform sampler2DArray samp_vmtrphysicalpagesmaparray0;
layout(set = 0, binding = 14) uniform sampler2D samp_vmtrphysicalpagesmap3;
layout(set = 0, binding = 15) uniform sampler2D samp_pagetablemap;
layout(set = 0, binding = 16) uniform sampler2D samp_physicalmappingsmap;
layout(set = 0, binding = 17) uniform sampler2D samp_physicalpagesmap4;
layout(set = 0, binding = 23, r32f) uniform writeonly image2D ib_feedbackbuffer;
layout(set = 0, binding = 18) uniform sampler2D samp_decalsatlasmap;
layout(set = 0, binding = 19) uniform sampler2D samp_lightsatlasmap;
layout(set = 0, binding = 20) uniform sampler2DShadow samp_shadowatlasdepthcomparemap;

layout(location = 2) in vec4 vofi_TexCoord0;
layout(location = 6) in vec4 vofi_TexCoord4;
layout(location = 3) in vec4 vofi_TexCoord1;
layout(location = 4) in vec4 vofi_TexCoord2;
layout(location = 7) in vec4 vofi_TexCoord5;
layout(location = 5) in vec4 vofi_TexCoord3;
layout(location = 0) out vec4 out_FragColor0;
layout(location = 1) out vec4 out_FragColor1;
layout(location = 2) out vec4 out_FragColor2;

float _408;

float dot2(vec2 a, vec2 b)
{
    return dot(a, b);
}

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

vec4 tex2D(sampler2D image, vec2 texcoord)
{
    return texture(image, texcoord);
}

vec4 tex2DARRAY(sampler2DArray image, vec3 texcoord, vec2 dx, vec2 dy)
{
    return textureGrad(image, texcoord, dx, dy);
}

vec4 tex2DArrayGrad(sampler2DArray image, float slice, vec2 texcoord, vec2 dx, vec2 dy)
{
    vec3 param = vec3(texcoord, slice);
    vec2 param_1 = dx;
    vec2 param_2 = dy;
    return tex2DARRAY(image, param, param_1, param_2);
}

vec4 texPhysArray(sampler2DArray image, float slice, vec2 texcoord, vec2 dx, vec2 dy)
{
    float param = slice;
    vec2 param_1 = texcoord;
    vec2 param_2 = dx;
    vec2 param_3 = dy;
    return tex2DArrayGrad(image, param, param_1, param_2, param_3);
}

vec4 tex2D(sampler2D image, vec2 texcoord, vec2 dx, vec2 dy)
{
    return textureGrad(image, texcoord, dx, dy);
}

vec4 texPhys(sampler2D image, vec2 texcoord, vec2 dx, vec2 dy)
{
    vec2 param = texcoord;
    vec2 param_1 = dx;
    vec2 param_2 = dy;
    return tex2D(image, param, param_1, param_2);
}

float SRGBlinear(float value)
{
    if (value <= 0.040449999272823333740234375)
    {
        return value / 12.9200000762939453125;
    }
    else
    {
        return pow((value / 1.05499994754791259765625) + 0.0521326996386051177978515625, 2.400000095367431640625);
    }
}

float DeGamma(float value)
{
    float param = value;
    return SRGBlinear(param);
}

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

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

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

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

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);
}

vec3 ReconstructNormal(vec3 normalTS, bool isFrontFacing)
{
    vec3 N = (normalTS * 2.0) - vec3(1.0);
    float param = (1.0 - (N.x * N.x)) - (N.y * N.y);
    N.z = sqrt(saturate(param));
    if (isFrontFacing == false)
    {
        N.z = -N.z;
    }
    return N;
}

vec3 TransformNormal(vec3 normal, mat3 mat)
{
    return normalize(vec3(dot(normal, mat[0]), dot(normal, mat[1]), dot(normal, mat[2])));
}

vec3 GetWorldSpaceNormal(vec3 normalTS, mat3 invTS, bool isFrontFacing)
{
    vec3 param = normalTS;
    bool param_1 = isFrontFacing;
    vec3 N = ReconstructNormal(param, param_1);
    vec3 param_2 = N;
    mat3 param_3 = invTS;
    return TransformNormal(param_2, param_3);
}

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

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 unpackR15G15B15A15(uvec2 value)
{
    return vec4(float((value.x >> uint(16)) & 65535u), float(value.x & 65535u), float((value.y >> uint(16)) & 65535u), float(value.y & 65535u)) * 3.0518509447574615478515625e-05;
}

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 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);
}

int asint(float x)
{
    return floatBitsToInt(x);
}

float asfloat(int x)
{
    return intBitsToFloat(x);
}

float sqrtIEEEIntApproximation(float inX, int inSqrtConst)
{
    float param = inX;
    int x = asint(param);
    x = inSqrtConst + (x >> 1);
    int param_1 = x;
    return asfloat(param_1);
}

float fastSqrtNR0(float inX)
{
    float param = inX;
    int param_1 = 532487669;
    return sqrtIEEEIntApproximation(param, param_1);
}

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

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

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

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 _635 = packR8G8B8A8(param_3);
    return _635;
}

uint getCubeMapFaceID(float x, float y, float z)
{
    bool _338 = abs(z) >= abs(x);
    bool _346;
    if (_338)
    {
        _346 = abs(z) >= abs(y);
    }
    else
    {
        _346 = _338;
    }
    if (_346)
    {
        int _349;
        if (z < 0.0)
        {
            _349 = 5;
        }
        else
        {
            _349 = 4;
        }
        return uint(_349);
    }
    if (abs(y) >= abs(x))
    {
        int _367;
        if (y < 0.0)
        {
            _367 = 3;
        }
        else
        {
            _367 = 2;
        }
        return uint(_367);
    }
    int _378;
    if (x < 0.0)
    {
        _378 = 1;
    }
    else
    {
        _378 = 0;
    }
    return uint(_378);
}

float shadow2Ddepth(sampler2DShadow image, vec3 texcoord)
{
    return textureLod(image, vec3(texcoord.xy, texcoord.z), 0.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);
}

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

float ApproxPow(float fBase, float fPower)
{
    float param = fBase;
    uint param_1 = uint((fPower * float(asuint(param))) - (((fPower - 1.0) * 127.0) * 8388608.0));
    return asfloat(param_1);
}

vec3 fresnelSchlick(vec3 f0, float costheta)
{
    float param = 50.0 * dot(f0, vec3(0.33329999446868896484375));
    float baked_spec_occl = saturate(param);
    float param_1 = 1.0 - costheta;
    float param_2 = saturate(param_1);
    float param_3 = 5.0;
    vec3 param_4 = f0 + ((vec3(baked_spec_occl) - f0) * ApproxPow(param_2, param_3));
    return saturate(param_4);
}

vec3 specBRDF(vec3 N, vec3 V, vec3 L, vec3 f0, float smoothness)
{
    vec3 H = normalize(V + L);
    float m = 1.0 - (smoothness * 0.800000011920928955078125);
    m *= m;
    m *= m;
    float m2 = m * m;
    float param = dot(N, H);
    float NdotH = saturate(param);
    float spec = ((NdotH * NdotH) * (m2 - 1.0)) + 1.0;
    spec = m2 / ((spec * spec) + 9.9999999392252902907785028219223e-09);
    float param_1 = dot(N, V);
    float Gv = (saturate(param_1) * (1.0 - m)) + m;
    float param_2 = dot(N, L);
    float Gl = (saturate(param_2) * (1.0 - m)) + m;
    spec /= (((4.0 * Gv) * Gl) + 9.9999999392252902907785028219223e-09);
    vec3 param_3 = f0;
    float param_4 = dot(L, H);
    return fresnelSchlick(param_3, param_4) * spec;
}

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

vec2 NormalOctEncode(inout vec3 n, bool compress_range)
{
    n /= vec3((abs(n.x) + abs(n.y)) + abs(n.z));
    vec2 _948;
    if (n.z >= 0.0)
    {
        _948 = n.xy;
    }
    else
    {
        vec2 param = n.xy;
        _948 = OctWrap(param);
    }
    n = vec3(_948.x, _948.y, n.z);
    if (compress_range)
    {
        vec2 _972 = (n.xy * 0.5) + vec2(0.5);
        n = vec3(_972.x, _972.y, n.z);
    }
    return n.xy;
}

float SmoothnessEncode(float s)
{
    float param = abs(s);
    float s1 = fastSqrtNR0(param);
    float _984;
    if (s > 0.0)
    {
        _984 = s1;
    }
    else
    {
        _984 = -s1;
    }
    return (_984 * 0.5) + 0.5;
}

void main()
{
    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));
    inputs.texCoords = vofi_TexCoord0;
    inputs.fragCoord = gl_FragCoord;
    inputs.position = freqLow_fragmentUniforms.globalvieworigin.xyz + vofi_TexCoord4.xyz;
    vec3 inNormal = normalize(vofi_TexCoord1.xyz);
    vec3 inTangent = normalize(vofi_TexCoord2.xyz);
    vec3 derivedBitangent = normalize(cross(inNormal, inTangent) * vofi_TexCoord2.w);
    inputs.invTS = mat3(vec3(inTangent.x, derivedBitangent.x, inNormal.x), vec3(inTangent.y, derivedBitangent.y, inNormal.y), vec3(inTangent.z, derivedBitangent.z, inNormal.z));
    inputs.view = normalize(-vofi_TexCoord4.xyz);
    uint feedback = 0u;
    vec4 sampleLightmap = vec4(0.0);
    vec4 sampleColorMask = vec4(0.0);
    vec4 sampleDiffuse = vec4(0.0);
    vec4 sampleSpecular = vec4(0.0);
    vec4 sampleNormal = vec4(0.0);
    vec4 vmtrSB = vofi_TexCoord5;
    vec2 texCoords = (fract(vofi_TexCoord0.zw) * vmtrSB.xy) + vmtrSB.zw;
    vec2 texCoordsLOD = vofi_TexCoord0.zw * vmtrSB.xy;
    float widthInTexels = freqLow_fragmentUniforms.vmtrfeedbackfloat.z;
    float maxAnisoLog2 = freqHigh_fragmentUniforms.physicalfilterparms.z;
    vec2 texelCoords = texCoordsLOD * widthInTexels;
    vec2 dx = dFdx(texelCoords);
    vec2 dy = dFdy(texelCoords);
    vec2 param = dx;
    vec2 param_1 = dx;
    float px = dot2(param, param_1);
    vec2 param_2 = dy;
    vec2 param_3 = dy;
    float py = dot2(param_2, param_3);
    float maxLod = 0.5 * log2(max(px, py));
    float minLod = 0.5 * log2(min(px, py));
    float anisoLOD = maxLod - min(maxAnisoLog2, maxLod - minLod);
    float sampleLOD = anisoLOD;
    float widthInPages = freqLow_fragmentUniforms.vmtrfeedbackfloat.y;
    float feedbackBias = freqHigh_fragmentUniforms.physicalfilterparms.y;
    uvec2 feedbackPageUV = uvec2(texCoords * widthInPages);
    uint feedbackLOD = uint(min(freqHigh_fragmentUniforms.physicalfilterparms.w, max(0.0, anisoLOD) + feedbackBias));
    uint feedbackPageSource = uint(freqLow_fragmentUniforms.vmtrfeedbackfloat.x);
    feedback = feedbackPageUV.x & 255u;
    feedback |= ((feedbackPageUV.y & 255u) << uint(8));
    feedback |= ((feedbackPageUV.x >> uint(8)) << uint(16));
    feedback |= ((feedbackPageUV.y >> uint(8)) << uint(24));
    feedback |= (feedbackLOD << uint(19));
    feedback |= (feedbackPageSource << uint(27));
    vec3 physCoords;
    if (freqLow_fragmentUniforms.virtualtextureoptions.y != 0.0)
    {
        float trilinearFraction = fract(sampleLOD);
        float triStart = 0.375;
        float triEnd = 0.625;
        bool twoSamples;
        float sampleLOD1;
        float sampleLOD2;
        if (trilinearFraction <= triStart)
        {
            twoSamples = false;
            sampleLOD1 = sampleLOD - 0.5;
            sampleLOD2 = 0.0;
        }
        else
        {
            if (trilinearFraction >= triEnd)
            {
                twoSamples = false;
                sampleLOD1 = sampleLOD + 0.5;
                sampleLOD2 = 0.0;
            }
            else
            {
                twoSamples = true;
                sampleLOD1 = sampleLOD - 0.5;
                sampleLOD2 = sampleLOD + 0.5;
            }
        }
        vec4 virtCoordsLod = vec4(texCoords.x, texCoords.y, 0.0, sampleLOD1);
        vec4 param_4 = virtCoordsLod;
        vec2 physPage = tex2Dlod(samp_vmtrpagetablemap, param_4).xy;
        vec2 param_5 = physPage;
        vec4 xform = tex2D(samp_vmtrphysicalmappingsmap, param_5);
        physCoords.x = (texCoords.x * xform.x) + xform.z;
        physCoords.y = (texCoords.y * (xform.x * freqLow_fragmentUniforms.vmtrphysicalpagesaspectratio.x)) + xform.w;
        physCoords.z = xform.y;
        vec2 dx_1 = dFdx(texCoordsLOD) * physCoords.z;
        vec2 dy_1 = dFdy(texCoordsLOD) * physCoords.z;
        float param_6 = 0.0;
        vec2 param_7 = physCoords.xy;
        vec2 param_8 = dx_1;
        vec2 param_9 = dy_1;
        sampleDiffuse = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_6, param_7, param_8, param_9);
        float param_10 = 1.0;
        vec2 param_11 = physCoords.xy;
        vec2 param_12 = dx_1;
        vec2 param_13 = dy_1;
        sampleSpecular = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_10, param_11, param_12, param_13);
        float param_14 = 2.0;
        vec2 param_15 = physCoords.xy;
        vec2 param_16 = dx_1;
        vec2 param_17 = dy_1;
        sampleLightmap = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_14, param_15, param_16, param_17);
        vec2 param_18 = physCoords.xy;
        vec2 param_19 = dx_1;
        vec2 param_20 = dy_1;
        sampleColorMask = texPhys(samp_vmtrphysicalpagesmap3, param_18, param_19, param_20);
        sampleNormal = vec4(0.0);
        float cover = sampleLightmap.z;
        float param_21 = sampleLightmap.w;
        float power = DeGamma(param_21);
        sampleNormal.y = sampleSpecular.w;
        sampleNormal.w = sampleDiffuse.w;
        sampleSpecular.w = cover;
        sampleLightmap.w = power;
        if (twoSamples)
        {
            vec4 virtCoordsLod_1 = vec4(texCoords.x, texCoords.y, 0.0, sampleLOD2);
            vec4 param_22 = virtCoordsLod_1;
            vec2 physPage_1 = tex2Dlod(samp_vmtrpagetablemap, param_22).xy;
            vec2 param_23 = physPage_1;
            vec4 xform_1 = tex2D(samp_vmtrphysicalmappingsmap, param_23);
            physCoords.x = (texCoords.x * xform_1.x) + xform_1.z;
            physCoords.y = (texCoords.y * (xform_1.x * freqLow_fragmentUniforms.vmtrphysicalpagesaspectratio.x)) + xform_1.w;
            physCoords.z = xform_1.y;
            vec2 dx_2 = dFdx(texCoordsLOD) * physCoords.z;
            vec2 dy_2 = dFdy(texCoordsLOD) * physCoords.z;
            float param_24 = 0.0;
            vec2 param_25 = physCoords.xy;
            vec2 param_26 = dx_2;
            vec2 param_27 = dy_2;
            vec4 sampleDiffuse2 = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_24, param_25, param_26, param_27);
            float param_28 = 1.0;
            vec2 param_29 = physCoords.xy;
            vec2 param_30 = dx_2;
            vec2 param_31 = dy_2;
            vec4 sampleSpecular2 = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_28, param_29, param_30, param_31);
            float param_32 = 2.0;
            vec2 param_33 = physCoords.xy;
            vec2 param_34 = dx_2;
            vec2 param_35 = dy_2;
            vec4 sampleLightmap2 = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_32, param_33, param_34, param_35);
            vec2 param_36 = physCoords.xy;
            vec2 param_37 = dx_2;
            vec2 param_38 = dy_2;
            vec4 sampleColorMask2 = texPhys(samp_vmtrphysicalpagesmap3, param_36, param_37, param_38);
            vec4 samplePower2 = vec4(0.0);
            float cover_1 = sampleLightmap2.z;
            float param_39 = sampleLightmap2.w;
            float power_1 = DeGamma(param_39);
            samplePower2.y = sampleSpecular2.w;
            samplePower2.w = sampleDiffuse2.w;
            sampleSpecular2.w = cover_1;
            sampleLightmap2.w = power_1;
            float lerpFactor = 0.0;
            float triStart_1 = 0.375;
            float param_40 = (trilinearFraction - triStart_1) * 4.0;
            lerpFactor = saturate(param_40);
            sampleSpecular = mix(sampleSpecular, sampleSpecular2, vec4(lerpFactor));
            sampleDiffuse = mix(sampleDiffuse, sampleDiffuse2, vec4(lerpFactor));
            sampleNormal = mix(sampleNormal, samplePower2, vec4(lerpFactor));
            sampleLightmap = mix(sampleLightmap, sampleLightmap2, vec4(lerpFactor));
            sampleColorMask = mix(sampleColorMask, sampleColorMask2, vec4(lerpFactor));
        }
    }
    else
    {
        vec4 virtCoordsLod_2 = vec4(texCoords.x, texCoords.y, 0.0, sampleLOD - 0.5);
        vec4 param_41 = virtCoordsLod_2;
        vec2 physPage_2 = tex2Dlod(samp_vmtrpagetablemap, param_41).xy;
        vec2 param_42 = physPage_2;
        vec4 xform_2 = tex2D(samp_vmtrphysicalmappingsmap, param_42);
        physCoords.x = (texCoords.x * xform_2.x) + xform_2.z;
        physCoords.y = (texCoords.y * (xform_2.x * freqLow_fragmentUniforms.vmtrphysicalpagesaspectratio.x)) + xform_2.w;
        physCoords.z = xform_2.y;
        vec2 dx_3 = dFdx(texCoordsLOD) * physCoords.z;
        vec2 dy_3 = dFdy(texCoordsLOD) * physCoords.z;
        float param_43 = 0.0;
        vec2 param_44 = physCoords.xy;
        vec2 param_45 = dx_3;
        vec2 param_46 = dy_3;
        sampleDiffuse = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_43, param_44, param_45, param_46);
        float param_47 = 1.0;
        vec2 param_48 = physCoords.xy;
        vec2 param_49 = dx_3;
        vec2 param_50 = dy_3;
        sampleSpecular = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_47, param_48, param_49, param_50);
        float param_51 = 2.0;
        vec2 param_52 = physCoords.xy;
        vec2 param_53 = dx_3;
        vec2 param_54 = dy_3;
        sampleLightmap = texPhysArray(samp_vmtrphysicalpagesmaparray0, param_51, param_52, param_53, param_54);
        vec2 param_55 = physCoords.xy;
        vec2 param_56 = dx_3;
        vec2 param_57 = dy_3;
        sampleColorMask = texPhys(samp_vmtrphysicalpagesmap3, param_55, param_56, param_57);
        sampleNormal = vec4(0.0);
        float cover_2 = sampleLightmap.z;
        float param_58 = sampleLightmap.w;
        float power_2 = DeGamma(param_58);
        sampleNormal.y = sampleSpecular.w;
        sampleNormal.w = sampleDiffuse.w;
        sampleSpecular.w = cover_2;
        sampleLightmap.w = power_2;
    }
    vec3 fragmentColor = vec3(vofi_TexCoord3.zw, vofi_TexCoord1.w);
    inputs.emissive = vec3(sampleLightmap.x * sampleLightmap.x) * fragmentColor;
    uint feedback2 = 0u;
    float widthInTexels_1 = freqHigh_fragmentUniforms.virtualtexturefeedbackfloat.z;
    float maxAnisoLog2_1 = freqHigh_fragmentUniforms.physicalfilterparms.z;
    vec2 texelCoords_1 = inputs.texCoords.xy * widthInTexels_1;
    vec2 dx_4 = dFdx(texelCoords_1);
    vec2 dy_4 = dFdy(texelCoords_1);
    vec2 param_59 = dx_4;
    vec2 param_60 = dx_4;
    float px_1 = dot2(param_59, param_60);
    vec2 param_61 = dy_4;
    vec2 param_62 = dy_4;
    float py_1 = dot2(param_61, param_62);
    float maxLod_1 = 0.5 * log2(max(px_1, py_1));
    float minLod_1 = 0.5 * log2(min(px_1, py_1));
    float anisoLOD_1 = maxLod_1 - min(maxAnisoLog2_1, maxLod_1 - minLod_1);
    float sampleLOD_1 = anisoLOD_1;
    float widthInPages_1 = freqHigh_fragmentUniforms.virtualtexturefeedbackfloat.y;
    float feedbackBias_1 = freqHigh_fragmentUniforms.physicalfilterparms.y;
    uvec2 feedbackPageUV_1 = uvec2(inputs.texCoords.xy * widthInPages_1);
    uint feedbackLOD_1 = uint(min(freqHigh_fragmentUniforms.physicalfilterparms.w, max(0.0, anisoLOD_1) + feedbackBias_1));
    uint feedbackPageSource_1 = uint(freqHigh_fragmentUniforms.virtualtexturefeedbackfloat.x);
    feedback2 = feedbackPageUV_1.x & 255u;
    feedback2 |= ((feedbackPageUV_1.y & 255u) << uint(8));
    feedback2 |= ((feedbackPageUV_1.x >> uint(8)) << uint(16));
    feedback2 |= ((feedbackPageUV_1.y >> uint(8)) << uint(24));
    feedback2 |= (feedbackLOD_1 << uint(19));
    feedback2 |= (feedbackPageSource_1 << uint(27));
    vec3 physCoords_1;
    if (freqLow_fragmentUniforms.virtualtextureoptions.y != 0.0)
    {
        float trilinearFraction_1 = fract(sampleLOD_1);
        float triStart_2 = 0.375;
        float triEnd_1 = 0.625;
        bool twoSamples_1;
        float sampleLOD1_1;
        float sampleLOD2_1;
        if (trilinearFraction_1 <= triStart_2)
        {
            twoSamples_1 = false;
            sampleLOD1_1 = sampleLOD_1 - 0.5;
            sampleLOD2_1 = 0.0;
        }
        else
        {
            if (trilinearFraction_1 >= triEnd_1)
            {
                twoSamples_1 = false;
                sampleLOD1_1 = sampleLOD_1 + 0.5;
                sampleLOD2_1 = 0.0;
            }
            else
            {
                twoSamples_1 = true;
                sampleLOD1_1 = sampleLOD_1 - 0.5;
                sampleLOD2_1 = sampleLOD_1 + 0.5;
            }
        }
        vec4 virtCoordsLod_3 = vec4(inputs.texCoords.x, inputs.texCoords.y, 0.0, sampleLOD1_1);
        vec4 param_63 = virtCoordsLod_3;
        vec2 physPage_3 = tex2Dlod(samp_pagetablemap, param_63).xy;
        vec2 param_64 = physPage_3;
        vec4 xform_3 = tex2D(samp_physicalmappingsmap, param_64);
        physCoords_1.x = (inputs.texCoords.x * xform_3.x) + xform_3.z;
        physCoords_1.y = (inputs.texCoords.y * (xform_3.x * freqLow_fragmentUniforms.physicalpagesaspectratio.x)) + xform_3.w;
        physCoords_1.z = xform_3.y;
        vec2 dx_5 = dFdx(inputs.texCoords.xy) * physCoords_1.z;
        vec2 dy_5 = dFdy(inputs.texCoords.xy) * physCoords_1.z;
        vec2 param_65 = physCoords_1.xy;
        vec2 param_66 = dx_5;
        vec2 param_67 = dy_5;
        vec3 _1840 = texPhys(samp_physicalpagesmap4, param_65, param_66, param_67).xyz;
        sampleLightmap = vec4(_1840.x, _1840.y, _1840.z, sampleLightmap.w);
        if (twoSamples_1)
        {
            vec4 virtCoordsLod_4 = vec4(inputs.texCoords.x, inputs.texCoords.y, 0.0, sampleLOD2_1);
            vec4 param_68 = virtCoordsLod_4;
            vec2 physPage_4 = tex2Dlod(samp_pagetablemap, param_68).xy;
            vec2 param_69 = physPage_4;
            vec4 xform_4 = tex2D(samp_physicalmappingsmap, param_69);
            physCoords_1.x = (inputs.texCoords.x * xform_4.x) + xform_4.z;
            physCoords_1.y = (inputs.texCoords.y * (xform_4.x * freqLow_fragmentUniforms.physicalpagesaspectratio.x)) + xform_4.w;
            physCoords_1.z = xform_4.y;
            vec2 dx_6 = dFdx(inputs.texCoords.xy) * physCoords_1.z;
            vec2 dy_6 = dFdy(inputs.texCoords.xy) * physCoords_1.z;
            vec2 param_70 = physCoords_1.xy;
            vec2 param_71 = dx_6;
            vec2 param_72 = dy_6;
            vec3 _1911 = texPhys(samp_physicalpagesmap4, param_70, param_71, param_72).xyz;
            vec4 sampleLightmap2_1;
            sampleLightmap2_1 = vec4(_1911.x, _1911.y, _1911.z, sampleLightmap2_1.w);
            float lerpFactor_1 = 0.0;
            float triStart_3 = 0.375;
            float param_73 = (trilinearFraction_1 - triStart_3) * 4.0;
            lerpFactor_1 = saturate(param_73);
            vec3 _1928 = mix(sampleLightmap.xyz, sampleLightmap2_1.xyz, vec3(lerpFactor_1));
            sampleLightmap2_1 = vec4(_1928.x, _1928.y, _1928.z, sampleLightmap2_1.w);
        }
    }
    else
    {
        vec4 virtCoordsLod_5 = vec4(inputs.texCoords.x, inputs.texCoords.y, 0.0, sampleLOD_1 - 0.5);
        vec4 param_74 = virtCoordsLod_5;
        vec2 physPage_5 = tex2Dlod(samp_pagetablemap, param_74).xy;
        vec2 param_75 = physPage_5;
        vec4 xform_5 = tex2D(samp_physicalmappingsmap, param_75);
        physCoords_1.x = (inputs.texCoords.x * xform_5.x) + xform_5.z;
        physCoords_1.y = (inputs.texCoords.y * (xform_5.x * freqLow_fragmentUniforms.physicalpagesaspectratio.x)) + xform_5.w;
        physCoords_1.z = xform_5.y;
        vec2 dx_7 = dFdx(inputs.texCoords.xy) * physCoords_1.z;
        vec2 dy_7 = dFdy(inputs.texCoords.xy) * physCoords_1.z;
        vec2 param_76 = physCoords_1.xy;
        vec2 param_77 = dx_7;
        vec2 param_78 = dy_7;
        vec3 _1997 = texPhys(samp_physicalpagesmap4, param_76, param_77, param_78).xyz;
        sampleLightmap = vec4(_1997.x, _1997.y, _1997.z, sampleLightmap.w);
    }
    bool _2001;
    if (mod(inputs.fragCoord.y, freqLow_fragmentUniforms.vmtrlightmapfeedback.z) > freqLow_fragmentUniforms.vmtrlightmapfeedback.w)
    {
        _2001 = freqLow_fragmentUniforms.vmtrlightmapfeedback.x != 0.0;
    }
    else
    {
        _2001 = freqLow_fragmentUniforms.vmtrlightmapfeedback.y != 0.0;
    }
    bool feedbackSource = _2001;
    vec2 TEXTURE_RESOLUTION = vec2(160.0, 120.0);
    vec2 FRAMEBUFFER_PIXEL_SIZE = TEXTURE_RESOLUTION * freqHigh_fragmentUniforms.positiontoviewtexture.zw;
    vec2 param_79 = gl_FragCoord.xy;
    vec4 param_80 = freqHigh_fragmentUniforms.positiontoviewtexture;
    vec2 tc = screenPosToTexcoord(param_79, param_80) * TEXTURE_RESOLUTION;
	float offsetMultiplier = floor(mod(tc.x + 0.25, 4.0));
    float xOffset = offsetMultiplier * FRAMEBUFFER_PIXEL_SIZE.x;
    bool _2059 = fract(tc.x - xOffset) < FRAMEBUFFER_PIXEL_SIZE.x;
    bool _2068;
    if (_2059)
    {
        _2068 = fract(tc.y) < FRAMEBUFFER_PIXEL_SIZE.y;
    }
    else
    {
        _2068 = _2059;
    }
    if (_2068)
    {
        uint _2078;
        if (feedbackSource)
        {
            _2078 = feedback2;
        }
        else
        {
            _2078 = feedback;
        }
        uint param_81 = _2078;
        imageStore(ib_feedbackbuffer, ivec2(tc), vec4(asfloat(param_81), 0.0, 0.0, 0.0));
    }
    uint _2089;
    if (feedbackSource)
    {
        _2089 = feedback;
    }
    else
    {
        _2089 = feedback2;
    }
    feedback = _2089;
    inputs.albedo = sampleDiffuse.xyz;
    inputs.specular = sampleSpecular.xyz;
    inputs.colorMask = sampleColorMask.xyz;
    inputs.lightmap = sampleLightmap.xyz;
    inputs.smoothness = sampleLightmap.w;
    inputs.normal = sampleNormal.wyz;
    int _2118;
    if (freqHigh_fragmentUniforms.staticmodel.x > 0.0)
    {
        _2118 = 8;
    }
    else
    {
        _2118 = 0;
    }
    uint skipStaticModel = uint(_2118);
    float NUM_CLUSTERS_X = 16.0;
    float NUM_CLUSTERS_Y = 8.0;
    float NUM_CLUSTERS_Z = 24.0;
    vec2 param_82 = inputs.fragCoord.xy;
    vec4 param_83 = freqHigh_fragmentUniforms.positiontoviewtexture;
//    param_83.x -= vk3d_params.stereo.x * 0.5;
    vec2 _2145 = screenPosToTexcoord(param_82, param_83) * freqLow_fragmentUniforms.resolutionscale.zw;

    // FIX FOR DECALS CLIPPING
    //_2145.x -= vk3d_params.stereo.x * 0.5;
    

    vec3 clusterCoordinate;
    clusterCoordinate = vec3(_2145.x, _2145.y, clusterCoordinate.z);
    clusterCoordinate.y = 1.0 - clusterCoordinate.y;
    clusterCoordinate.x -= vk3d_params.stereo.x * 0.5;
    
    
    vec2 _2158 = floor(clusterCoordinate.xy * vec2(NUM_CLUSTERS_X, NUM_CLUSTERS_Y));
    clusterCoordinate = vec3(_2158.x, _2158.y, clusterCoordinate.z);
    float param_84 = inputs.fragCoord.z;
    vec4 param_85 = freqLow_fragmentUniforms.projectionmatrixz;
    float param_86 = 1.0;
    bool param_87 = false;
    float curr_z = GetLinearDepth(param_84, param_85, param_86, param_87);
    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));
    //clusterCoordinate.x -= vk3d_params.stereo.x * 0.5;
    
    uint clusterOffset = uint((clusterCoordinate.x + (clusterCoordinate.y * NUM_CLUSTERS_X)) + ((clusterCoordinate.z * NUM_CLUSTERS_X) * NUM_CLUSTERS_Y));
    vec3 param_88 = inputs.albedo;
    uint _2208 = packR10G10B10(param_88);
    inputs.albedo_packed = _2208;
    vec3 param_89 = inputs.specular;
    uint _2214 = packR10G10B10(param_89);
    inputs.specular_packed = _2214;
    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 = _2231.clusternumlights[clusterOffset].offset;
    cluster.numItems = _2231.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);
    bool isFrontFacing = true;
    vec3 param_90 = inputs.normal;
    bool param_91 = isFrontFacing;
    inputs.normalTS = ReconstructNormal(param_90, param_91);
    vec3 param_92 = inputs.normal;
    mat3 param_93 = inputs.invTS;
    bool param_94 = isFrontFacing;
    inputs.normal = GetWorldSpaceNormal(param_92, param_93, param_94);

    vec3 posDDX = dFdx(inputs.position);
    vec3 posDDY = dFdy(inputs.position);
    bool _2310 = skipStaticModel == 0u;
    bool _2316;
    if (_2310)
    {
        _2316 = freqHigh_fragmentUniforms.staticmodel.y == 0.0;
    }
    else
    {
        _2316 = _2310;
    }
    uint _2308;
    if (_2316)
    {
        _2308 = decalsMax;
    }
    else
    {
        _2308 = decalsMin;
    }
    decalsMin = _2308;
    uint d = decalsMin;
    decal_t decal;
    vec3 _2728;
    while (d < decalsMax)
    {
        uint temp = _2337.clusterlightsid[d];
        uint divergentId = (temp >> uint(12)) & 4095u;
        uint decal_id = divergentId;
        if (decal_id >= divergentId)
        {
            d++;
        }
        int decalParms1Size = 2;
        int decalParms2Size = 2;
        int decalParms3Size = 2;
        decal.projS = _2367.decalparms1[(uint(decalParms1Size) * decal_id) + 0u];
        decal.projT = _2367.decalparms1[(uint(decalParms1Size) * decal_id) + 1u];
        decal.projR = _2387.decalparms2[(uint(decalParms2Size) * decal_id) + 0u];
        float param_95 = _2387.decalparms2[(uint(decalParms2Size) * decal_id) + 1u].x;
        decal.albedoScaleBias.x = asuint(param_95);
        float param_96 = _2387.decalparms2[(uint(decalParms2Size) * decal_id) + 1u].y;
        decal.albedoScaleBias.y = asuint(param_96);
        float param_97 = _2387.decalparms2[(uint(decalParms2Size) * decal_id) + 1u].z;
        decal.specScaleBias.x = asuint(param_97);
        float param_98 = _2387.decalparms2[(uint(decalParms2Size) * decal_id) + 1u].w;
        decal.specScaleBias.y = asuint(param_98);
        float param_99 = _2439.decalparms3[(uint(decalParms3Size) * decal_id) + 0u].x;
        decal.normalScaleBias.x = asuint(param_99);
        float param_100 = _2439.decalparms3[(uint(decalParms3Size) * decal_id) + 0u].y;
        decal.normalScaleBias.y = asuint(param_100);
        float param_101 = _2439.decalparms3[(uint(decalParms3Size) * decal_id) + 0u].z;
        decal.opacity = asuint(param_101);
        float param_102 = _2439.decalparms3[(uint(decalParms3Size) * decal_id) + 0u].w;
        decal.decalParms = asuint(param_102);
        float param_103 = _2439.decalparms3[(uint(decalParms3Size) * decal_id) + 1u].x;
        decal.albedo = asuint(param_103);
        float param_104 = _2439.decalparms3[(uint(decalParms3Size) * decal_id) + 1u].y;
        decal.emissive = asuint(param_104);
        float param_105 = _2439.decalparms3[(uint(decalParms3Size) * decal_id) + 1u].z;
        decal.specOverride = asuint(param_105);
        float param_106 = _2439.decalparms3[(uint(decalParms3Size) * decal_id) + 1u].w;
        decal.decalParms2 = asuint(param_106);
        vec4 projS = decal.projS;
        vec4 projR = decal.projR;
        vec4 projT = decal.projT;
        vec3 projTC = vec3((inputs.position.x * projS.x) + ((inputs.position.y * projS.y) + ((inputs.position.z * projS.z) + projS.w)), (inputs.position.x * projT.x) + ((inputs.position.y * projT.y) + ((inputs.position.z * projT.z) + projT.w)), (inputs.position.x * projR.x) + ((inputs.position.y * projR.y) + ((inputs.position.z * projR.z) + projR.w)));
        float clip_min = 0.0039215688593685626983642578125;
        float param_107 = projTC.x;
        float param_108 = projTC.y;
        float param_109 = projTC.z;
        bool _2605 = fmin3(param_107, param_108, param_109) <= clip_min;
        bool _2622;
        if (!_2605)
        {
            float param_110 = projTC.x;
            float param_111 = projTC.y;
            float param_112 = projTC.z;
            _2622 = fmax3(param_110, param_111, param_112) >= (1.0 - clip_min);
        }
        else
        {
            _2622 = _2605;
        }
        if (_2622)
        {
            continue;
        }
        uint decalParms2 = decal.decalParms2;
        bool _2630 = skipStaticModel != 0u;
        bool _2637;
        if (_2630)
        {
            _2637 = (decalParms2 & 512u) != 0u;
        }
        else
        {
            _2637 = _2630;
        }
        bool _2650;
        if (!_2637)
        {
            bool _2642 = skipStaticModel == 0u;
            bool _2649;
            if (_2642)
            {
                _2649 = (decalParms2 & 1024u) != 0u;
            }
            else
            {
                _2649 = _2642;
            }
            _2650 = _2649;
        }
        else
        {
            _2650 = _2637;
        }
        if (_2650)
        {
            continue;
        }
        vec2 uvDDX = vec2(dot(posDDX, projS.xyz), dot(posDDX, projT.xyz));
        vec2 uvDDY = vec2(dot(posDDY, projS.xyz), dot(posDDY, projT.xyz));
        float decalAlpha = 1.0;
        vec3 decalNormal = vec3(0.5, 0.5, 1.0);
        vec3 decalNormalTS = vec3(0.0, 0.0, 1.0);
        uint decalParms = decal.decalParms;
        uvec2 param_113 = decal.normalScaleBias;
        vec4 normalScaleBias = unpackR15G15B15A15(param_113);
        vec2 normalUVDDX = uvDDX * normalScaleBias.xy;
        vec2 normalUVDDY = uvDDY * normalScaleBias.xy;
        vec2 param_114 = (projTC.xy * normalScaleBias.xy) + normalScaleBias.zw;
        vec2 param_115 = normalUVDDX;
        vec2 param_116 = normalUVDDY;
        vec4 temp_1 = texPhys(samp_decalsatlasmap, param_114, param_115, param_116);
        decalNormal = temp_1.xyz;
        decalAlpha = temp_1.w;
        decalNormalTS = (decalNormal * 2.0) - vec3(1.0);
        if (decalAlpha <= (4.0 * clip_min))
        {
            continue;
        }
        decalNormal = decalNormalTS;
        if ((decalParms2 & 128u) != 0u)
        {
            _2728 = vec3(-decalNormal.x, -decalNormal.y, decalNormal.z);
        }
        else
        {
            _2728 = decalNormal;
        }
        decalNormal = _2728;
        uint packed_albedo = decal.albedo;
        uint param_117 = packed_albedo;
        float z_soft_scale = 1.0 + (unpackUintR8G8B8A8(param_117).w * 0.062745101749897003173828125);
        uint param_118 = decalParms;
        float emissive_blending_time = unpackR8G8B8A8(param_118).z;
        uint param_119 = packed_albedo;
        vec3 decalAlbedo = unpackR8G8B8A8(param_119).xyz;
        float param_120 = z_soft_scale - (z_soft_scale * abs((projTC.z * 2.0) - 1.0));
        decalAlpha *= saturate(param_120);
        float emissiveMask = decalAlpha;
        if ((decalParms & 1u) != 0u)
        {
            vec3 albedoTint = decalAlbedo;
            decalAlbedo = vec3(0.0);
            uvec2 param_121 = decal.albedoScaleBias;
            vec4 albedoScaleBias = unpackR15G15B15A15(param_121);
            vec2 albedoUVDDX = uvDDX * albedoScaleBias.xy;
            vec2 albedoUVDDY = uvDDY * albedoScaleBias.xy;
            vec2 param_122 = (projTC.xy * albedoScaleBias.xy) + albedoScaleBias.zw;
            vec2 param_123 = albedoUVDDX;
            vec2 param_124 = albedoUVDDY;
            vec4 temp_2 = texPhys(samp_decalsatlasmap, param_122, param_123, param_124);
            temp_2 *= temp_2;
            decalAlbedo = temp_2.xyz;
            emissiveMask = temp_2.w;
            decalAlbedo *= albedoTint;
        }
        vec3 vertexNormal = normalize(vec3(inputs.invTS[0].z, inputs.invTS[1].z, inputs.invTS[2].z));
        float param_125 = dot(vertexNormal, normalize(projR.xyz));
        float angleWeight = saturate(param_125);
        uint packed_emissive = decal.emissive;
        uint param_126 = packed_emissive;
        vec4 emissive_parms = unpackR8G8B8A8(param_126);
        inputs.emissive += ((decalAlbedo * angleWeight) * ((emissive_parms.xyz * ((emissiveMask * emissive_parms.w) * 16.0)) * emissive_blending_time));
        uint specOverride = decal.specOverride;
        uint param_127 = specOverride;
        vec4 decalSpecular = unpackR8G8B8A8(param_127);
        if ((decalParms & 2u) != 0u)
        {
            uvec2 param_128 = decal.specScaleBias;
            vec4 specScaleBias = unpackR15G15B15A15(param_128);
            vec2 specUVDDX = uvDDX * specScaleBias.xy;
            vec2 specUVDDY = uvDDY * specScaleBias.xy;
            vec2 param_129 = (projTC.xy * specScaleBias.xy) + specScaleBias.zw;
            vec2 param_130 = specUVDDX;
            vec2 param_131 = specUVDDY;
            decalSpecular = texPhys(samp_decalsatlasmap, param_129, param_130, param_131);
            decalSpecular *= decalSpecular;
        }
        if ((decalParms & 32u) != 0u)
        {
            uint param_132 = decalParms;
            float blending_time = unpackR8G8B8A8(param_132).x;
            uint param_133 = decalParms;
            float threshold_softness = unpackUintR8G8B8A8(param_133).y;
            float param_134 = dot((projTC.xy + decalNormalTS.xy) - vec2(0.5), (projTC.xy + decalNormalTS.xy) - vec2(0.5));
            float center_attenuation = saturate(param_134);
            float param_135 = threshold_softness * (blending_time - center_attenuation);
            float param_136 = saturate(param_135);
            float threshold_alpha = fastSqrtNR0(param_136);
            decalAlpha = min(decalAlpha, threshold_alpha);
        }
        float alpha_mask = decalAlpha * angleWeight;
        uint packed_opacity = decal.opacity;
        uint param_137 = packed_opacity;
        vec4 opacity = unpackR8G8B8A8(param_137) * alpha_mask;
        inputs.alpha = max(inputs.alpha, opacity.x);
        uint param_138 = inputs.albedo_packed;
        vec3 param_139 = mix(unpackR10G10B10(param_138), decalAlbedo, opacity.xxx);
        uint _2991 = packR10G10B10(param_139);
        inputs.albedo_packed = _2991;
        uint param_140 = inputs.specular_packed;
        vec3 param_141 = mix(unpackR10G10B10(param_140), decalSpecular.xyz, opacity.yyy);
        uint _3003 = packR10G10B10(param_141);
        inputs.specular_packed = _3003;
        vec3 projNormal = vertexNormal;
        vec3 _3015 = projS.xyz + (projNormal * dot(projS.xyz, projNormal));
        projS = vec4(_3015.x, _3015.y, _3015.z, projS.w);
        vec3 _3026 = projT.xyz + (projNormal * dot(projT.xyz, projNormal));
        projT = vec4(_3026.x, _3026.y, _3026.z, projT.w);
        decalNormal = ((normalize(projS.xyz) * decalNormal.x) + (normalize(projT.xyz) * decalNormal.y)) + (projNormal * decalNormal.z);
        if ((decalParms2 & 256u) != 0u)
        {
            vec3 decalBlend = mix(vertexNormal, decalNormal, opacity.www);
            float normalProj = dot(decalBlend, vertexNormal);
            decalNormal = (inputs.normal * normalProj) + ((decalBlend - (vertexNormal * normalProj)) * dot(inputs.normal, vertexNormal));
        }
        else
        {
            if ((decalParms2 & 64u) != 0u)
            {
                decalNormal = mix(mix(inputs.normal, vertexNormal, vec3(alpha_mask)), decalNormal, opacity.www);
            }
            else
            {
                decalNormal = mix(inputs.normal, decalNormal, opacity.www);
            }
        }
        inputs.normal = normalize(decalNormal);
        float param_142 = length(decalNormal);
        float Na = saturate(param_142);
        if (Na < 1.0)
        {
            float roughness = 1.0 - decalSpecular.w;
            float Na2 = Na * Na;
            float k = ((3.0 * Na) - (Na * Na2)) / (1.0 - Na2);
            float variance = 1.0 / (2.0 * k);
            float param_143 = (roughness * roughness) + variance;
            decalSpecular.w = 1.0 - fastSqrtNR0(param_143);
        }
        inputs.smoothness = mix(inputs.smoothness, decalSpecular.w, opacity.z);
    }
    vec3 ambient = vec3(0.0);
    ambient = (inputs.lightmap * freqLow_fragmentUniforms.lightmapscale.xyz) * freqLow_fragmentUniforms.envlightmapscale.x;
    ambient += inputs.emissive;
    float _3168;
    if (dot(inputs.emissive, vec3(1.0)) > 0.0)
    {
        _3168 = -inputs.smoothness;
    }
    else
    {
        _3168 = inputs.smoothness;
    }
    inputs.smoothness = _3168;
    vec3 param_144 = ambient;
    ambient = mix(vec3(GetLuma(param_144)), ambient, freqLow_fragmentUniforms.pbrdebugparms.www);
    inputs.ambient_lighting = ambient;
    vec3 param_145 = ambient;
    inputs.diffuse_lighting_packed = packRGBE(param_145);
    uint lightIdx = lightsMin;
    light_t lightParms;
    shadowparms_t shadow_parms;
    shadowparms_t shadow_parms_1;
    shadowparms_t shadow_parms_2;
    int _3950;
    shadowparms_t shadow_parms_3;
    float _4440;
    float _4584;
    vec3 _4694;
    while (lightIdx < lightsMax)
    {
        uint temp_3 = _2337.clusterlightsid[lightIdx];
        uint divergentLightId = temp_3 & 4095u;
        uint light_id = divergentLightId;
        if (light_id >= divergentLightId)
        {
            lightIdx++;
        }
        int lightParms1Size = 4;
        int lightParms2Size = 4;
        int lightParms3Size = 3;
        lightParms.pos = _3234.lightparms1[(uint(lightParms1Size) * light_id) + 0u].xyz;
        float param_146 = _3234.lightparms1[(uint(lightParms1Size) * light_id) + 0u].w;
        lightParms.lightParms = asuint(param_146);
        lightParms.posShadow = _3234.lightparms1[(uint(lightParms1Size) * light_id) + 1u];
        lightParms.falloffR = _3234.lightparms1[(uint(lightParms1Size) * light_id) + 2u];
        lightParms.projS = _3273.lightparms2[(uint(lightParms2Size) * light_id) + 0u];
        lightParms.projT = _3273.lightparms2[(uint(lightParms2Size) * light_id) + 1u];
        lightParms.projQ = _3273.lightparms2[(uint(lightParms2Size) * light_id) + 2u];
        float param_147 = _3234.lightparms1[(uint(lightParms1Size) * light_id) + 3u].x;
        lightParms.scaleBias.x = asuint(param_147);
        float param_148 = _3234.lightparms1[(uint(lightParms1Size) * light_id) + 3u].y;
        lightParms.scaleBias.y = asuint(param_148);
        float param_149 = _3234.lightparms1[(uint(lightParms1Size) * light_id) + 3u].z;
        lightParms.scaleBias.z = asuint(param_149);
        float param_150 = _3234.lightparms1[(uint(lightParms1Size) * light_id) + 3u].w;
        lightParms.scaleBias.w = asuint(param_150);
        lightParms.boxMin = _3341.lightparms3[(uint(lightParms3Size) * light_id) + 0u];
        lightParms.boxMax = _3341.lightparms3[(uint(lightParms3Size) * light_id) + 1u];
        lightParms.areaPlane = _3341.lightparms3[(uint(lightParms3Size) * light_id) + 2u];
        float param_151 = _3273.lightparms2[(uint(lightParms2Size) * light_id) + 3u].x;
        lightParms.lightParms2 = asuint(param_151);
        float param_152 = _3273.lightparms2[(uint(lightParms2Size) * light_id) + 3u].y;
        lightParms.colorPacked = asuint(param_152);
        lightParms.specMultiplier = _3273.lightparms2[(uint(lightParms2Size) * light_id) + 3u].z;
        lightParms.shadowBleedReduce = _3273.lightparms2[(uint(lightParms2Size) * light_id) + 3u].w;
        float clip_min_1 = 0.0039215688593685626983642578125;
        vec3 projTC_1 = 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 _3470 = projTC_1.xy / vec2(projTC_1.z);
        projTC_1 = vec3(_3470.x, _3470.y, projTC_1.z);
        projTC_1.z = (inputs.position.x * lightParms.falloffR.x) + ((inputs.position.y * lightParms.falloffR.y) + ((inputs.position.z * lightParms.falloffR.z) + lightParms.falloffR.w));
        uint light_parms = lightParms.lightParms;
        uint light_flags = skipStaticModel;
        light_flags |= 64u;
        float param_153 = projTC_1.x;
        float param_154 = projTC_1.y;
        float param_155 = projTC_1.z;
        bool _3512 = fmin3(param_153, param_154, param_155) <= clip_min_1;
        bool _3529;
        if (!_3512)
        {
            float param_156 = projTC_1.x;
            float param_157 = projTC_1.y;
            float param_158 = projTC_1.z;
            _3529 = fmax3(param_156, param_157, param_158) >= (1.0 - clip_min_1);
        }
        else
        {
            _3529 = _3512;
        }
        bool _3537;
        if (!_3529)
        {
            _3537 = (light_parms & light_flags) != 0u;
        }
        else
        {
            _3537 = _3529;
        }
        if (_3537)
        {
            continue;
        }
        vec3 light_position = lightParms.pos;
        vec3 light_vector = light_position - inputs.position;
        float param_159 = dot(inputs.normal, light_vector);
        float NdotL = saturate(param_159);
        bool _3558 = NdotL <= clip_min_1;
        bool _3565;
        if (_3558)
        {
            _3565 = (light_parms & 48u) == 0u;
        }
        else
        {
            _3565 = _3558;
        }
        if (_3565)
        {
            continue;
        }
        uvec2 param_160 = lightParms.scaleBias.xy;
        vec4 falloffScaleBias = unpackR15G15B15A15(param_160);
        uvec2 param_161 = lightParms.scaleBias.zw;
        vec4 projFilterScaleBias = unpackR15G15B15A15(param_161);
        vec4 param_162 = vec4((projTC_1.xy * projFilterScaleBias.xy) + projFilterScaleBias.zw, 0.0, 0.0);
        float projFilter = tex2Dlod(samp_lightsatlasmap, param_162).x;
        vec4 param_163 = vec4((vec2(projTC_1.z, 0.5) * falloffScaleBias.xy) + falloffScaleBias.zw, 0.0, 0.0);
        float falloff = tex2Dlod(samp_lightsatlasmap, param_163).x;
        float light_attenuation = (falloff * falloff) * (projFilter * projFilter);
        if (light_attenuation <= (clip_min_1 / 256.0))
        {
            continue;
        }
        float shadow = 1.0;
        if ((light_parms & 4u) != 0u)
        {
            float normal_bias_scale = 0.5;
            vec3 pos = inputs.position + (inputs.normal * normal_bias_scale);
            
            pos.x -= 0.02;
            
            uint idx = 0u;
            if ((light_parms & 3u) == 0u)
            {
                vec3 light_dir = pos - lightParms.posShadow.xyz;
                float param_164 = light_dir.x;
                float param_165 = light_dir.y;
                float param_166 = light_dir.z;
                idx = getCubeMapFaceID(param_164, param_165, param_166);
            }
            else
            {
                if ((light_parms & 3u) == 2u)
                {
                    float border = 1.0;
                    int shadowParmSize = 5;
                    shadow_parms.shadowLightS = _3682.shadowsparmsubo[(uint(shadowParmSize) * (light_parms >> uint(22))) + 0u];
                    shadow_parms.shadowLightT = _3682.shadowsparmsubo[(uint(shadowParmSize) * (light_parms >> uint(22))) + 1u];
                    shadow_parms.shadowLightR = _3682.shadowsparmsubo[(uint(shadowParmSize) * (light_parms >> uint(22))) + 2u];
                    shadow_parms.shadowLightQ = _3682.shadowsparmsubo[(uint(shadowParmSize) * (light_parms >> uint(22))) + 3u];
                    shadow_parms.shadowAtlasScaleBias = _3682.shadowsparmsubo[(uint(shadowParmSize) * (light_parms >> uint(22))) + 4u];
                    vec2 shadowTC = vec2(dot(pos, shadow_parms.shadowLightS.xyz) + shadow_parms.shadowLightS.w, dot(pos, shadow_parms.shadowLightT.xyz) + shadow_parms.shadowLightT.w);
                    shadowTC = abs((shadowTC * 2.0) - vec2(1.0));
                    bool _3754 = shadowTC.x >= border;
                    bool _3762;
                    if (!_3754)
                    {
                        _3762 = shadowTC.y >= border;
                    }
                    else
                    {
                        _3762 = _3754;
                    }
                    if (_3762)
                    {
                        idx = 1u;
                        int shadowParmSize_1 = 5;
                        shadow_parms_1.shadowLightS = _3682.shadowsparmsubo[(uint(shadowParmSize_1) * ((light_parms >> uint(22)) + 1u)) + 0u];
                        shadow_parms_1.shadowLightT = _3682.shadowsparmsubo[(uint(shadowParmSize_1) * ((light_parms >> uint(22)) + 1u)) + 1u];
                        shadow_parms_1.shadowLightR = _3682.shadowsparmsubo[(uint(shadowParmSize_1) * ((light_parms >> uint(22)) + 1u)) + 2u];
                        shadow_parms_1.shadowLightQ = _3682.shadowsparmsubo[(uint(shadowParmSize_1) * ((light_parms >> uint(22)) + 1u)) + 3u];
                        shadow_parms_1.shadowAtlasScaleBias = _3682.shadowsparmsubo[(uint(shadowParmSize_1) * ((light_parms >> uint(22)) + 1u)) + 4u];
                        shadowTC = vec2(dot(pos, shadow_parms_1.shadowLightS.xyz) + shadow_parms_1.shadowLightS.w, dot(pos, shadow_parms_1.shadowLightT.xyz) + shadow_parms_1.shadowLightT.w);
                        shadowTC = abs((shadowTC * 2.0) - vec2(1.0));
                        bool _3842 = shadowTC.x >= border;
                        bool _3850;
                        if (!_3842)
                        {
                            _3850 = shadowTC.y >= border;
                        }
                        else
                        {
                            _3850 = _3842;
                        }
                        if (_3850)
                        {
                            idx = 2u;
                            int shadowParmSize_2 = 5;
                            shadow_parms_2.shadowLightS = _3682.shadowsparmsubo[(uint(shadowParmSize_2) * ((light_parms >> uint(22)) + 2u)) + 0u];
                            shadow_parms_2.shadowLightT = _3682.shadowsparmsubo[(uint(shadowParmSize_2) * ((light_parms >> uint(22)) + 2u)) + 1u];
                            shadow_parms_2.shadowLightR = _3682.shadowsparmsubo[(uint(shadowParmSize_2) * ((light_parms >> uint(22)) + 2u)) + 2u];
                            shadow_parms_2.shadowLightQ = _3682.shadowsparmsubo[(uint(shadowParmSize_2) * ((light_parms >> uint(22)) + 2u)) + 3u];
                            shadow_parms_2.shadowAtlasScaleBias = _3682.shadowsparmsubo[(uint(shadowParmSize_2) * ((light_parms >> uint(22)) + 2u)) + 4u];
                            shadowTC = vec2(dot(pos, shadow_parms_2.shadowLightS.xyz) + shadow_parms_2.shadowLightS.w, dot(pos, shadow_parms_2.shadowLightT.xyz) + shadow_parms_2.shadowLightT.w);
                            shadowTC = abs((shadowTC * 2.0) - vec2(1.0));
                        }
                    }
                    float fraction = (1.0 - max(shadowTC.x, shadowTC.y)) * freqLow_fragmentUniforms.parallellightslicescale.w;
                    vec2 screenNoise = fract(gl_FragCoord.xy * 0.5);
                    screenNoise.x = fract((screenNoise.x * 0.5) + screenNoise.y);
                    if (screenNoise.x > fraction)
                    {
                        _3950 = 1;
                    }
                    else
                    {
                        _3950 = 0;
                    }
                    idx += uint(_3950);
                }
            }
            int shadowParmSize_3 = 5;
            shadow_parms_3.shadowLightS = _3682.shadowsparmsubo[(uint(shadowParmSize_3) * ((light_parms >> uint(22)) + idx)) + 0u];
            shadow_parms_3.shadowLightT = _3682.shadowsparmsubo[(uint(shadowParmSize_3) * ((light_parms >> uint(22)) + idx)) + 1u];
            shadow_parms_3.shadowLightR = _3682.shadowsparmsubo[(uint(shadowParmSize_3) * ((light_parms >> uint(22)) + idx)) + 2u];
            shadow_parms_3.shadowLightQ = _3682.shadowsparmsubo[(uint(shadowParmSize_3) * ((light_parms >> uint(22)) + idx)) + 3u];
            shadow_parms_3.shadowAtlasScaleBias = _3682.shadowsparmsubo[(uint(shadowParmSize_3) * ((light_parms >> uint(22)) + idx)) + 4u];
            

            
            vec4 shadowTC_1 = vec4((pos.x * shadow_parms_3.shadowLightS.x) + ((pos.y * shadow_parms_3.shadowLightS.y) + ((pos.z * shadow_parms_3.shadowLightS.z) + shadow_parms_3.shadowLightS.w)), (pos.x * shadow_parms_3.shadowLightT.x) + ((pos.y * shadow_parms_3.shadowLightT.y) + ((pos.z * shadow_parms_3.shadowLightT.z) + shadow_parms_3.shadowLightT.w)), (pos.x * shadow_parms_3.shadowLightR.x) + ((pos.y * shadow_parms_3.shadowLightR.y) + ((pos.z * shadow_parms_3.shadowLightR.z) + shadow_parms_3.shadowLightR.w)), (pos.x * shadow_parms_3.shadowLightQ.x) + ((pos.y * shadow_parms_3.shadowLightQ.y) + ((pos.z * shadow_parms_3.shadowLightQ.z) + shadow_parms_3.shadowLightQ.w)));
            vec3 _4106 = shadowTC_1.xyz / vec3(shadowTC_1.w);
            shadowTC_1 = vec4(_4106.x, _4106.y, _4106.z, shadowTC_1.w);
            
            
            //shadowTC_1.x += vk3d_params.stereo.x * (shadowTC_1.w - vk3d_params.stereo.y);
            
            bool _4111 = shadowTC_1.x > 0.0;
            bool _4117;
            if (_4111)
            {
                _4117 = shadowTC_1.x < 1.0;
            }
            else
            {
                _4117 = _4111;
            }
            bool _4123;
            if (_4117)
            {
                _4123 = shadowTC_1.y > 0.0;
            }
            else
            {
                _4123 = _4117;
            }
            bool _4129;
            if (_4123)
            {
                _4129 = shadowTC_1.y < 1.0;
            }
            else
            {
                _4129 = _4123;
            }
            if (_4129)
            {
                vec2 _4141 = (shadowTC_1.xy * shadow_parms_3.shadowAtlasScaleBias.xy) + shadow_parms_3.shadowAtlasScaleBias.zw;
                shadowTC_1 = vec4(_4141.x, _4141.y, shadowTC_1.z, shadowTC_1.w);
                
                //shadowTC_1.x -= vk3d_params.stereo.x;
                
                if (false)
                {
                    vec3 param_167 = shadowTC_1.xyz;
                    shadow = shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_167);
                }
                else
                {
                    vec2 uv = shadowTC_1.xy * freqLow_fragmentUniforms.shadowatlasresolution.xy;
                    vec2 shadowMapSizeInv = freqLow_fragmentUniforms.shadowatlasresolution.zw;
                    vec2 base_uv = vec2(floor(uv.x + 0.5), floor(uv.y + 0.5));
                    float s = (uv.x + 0.5) - base_uv.x;
                    float t = (uv.y + 0.5) - base_uv.y;
                    base_uv -= vec2(0.5);
                    base_uv *= shadowMapSizeInv;
                    float uw0 = 4.0 - (3.0 * s);
                    float uw1 = 7.0;
                    float uw2 = 1.0 + (3.0 * s);
                    float u0 = ((3.0 - (2.0 * s)) / uw0) - 2.0;
                    float u1 = (3.0 + s) / uw1;
                    float u2 = (s / uw2) + 2.0;
                    float vw0 = 4.0 - (3.0 * t);
                    float v0 = ((3.0 - (2.0 * t)) / vw0) - 2.0;
                    vec3 param_168 = vec3(base_uv + (vec2(u0, v0) * shadowMapSizeInv), shadowTC_1.z);
                    float s0 = (uw0 * vw0) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_168);
                    vec3 param_169 = vec3(base_uv + (vec2(u1, v0) * shadowMapSizeInv), shadowTC_1.z);
                    float s1 = (uw1 * vw0) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_169);
                    vec3 param_170 = vec3(base_uv + (vec2(u2, v0) * shadowMapSizeInv), shadowTC_1.z);
                    float s2 = (uw2 * vw0) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_170);
                    shadow = (s0 + s1) + s2;
                    float vw1 = 7.0;
                    float v1 = (3.0 + t) / vw1;
                    vec3 param_171 = vec3(base_uv + (vec2(u0, v1) * shadowMapSizeInv), shadowTC_1.z);
                    float s0_1 = (uw0 * vw1) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_171);
                    vec3 param_172 = vec3(base_uv + (vec2(u1, v1) * shadowMapSizeInv), shadowTC_1.z);
                    float s1_1 = (uw1 * vw1) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_172);
                    vec3 param_173 = vec3(base_uv + (vec2(u2, v1) * shadowMapSizeInv), shadowTC_1.z);
                    float s2_1 = (uw2 * vw1) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_173);
                    shadow += ((s0_1 + s1_1) + s2_1);
                    float vw2 = 1.0 + (3.0 * t);
                    float v2 = (t / vw2) + 2.0;
                    vec3 param_174 = vec3(base_uv + (vec2(u0, v2) * shadowMapSizeInv), shadowTC_1.z);
                    float s0_2 = (uw0 * vw2) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_174);
                    vec3 param_175 = vec3(base_uv + (vec2(u1, v2) * shadowMapSizeInv), shadowTC_1.z);
                    float s1_2 = (uw1 * vw2) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_175);
                    vec3 param_176 = vec3(base_uv + (vec2(u2, v2) * shadowMapSizeInv), shadowTC_1.z);
                    float s2_2 = (uw2 * vw2) * shadow2Ddepth(samp_shadowatlasdepthcomparemap, param_176);
                    shadow += ((s0_2 + s1_2) + s2_2);
                    shadow /= 144.0;
                }
            }
            else
            {
                if ((light_parms & 3u) == 2u)
                {
                    _4440 = 1.0;
                }
                else
                {
                    _4440 = 0.0;
                }
                shadow = _4440;
            }
            float shadow_fade = float((light_parms >> uint(16)) & 63u) / 63.0;
            float param_177 = ((shadow * shadow_fade) + 1.0) - shadow_fade;
            shadow = saturate(param_177);
        }
        uint param_178 = lightParms.colorPacked;
        vec3 light_color = (unpackRGBE(param_178) * shadow) * light_attenuation;
        float light_spec_multiplier = lightParms.specMultiplier;
        if ((light_parms & 48u) != 0u)
        {
            vec4 areaLightPlane = lightParms.areaPlane;
            vec4 areaLightPlaneU = lightParms.boxMin;
            vec4 areaLightPlaneV = lightParms.boxMax;
            float projToOrigin = dot(inputs.position, areaLightPlane.xyz) + areaLightPlane.w;
            if (projToOrigin < 0.0)
            {
                continue;
            }
            float falloffDistance = length(areaLightPlane.xyz);
            float param_179 = projToOrigin;
            float falloff_1 = saturate(param_179);
            light_color *= (falloff_1 * falloff_1);
            projToOrigin /= falloffDistance;
            areaLightPlane /= vec4(falloffDistance);
            vec3 mirrorDir = reflect(-inputs.view, inputs.normal);
            if (dot(mirrorDir, areaLightPlane.xyz) > 0.0)
            {
                mirrorDir = reflect(mirrorDir, areaLightPlane.xyz);
            }
            float projToPlane = dot(mirrorDir, areaLightPlane.xyz);
            float projLength = projToOrigin / projToPlane;
            vec3 hitPos = inputs.position - (mirrorDir * projLength);
            vec3 hitDir = hitPos - light_position;
            float u = dot(hitDir, areaLightPlaneU.xyz);
            float v = dot(hitDir, areaLightPlaneV.xyz);
            float lenCircle = length(vec2(u, v));
            float lenRect = max(abs(u), abs(v));
            if ((light_parms & 48u) == 32u)
            {
                _4584 = lenCircle;
            }
            else
            {
                _4584 = lenRect;
            }
            float len = _4584;
            if ((light_parms & 48u) == 48u)
            {
                vec2 param_180 = vec2(u, v);
                vec2 _4603 = saturate(param_180);
                projTC_1 = vec3(_4603.x, _4603.y, projTC_1.z);
            }
            len = min(1.0, len) / len;
            u *= (len * areaLightPlaneU.w);
            v *= (len * areaLightPlaneV.w);
            hitDir = (areaLightPlaneU.xyz * u) + (areaLightPlaneV.xyz * v);
            light_position += hitDir;
        }
        vec3 light_color_final = light_color;
        vec3 param_181 = light_color_final;
        light_color_final = mix(vec3(GetLuma(param_181)), light_color_final, freqLow_fragmentUniforms.pbrdebugparms.www);
        vec3 light_vector_1 = normalize(light_position - inputs.position);
        float param_182 = dot(inputs.normal, light_vector_1);
        float NdotL_1 = saturate(param_182);
        uint param_183 = inputs.specular_packed;
        vec3 param_184 = inputs.normal;
        vec3 param_185 = inputs.view;
        vec3 param_186 = light_vector_1;
        vec3 param_187 = unpackR10G10B10(param_183);
        float param_188 = abs(inputs.smoothness);
        vec3 spec = specBRDF(param_184, param_185, param_186, param_187, param_188);
        uint param_189 = inputs.specular_lighting_packed;
        vec3 param_190 = (((spec * light_spec_multiplier) * light_color_final) * NdotL_1) + unpackRGBE(param_189);
        inputs.specular_lighting_packed = packRGBE(param_190);
        if ((light_parms & 256u) > 0u)
        {
            _4694 = vec3(0.0);
        }
        else
        {
            _4694 = light_color_final;
        }
        vec3 diffuse_light_color = _4694;
        uint param_191 = inputs.diffuse_lighting_packed;
        vec3 param_192 = (diffuse_light_color * NdotL_1) + unpackRGBE(param_191);
        inputs.diffuse_lighting_packed = packRGBE(param_192);
    }
    uint param_193 = inputs.diffuse_lighting_packed;
    uint param_194 = inputs.albedo_packed;
    inputs.diffuse_lighting = unpackRGBE(param_193) * unpackR10G10B10(param_194);
    uint param_195 = inputs.specular_lighting_packed;
    inputs.specular_lighting = unpackRGBE(param_195);
    inputs.output_lighting = inputs.diffuse_lighting + inputs.specular_lighting;
    vec3 _4742 = inputs.diffuse_lighting + inputs.specular_lighting;
    out_FragColor0 = vec4(_4742.x, _4742.y, _4742.z, out_FragColor0.w);
    vec3 param_196 = inputs.normal;
    bool param_197 = false;
    vec2 _4750 = NormalOctEncode(param_196, param_197);
    out_FragColor1 = vec4(_4750.x, _4750.y, out_FragColor1.z, out_FragColor1.w);
    float param_198 = inputs.specular.x;
    float param_199 = inputs.specular.y;
    float param_200 = inputs.specular.z;
    float param_201 = inputs.smoothness;
    out_FragColor2 = vec4(fastSqrtNR0(param_198), fastSqrtNR0(param_199), fastSqrtNR0(param_200), SmoothnessEncode(param_201));
    vec3 _4776 = out_FragColor0.xyz + freqLow_fragmentUniforms.highlightcolor.xyz;
    out_FragColor0 = vec4(_4776.x, _4776.y, _4776.z, out_FragColor0.w);
}






