//Specular reflections PS, something 3.
#version 450
#extension GL_EXT_nonuniform_qualifier : require

struct MaterialData
{
    uvec4 paramIntData0;
    vec4 paramFloatData0;
    vec4 paramFloatData1;
    vec4 paramFloatData2;
    vec4 paramFloatData3;
    vec4 paramFloatData4;
    vec4 paramFloatData5;
    vec4 paramFloatData6;
    vec4 paramFloatData7;
    vec4 paramFloatData8;
    vec4 paramFloatData9;
    uvec4 paramImgIDs0;
    uvec4 paramImgIDs1;
    uvec4 paramImgIDs2;
};

struct LightingData
{
    vec3 L;
    vec2 energyDiffuseSpecular;
    vec3 posWS;
    vec3 posWSa;
    vec3 posVS;
    vec3 cameraPosWS;
    vec3 V;
    vec3 N;
    vec3 NVtx;
    vec3 T;
    vec4 lightingWeights0;
    vec4 lightingWeights1;
    vec3 baseColor;
    float metalness;
    float specular;
    float roughness;
    float occlusion;
    float translucency;
    float ambientOcclusion;
    vec3 emissive;
    vec3 irradiance;
    vec4 materialBlendMask;
    uint materialId;
    MaterialData materialData;
    vec4 ssrSample;
    vec3 diffuseColor;
    vec3 specularColor;
    vec3 R;
    vec3 H;
    float NdL;
    float NdV;
    float NdH;
    float VdH;
    float LdH;
    float roughness2;
    float roughness4;
    vec3 posWSneighborX;
    vec3 posWSneighborY;
    float time;
    float depthFixup;
};

struct LightingDataDesc
{
    vec3 baseColor;
    float roughness;
    float metalness;
    float occlusion;
    float translucency;
    vec3 N;
    vec3 NVtx;
    float ambientOcclusion;
    vec3 emissive;
    vec3 irradiance;
    vec4 materialBlendMask;
    vec4 lightingWeights0;
    vec4 lightingWeights1;
    vec3 cameraPosWS;
    vec3 posWS;
    vec3 posWSa;
    vec3 posVS;
    uint materialId;
    MaterialData materialData;
};

struct LightData
{
    vec4 posAndRadiusWS;
    vec4 colorAndIntensity;
    vec4 lightDirectionAndFalloffExp;
    vec4 lightTangent;
    uvec4 lightTypeAndFlags;
    vec4 spotLightAngles;
    vec4 sphereAndShadowParams;
};

struct ExtendedLightData
{
    mat4 boxInverseWorldMatrix;
    mat4 viewProjectionMatrix;
    uvec4 params0;
    vec4 projectorTransform;
};

struct SH9
{
    vec3 L[9];
};

struct SpecularProbeData
{
    vec4 posAndRadiusWS;
    mat4 worldMatrix;
    mat4 inverseWorldMatrix;
    uvec4 imageIdAndFlags;
    vec4 params0;
    vec4 params1;
};

struct FlrInput
{
    vec3 normal;
    vec3 binormal;
    vec4 tangent;
    vec2 uv0;
    vec4 color;
    vec4 pos;
    vec3 posWS;
    vec4 prevPos;
};

struct FlrOutput
{
    vec4 albedo;
    vec4 normals;
    vec4 parameter;
    uint materialId;
    uint miscParams0;
    vec2 motionVector;
    vec3 normalsTS;
};

struct SH9Compressed
{
    uvec4 data0[2];
    uvec4 data1;
};

struct SH9Compressed_1
{
    uvec4 data0[2];
    uvec4 data1;
};

struct DecalData
{
    mat4 viewMatrix;
    mat4 viewProjMatrix;
    uvec4 decalIntParams0;
    vec4 decalOpacityParams;
    vec4 decalUVScaleOffset;
    vec4 decalMaskUVScaleOffset;
    vec4 decalParams0;
    vec4 decalParams1;
    vec4 decalParams2;
    vec4 decalNormal;
    vec4 decalTangent;
};

struct TexturePatchData
{
    uvec4 index;
    vec4 transform;
    vec4 uvScaleOffset;
};

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

layout(set = 0, binding = 32, std140) uniform PerView
{
    mat4 invViewProjMatrix;
    mat4 invProjMatrix;
    vec4 nearFar;
    vec4 nearFarWidthHeight;
    vec4 cameraPositionWS;
    vec4 dirLightDirWS;
    vec4 dirLightColorAndIntens;
    uvec4 dirLightProjectorParams;
    vec4 dirLightProjectorTransform;
    mat4 dirLightProjectorViewProjMatrix;
    SH9Compressed skyModelSH;
    SH9Compressed globalBackgroundSH;
    mat4 pssmViewProjMatrices[5];
    mat4 localLightViewProjMatrices[16];
    vec4 shadowParameters0;
    vec4 playerWorldPosition;
    vec4 lightingWeights0;
    vec4 lightingWeights1;
    vec4 dynamicResolutionParameters;
    vec4 frameParameters0;
    vec4 frameParameters1;
    vec4 projectionOffsets;
    vec4 irradianceGridWorldPosition;
    vec4 irradianceGridHalfExtents;
    uvec4 irradianceGridResolution;
    mat4 viewMatrix;
    vec4 volumetricsParams2;
} _3112;

layout(set = 0, binding = 42, std430) readonly buffer extendedLightBuffer
{
    ExtendedLightData _extendedLightBuffer[];
} _3512;

layout(set = 0, binding = 48, std430) readonly buffer irradianceGridBuffer
{
    SH9Compressed_1 _irradianceGridBuffer[];
} _4366;

layout(set = 0, binding = 46, std430) readonly buffer resourceIndexBuffer
{
    uint _resourceIndexBuffer[];
} _4722;

layout(set = 0, binding = 44, std430) readonly buffer specularProbeBuffer
{
    SpecularProbeData _specularProbeBuffer[];
} _4765;

layout(set = 0, binding = 41, std430) readonly buffer lightBuffer
{
    LightData _lightBuffer[];
} _4907;

layout(set = 0, binding = 31, std140) uniform PerMaterial
{
    uvec4 paramIntData0;
    vec4 tint;
    vec4 parameters0;
    vec4 uvTransform;
    vec4 paramData3;
    vec4 normalParams;
    vec4 paramData5;
    vec4 paramData6;
    vec4 paramData7;
    vec4 paramData8;
    vec4 paramData9;
    uvec4 paramImgIDs0;
    uvec4 paramImgIDs1;
    uvec4 paramImgIDs2;
} _5289;

layout(set = 0, binding = 30, std140) uniform PerInstance
{
    uvec4 params0;
    vec4 materialParams0;
    vec4 materialParams1;
    vec4 materialParams2;
    vec4 materialParams3;
} _5328;

layout(set = 0, binding = 47, std430) readonly buffer materialDataBuffer
{
    MaterialData _materialDataBuffer[];
} _5788;

layout(set = 0, binding = 45, std430) readonly buffer decalBuffer
{
    DecalData _decalBuffer[];
} _5976;

layout(set = 0, binding = 8, std430) readonly buffer TexturePatchBuffer
{
    TexturePatchData _TexturePatchBuffer[];
} _5981;

layout(set = 0, binding = 100, std430) buffer DebugBuffer
{
    uint debugBuffer[];
} _5985;

layout(set = 2, binding = 0) uniform texture2D globalTextures[];
layout(set = 2, binding = 0) uniform textureCube globalCubeTextures[];
layout(set = 1, binding = 1) uniform sampler linearRepeatSampler;
layout(set = 0, binding = 40) uniform sampler2DArrayShadow shadowBufferTex;
layout(set = 1, binding = 0) uniform sampler linearClampSampler;
layout(set = 0, binding = 20) uniform sampler2D albedoTex;
layout(set = 0, binding = 26) uniform sampler2D dissolveTex;
layout(set = 0, binding = 22) uniform sampler2D parameterTex;
layout(set = 0, binding = 23) uniform sampler2D parameterOptional0Tex;
layout(set = 0, binding = 21) uniform sampler2D normalTex;
layout(set = 0, binding = 24) uniform sampler2D detailNormalTex;
layout(set = 0, binding = 27) uniform sampler2D colorCorrectionMaskTex;
layout(set = 0, binding = 28) uniform sampler3D scatterBufferTex;
layout(set = 2, binding = 0) uniform texture3D global3DTextures[];
layout(set = 1, binding = 2) uniform sampler nearestClampSampler;
layout(set = 1, binding = 3) uniform sampler nearestRepeatSampler;
layout(set = 1, binding = 4) uniform sampler shadowSampler;
layout(set = 0, binding = 25) uniform sampler2D flowTex;
layout(set = 0, binding = 29) uniform sampler2D refractionTex;
layout(set = 0, binding = 39) uniform sampler2D irradianceTex;

layout(location = 1) in vec2 inUV0;
layout(location = 0) in vec3 inNormal;
layout(location = 2) in vec4 inTangent;
layout(location = 3) in vec3 inBinormal;
layout(location = 6) in vec4 inPosition;
layout(location = 7) in vec4 inPrevPosition;
layout(location = 4) in vec3 inPosWS;
layout(location = 0) out vec4 outColor;
layout(location = 1) out vec4 outMotionVector;

float _974;
float _991;
float _1008;
bool _3915;

vec3 decodeNormalMap(vec4 normalSample)
{
    vec2 _795 = (normalSample.wy - vec2(0.5)) * 2.0;
    vec3 normal;
    normal = vec3(_795.x, _795.y, normal.z);
    normal.z = sqrt(1.0 - ((normal.x * normal.x) - (normal.y * normal.y)));
    return normal;
}

vec3 blendNormalMaps(vec3 base, vec3 blend)
{
    vec3 blendedNormal = normalize(vec3(base.xy + blend.xy, base.z * blend.z));
    return blendedNormal;
}

vec2 signNotZero(vec2 v)
{
    return vec2((v.x >= 0.0) ? 1.0 : (-1.0), (v.y >= 0.0) ? 1.0 : (-1.0));
}

vec2 encodeNormal(vec3 v)
{
    vec2 p = v.xy * (1.0 / ((abs(v.x) + abs(v.y)) + abs(v.z)));
    vec2 _620;
    if (v.z <= 0.0)
    {
        vec2 param = p;
        _620 = (vec2(1.0) - abs(p.yx)) * signNotZero(param);
    }
    else
    {
        _620 = p;
    }
    return _620;
}

vec4 decodeRGBA8uint(uint colorU)
{
    return vec4(float((colorU & 4278190080u) >> uint(24)) * 0.003921560011804103851318359375, float((colorU & 16711680u) >> uint(16)) * 0.003921560011804103851318359375, float((colorU & 65280u) >> uint(8)) * 0.003921560011804103851318359375, float(colorU & 255u) * 0.003921560011804103851318359375);
}

vec3 gammaToLinear(vec3 color)
{
    return pow(clamp(color, vec3(0.0), vec3(1.0)), vec3(2.2000000476837158203125));
}

float getLuminance(vec3 color)
{
    return dot(color, vec3(0.2125999927520751953125, 0.715200006961822509765625, 0.072200000286102294921875));
}

vec4 decodeARGB8uint(uint colorU)
{
    return vec4(float((colorU & 16711680u) >> uint(16)) * 0.003921560011804103851318359375, float((colorU & 65280u) >> uint(8)) * 0.003921560011804103851318359375, float(colorU & 255u) * 0.003921560011804103851318359375, float((colorU & 4278190080u) >> uint(24)) * 0.003921560011804103851318359375);
}

vec2 getMotionVector(vec4 currPos, vec4 prevPos, vec4 projectionOffsets)
{
    vec2 currPosNDC = (currPos.xy / vec2(currPos.w)) + projectionOffsets.xy;
    vec2 prevPosNDC = (prevPos.xy / vec2(prevPos.w)) + projectionOffsets.zw;
    currPosNDC.y = 1.0 - currPosNDC.y;
    prevPosNDC.y = 1.0 - prevPosNDC.y;
    vec2 motionVector = (prevPosNDC - currPosNDC) * vec2(0.5, -0.5);
    motionVector = clamp(motionVector, vec2(-1.0), vec2(1.0));
    return motionVector;
}

void flrMain(FlrInput flrInput, inout FlrOutput flrOutput)
{
    vec2 uv = (flrInput.uv0 * _5289.uvTransform.xy) + _5289.uvTransform.zw;
    if ((_5289.paramIntData0.x & 8u) > 0u)
    {
        uv = (flrInput.uv0 * _5289.uvTransform.xy) + (_5289.uvTransform.zw * _3112.frameParameters0.x);
    }
    vec4 albedoValue = texture(albedoTex, uv, _3112.frameParameters1.x);
    if (floatBitsToUint(_5328.materialParams1.x) == 501163121u)
    {
        float dissolveValue = texture(dissolveTex, uv * _5289.paramData6.x).x;
        vec3 _5358 = albedoValue.xyz + ((vec3(0.0, 0.5, 1.0) * float(abs(dissolveValue - _5328.materialParams0.z) < 0.100000001490116119384765625)) * 1000.0);
        albedoValue = vec4(_5358.x, _5358.y, _5358.z, albedoValue.w);
        vec3 _5364 = min(albedoValue.xyz, vec3(8.0));
        albedoValue = vec4(_5364.x, _5364.y, _5364.z, albedoValue.w);
    }
    float _5371;
    if ((_5289.paramIntData0.x & 128u) > 0u)
    {
        _5371 = 1.0 / max(albedoValue.w, 0.00999999977648258209228515625);
    }
    else
    {
        _5371 = 1.0;
    }
    vec3 _5382 = albedoValue.xyz * _5371;
    albedoValue = vec4(_5382.x, _5382.y, _5382.z, albedoValue.w);
    vec4 parameterValue = texture(parameterTex, uv, _3112.frameParameters1.x);
    vec4 parameterOptional0Value = texture(parameterOptional0Tex, uv, _3112.frameParameters1.x);
    float translucency = parameterOptional0Value.x;
    vec4 normalValue = texture(normalTex, uv, _5289.normalParams.y + _3112.frameParameters1.x);
    vec4 param = normalValue;
    vec3 normal = decodeNormalMap(param);
    vec2 _5420 = normal.xy * _5289.normalParams.x;
    normal = vec3(_5420.x, _5420.y, normal.z);
    flrOutput.normalsTS = normal;
    if (_5289.normalParams.z > 0.0)
    {
        vec2 detailNormalUV = uv * _5289.normalParams.w;
        vec4 param_1 = texture(detailNormalTex, detailNormalUV, _3112.frameParameters1.x);
        vec3 detailNormal = decodeNormalMap(param_1);
        vec2 _5448 = detailNormal.xy * _5289.normalParams.z;
        detailNormal = vec3(_5448.x, _5448.y, detailNormal.z);
        detailNormal = normalize(detailNormal);
        vec3 param_2 = normal;
        vec3 param_3 = detailNormal;
        normal = blendNormalMaps(param_2, param_3);
    }
    normal = normalize(((flrInput.tangent.xyz * normal.x) + (flrInput.binormal * normal.y)) + (flrInput.normal * normal.z));
    flrOutput.albedo = vec4(albedoValue.xyz.x, albedoValue.xyz.y, albedoValue.xyz.z, flrOutput.albedo.w);
    flrOutput.albedo.w = albedoValue.w;
    vec3 param_4 = normal;
    vec3 param_5 = flrInput.normal;
    flrOutput.normals = vec4(encodeNormal(param_4), encodeNormal(param_5));
    flrOutput.materialId = _5328.params0.w;
    vec3 colorCorrectionValue = texture(colorCorrectionMaskTex, uv).xyz;
    float correctionMask = clamp(colorCorrectionValue.x * flrInput.color.w, 0.0, 1.0);
    uint param_6 = floatBitsToUint(_5328.materialParams2.x);
    vec3 param_7 = decodeRGBA8uint(param_6).xyz;
    vec3 tintPerInstance = gammaToLinear(param_7);
    vec3 perInstanceColor = tintPerInstance * flrOutput.albedo.xyz;
    vec3 _5538 = mix(flrOutput.albedo.xyz, perInstanceColor, vec3(correctionMask)) * _5328.materialParams2.z;
    flrOutput.albedo = vec4(_5538.x, _5538.y, _5538.z, flrOutput.albedo.w);
    vec3 correctedAlbedo = flrInput.color.zyx * flrOutput.albedo.xyz;
    vec3 param_8 = correctedAlbedo;
    float lum = getLuminance(param_8);
    correctedAlbedo = vec3(lum) + ((correctedAlbedo - vec3(lum)) * _5289.tint.z);
    uint param_9 = floatBitsToUint(_5289.tint.x);
    vec3 param_10 = decodeARGB8uint(param_9).xyz;
    correctedAlbedo = (correctedAlbedo * gammaToLinear(param_10)) * _5289.tint.y;
    vec3 _5583 = mix(flrOutput.albedo.xyz, correctedAlbedo, vec3(correctionMask));
    flrOutput.albedo = vec4(_5583.x, _5583.y, _5583.z, flrOutput.albedo.w);
    vec3 parameterScale = _5289.parameters0.xyz;
    flrOutput.parameter = vec4(parameterValue.xyz, 1.0);
    flrOutput.parameter.x = clamp((flrOutput.parameter.x * clamp(parameterScale.x, 0.0, 1.0)) + clamp(parameterScale.x - 1.0, 0.0, 1.0), 0.0, 1.0);
    flrOutput.parameter.y = clamp((flrOutput.parameter.y * clamp(parameterScale.y, 0.0, 1.0)) + clamp(parameterScale.y - 1.0, 0.0, 1.0), 0.0, 1.0);
    flrOutput.parameter.z = 1.0 - clamp((1.0 - flrOutput.parameter.z) * parameterScale.z, 0.0, 1.0);
    flrOutput.parameter.w = translucency;
    vec4 param_11 = flrInput.pos;
    vec4 param_12 = flrInput.prevPos;
    vec4 param_13 = _3112.projectionOffsets;
    flrOutput.motionVector = getMotionVector(param_11, param_12, param_13);
    flrOutput.miscParams0 = _5328.params0.x & 8191u;
    if ((_5289.paramIntData0.x & 1024u) > 0u)
    {
        flrOutput.miscParams0 |= 16384u;
    }
    flrOutput.miscParams0 |= 32768u;
    flrOutput.albedo.w *= _5328.materialParams0.z;
}

vec3 decodeNormal(vec2 e)
{
    vec3 v = vec3(e, (1.0 - abs(e.x)) - abs(e.y));
    if (v.z < 0.0)
    {
        vec2 param = v.xy;
        vec2 _664 = (vec2(1.0) - abs(v.yx)) * signNotZero(param);
        v = vec3(_664.x, _664.y, v.z);
    }
    return normalize(v);
}

void initLightingData(inout LightingData d, LightingDataDesc desc)
{
    d.L = vec3(0.0);
    d.V = vec3(0.0, 0.0, 1.0);
    d.energyDiffuseSpecular = vec2(0.0);
    d.diffuseColor = vec3(0.0);
    d.specularColor = vec3(0.0);
    d.R = vec3(0.0);
    d.H = vec3(0.0);
    d.NdL = 0.0;
    d.NdV = 0.0;
    d.NdH = 0.0;
    d.VdH = 0.0;
    d.LdH = 0.0;
    d.roughness2 = 0.0;
    d.roughness4 = 0.0;
    d.ssrSample = vec4(0.0);
    d.baseColor = desc.baseColor;
    d.roughness = desc.roughness;
    d.metalness = desc.metalness;
    d.occlusion = desc.occlusion;
    d.translucency = desc.translucency;
    d.materialBlendMask = desc.materialBlendMask;
    d.materialId = desc.materialId;
    d.materialData = desc.materialData;
    d.specular = desc.materialData.paramFloatData8.x;
    d.lightingWeights0 = desc.lightingWeights0;
    d.lightingWeights1 = desc.lightingWeights1;
    d.cameraPosWS = desc.cameraPosWS;
    d.posWS = desc.posWS;
    d.posWSa = desc.posWSa;
    d.posVS = desc.posVS;
    d.N = desc.N;
    d.NVtx = desc.NVtx;
    d.T = vec3(0.0);
    d.ambientOcclusion = desc.ambientOcclusion;
    d.emissive = desc.emissive;
    d.irradiance = desc.irradiance;
    d.posWSneighborX = vec3(0.0);
    d.posWSneighborY = vec3(0.0);
    d.time = 0.0;
    d.depthFixup = 1.0;
}

uint calcGridDepthIndex(float depthVS)
{
    return uint((24.0 * log(depthVS)) * 0.0819264352321624755859375);
}

float calcGridDepthSlice(uint depthSliceIdx)
{
    return pow(200000.0, float(depthSliceIdx) * 0.0416666679084300994873046875);
}

uvec3 clampGridPos(uvec3 gridPos)
{
    return clamp(gridPos, uvec3(0u), uvec3(15u, 7u, 23u));
}

uvec3 calcGridPosForViewPos(vec3 posVS, vec2 nearFar, vec4 nearFarWidthHeight)
{
    float param = -posVS.z;
    uint depthIdx = calcGridDepthIndex(param);
    uint param_1 = depthIdx + 1u;
    float gridEndDepth = calcGridDepthSlice(param_1);
    float rayPos = (gridEndDepth - nearFar.x) / (nearFar.y - nearFar.x);
    vec2 gridHalfWidthHeight = mix(nearFarWidthHeight.xy, nearFarWidthHeight.zw, vec2(rayPos)) * 0.5;
    vec2 localPos = posVS.xy / gridHalfWidthHeight;
    uvec3 gridPos = uvec3(uvec2(((localPos * 0.5) + vec2(0.5)) * vec2(16.0, 8.0)), depthIdx);
    uvec3 param_2 = gridPos;
    return clampGridPos(param_2);
}

uint calcClusterIndex(uvec3 gridPos)
{
    return uint(dot(vec3(gridPos), vec3(390.0, 6240.0, 49920.0))) / 2u;
}

vec4 unpackUNorm4x8(uint p_PackedValue)
{
    return vec4(float(p_PackedValue & 255u), float((p_PackedValue >> uint(8)) & 255u), float((p_PackedValue >> uint(16)) & 255u), float((p_PackedValue >> uint(24)) & 255u)) * 0.00392160005867481231689453125;
}

SH9 decodeSH9(vec4 data[7])
{
    SH9 result;
    result.L[0] = data[0].xyz;
    result.L[1] = vec3(data[0].w, data[1].xy);
    result.L[2] = vec3(data[1].zw, data[2].x);
    result.L[3] = data[2].yzw;
    result.L[4] = data[3].xyz;
    result.L[5] = vec3(data[3].w, data[4].xy);
    result.L[6] = vec3(data[4].zw, data[5].x);
    result.L[7] = data[5].yzw;
    result.L[8] = data[6].xyz;
    return result;
}

SH9 decodeSH9(uvec4 data0[2], uvec4 data1)
{
    uint param = data0[0].x;
    vec4 tempCoeff = (unpackUNorm4x8(param) * 2.0) - vec4(1.0);
    float tempCoeffLen = unpackHalf2x16(data1.x & 65535u).x;
    vec4 coeffs[7];
    coeffs[0] = tempCoeff * tempCoeffLen;
    uint param_1 = data0[0].y;
    tempCoeff = (unpackUNorm4x8(param_1) * 2.0) - vec4(1.0);
    tempCoeffLen = unpackHalf2x16((data1.x >> uint(16)) & 65535u).x;
    coeffs[1] = tempCoeff * tempCoeffLen;
    uint param_2 = data0[0].z;
    tempCoeff = (unpackUNorm4x8(param_2) * 2.0) - vec4(1.0);
    tempCoeffLen = unpackHalf2x16(data1.y & 65535u).x;
    coeffs[2] = tempCoeff * tempCoeffLen;
    uint param_3 = data0[0].w;
    tempCoeff = (unpackUNorm4x8(param_3) * 2.0) - vec4(1.0);
    tempCoeffLen = unpackHalf2x16((data1.y >> uint(16)) & 65535u).x;
    coeffs[3] = tempCoeff * tempCoeffLen;
    uint param_4 = data0[1].x;
    tempCoeff = (unpackUNorm4x8(param_4) * 2.0) - vec4(1.0);
    tempCoeffLen = unpackHalf2x16(data1.z & 65535u).x;
    coeffs[4] = tempCoeff * tempCoeffLen;
    uint param_5 = data0[1].y;
    tempCoeff = (unpackUNorm4x8(param_5) * 2.0) - vec4(1.0);
    tempCoeffLen = unpackHalf2x16((data1.z >> uint(16)) & 65535u).x;
    coeffs[5] = tempCoeff * tempCoeffLen;
    uint param_6 = data0[1].z;
    tempCoeff = (unpackUNorm4x8(param_6) * 2.0) - vec4(1.0);
    tempCoeffLen = unpackHalf2x16(data1.w & 65535u).x;
    coeffs[6] = tempCoeff * tempCoeffLen;
    vec4 param_7[7] = coeffs;
    return decodeSH9(param_7);
}

SH9 projectOntoSH9(vec3 n)
{
    SH9 sh;
    sh.L[0] = vec3(0.88622760772705078125);
    vec3 a1 = n.yzx * 0.48860299587249755859375;
    sh.L[1] = vec3(2.094399929046630859375) * a1.x;
    sh.L[2] = vec3(2.094399929046630859375) * a1.y;
    sh.L[3] = vec3(2.094399929046630859375) * a1.z;
    sh.L[4] = vec3(0.785398006439208984375) * ((1.09254801273345947265625 * n.x) * n.y);
    sh.L[5] = vec3(0.785398006439208984375) * ((1.09254801273345947265625 * n.y) * n.z);
    sh.L[6] = vec3(0.785398006439208984375) * (0.3153919875621795654296875 * (((3.0 * n.z) * n.z) - 1.0));
    sh.L[7] = vec3(0.785398006439208984375) * ((1.09254801273345947265625 * n.x) * n.z);
    sh.L[8] = vec3(0.785398006439208984375) * (0.546274006366729736328125 * ((n.x * n.x) - (n.y * n.y)));
    return sh;
}

vec3 shDotProduct(SH9 a, SH9 b)
{
    vec3 result = a.L[0] * b.L[0];
    result += (a.L[1] * b.L[1]);
    result += (a.L[2] * b.L[2]);
    result += (a.L[3] * b.L[3]);
    result += (a.L[4] * b.L[4]);
    result += (a.L[5] * b.L[5]);
    result += (a.L[6] * b.L[6]);
    result += (a.L[7] * b.L[7]);
    result += (a.L[8] * b.L[8]);
    return result;
}

vec3 sampleSH(uvec4 data0[2], uvec4 data1, vec3 dir)
{
    uvec4 param[2] = data0;
    uvec4 param_1 = data1;
    SH9 sh = decodeSH9(param, param_1);
    vec3 param_2 = dir;
    SH9 dirSH = projectOntoSH9(param_2);
    SH9 param_3 = dirSH;
    SH9 param_4 = sh;
    return max(shDotProduct(param_3, param_4), vec3(0.0));
}

uint _mortonPart1By2(inout uint x)
{
    x &= 1023u;
    x = (x ^ (x << uint(16))) & 4278190335u;
    x = (x ^ (x << uint(8))) & 50393103u;
    x = (x ^ (x << uint(4))) & 51130563u;
    x = (x ^ (x << uint(2))) & 153391689u;
    return x;
}

uint mortonEncode(uvec3 x)
{
    uint param = x.z;
    uint _734 = _mortonPart1By2(param);
    uint param_1 = x.y;
    uint _739 = _mortonPart1By2(param_1);
    uint param_2 = x.x;
    uint _746 = _mortonPart1By2(param_2);
    return ((_734 << uint(2)) + (_739 << uint(1))) + _746;
}

uint calcIrradianceGridCellIdx(uvec3 p_CellCoord)
{
    uvec3 param = p_CellCoord;
    return mortonEncode(param);
}

uint _mortonCompact1By2(inout uint x)
{
    x &= 153391689u;
    x = (x ^ (x >> uint(2))) & 51130563u;
    x = (x ^ (x >> uint(4))) & 50393103u;
    x = (x ^ (x >> uint(8))) & 4278190335u;
    x = (x ^ (x >> uint(16))) & 1023u;
    return x;
}

uvec3 mortonDecode(uint x)
{
    uint param = x >> uint(0);
    uint _754 = _mortonCompact1By2(param);
    uint param_1 = x >> uint(1);
    uint _758 = _mortonCompact1By2(param_1);
    uint param_2 = x >> uint(2);
    uint _762 = _mortonCompact1By2(param_2);
    return uvec3(_754, _758, _762);
}

void evaluateCell(uint i, vec3 globalIrrad, vec3 NVtx, vec3 N, vec3 posWS, vec3 cellExtents, uint baseCellIdx, vec3 alpha, inout vec4 gridIrrad)
{
    ivec3 offset = ivec3(int(i), int(i >> uint(1)), int(i >> uint(2))) & ivec3(1);
    uint param = baseCellIdx;
    ivec3 offsetGridCoord = clamp(ivec3(mortonDecode(param)) + offset, ivec3(0), ivec3(_3112.irradianceGridResolution.xyz) - ivec3(1));
    uvec3 param_1 = uvec3(offsetGridCoord);
    uint _4370 = calcIrradianceGridCellIdx(param_1);
    SH9Compressed_1 sh;
    sh.data0[0] = _4366._irradianceGridBuffer[_4370].data0[0];
    sh.data0[1] = _4366._irradianceGridBuffer[_4370].data0[1];
    sh.data1 = _4366._irradianceGridBuffer[_4370].data1;
    bool empty = sh.data0[1].w == 0u;
    vec3 _4389;
    if (!empty)
    {
        uint param_2 = sh.data0[1].w;
        _4389 = (((unpackUNorm4x8(param_2).xyz * 2.0) - vec3(1.0)) * cellExtents) * 0.5;
    }
    else
    {
        _4389 = vec3(0.0);
    }
    vec3 probeOffset = _4389;
    vec3 tri = mix(vec3(1.0) - alpha, alpha, vec3(offset));
    vec3 cellWorldPos = (((_3112.irradianceGridWorldPosition.xyz + (vec3(offsetGridCoord) * cellExtents)) - _3112.irradianceGridHalfExtents.xyz) + cellExtents) + probeOffset;
    vec3 posToCellDir = -normalize(posWS - cellWorldPos);
    float weight = ((tri.x * tri.y) * tri.z) * max(dot(NVtx, posToCellDir), 0.100000001490116119384765625);
    uvec4 param_3[2] = sh.data0;
    uvec4 param_4 = sh.data1;
    vec3 param_5 = N;
    gridIrrad += vec4(mix(sampleSH(param_3, param_4, param_5) * weight, globalIrrad * weight, vec3(float(empty))), weight);
}

void calcIrradiance(vec3 posWS, vec3 NVtx, vec3 N, inout vec3 irrad)
{
    vec3 cellExtents = (_3112.irradianceGridHalfExtents.xyz * 2.0) / vec3(_3112.irradianceGridResolution.xyz);
    vec3 gridPos = clamp((((posWS - _3112.irradianceGridWorldPosition.xyz) / _3112.irradianceGridHalfExtents.xyz) * 0.5) + vec3(0.5), vec3(0.0), vec3(1.0));
    vec4 gridIrrad = vec4(0.0);
    uvec4 param[2];
    param[0] = _3112.skyModelSH.data0[0];
    param[1] = _3112.skyModelSH.data0[1];
    uvec4 param_1 = _3112.skyModelSH.data1;
    vec3 param_2 = N;
    irrad = sampleSH(param, param_1, param_2);
    vec3 gridCoordFloat = (gridPos * vec3(_3112.irradianceGridResolution.xyz)) - vec3(1.0, 0.5, 1.0);
    uvec3 param_3 = uvec3(gridCoordFloat);
    uint baseCellIdx = calcIrradianceGridCellIdx(param_3);
    vec3 alpha = fract(gridCoordFloat);
    for (uint i = 0u; i < 4u; i++)
    {
        uint param_4 = i;
        vec3 param_5 = irrad;
        vec3 param_6 = NVtx;
        vec3 param_7 = N;
        vec3 param_8 = posWS;
        vec3 param_9 = cellExtents;
        uint param_10 = baseCellIdx;
        vec3 param_11 = alpha;
        vec4 param_12 = gridIrrad;
        evaluateCell(param_4, param_5, param_6, param_7, param_8, param_9, param_10, param_11, param_12);
        gridIrrad = param_12;
        uint param_13 = i + 4u;
        vec3 param_14 = irrad;
        vec3 param_15 = NVtx;
        vec3 param_16 = N;
        vec3 param_17 = posWS;
        vec3 param_18 = cellExtents;
        uint param_19 = baseCellIdx;
        vec3 param_20 = alpha;
        vec4 param_21 = gridIrrad;
        evaluateCell(param_13, param_14, param_15, param_16, param_17, param_18, param_19, param_20, param_21);
        gridIrrad = param_21;
    }
    vec4 _4585;
    if (gridIrrad.w > 9.9999999392252902907785028219223e-09)
    {
        _4585 = gridIrrad / vec4(gridIrrad.w);
    }
    else
    {
        _4585 = vec4(0.0);
    }
    gridIrrad = _4585;
    vec3 fadeBox = vec3(1.0) - (clamp(abs((gridPos * 2.0) - vec3(1.0)) - vec3(0.949999988079071044921875), vec3(0.0), vec3(1.0)) * 20.0);
    float gridBlendWeight = min(fadeBox.x, min(fadeBox.y, fadeBox.z));
    irrad = mix(irrad, gridIrrad.xyz, vec3(gridBlendWeight)) * 1.39999997615814208984375;
}

vec3 calcAOMultiBounce(vec3 ao, vec3 albedo)
{
    vec3 a = (albedo * 2.040400028228759765625) - vec3(0.3323999941349029541015625);
    vec3 b = (albedo * (-4.79510021209716796875)) + vec3(0.6417000293731689453125);
    vec3 c = (albedo * 2.755199909210205078125) + vec3(0.69029998779296875);
    return max(ao, ((((ao * a) + b) * ao) + c) * ao);
}

vec3 calcAOMultiBounce(float ao, vec3 albedo)
{
    vec3 param = vec3(ao);
    vec3 param_1 = albedo;
    return calcAOMultiBounce(param, param_1);
}

void initLightingDataFromGBuffer(inout LightingData d)
{
    float adjRough = (d.roughness * 0.949999988079071044921875) + 0.0500000007450580596923828125;
    d.roughness2 = adjRough * adjRough;
    d.roughness4 = d.roughness2 * d.roughness2;
    d.metalness = mix(0.0, d.metalness, d.lightingWeights1.y);
    d.diffuseColor = d.baseColor - (d.baseColor * d.metalness);
    d.specularColor = mix(vec3(d.specular) * 0.07999999821186065673828125, d.baseColor, vec3(d.metalness));
}

void calculateLightingDataBase(inout LightingData d)
{
    d.V = normalize(d.cameraPosWS - d.posWSa);
    d.NdV = clamp(abs(dot(d.N, d.V)) + 9.9999999392252902907785028219223e-09, 0.0, 1.0);
    d.R = reflect(-d.V, d.N);
    d.R = normalize(mix(d.N, d.R, vec3((1.0 - d.roughness2) * (sqrt(1.0 - d.roughness2) + d.roughness2))));
}

float roughnessToMipIdx(float roughness)
{
    return max((max(roughness - 0.0500000007450580596923828125, 0.0) / 0.949999988079071044921875) * 7.0, 0.0);
}

vec3 envBRDFApprox(vec3 specularColor, float roughness, float NdV)
{
    vec4 r = (vec4(-1.0, -0.0274999998509883880615234375, -0.572000026702880859375, 0.02199999988079071044921875) * roughness) + vec4(1.0, 0.0425000004470348358154296875, 1.03999996185302734375, -0.039999999105930328369140625);
    float a = (min(r.x * r.x, exp2((-9.27999973297119140625) * NdV)) * r.x) + r.y;
    vec2 AB = (vec2(-1.03999996185302734375, 1.03999996185302734375) * a) + r.zw;
    AB.y *= clamp(50.0 * specularColor.y, 0.0, 1.0);
    return (specularColor * AB.x) + vec3(AB.y);
}

vec4 flrSampleLevelBindlessCube(sampler samplerState, vec3 normal, float lod, uint textureIdx)
{
    return textureLod(samplerCube(globalCubeTextures[nonuniformEXT(textureIdx)], samplerState), normal, lod);
}

void calcLocalSpecular(SpecularProbeData sd, vec3 posWS, vec3 posWSa, vec3 camPosWS, vec3 N, vec3 R0, float specMipIdx, vec3 envBRDF, inout vec3 specular, inout vec3 specularIrrad, inout float totalWeight)
{
    float fadePercentageStart = 1.0 - sd.params1.x;
    uint probeType = uint(sd.params0.w);
    float fade = 0.0;
    vec3 posProbe = vec3(0.0);
    vec3 posProbea = vec3(0.0);
    if (probeType == 0u)
    {
        posProbe = (sd.inverseWorldMatrix * vec4(posWS, 1.0)).xyz;
        posProbea = (sd.inverseWorldMatrix * vec4(posWSa, 1.0)).xyz;
        bool _4140 = all(lessThanEqual(posProbe, vec3(1.0)));
        bool _4146;
        if (_4140)
        {
            _4146 = all(greaterThanEqual(posProbe, vec3(-1.0)));
        }
        else
        {
            _4146 = _4140;
        }
        if (_4146)
        {
            vec3 fadeBox = vec3(1.0) - (clamp(abs(posProbe) - vec3(fadePercentageStart), vec3(0.0), vec3(1.0)) / vec3(sd.params1.x));
            fade = min(fadeBox.x, min(fadeBox.y, fadeBox.z));
        }
    }
    else
    {
        if (probeType == 1u)
        {
            float dist = distance(posWSa, sd.posAndRadiusWS.xyz) / sd.posAndRadiusWS.w;
            if (dist <= 1.0)
            {
                fade = 1.0 - (clamp(dist - fadePercentageStart, 0.0, 1.0) / sd.params1.x);
            }
        }
    }
    float weight = sd.params0.x * fade;
    if (weight > 9.9999999392252902907785028219223e-09)
    {
        vec3 R = R0;
        uint probeFlags = sd.imageIdAndFlags.y;
        if ((probeFlags & 1u) > 0u)
        {
            vec3 camPosProbe = (sd.inverseWorldMatrix * vec4(camPosWS, 1.0)).xyz;
            vec3 normalProbe = normalize((sd.inverseWorldMatrix * vec4(N, 0.0)).xyz);
            vec3 camVecProbe = posProbea - camPosProbe;
            vec3 reflectDirProbe = reflect(camVecProbe, normalProbe);
            vec3 is0 = (vec3(1.0) - posProbe) / reflectDirProbe;
            vec3 is1 = (vec3(-1.0) - posProbe) / reflectDirProbe;
            vec3 isMax = max(is0, is1);
            float dist_1 = min(isMax.x, min(isMax.y, isMax.z));
            vec3 isProbe = reflectDirProbe * dist_1;
            vec3 isWS = posWS + (sd.worldMatrix * vec4(isProbe, 0.0)).xyz;
            R = isWS - sd.posAndRadiusWS.xyz;
        }
        vec3 param = R;
        float param_1 = specMipIdx;
        uint param_2 = sd.imageIdAndFlags.x;
        vec3 specSample = flrSampleLevelBindlessCube(linearClampSampler, param, param_1, param_2).xyz;
        vec3 spec = (specSample * sd.params0.y) * envBRDF;
        specular = mix(specular, spec, vec3(weight));
        vec3 param_3 = R;
        float param_4 = 5.0;
        uint param_5 = sd.imageIdAndFlags.x;
        vec3 specIrradSample = flrSampleLevelBindlessCube(linearClampSampler, param_3, param_4, param_5).xyz;
        specularIrrad = mix(specularIrrad, specIrradSample, vec3(weight));
        totalWeight = mix(totalWeight, 1.0, weight);
    }
}

float calcExponentialFalloff(LightData ld, vec3 lightDistVec)
{
    vec3 nlv = lightDistVec / vec3(ld.posAndRadiusWS.w + 0.001000000047497451305389404296875);
    float d2 = dot(nlv, nlv);
    return pow(abs(1.0 - clamp(d2, 0.0, 1.0)), ld.lightDirectionAndFalloffExp.w);
}

float calcSpecularOcclusionFromAo(float ao, float NdV, float r)
{
    return clamp((pow(abs(NdV + ao), exp2(((-16.0) * r) - 1.0)) - 1.0) + ao, 0.0, 1.0);
}

vec4 calcPosLS(vec3 posWS, mat4 shadowViewProjMatrix)
{
    vec4 posLS = shadowViewProjMatrix * vec4(posWS, 1.0);
    vec3 _1269 = posLS.xyz / posLS.www;
    posLS = vec4(_1269.x, _1269.y, _1269.z, posLS.w);
    vec2 _1276 = (posLS.xy * 0.5) + vec2(0.5);
    posLS = vec4(_1276.x, _1276.y, posLS.z, posLS.w);
    return posLS;
}

uint findBestFittingSplit(vec3 posWS, inout vec4 posLS)
{
    for (uint i = 0u; i < uint(_3112.shadowParameters0.x); i++)
    {
        vec3 param = posWS;
        mat4 param_1 = _3112.pssmViewProjMatrices[i];
        posLS = calcPosLS(param, param_1);
        bool _3129 = all(lessThanEqual(posLS.xyz, vec3(1.0)));
        bool _3136;
        if (_3129)
        {
            _3136 = all(greaterThanEqual(posLS.xyz, vec3(0.0)));
        }
        else
        {
            _3136 = _3129;
        }
        if (_3136)
        {
            return i;
        }
    }
    return 4294967295u;
}

vec2 calcBiasedShadowUV(vec3 posWS, vec3 normalVtx, vec3 L, mat4 projMatrix, float factor)
{
    float weight = max(1.0 - max(dot(normalVtx, L), 0.0), 0.1500000059604644775390625);
    vec3 offsetWS = (normalVtx * weight) * factor;
    vec3 offsetPosWS = posWS + offsetWS;
    vec4 offsetPosLS = projMatrix * vec4(offsetPosWS, 1.0);
    vec2 offsetUV = ((offsetPosLS.xy / vec2(offsetPosLS.w)) * 0.5) + vec2(0.5);
    return offsetUV;
}

float sampleShadowMap(vec2 baseUv, float u, float v, vec2 shadowMapSizeInv, float depth, uint shadowMapIdx, sampler2DArrayShadow shadowBufferTex_1)
{
    vec2 uv = baseUv + (vec2(u, v) * shadowMapSizeInv);
    vec4 _1301 = vec4(vec3(uv, float(shadowMapIdx)), depth);
    return texture(shadowBufferTex_1, vec4(_1301.xyz, _1301.w));
}

float pcf(vec3 shadowPos, uint shadowMapIdx, sampler2DArrayShadow shadowBufferTex_1)
{
    ivec3 size = textureSize(shadowBufferTex_1, 0);
    vec2 shadowMapSize;
    shadowMapSize.x = float(size.x);
    shadowMapSize.y = float(size.y);
    float elements = float(size.z);
    vec2 shadowMapSizeInv = vec2(1.0) / shadowMapSize;
    float lightDepth = shadowPos.z;
    vec2 uv = shadowPos.xy * shadowMapSize;
    vec2 baseUv;
    baseUv.x = floor(uv.x + 0.5);
    baseUv.y = floor(uv.y + 0.5);
    float s = (uv.x + 0.5) - baseUv.x;
    float t = (uv.y + 0.5) - baseUv.y;
    baseUv -= vec2(0.5);
    baseUv *= shadowMapSizeInv;
    float sum = 0.0;
    float uw0 = 3.0 - (2.0 * s);
    float uw1 = 1.0 + (2.0 * s);
    float u0 = ((2.0 - s) / uw0) - 1.0;
    float u1 = (s / uw1) + 1.0;
    float vw0 = 3.0 - (2.0 * t);
    float vw1 = 1.0 + (2.0 * t);
    float v0 = ((2.0 - t) / vw0) - 1.0;
    float v1 = (t / vw1) + 1.0;
    vec2 param = baseUv;
    float param_1 = u0;
    float param_2 = v0;
    vec2 param_3 = shadowMapSizeInv;
    float param_4 = lightDepth;
    uint param_5 = shadowMapIdx;
    sum += ((uw0 * vw0) * sampleShadowMap(param, param_1, param_2, param_3, param_4, param_5, shadowBufferTex_1));
    vec2 param_6 = baseUv;
    float param_7 = u1;
    float param_8 = v0;
    vec2 param_9 = shadowMapSizeInv;
    float param_10 = lightDepth;
    uint param_11 = shadowMapIdx;
    sum += ((uw1 * vw0) * sampleShadowMap(param_6, param_7, param_8, param_9, param_10, param_11, shadowBufferTex_1));
    vec2 param_12 = baseUv;
    float param_13 = u0;
    float param_14 = v1;
    vec2 param_15 = shadowMapSizeInv;
    float param_16 = lightDepth;
    uint param_17 = shadowMapIdx;
    sum += ((uw0 * vw1) * sampleShadowMap(param_12, param_13, param_14, param_15, param_16, param_17, shadowBufferTex_1));
    vec2 param_18 = baseUv;
    float param_19 = u1;
    float param_20 = v1;
    vec2 param_21 = shadowMapSizeInv;
    float param_22 = lightDepth;
    uint param_23 = shadowMapIdx;
    sum += ((uw1 * vw1) * sampleShadowMap(param_18, param_19, param_20, param_21, param_22, param_23, shadowBufferTex_1));
    return sum * 0.0625;
}

float calcFading(inout vec3 posLS)
{
    posLS = abs((posLS * 2.0) - vec3(1.0));
    float l = max(max(posLS.x, posLS.y), posLS.z);
    return smoothstep(0.89999997615814208984375, 1.0, l);
}

float calcDirShadowAttenuation(inout vec3 posWS, vec3 normalVtx, vec3 L, float shadowFactor)
{
    float shadowAttenuation = 1.0;
    posWS += (L * 6.0);
    vec3 param = posWS;
    vec4 param_1;
    uint _3321 = findBestFittingSplit(param, param_1);
    vec4 posLS = param_1;
    uint shadowMapIdx = _3321;
    if (shadowMapIdx != 4294967295u)
    {
        vec3 param_2 = posWS;
        vec3 param_3 = normalVtx;
        vec3 param_4 = L;
        mat4 param_5 = _3112.pssmViewProjMatrices[shadowMapIdx];
        float param_6 = 10.0 + ((10.0 * float(shadowMapIdx)) * 1.0);
        vec2 _3343 = calcBiasedShadowUV(param_2, param_3, param_4, param_5, param_6);
        posLS = vec4(_3343.x, _3343.y, posLS.z, posLS.w);
        vec3 param_7 = posLS.xyz;
        uint param_8 = shadowMapIdx;
        shadowAttenuation = pcf(param_7, param_8, shadowBufferTex);
        float shadowAttenuation2 = 1.0;
        vec3 param_9 = posLS.xyz;
        float _3358 = calcFading(param_9);
        float fadeSplits = _3358;
        uint nextShadowMapIdx = shadowMapIdx + 1u;
        if (nextShadowMapIdx < uint(_3112.shadowParameters0.x))
        {
            vec3 param_10 = posWS;
            mat4 param_11 = _3112.pssmViewProjMatrices[nextShadowMapIdx];
            vec4 tempPosLS = calcPosLS(param_10, param_11);
            vec3 param_12 = posWS;
            vec3 param_13 = normalVtx;
            vec3 param_14 = L;
            mat4 param_15 = _3112.pssmViewProjMatrices[nextShadowMapIdx];
            float param_16 = 10.0 + ((10.0 * float(shadowMapIdx)) * 1.0);
            vec2 _3393 = calcBiasedShadowUV(param_12, param_13, param_14, param_15, param_16);
            tempPosLS = vec4(_3393.x, _3393.y, tempPosLS.z, tempPosLS.w);
            vec3 param_17 = tempPosLS.xyz;
            uint param_18 = nextShadowMapIdx;
            shadowAttenuation2 = pcf(param_17, param_18, shadowBufferTex);
            shadowAttenuation = mix(shadowAttenuation, shadowAttenuation2, fadeSplits);
        }
        else
        {
            if (shadowMapIdx == (uint(_3112.shadowParameters0.x) - 1u))
            {
                vec3 param_19 = posWS;
                mat4 param_20 = _3112.pssmViewProjMatrices[shadowMapIdx];
                vec4 posLSLastSplit = calcPosLS(param_19, param_20);
                vec3 param_21 = posLSLastSplit.xyz;
                float _3427 = calcFading(param_21);
                float fadeGlobal = _3427;
                shadowAttenuation = mix(shadowAttenuation, 1.0, fadeGlobal);
            }
        }
    }
    return mix(1.0, shadowAttenuation, shadowFactor);
}

vec4 flrSampleLevelBindless(sampler samplerState, vec2 uv, float lod, uint textureIdx)
{
    return textureLod(sampler2D(globalTextures[nonuniformEXT(textureIdx)], samplerState), uv, lod);
}

vec3 calcDirProjectorAttenuation(vec3 posWS)
{
    vec3 att = vec3(1.0);
    uint projImageId = _3112.dirLightProjectorParams.x;
    if (projImageId != 4294967295u)
    {
        vec3 posLS = (_3112.dirLightProjectorViewProjMatrix * vec4(posWS, 1.0)).xyw;
        vec2 _3215 = posLS.xy / vec2(posLS.z);
        posLS = vec3(_3215.x, _3215.y, posLS.z);
        vec2 _3224 = posLS.xy * _3112.dirLightProjectorTransform.xy;
        posLS = vec3(_3224.x, _3224.y, posLS.z);
        vec2 _3239 = posLS.xy + ((_3112.dirLightProjectorTransform.zw * _3112.frameParameters0.x) * _3112.dirLightProjectorTransform.xy);
        posLS = vec3(_3239.x, _3239.y, posLS.z);
        vec2 _3246 = (posLS.xy * 0.5) + vec2(0.5);
        posLS = vec3(_3246.x, _3246.y, posLS.z);
        float projectorFactor = uintBitsToFloat(_3112.dirLightProjectorParams.y);
        vec2 param = posLS.xy;
        float param_1 = 0.0;
        uint param_2 = projImageId;
        att *= max(mix(vec3(1.0), flrSampleLevelBindless(linearRepeatSampler, param, param_1, param_2).xyz, vec3(projectorFactor)), vec3(0.0));
    }
    return att;
}

float calcDistanceFieldShadowing(inout vec3 L, inout vec3 N, inout vec3 posWS, inout float rayLength, inout uint stepsMax, inout float k, out uint totalSteps)
{
    L = L;
    N = N;
    posWS = posWS;
    rayLength = rayLength;
    k = k;
    stepsMax = stepsMax;
    totalSteps = 0u;
    return 1.0;
}

float calcDistanceFieldShadowing(vec3 L, vec3 N, vec3 posWS, float rayLength)
{
    vec3 param = L;
    vec3 param_1 = N;
    vec3 param_2 = posWS;
    float param_3 = rayLength;
    uint param_4 = 32u;
    float param_5 = 10.0;
    uint param_6;
    float _3168 = calcDistanceFieldShadowing(param, param_1, param_2, param_3, param_4, param_5, param_6);
    uint totalSteps = param_6;
    return _3168;
}

void calculateLDisc(inout LightingData d, float discRadius)
{
    float discR = sin(discRadius);
    float discD = cos(discRadius);
    float DdR = dot(d.L, d.R);
    vec3 S = d.R - (d.L * DdR);
    vec3 _1624;
    if (DdR < discD)
    {
        _1624 = normalize((d.L * discD) + (normalize(S) * discR));
    }
    else
    {
        _1624 = d.R;
    }
    d.L = _1624;
}

void calculateLightingData(inout LightingData d)
{
    d.H = normalize(d.L + d.V);
    d.NdH = dot(d.N, d.H);
    d.VdH = dot(d.V, d.H);
    d.LdH = dot(d.L, d.H);
}

float calcMicroShadowing(float AO, float NdL, float opacity)
{
    float aperture = (2.0 * AO) * AO;
    float microshadow = clamp((NdL + aperture) - 1.0, 0.0, 1.0);
    return mix(1.0, microshadow, opacity);
}

float diffuseLambert()
{
    return 1.0;
}

vec3 calcDiffuse(LightingData d)
{
    return (((d.diffuseColor * (d.lightingWeights0.x * d.energyDiffuseSpecular.x)) * 0.3183098733425140380859375) * diffuseLambert()) * d.NdL;
}

vec3 calcDiffuseOcclusionDirectLighting(float ssao, vec3 albedo, float intens)
{
    float param = ssao;
    vec3 param_1 = albedo;
    return mix(vec3(1.0), calcAOMultiBounce(param, param_1), vec3(intens));
}

float D_GGX(float NdH, float roughness4)
{
    float denom = ((NdH * NdH) * (roughness4 - 1.0)) + 1.0;
    return roughness4 / ((3.1415927410125732421875 * denom) * denom);
}

float V_Schlick(float NdL, float NdV, float roughness2)
{
    float k = roughness2 * 0.5;
    float V = (NdV * (1.0 - k)) + k;
    float L = (NdL * (1.0 - k)) + k;
    return 0.25 / (V * L);
}

vec3 F_Schlick(vec3 specularColor, float VdH)
{
    float fc = pow(abs(1.0 - VdH), 5.0);
    return vec3(clamp(50.0 * specularColor.y, 0.0, 1.0) * fc) + (specularColor * (1.0 - fc));
}

vec3 calcSpecular(LightingData d, float r2, float r4)
{
    float param = d.NdH;
    float param_1 = r4;
    float D = D_GGX(param, param_1) * d.energyDiffuseSpecular.y;
    float param_2 = d.NdL;
    float param_3 = d.NdV;
    float param_4 = r2;
    float V = V_Schlick(param_2, param_3, param_4);
    vec3 param_5 = d.specularColor;
    float param_6 = d.VdH;
    vec3 F = F_Schlick(param_5, param_6);
    return (F * ((d.lightingWeights0.y * D) * V)) * d.NdL;
}

vec3 calcTranslucentLighting(vec3 N, vec3 L, vec3 V, float pixelTranslucency, float materialTranslucencyPower, float materialTranslucencyDistortion, vec3 materialTranslucencyColor)
{
    vec3 translucencyColor = materialTranslucencyColor * pixelTranslucency;
    vec3 sssLightVector = L + ((-N) * materialTranslucencyDistortion);
    float sssDot = exp2((clamp(dot(V, -sssLightVector), 0.0, 1.0) * materialTranslucencyPower) - materialTranslucencyPower);
    return translucencyColor * sssDot;
}

void applyTranslucentLighting(inout vec3 outLightingDiffuse, LightingData d)
{
    bool _2031 = (d.materialData.paramIntData0.x & 4u) > 0u;
    bool _2037;
    if (_2031)
    {
        _2037 = d.translucency > 0.0;
    }
    else
    {
        _2037 = _2031;
    }
    if (_2037)
    {
        float materialTranslucencyPower = d.materialData.paramFloatData7.x;
        float materialTranslucencyDistortion = d.materialData.paramFloatData7.y;
        float materialTranslucencyStrength = d.materialData.paramFloatData7.z;
        uint param = floatBitsToUint(d.materialData.paramFloatData7.w);
        vec3 param_1 = decodeARGB8uint(param).xyz;
        vec3 materialTranslucencyColor = gammaToLinear(param_1);
        vec3 param_2 = d.N;
        vec3 param_3 = d.L;
        vec3 param_4 = d.V;
        float param_5 = d.translucency;
        float param_6 = materialTranslucencyPower;
        float param_7 = materialTranslucencyDistortion;
        vec3 param_8 = materialTranslucencyColor;
        vec3 translucentLighting = calcTranslucentLighting(param_2, param_3, param_4, param_5, param_6, param_7, param_8);
        vec3 translucencyScalar = (((translucentLighting * materialTranslucencyStrength) * d.lightingWeights0.x) * d.energyDiffuseSpecular.x) * 0.3183098733425140380859375;
        outLightingDiffuse += translucencyScalar;
    }
}

void calcDirLightLighting(inout LightingData d, float energy, vec3 lightColor, vec3 L, inout vec3 outLighting0, inout vec3 outLighting1, vec4 diffuseSpecularWeights, vec3 shadowAttenuation)
{
    d.L = L;
    d.energyDiffuseSpecular = vec2(energy);
    LightingData param = d;
    float param_1 = 0.0670000016689300537109375;
    calculateLDisc(param, param_1);
    d = param;
    d.NdL = dot(d.N, d.L);
    LightingData param_2 = d;
    calculateLightingData(param_2);
    d = param_2;
    vec3 lightDiffuse = vec3(0.0);
    vec3 lightSpecular = vec3(0.0);
    if (d.NdL > 0.0)
    {
        float param_3 = d.occlusion;
        float param_4 = d.NdL;
        float param_5 = 0.75;
        vec3 attenuation = (shadowAttenuation * calcMicroShadowing(param_3, param_4, param_5)) * lightColor;
        LightingData param_6 = d;
        float param_7 = d.ambientOcclusion;
        vec3 param_8 = d.baseColor;
        float param_9 = 0.85000002384185791015625;
        lightDiffuse = (calcDiffuse(param_6) * attenuation) * calcDiffuseOcclusionDirectLighting(param_7, param_8, param_9);
        float r = max(d.roughness, 0.60000002384185791015625);
        float r2 = r * r;
        float r4 = r2 * r2;
        LightingData param_10 = d;
        float param_11 = r2;
        float param_12 = r4;
        lightSpecular = calcSpecular(param_10, param_11, param_12) * attenuation;
    }
    else
    {
        vec3 param_13 = lightDiffuse;
        LightingData param_14 = d;
        applyTranslucentLighting(param_13, param_14);
        lightDiffuse = param_13;
        lightDiffuse *= 0.100000001490116119384765625;
        lightDiffuse *= lightColor;
    }
    outLighting0 += ((lightDiffuse * diffuseSpecularWeights.x) + (lightSpecular * diffuseSpecularWeights.y));
    outLighting1 += ((lightDiffuse * diffuseSpecularWeights.z) + (lightSpecular * diffuseSpecularWeights.w));
}

vec3 calcLocalLightShadowAttenuation(LightData ld, inout vec3 posWS, vec3 shadowBiasNormal)
{
    vec3 L = normalize(ld.posAndRadiusWS.xyz - posWS);
    posWS += (L * 6.0);
    uint localShadowBufferIdx = floatBitsToUint(ld.sphereAndShadowParams.z);
    float shadowAtt = 1.0;
    if (localShadowBufferIdx != 255u)
    {
        uint shadowBufferIdx = floatBitsToUint(ld.sphereAndShadowParams.w);
        vec3 param = posWS;
        mat4 param_1 = _3112.localLightViewProjMatrices[localShadowBufferIdx];
        vec3 posLS = calcPosLS(param, param_1).xyz;
        vec3 param_2 = posWS;
        vec3 param_3 = shadowBiasNormal;
        vec3 param_4 = L;
        mat4 param_5 = _3112.localLightViewProjMatrices[localShadowBufferIdx];
        float param_6 = 2.0;
        vec2 _3480 = calcBiasedShadowUV(param_2, param_3, param_4, param_5, param_6);
        posLS = vec3(_3480.x, _3480.y, posLS.z);
        vec3 param_7 = posLS;
        uint param_8 = shadowBufferIdx;
        shadowAtt = pcf(param_7, param_8, shadowBufferTex);
    }
    float shadowFactor = ld.lightTangent.w;
    vec3 coloredAtt = mix(vec3(1.0), vec3(shadowAtt), vec3(shadowFactor));
    uint flags = (ld.lightTypeAndFlags.x >> 16u) & 65535u;
    if ((flags & 4u) > 0u)
    {
        uint _3520 = ld.lightTypeAndFlags.y + (floatBitsToUint(_3112.frameParameters0.w) * 128u);
        ExtendedLightData eld;
        eld.boxInverseWorldMatrix = _3512._extendedLightBuffer[_3520].boxInverseWorldMatrix;
        eld.viewProjectionMatrix = _3512._extendedLightBuffer[_3520].viewProjectionMatrix;
        eld.params0 = _3512._extendedLightBuffer[_3520].params0;
        eld.projectorTransform = _3512._extendedLightBuffer[_3520].projectorTransform;
        vec3 posLS_1 = (eld.viewProjectionMatrix * vec4(posWS, 1.0)).xyw;
        vec2 _3547 = posLS_1.xy / vec2(posLS_1.z);
        posLS_1 = vec3(_3547.x, _3547.y, posLS_1.z);
        vec2 _3555 = posLS_1.xy * eld.projectorTransform.xy;
        posLS_1 = vec3(_3555.x, _3555.y, posLS_1.z);
        vec2 _3570 = posLS_1.xy + ((eld.projectorTransform.zw * _3112.frameParameters0.x) * eld.projectorTransform.xy);
        posLS_1 = vec3(_3570.x, _3570.y, posLS_1.z);
        vec2 _3577 = (posLS_1.xy * 0.5) + vec2(0.5);
        posLS_1 = vec3(_3577.x, _3577.y, posLS_1.z);
        float projectorFactor = uintBitsToFloat(eld.params0.y);
        vec2 param_9 = posLS_1.xy;
        float param_10 = 0.0;
        uint param_11 = eld.params0.x;
        vec3 projAtt = mix(vec3(1.0), flrSampleLevelBindless(linearRepeatSampler, param_9, param_10, param_11).xyz, vec3(projectorFactor));
        coloredAtt *= projAtt;
    }
    return coloredAtt;
}

float smoothLine(float dist, float lineDist, float lineWidth)
{
    float lineVal = 1.0;
    lineVal *= smoothstep(lineDist - lineWidth, lineDist - (lineWidth * 0.5), dist);
    lineVal *= (1.0 - smoothstep(lineDist - (lineWidth * 0.5), lineDist, dist));
    return lineVal;
}

bool renderCustomPointLight(float dist, vec3 lightDistVec, LightData ld, LightingData d, float factor, inout vec3 outLighting)
{
    bool isEffectHeartbeatSensor = ld.lightTypeAndFlags.w == 3718345796u;
    float outerPerimeter = ld.posAndRadiusWS.w * 0.4000000059604644775390625;
    if (isEffectHeartbeatSensor && (dist > outerPerimeter))
    {
        return true;
    }
    else
    {
        if (isEffectHeartbeatSensor)
        {
            vec3 effectColor = ld.colorAndIntensity.xyz;
            vec3 color = vec3(0.0);
            float distFade = pow(1.0 - clamp(ld.posAndRadiusWS.w / 2600.0, 0.0, 1.0), 0.5) * pow(clamp((ld.posAndRadiusWS.w / 2600.0) - 0.20000000298023223876953125, 0.0, 1.0), 3.0);
            float param = dist;
            float param_1 = outerPerimeter;
            float param_2 = 5.0;
            outLighting += (((effectColor * (smoothLine(param, param_1, param_2) * 500.0)) * factor) * distFade);
            float innerPerimeter = ld.posAndRadiusWS.w * 0.100000001490116119384765625;
            float innerPerimeterRange = outerPerimeter - innerPerimeter;
            float param_3 = dist;
            float param_4 = innerPerimeter;
            float param_5 = 5.0;
            outLighting += (((effectColor * (smoothLine(param_3, param_4, param_5) * 500.0)) * factor) * distFade);
            if ((dist <= outerPerimeter) && (dist >= innerPerimeter))
            {
                float fade = pow(1.0 - min(abs(dist - (innerPerimeter + (innerPerimeterRange * 0.5))) / (innerPerimeterRange * 0.5), 1.0), 2.0) * distFade;
                fade *= pow(abs(dot(d.NVtx, vec3(0.0, 1.0, 0.0))), 5.0);
                float pulse = max(sin((dist * 0.00999999977648258209228515625) - (_3112.frameParameters0.x * 3.0)), 0.0) + 0.5;
                vec2 p = (d.posWS.xz * 0.02999999932944774627685546875) + ((normalize(lightDistVec).xz * pulse) * 0.25);
                vec4 hC = floor(vec4(p, p - vec2(0.5, 1.0)) / vec4(1.0, 1.73205077648162841796875, 1.0, 1.73205077648162841796875)) + vec4(0.5);
                vec4 h = vec4(p - (hC.xy * vec2(1.0, 1.73205077648162841796875)), p - ((hC.zw + vec2(0.5)) * vec2(1.0, 1.73205077648162841796875)));
                vec4 _3814;
                if (dot(h.xy, h.xy) < dot(h.zw, h.zw))
                {
                    _3814 = vec4(h.xy, hC.xy);
                }
                else
                {
                    _3814 = vec4(h.zw, hC.zw + vec2(9.729999542236328125));
                }
                vec4 hex = _3814;
                float hexRand = fract(sin(dot(hex.zw, vec2(141.1300048828125, 289.970001220703125))) * 43758.546875);
                float hexRandAnimated = (sin((hexRand * 6.28299999237060546875) + (_3112.frameParameters0.x * 5.0)) * 0.5) + 0.5;
                vec2 p0 = abs(hex.xy);
                float hexEdgeDist = max(dot(p0, vec2(0.5, 0.866025388240814208984375)), p0.x);
                float param_6 = hexEdgeDist;
                float param_7 = 0.5;
                float param_8 = 0.0500000007450580596923828125;
                color += ((effectColor * 100.0) * smoothLine(param_6, param_7, param_8));
                float param_9 = hexEdgeDist;
                float param_10 = 0.4000000059604644775390625;
                float param_11 = 0.0500000007450580596923828125;
                color += (vec3(1.0) * smoothLine(param_9, param_10, param_11));
                color += ((effectColor * 5.0) * (1.0 - hexEdgeDist));
                outLighting = mix(outLighting, color, vec3(((fade * pulse) * hexRandAnimated) * factor));
            }
            return true;
        }
        else
        {
            return false;
        }
    }
}

float calcDist2(vec3 lightDistVec, float biasSqr)
{
    return dot(lightDistVec, lightDistVec) + biasSqr;
}

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

float calcInverseSqrRadiusCutoff(float dist2, float radius)
{
    float rcA = 1.0 / radius;
    float param = rcA;
    float rcB = square(param) * dist2;
    float param_1 = rcB;
    float rcC = clamp(1.0 - square(param_1), 0.0, 1.0);
    float param_2 = rcC;
    return square(param_2);
}

float calcInverseSqrFalloff(inout float dist2)
{
    dist2 *= 9.9999997473787516355514526367188e-05;
    return 1.0 / (dist2 + 1.0);
}

float calculateAreaLightFalloff(vec3 lightDistVec, LightData ld, inout float NdL, vec3 N, float biasSqr)
{
    vec3 param = lightDistVec;
    float param_1 = biasSqr;
    float dist2 = calcDist2(param, param_1);
    float param_2 = dist2;
    float param_3 = ld.posAndRadiusWS.w;
    float radialCutoff = calcInverseSqrRadiusCutoff(param_2, param_3);
    float radialFalloff = 1.0;
    if (ld.sphereAndShadowParams.y > 9.9999999392252902907785028219223e-09)
    {
        vec3 L0 = ld.lightTangent.xyz * ld.sphereAndShadowParams.y;
        vec3 L1 = lightDistVec - (L0 * 0.5);
        vec3 L2 = lightDistVec + (L0 * 0.5);
        float L1Sqr = dot(L1, L1) + biasSqr;
        float L2Sqr = dot(L2, L2) + biasSqr;
        float L1RSqr = inversesqrt(L1Sqr);
        float L2RSqr = inversesqrt(L2Sqr);
        float L1Len = L1Sqr * L1RSqr;
        float L2Len = L2Sqr * L2RSqr;
        radialFalloff = 10000.0 / (((L1Len * L2Len) + dot(L1, L2)) * 0.5);
        NdL = clamp(0.5 * ((dot(N, L1) * L1RSqr) + (dot(N, L2) * L2RSqr)), 0.0, 1.0);
    }
    else
    {
        float param_4 = dist2;
        float _1923 = calcInverseSqrFalloff(param_4);
        radialFalloff = _1923;
    }
    return radialCutoff * radialFalloff;
}

void conserveEnergyTube(inout float energy, float radius, float roughness4, float NdV, float invDistToLight2)
{
    float param = radius;
    float a2 = clamp(square(param) * invDistToLight2, 0.0, 1.0);
    energy *= sqrt(roughness4 / (roughness4 + (a2 / ((NdV * 3.599999904632568359375) + 0.4000000059604644775390625))));
}

void conserveEnergySphere(inout float energy, float radius, float roughness4, float NdV, float invDistToLight2)
{
    float param = radius;
    float a2 = clamp(square(param) * invDistToLight2, 0.0, 1.0);
    energy *= (roughness4 / (roughness4 + (a2 / ((NdV * 3.599999904632568359375) + 0.4000000059604644775390625))));
}

void calculateAreaLightL(inout LightingData d, inout float sphereRadius, float tubeLength, vec3 lightTangent, inout vec3 lightDistVec)
{
    float sphereLightHack = smoothstep(0.0, 0.100000001490116119384765625, d.roughness);
    sphereRadius = mix(1.0, sphereRadius, sphereLightHack * sphereLightHack);
    float invDistToLight2 = 1.0 / dot(lightDistVec, lightDistVec);
    if (tubeLength > 9.9999999392252902907785028219223e-09)
    {
        float param = d.energyDiffuseSpecular.y;
        float param_1 = tubeLength * 0.5;
        float param_2 = d.roughness4;
        float param_3 = d.NdV;
        float param_4 = invDistToLight2;
        conserveEnergyTube(param, param_1, param_2, param_3, param_4);
        d.energyDiffuseSpecular.y = param;
        vec3 L0 = lightTangent * tubeLength;
        vec3 L1 = lightDistVec - (L0 * 0.5);
        float param_5 = tubeLength;
        float len2 = square(param_5);
        float b = dot(d.R, L0);
        float param_6 = b;
        float b2 = square(param_6);
        float t = clamp(dot(L1, (d.R * b) - L0) / (len2 - b2), 0.0, 1.0);
        lightDistVec = L1 + (L0 * t);
    }
    float param_7 = d.energyDiffuseSpecular.y;
    float param_8 = sphereRadius;
    float param_9 = d.roughness4;
    float param_10 = d.NdV;
    float param_11 = invDistToLight2;
    conserveEnergySphere(param_7, param_8, param_9, param_10, param_11);
    d.energyDiffuseSpecular.y = param_7;
    vec3 closestPointRay = d.R * dot(lightDistVec, d.R);
    vec3 centerToRay = closestPointRay - lightDistVec;
    lightDistVec += (centerToRay * clamp(sphereRadius * inversesqrt(dot(centerToRay, centerToRay)), 0.0, 1.0));
    d.L = normalize(lightDistVec);
}

vec3 calcSpecular(LightingData d)
{
    LightingData param = d;
    float param_1 = d.roughness2;
    float param_2 = d.roughness4;
    return calcSpecular(param, param_1, param_2);
}

void calcLighting(LightingData d, out vec3 diffuse, out vec3 specular)
{
    LightingData param = d;
    diffuse = calcDiffuse(param);
    LightingData param_1 = d;
    specular = calcSpecular(param_1);
}

void calcPointLightLighting(LightData ld, inout LightingData d, inout vec3 outLighting0, inout vec3 outLighting1, vec4 diffuseSpecularWeights, vec3 shadowAttenuation)
{
    vec3 lightDistVec = ld.posAndRadiusWS.xyz - d.posWS;
    d.L = normalize(lightDistVec);
    d.NdL = dot(d.N, d.L);
    float sphereRadius = ld.sphereAndShadowParams.x;
    float tubeLength = ld.sphereAndShadowParams.y;
    vec3 attenuation = vec3(1.0);
    if ((((ld.lightTypeAndFlags.x >> 16u) & 65535u) & 1u) == 0u)
    {
        vec3 param = lightDistVec;
        LightData param_1 = ld;
        float param_2 = d.NdL;
        vec3 param_3 = d.N;
        float param_4 = 0.0;
        float _2394 = calculateAreaLightFalloff(param, param_1, param_2, param_3, param_4);
        d.NdL = param_2;
        attenuation = vec3(_2394);
    }
    else
    {
        LightData param_5 = ld;
        vec3 param_6 = lightDistVec;
        attenuation = vec3(calcExponentialFalloff(param_5, param_6));
    }
    attenuation *= ld.colorAndIntensity.xyz;
    if (any(greaterThan(attenuation, vec3(9.9999999392252902907785028219223e-09))))
    {
        d.energyDiffuseSpecular = ld.colorAndIntensity.ww;
        LightingData param_7 = d;
        float param_8 = sphereRadius;
        float param_9 = tubeLength;
        vec3 param_10 = ld.lightTangent.xyz;
        vec3 param_11 = lightDistVec;
        calculateAreaLightL(param_7, param_8, param_9, param_10, param_11);
        d = param_7;
        lightDistVec = param_11;
        LightingData param_12 = d;
        calculateLightingData(param_12);
        d = param_12;
        vec3 lightDiffuse = vec3(0.0);
        vec3 lightSpecular = vec3(0.0);
        if (d.NdL > 0.0)
        {
            LightingData param_13 = d;
            vec3 param_14;
            vec3 param_15;
            calcLighting(param_13, param_14, param_15);
            lightDiffuse = param_14;
            lightSpecular = param_15;
            float param_16 = d.ambientOcclusion;
            vec3 param_17 = d.baseColor;
            float param_18 = 0.85000002384185791015625;
            lightDiffuse *= (shadowAttenuation * calcDiffuseOcclusionDirectLighting(param_16, param_17, param_18));
            lightSpecular *= shadowAttenuation;
        }
        else
        {
            vec3 param_19 = lightDiffuse;
            LightingData param_20 = d;
            applyTranslucentLighting(param_19, param_20);
            lightDiffuse = param_19;
            lightDiffuse *= 0.100000001490116119384765625;
        }
        lightDiffuse *= attenuation;
        lightSpecular *= attenuation;
        outLighting0 += ((lightDiffuse * diffuseSpecularWeights.x) + (lightSpecular * diffuseSpecularWeights.y));
        outLighting1 += ((lightDiffuse * diffuseSpecularWeights.z) + (lightSpecular * diffuseSpecularWeights.w));
    }
}

float calcSpotLightAttenuation(LightData ld, vec3 L)
{
    float att = clamp((dot(L, -ld.lightDirectionAndFalloffExp.xyz) - ld.spotLightAngles.x) * ld.spotLightAngles.y, 0.0, 1.0);
    float param = att;
    return square(param);
}

void calcSpotLightLighting(LightData ld, inout LightingData d, inout vec3 outLighting0, inout vec3 outLighting1, vec4 diffuseSpecularWeights, vec3 factor)
{
    LightData param = ld;
    vec3 param_1 = d.L;
    vec3 spotAtt = factor * calcSpotLightAttenuation(param, param_1);
    if (any(greaterThan(spotAtt, vec3(9.9999999392252902907785028219223e-09))))
    {
        LightData param_2 = ld;
        LightingData param_3 = d;
        vec3 param_4 = outLighting0;
        vec3 param_5 = outLighting1;
        vec4 param_6 = diffuseSpecularWeights;
        vec3 param_7 = spotAtt;
        calcPointLightLighting(param_2, param_3, param_4, param_5, param_6, param_7);
        d = param_3;
        outLighting0 = param_4;
        outLighting1 = param_5;
    }
}

float calcExponentialFalloff(LightData ld, float _distance)
{
    float d2 = _distance * _distance;
    return pow(abs(1.0 - clamp(d2, 0.0, 1.0)), ld.lightDirectionAndFalloffExp.w);
}

float calcBoxLightAttenuation(vec3 posWS, LightData ld, ExtendedLightData eld)
{
    vec3 posBS = (eld.boxInverseWorldMatrix * vec4(posWS, 1.0)).xyz;
    float ret = 0.0;
    bool _2549 = all(lessThanEqual(posBS, vec3(1.0)));
    bool _2556;
    if (_2549)
    {
        _2556 = all(greaterThanEqual(posBS, vec3(-1.0)));
    }
    else
    {
        _2556 = _2549;
    }
    if (_2556)
    {
        vec2 a = vec2(1.0) - (clamp(abs(posBS.xz) - vec2(0.800000011920928955078125), vec2(0.0), vec2(1.0)) / vec2(0.20000000298023223876953125));
        ret = min(a.x, a.y);
        LightData param = ld;
        float param_1 = (posBS.y * 0.5) + 0.5;
        ret *= calcExponentialFalloff(param, param_1);
    }
    return ret;
}

void calcLocalLightLighting(LightData ld, inout LightingData d, inout vec3 outLighting0, inout vec3 outLighting1, vec4 diffuseSpecularWeights, inout vec3 factor)
{
    vec3 lightDistVec = ld.posAndRadiusWS.xyz - d.posWS;
    float dist = length(lightDistVec);
    d.L = lightDistVec / vec3(dist);
    uint lightType = ld.lightTypeAndFlags.x & 65535u;
    if ((lightType == 2u) || (lightType == 1u))
    {
        LightData param = ld;
        vec3 param_1 = d.posWS;
        vec3 param_2 = d.NVtx;
        vec3 _3950 = calcLocalLightShadowAttenuation(param, param_1, param_2);
        factor *= _3950;
    }
    vec3 param_3 = d.L;
    vec3 param_4 = d.NVtx;
    vec3 param_5 = d.posWS;
    float param_6 = dist;
    factor *= calcDistanceFieldShadowing(param_3, param_4, param_5, param_6);
    vec3 lightingDiffuse = vec3(0.0);
    vec3 lightingSpecular = vec3(0.0);
    if (lightType == 0u)
    {
        float param_7 = dist;
        vec3 param_8 = lightDistVec;
        LightData param_9 = ld;
        LightingData param_10 = d;
        float param_11 = 1.0;
        vec3 param_12 = outLighting0;
        bool _3984 = renderCustomPointLight(param_7, param_8, param_9, param_10, param_11, param_12);
        outLighting0 = param_12;
        if (_3984)
        {
            return;
        }
        LightData param_13 = ld;
        LightingData param_14 = d;
        vec3 param_15 = lightingDiffuse;
        vec3 param_16 = lightingSpecular;
        vec4 param_17 = diffuseSpecularWeights;
        vec3 param_18 = factor;
        calcPointLightLighting(param_13, param_14, param_15, param_16, param_17, param_18);
        d = param_14;
        lightingDiffuse = param_15;
        lightingSpecular = param_16;
        outLighting0 += lightingDiffuse;
        outLighting1 += lightingSpecular;
    }
    else
    {
        if (lightType == 1u)
        {
            float cutoff = clamp(max(dist - ld.spotLightAngles.w, 0.0) / ld.spotLightAngles.w, 0.0, 1.0);
            LightData param_19 = ld;
            LightingData param_20 = d;
            vec3 param_21 = lightingDiffuse;
            vec3 param_22 = lightingSpecular;
            vec4 param_23 = diffuseSpecularWeights;
            vec3 param_24 = factor * cutoff;
            calcSpotLightLighting(param_19, param_20, param_21, param_22, param_23, param_24);
            d = param_20;
            lightingDiffuse = param_21;
            lightingSpecular = param_22;
            outLighting0 += lightingDiffuse;
            outLighting1 += lightingSpecular;
        }
        else
        {
            if (lightType == 2u)
            {
                uint _4062 = ld.lightTypeAndFlags.y + (floatBitsToUint(_3112.frameParameters0.w) * 128u);
                ExtendedLightData eld;
                eld.boxInverseWorldMatrix = _3512._extendedLightBuffer[_4062].boxInverseWorldMatrix;
                eld.viewProjectionMatrix = _3512._extendedLightBuffer[_4062].viewProjectionMatrix;
                eld.params0 = _3512._extendedLightBuffer[_4062].params0;
                eld.projectorTransform = _3512._extendedLightBuffer[_4062].projectorTransform;
                vec3 param_25 = d.posWS;
                LightData param_26 = ld;
                ExtendedLightData param_27 = eld;
                vec3 att = factor * calcBoxLightAttenuation(param_25, param_26, param_27);
                if (any(greaterThan(att, vec3(9.9999999392252902907785028219223e-09))))
                {
                    LightingData param_28 = d;
                    float param_29 = ld.colorAndIntensity.w;
                    vec3 param_30 = ld.colorAndIntensity.xyz;
                    vec3 param_31 = -ld.lightDirectionAndFalloffExp.xyz;
                    vec3 param_32 = outLighting0;
                    vec3 param_33 = outLighting1;
                    vec4 param_34 = diffuseSpecularWeights;
                    vec3 param_35 = att;
                    calcDirLightLighting(param_28, param_29, param_30, param_31, param_32, param_33, param_34, param_35);
                    d = param_28;
                    outLighting0 = param_32;
                    outLighting1 = param_33;
                }
            }
        }
    }
}

float colormapRed(float x)
{
    if (x < 0.75)
    {
        return (1012.0 * x) - 389.0;
    }
    else
    {
        return ((-1113.2276611328125) * x) + 1244.6119384765625;
    }
}

float colormapGreen(float x)
{
    if (x < 0.5)
    {
        return (1012.0 * x) - 129.0;
    }
    else
    {
        return ((-1012.0) * x) + 899.0;
    }
}

float colormapBlue(float x)
{
    if (x < 0.25)
    {
        return (1012.0 * x) + 131.0;
    }
    else
    {
        return ((-1012.0) * x) + 643.0;
    }
}

vec4 colormap(float x)
{
    float param = x;
    float r = clamp(colormapRed(param) / 255.0, 0.0, 1.0);
    float param_1 = x;
    float g = clamp(colormapGreen(param_1) / 255.0, 0.0, 1.0);
    float param_2 = x;
    float b = clamp(colormapBlue(param_2) / 255.0, 0.0, 1.0);
    return vec4(r, g, b, 1.0);
}

void calcLightingAll(inout LightingData d, inout vec3 outLighting0, inout vec3 outLighting1)
{
    vec3 param = d.posVS;
    vec2 param_1 = _3112.nearFar.xy;
    vec4 param_2 = _3112.nearFarWidthHeight;
    uvec3 clusterGridPos = calcGridPosForViewPos(param, param_1, param_2);
    uvec3 param_3 = clusterGridPos;
    uint clusterIdxNonUniform = calcClusterIndex(param_3);
    vec3 param_4 = d.posWS;
    vec3 param_5 = d.NVtx;
    vec3 param_6 = d.N;
    vec3 param_7;
    calcIrradiance(param_4, param_5, param_6, param_7);
    d.irradiance = param_7;
    vec3 irrad = d.irradiance;
    float ao = min(d.occlusion, d.ambientOcclusion);
    float param_8 = ao;
    vec3 param_9 = d.baseColor;
    irrad *= calcAOMultiBounce(param_8, param_9);
    d.baseColor = mix(vec3(0.5), d.baseColor, vec3(d.lightingWeights1.z));
    LightingData param_10 = d;
    initLightingDataFromGBuffer(param_10);
    d = param_10;
    LightingData param_11 = d;
    calculateLightingDataBase(param_11);
    d = param_11;
    irrad *= ((d.diffuseColor * 0.3183098733425140380859375) * _3112.lightingWeights0.z);
    vec3 specular = vec3(0.0);
    vec3 specularIrrad = vec3(0.0);
    float param_12 = d.roughness;
    float specMipIdx = roughnessToMipIdx(param_12);
    vec3 param_13 = d.specularColor;
    float param_14 = d.roughness;
    float param_15 = d.NdV;
    vec3 envBRDF = envBRDFApprox(param_13, param_14, param_15);
    float totalWeight = 0.0;
    uint clusterIdx = clusterIdxNonUniform;
    uint specularProbeCount = (_4722._resourceIndexBuffer[(clusterIdx + 1u) + (floatBitsToUint(_3112.frameParameters0.w) * 599040u)] >> uint(16)) & 65535u;
    SpecularProbeData sd;
    for (uint i = 0u; i < specularProbeCount; i++)
    {
        uint specularProbeIndex = (_4722._resourceIndexBuffer[(((clusterIdx + (i * 3u)) + 3u) + 1u) + (floatBitsToUint(_3112.frameParameters0.w) * 599040u)] >> uint(16)) & 65535u;
        uint _4771 = specularProbeIndex + (floatBitsToUint(_3112.frameParameters0.w) * 32u);
        sd.posAndRadiusWS = _4765._specularProbeBuffer[_4771].posAndRadiusWS;
        sd.worldMatrix = _4765._specularProbeBuffer[_4771].worldMatrix;
        sd.inverseWorldMatrix = _4765._specularProbeBuffer[_4771].inverseWorldMatrix;
        sd.imageIdAndFlags = _4765._specularProbeBuffer[_4771].imageIdAndFlags;
        sd.params0 = _4765._specularProbeBuffer[_4771].params0;
        sd.params1 = _4765._specularProbeBuffer[_4771].params1;
        SpecularProbeData param_16 = sd;
        vec3 param_17 = d.posWS;
        vec3 param_17a = d.posWSa;
        vec3 param_18 = d.cameraPosWS;
        vec3 param_19 = d.N;
        vec3 param_20 = d.R;
        float param_21 = specMipIdx;
        vec3 param_22 = envBRDF;
        vec3 param_23 = specular;
        vec3 param_24 = specularIrrad;
        float param_25 = totalWeight;
        calcLocalSpecular(param_16, param_17, param_17a, param_18, param_19, param_20, param_21, param_22, param_23, param_24, param_25);
        specular = param_23;
        specularIrrad = param_24;
        totalWeight = param_25;
    }
    if (totalWeight < 0.9900000095367431640625)
    {
        uint defaultSpecularId = 7u;
        defaultSpecularId++;
        vec3 param_26 = d.R;
        float param_27 = specMipIdx;
        uint param_28 = defaultSpecularId;
        vec3 specSample = flrSampleLevelBindlessCube(linearClampSampler, param_26, param_27, param_28).xyz;
        specular = mix(specSample * envBRDF, specular, vec3(totalWeight));
    }
    vec3 param_29 = d.specularColor;
    float param_30 = d.roughness;
    float param_31 = d.NdV;
    vec3 ssr = d.ssrSample.xyz * envBRDFApprox(param_29, param_30, param_31);
    specular = mix(specular, ssr, vec3(d.ssrSample.w));
    uint clusterIdx_1 = clusterIdxNonUniform;
    uint lightCount = (_4722._resourceIndexBuffer[(clusterIdx_1 + 2u) + (floatBitsToUint(_3112.frameParameters0.w) * 599040u)] >> uint(16)) & 65535u;
    LightData ld;
    vec3 _4991;
    vec3 _4997;
    for (uint i_1 = 0u; i_1 < lightCount; i_1++)
    {
        uint lightIndex = (_4722._resourceIndexBuffer[(((clusterIdx_1 + (i_1 * 3u)) + 3u) + 2u) + (floatBitsToUint(_3112.frameParameters0.w) * 599040u)] >> uint(16)) & 65535u;
        uint _4913 = lightIndex + (floatBitsToUint(_3112.frameParameters0.w) * 128u);
        ld.posAndRadiusWS = _4907._lightBuffer[_4913].posAndRadiusWS;
        ld.colorAndIntensity = _4907._lightBuffer[_4913].colorAndIntensity;
        ld.lightDirectionAndFalloffExp = _4907._lightBuffer[_4913].lightDirectionAndFalloffExp;
        ld.lightTangent = _4907._lightBuffer[_4913].lightTangent;
        ld.lightTypeAndFlags = _4907._lightBuffer[_4913].lightTypeAndFlags;
        ld.spotLightAngles = _4907._lightBuffer[_4913].spotLightAngles;
        ld.sphereAndShadowParams = _4907._lightBuffer[_4913].sphereAndShadowParams;
        uint lightType = ld.lightTypeAndFlags.x & 65535u;
        float falloffStartDistance = uintBitsToFloat(ld.lightTypeAndFlags.z);
        vec3 lightDistVec = ld.posAndRadiusWS.xyz - d.posWS;
        float distToLight = length(lightDistVec);
        vec3 lightVec = lightDistVec / vec3(distToLight);
        lightDistVec = lightVec * max(distToLight - falloffStartDistance, 0.0);
        ld.posAndRadiusWS.w -= falloffStartDistance;
        bool applyToAll = lightType == 5u;
        LightData param_32 = ld;
        vec3 param_33 = lightDistVec;
        float falloff = calcExponentialFalloff(param_32, param_33);
        vec3 _mod = mix(vec3(1.0), ld.colorAndIntensity.xyz * ld.colorAndIntensity.w, vec3(falloff * d.lightingWeights1.x));
        if (applyToAll || (lightType == 3u))
        {
            if (ld.colorAndIntensity.w < 1.0)
            {
                vec3 param_34 = _mod;
                vec3 param_35 = d.baseColor;
                _4997 = calcAOMultiBounce(param_34, param_35);
            }
            else
            {
                _4997 = _mod;
            }
            _4991 = _4997;
        }
        else
        {
            _4991 = vec3(1.0);
        }
        irrad *= _4991;
        specular *= mix(vec3(1.0), _mod, bvec3(applyToAll || (lightType == 4u)));
    }
    float param_36 = d.ambientOcclusion;
    float param_37 = d.NdV;
    float param_38 = d.roughness;
    specular *= calcSpecularOcclusionFromAo(param_36, param_37, param_38);
    specular *= _3112.lightingWeights0.w;
    outLighting0 = (irrad * 1.0) + (specular * 0.0);
    outLighting1 = (irrad * 0.0) + (specular * 1.0);
    if (_3112.dirLightColorAndIntens.w > 9.9999999392252902907785028219223e-09)
    {
        vec3 shadowBiasNormal = d.NVtx;
        float shadowFactor = _3112.dirLightDirWS.w;
        vec3 param_39 = d.posWS;
        vec3 param_40 = shadowBiasNormal;
        vec3 param_41 = _3112.dirLightDirWS.xyz;
        float param_42 = shadowFactor;
        float _5073 = calcDirShadowAttenuation(param_39, param_40, param_41, param_42);
        vec3 param_43 = d.posWS;
        vec3 dirLightAttenuation = vec3(_5073) * calcDirProjectorAttenuation(param_43);
        vec3 param_44 = _3112.dirLightDirWS.xyz;
        vec3 param_45 = d.NVtx;
        vec3 param_46 = d.posWS;
        float param_47 = 50000.0;
        dirLightAttenuation *= calcDistanceFieldShadowing(param_44, param_45, param_46, param_47);
        if (any(greaterThan(dirLightAttenuation, vec3(9.9999999392252902907785028219223e-09))))
        {
            LightingData param_48 = d;
            float param_49 = _3112.dirLightColorAndIntens.w;
            vec3 param_50 = _3112.dirLightColorAndIntens.xyz;
            vec3 param_51 = _3112.dirLightDirWS.xyz;
            vec3 param_52 = outLighting0;
            vec3 param_53 = outLighting1;
            vec4 param_54 = vec4(1.0, 0.0, 0.0, 1.0);
            vec3 param_55 = dirLightAttenuation;
            calcDirLightLighting(param_48, param_49, param_50, param_51, param_52, param_53, param_54, param_55);
            d = param_48;
            outLighting0 = param_52;
            outLighting1 = param_53;
        }
    }
    uint clusterIdx_2 = clusterIdxNonUniform;
    uint lightCount_1 = _4722._resourceIndexBuffer[clusterIdx_2 + (floatBitsToUint(_3112.frameParameters0.w) * 599040u)] & 65535u;
    LightData ld_1;
    for (uint i_2 = 0u; i_2 < lightCount_1; i_2++)
    {
        uint lightIndex_1 = _4722._resourceIndexBuffer[((clusterIdx_2 + (i_2 * 3u)) + 3u) + (floatBitsToUint(_3112.frameParameters0.w) * 599040u)] & 65535u;
        uint _5166 = lightIndex_1 + (floatBitsToUint(_3112.frameParameters0.w) * 128u);
        ld_1.posAndRadiusWS = _4907._lightBuffer[_5166].posAndRadiusWS;
        ld_1.colorAndIntensity = _4907._lightBuffer[_5166].colorAndIntensity;
        ld_1.lightDirectionAndFalloffExp = _4907._lightBuffer[_5166].lightDirectionAndFalloffExp;
        ld_1.lightTangent = _4907._lightBuffer[_5166].lightTangent;
        ld_1.lightTypeAndFlags = _4907._lightBuffer[_5166].lightTypeAndFlags;
        ld_1.spotLightAngles = _4907._lightBuffer[_5166].spotLightAngles;
        ld_1.sphereAndShadowParams = _4907._lightBuffer[_5166].sphereAndShadowParams;
        LightData param_56 = ld_1;
        LightingData param_57 = d;
        vec3 param_58 = outLighting0;
        vec3 param_59 = outLighting1;
        vec4 param_60 = vec4(1.0, 0.0, 0.0, 1.0);
        vec3 param_61 = vec3(1.0);
        calcLocalLightLighting(param_56, param_57, param_58, param_59, param_60, param_61);
        outLighting0 = param_58;
        outLighting1 = param_59;
    }
    outLighting0 += d.emissive;
    uint clusterIdx_3 = clusterIdxNonUniform;
    uint debugMode = floatBitsToUint(d.lightingWeights1.w);
    if (debugMode > 0u)
    {
        uint resourceOffset = debugMode - 1u;
        uint resourceCount = (_4722._resourceIndexBuffer[(clusterIdx_3 + (resourceOffset / 2u)) + (floatBitsToUint(_3112.frameParameters0.w) * 599040u)] >> uint(((resourceOffset % 2u) == 0u) ? 0 : 16)) & 65535u;
        if (resourceCount > 0u)
        {
            float param_62 = clamp(float(resourceCount) / 6.0, 0.0, 1.0);
            vec3 color = colormap(param_62).xyz;
            float maxResourceCountImportance = clamp(float(max((int(resourceCount) - 6), 0)) / 6.0, 0.0, 1.0);
            outLighting0 = mix(outLighting0, mix(color, vec3(1.0, 0.0, 1.0), vec3(maxResourceCountImportance)), vec3(0.5));
        }
    }
    vec3 _5266;
    if (false == all(equal(outLighting0, outLighting0)))
    {
        _5266 = vec3(1.0, 0.0, 0.0);
    }
    else
    {
        _5266 = outLighting0;
    }
    outLighting0 = _5266;
    vec3 _5278;
    if (false == all(equal(outLighting1, outLighting1)))
    {
        _5278 = vec3(1.0, 0.0, 0.0);
    }
    else
    {
        _5278 = outLighting1;
    }
    outLighting1 = _5278;
}

float deviceDepthToLinear(float deviceDepth, float near, float far)
{
    return -((far * near) / ((deviceDepth * (far - near)) + near));
}

float nativeDepthToVolumeZ(float depth, float invDepthExp, float depthRange, vec2 nearFar)
{
    float param = depth;
    float param_1 = nearFar.x;
    float param_2 = nearFar.y;
    float depthLinear = -deviceDepthToLinear(param, param_1, param_2);
    return pow(clamp((depthLinear - nearFar.x) / depthRange, 0.0, 1.0) + 9.9999999392252902907785028219223e-09, invDepthExp);
}

vec3 cellCenterSSToUVW(inout vec3 cellCenter, float invDepthExp, float depthRange, vec2 nearFar)
{
    float param = cellCenter.z;
    float param_1 = invDepthExp;
    float param_2 = depthRange;
    vec2 param_3 = nearFar;
    cellCenter.z = nativeDepthToVolumeZ(param, param_1, param_2, param_3);
    return cellCenter;
}

float encodeMaterialId(uint materialID)
{
    return unpackSnorm2x16(materialID).x;
}

float packUInt16(uint i)
{
    return 1.52587890625e-05 * float(i);
}

void main()
{
    bool _5685;
    if (!gl_FrontFacing)
    {
        _5685 = (_5289.paramIntData0.x & 2u) == 0u;
    }
    else
    {
        _5685 = gl_FrontFacing;
    }
    float normalSign = _5685 ? 1.0 : (-1.0);
    FlrInput flrInput;
    flrInput.uv0 = inUV0;
    flrInput.normal = inNormal * normalSign;
    flrInput.tangent = inTangent * normalSign;
    flrInput.binormal = inBinormal * normalSign;
    flrInput.color = vec4(1.0);
    flrInput.pos = inPosition;
    flrInput.prevPos = inPrevPosition;
    flrInput.posWS = inPosWS;
    FlrInput param = flrInput;
    FlrOutput param_1;
    flrMain(param, param_1);
    FlrOutput flrOutput = param_1;
    LightingDataDesc desc;
    desc.baseColor = flrOutput.albedo.xyz;
    desc.roughness = flrOutput.parameter.x;
    desc.metalness = flrOutput.parameter.y;
    desc.occlusion = flrOutput.parameter.z;
    desc.translucency = flrOutput.parameter.w;
    desc.materialBlendMask = vec4(0.0);
    desc.lightingWeights0 = _3112.lightingWeights0;
    desc.lightingWeights1 = _3112.lightingWeights1;
    desc.cameraPosWS = _3112.cameraPositionWS.xyz;
    desc.posWS = inPosWS;
    
    //Fix here.
    vec3 posWSa = inPosWS;
    if (vk3d_params.custom_params.x!=1) {
        posWSa.x -= vk3d_params.stereo.x * vk3d_params.stereo.y*_3112.viewMatrix[0].x*_3112.invProjMatrix[0].x;
        posWSa.y -= vk3d_params.stereo.x * vk3d_params.stereo.y*_3112.viewMatrix[1].x*_3112.invProjMatrix[0].x;
        posWSa.z -= vk3d_params.stereo.x * vk3d_params.stereo.y*_3112.viewMatrix[2].x*_3112.invProjMatrix[0].x;
    }
    desc.posWSa = posWSa;
    
    desc.posVS = (_3112.viewMatrix * vec4(inPosWS, 1.0)).xyz;
    vec2 param_2 = flrOutput.normals.zw;
    desc.NVtx = decodeNormal(param_2);
    vec2 param_3 = flrOutput.normals.xy;
    desc.N = decodeNormal(param_3);
    desc.ambientOcclusion = 1.0;
    desc.emissive = vec3(0.0);
    desc.irradiance = vec3(0.0);
    desc.materialId = _5328.params0.w;
    uint _5790 = desc.materialId;
    uint _5792 = clamp(_5790, 0u, 4096u);
    desc.materialData.paramIntData0 = _5788._materialDataBuffer[_5792].paramIntData0;
    desc.materialData.paramFloatData0 = _5788._materialDataBuffer[_5792].paramFloatData0;
    desc.materialData.paramFloatData1 = _5788._materialDataBuffer[_5792].paramFloatData1;
    desc.materialData.paramFloatData2 = _5788._materialDataBuffer[_5792].paramFloatData2;
    desc.materialData.paramFloatData3 = _5788._materialDataBuffer[_5792].paramFloatData3;
    desc.materialData.paramFloatData4 = _5788._materialDataBuffer[_5792].paramFloatData4;
    desc.materialData.paramFloatData5 = _5788._materialDataBuffer[_5792].paramFloatData5;
    desc.materialData.paramFloatData6 = _5788._materialDataBuffer[_5792].paramFloatData6;
    desc.materialData.paramFloatData7 = _5788._materialDataBuffer[_5792].paramFloatData7;
    desc.materialData.paramFloatData8 = _5788._materialDataBuffer[_5792].paramFloatData8;
    desc.materialData.paramFloatData9 = _5788._materialDataBuffer[_5792].paramFloatData9;
    desc.materialData.paramImgIDs0 = _5788._materialDataBuffer[_5792].paramImgIDs0;
    desc.materialData.paramImgIDs1 = _5788._materialDataBuffer[_5792].paramImgIDs1;
    desc.materialData.paramImgIDs2 = _5788._materialDataBuffer[_5792].paramImgIDs2;
    desc.materialBlendMask = vec4(1.0);
    LightingData d;
    LightingData param_4 = d;
    LightingDataDesc param_5 = desc;
    initLightingData(param_4, param_5);
    d = param_4;
    desc = param_5;
    d.T = inTangent.xyz;
    d.posWSneighborX = inPosWS + dFdx(inPosWS);
    d.posWSneighborY = inPosWS + dFdy(inPosWS);
    d.time = _3112.frameParameters0.x;
    d.depthFixup = 1.0;
    LightingData param_6 = d;
    vec3 param_7;
    vec3 param_8;
    calcLightingAll(param_6, param_7, param_8);
    d = param_6;
    vec3 outLighting0 = param_7;
    vec3 outLighting1 = param_8;
    float opacity = _5289.paramData3.x;
    float fadeFactor = _5289.paramData3.y;
    float refractionNormalScale = _5289.paramData3.z;
    vec3 screenSpacePos = inPosition.xyz / vec3(inPosition.w);
    vec2 screenUV = (screenSpacePos.xy * 0.5) + vec2(0.5);
    float finalFadeFactor = fadeFactor * _5328.materialParams0.x;
    float finalOpacity = flrOutput.albedo.w * opacity;
    vec3 _5900 = (outLighting0 + outLighting1) * finalOpacity;
    outColor = vec4(_5900.x, _5900.y, _5900.z, outColor.w);
    finalFadeFactor *= finalOpacity;
    vec3 param_9 = vec3(screenUV, screenSpacePos.z);
    float param_10 = _3112.volumetricsParams2.y;
    float param_11 = _3112.volumetricsParams2.z;
    vec2 param_12 = _3112.nearFar.xy;
    
    //Fix here. No convergence scaling for volumetric.
    param_9.x -= vk3d_params.stereo.x *(1-vk3d_params.stereo.y*param_9.z*0.0)*0.5;
    
    vec3 _5924 = cellCenterSSToUVW(param_9, param_10, param_11, param_12);
    vec3 scatteringUVW = _5924;
    vec4 volSample = textureLod(scatterBufferTex, scatteringUVW, 0.0);
    vec3 _5940 = mix(volSample.xyz, outColor.xyz, vec3(volSample.w));
    outColor = vec4(_5940.x, _5940.y, _5940.z, outColor.w);
    outColor.w = finalFadeFactor;
    flrOutput.miscParams0 = 16962u;
    outMotionVector = vec4(flrOutput.motionVector.x, flrOutput.motionVector.y, outMotionVector.z, outMotionVector.w);
    uint param_13 = flrOutput.materialId;
    outMotionVector.z = encodeMaterialId(param_13);
    uint param_14 = flrOutput.miscParams0;
    outMotionVector.w = packUInt16(param_14);
}



