//Lighting PS 1.
#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 posVS;
    vec3 posWSa;
    vec3 posVSa;
    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 posVS;
    vec3 posWSa;
    vec3 posVSa;
    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 DecalData
{
    mat4 viewMatrix;
    mat4 viewProjMatrix;
    uvec4 decalIntParams0;
    vec4 decalOpacityParams;
    vec4 decalUVScaleOffset;
    vec4 decalMaskUVScaleOffset;
    vec4 decalParams0;
    vec4 decalParams1;
    vec4 decalParams2;
    vec4 decalNormal;
    vec4 decalTangent;
};

struct DecalDataComputed
{
    vec4 decalPos;
    vec2 decalUV;
    vec4 decalUVdxdy;
    uint decalMaskChannelIdx;
    uint blendMaskChannelIdx;
    uint decalFeatures;
    uint decalGroupMask;
};

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

struct FlrInput
{
    vec2 uv0;
};

struct FlrOutput
{
    vec4 hdrColor;
};

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

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

// 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 = 0, 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;
} _3942;

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

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

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

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

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

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

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

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

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 = 6) uniform sampler2DArrayShadow shadowBufferTex;
layout(set = 1, binding = 0) uniform sampler linearClampSampler;
layout(set = 0, binding = 1) uniform sampler2D albedoTex;
layout(set = 0, binding = 4) uniform sampler2D depthBufferTex;
layout(set = 0, binding = 7) uniform sampler2D materialBlendMaskTex;
layout(set = 0, binding = 8) uniform sampler2D motionVectorsTex;
layout(set = 0, binding = 2) uniform sampler2D normalsTex;
layout(set = 0, binding = 3) uniform sampler2D parameterTex;
layout(set = 0, binding = 5) uniform sampler2D ssaoTex;
layout(set = 0, binding = 9) uniform sampler2D irradianceTex;
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 = 18) uniform sampler2D ssrTex;
layout(set = 0, binding = 19) uniform sampler2D depthBufferHalfTex;
layout(set = 0, binding = 20) uniform sampler2D depthBufferQuarterTex;
layout(set = 0, binding = 21) uniform sampler3D distanceFieldTex;

layout(location = 0) in vec2 inUV0;
layout(location = 0) out vec4 outHdrColor;

float _937;
float _954;
float _971;
bool _4744;

uint decodeMaterialId(float source)
{
    return packSnorm2x16(vec2(source, 0.0));
}

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

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 _653 = (vec2(1.0) - abs(v.yx)) * signNotZero(param);
        v = vec3(_653.x, _653.y, v.z);
    }
    return normalize(v);
}

vec3 unproject(vec2 uv0, float depth, mat4 invProjMatrix)
{
    vec4 unprojPos = invProjMatrix * vec4((uv0 * 2.0) - vec2(1.0), depth, 1.0);
    return unprojPos.xyz / unprojPos.www;
}

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.posVS = desc.posVS;
    d.posWSa = desc.posWSa;
    d.posVSa = desc.posVSa;
    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;
}

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 updateDecalDataComputed(LightingData d, DecalData dd, inout DecalDataComputed ddComputed)
{
    
    ddComputed.decalPos = dd.viewProjMatrix * vec4(d.posWS, 1.0);
    ddComputed.decalUV = (ddComputed.decalPos.xy * 0.5) + vec2(0.5);
    vec3 decalPosNeighborX = (dd.viewProjMatrix * vec4(d.posWSneighborX, 1.0)).xyz;
    vec2 _3807 = ((decalPosNeighborX.xy * 0.5) + vec2(0.5)) - ddComputed.decalUV;
    ddComputed.decalUVdxdy = vec4(_3807.x, _3807.y, ddComputed.decalUVdxdy.z, ddComputed.decalUVdxdy.w);
    vec3 decalPosNeighborY = (dd.viewProjMatrix * vec4(d.posWSneighborY, 1.0)).xyz;
    vec2 _3829 = ((decalPosNeighborY.xy * 0.5) + vec2(0.5)) - ddComputed.decalUV;
    ddComputed.decalUVdxdy = vec4(ddComputed.decalUVdxdy.x, ddComputed.decalUVdxdy.y, _3829.x, _3829.y);
    vec2 decalScale = dd.decalUVScaleOffset.xy * vec2(d.depthFixup);
    ddComputed.decalUVdxdy *= decalScale.xxyy;
    uint packedParams = dd.decalIntParams0.x;
    ddComputed.decalMaskChannelIdx = clamp((packedParams & 4278190080u) >> uint(24), 0u, 3u);
    ddComputed.blendMaskChannelIdx = clamp((packedParams & 16711680u) >> uint(16), 0u, 3u);
    ddComputed.decalFeatures = (packedParams & 65280u) >> uint(8);
    ddComputed.decalGroupMask = packedParams & 255u;
}

float computeDecalBlendFactor(LightingData d, DecalData dd, DecalDataComputed ddComputed)
{
    uint materialDecalGroupMask = d.materialData.paramIntData0.z;
    float decalBlendFactor = 0.0;
    bool _3643 = all(lessThanEqual(ddComputed.decalPos.xyz, vec3(1.0)));
    bool _3652;
    if (_3643)
    {
        _3652 = all(greaterThanEqual(ddComputed.decalPos.xyz, vec3(-1.0, -1.0, 0.0)));
    }
    else
    {
        _3652 = _3643;
    }
    bool _3660;
    if (_3652)
    {
        _3660 = (ddComputed.decalGroupMask & materialDecalGroupMask) > 0u;
    }
    else
    {
        _3660 = _3652;
    }
    if (_3660)
    {
        decalBlendFactor = 1.0;
        if ((ddComputed.decalFeatures & 2u) > 0u)
        {
            float gradientMaskOpacity = dd.decalParams0.x;
            float gradientMaskThreshold = dd.decalParams0.y;
            float gradientMaskThresholdSoftness = dd.decalParams0.z;
            float min0 = (1.0 - gradientMaskThreshold) - gradientMaskThresholdSoftness;
            float max0 = 1.0 - gradientMaskThreshold;
            float gradientBlendFactor = smoothstep(min0, max0, dot(d.N, -dd.decalNormal.xyz));
            decalBlendFactor *= (gradientBlendFactor * gradientMaskOpacity);
        }
        if ((ddComputed.decalFeatures & 4u) > 0u)
        {
            float blendMaskValue = d.materialBlendMask.x;
            if (ddComputed.blendMaskChannelIdx == 1u)
            {
                blendMaskValue = d.materialBlendMask.y;
            }
            else
            {
                if (ddComputed.blendMaskChannelIdx == 2u)
                {
                    blendMaskValue = d.materialBlendMask.z;
                }
                else
                {
                    if (ddComputed.blendMaskChannelIdx == 3u)
                    {
                        blendMaskValue = d.materialBlendMask.w;
                    }
                }
            }
            float materialMaskOpacity = dd.decalParams1.x;
            float materialMaskThreshold = dd.decalParams1.y;
            float materialMaskThresholdSoftness = dd.decalParams1.z;
            float min0_1 = materialMaskThreshold - materialMaskThresholdSoftness;
            float max0_1 = materialMaskThreshold;
            float materialMaskBlendFactor = (1.0 - smoothstep(max0_1, min0_1, decalBlendFactor)) * blendMaskValue;
            decalBlendFactor = mix(decalBlendFactor, materialMaskBlendFactor, materialMaskOpacity);
        }
        decalBlendFactor *= (1.0 - (clamp(ddComputed.decalPos.z - 0.75, 0.0, 1.0) / 0.25));
    }
    return decalBlendFactor;
}

vec4 flrSampleBindless(sampler samplerState, vec2 uv, uint textureIdx)
{
    return texture(sampler2D(globalTextures[nonuniformEXT(textureIdx)], samplerState), uv);
}

vec4 sampleDecalTexture(uint textureIdx, vec2 uv)
{
    vec2 param = uv;
    uint param_1 = textureIdx;
    return flrSampleBindless(linearRepeatSampler, param, param_1);
}

vec4 triplanar(uint textureID, vec3 p, vec4 uvScaleOffset, vec4 weights)
{
    uint param = textureID;
    vec2 param_1 = (p.xy * uvScaleOffset.xy) + uvScaleOffset.zw;
    vec4 result = sampleDecalTexture(param, param_1) * weights.z;
    uint param_2 = textureID;
    vec2 param_3 = (p.zy * uvScaleOffset.xy) + uvScaleOffset.zw;
    result += (sampleDecalTexture(param_2, param_3) * weights.x);
    uint param_4 = textureID;
    vec2 param_5 = (p.xz * uvScaleOffset.xy) + uvScaleOffset.zw;
    result += (sampleDecalTexture(param_4, param_5) * weights.y);
    result *= weights.w;
    return result;
}

vec4 flrSampleGradBindless(sampler samplerState, vec2 uv, uint textureIdx, vec2 uvDX, vec2 uvDY)
{
    return textureGrad(sampler2D(globalTextures[nonuniformEXT(textureIdx)], samplerState), uv, uvDX, uvDY);
}

vec4 computeFlowData(inout vec2 flowSample, float time, float flowSpeed, float flowStrength)
{
    float l0 = length(flowSample);
    if (l0 < 0.00999999977648258209228515625)
    {
        flowSample = vec2(0.0);
    }
    vec2 flow = flowSample * flowStrength;
    vec2 scale = fract(vec2((time * flowSpeed) - 0.5, time * flowSpeed));
    return vec4(flow, scale);
}

vec4 computeFlowDataGradient(uint _flowMapImageID, vec2 _flowMapUV, float time, float flowSpeed, float flowStrength, vec4 uvDXDY)
{
    vec2 param = _flowMapUV;
    uint param_1 = _flowMapImageID;
    vec2 param_2 = uvDXDY.xy;
    vec2 param_3 = uvDXDY.zw;
    vec2 flowSample = (flrSampleGradBindless(linearRepeatSampler, param, param_1, param_2, param_3).wy * 2.0) - vec2(1.0);
    vec2 param_4 = flowSample;
    float param_5 = time;
    float param_6 = flowSpeed;
    float param_7 = flowStrength;
    vec4 _816 = computeFlowData(param_4, param_5, param_6, param_7);
    return _816;
}

vec4 computeFlowmapColorGradient(uint _inputImageID, vec2 _inputUV, vec4 _flowData, vec4 uvDXDY)
{
    vec2 scale = _flowData.zw;
    float flowLayerBlendFactor = abs((0.5 - scale.x) / 0.5);
    vec4 flowUV = _flowData.xyxy * scale.xxyy;
    vec2 param = _inputUV + flowUV.xy;
    uint param_1 = _inputImageID;
    vec2 param_2 = uvDXDY.xy;
    vec2 param_3 = uvDXDY.zw;
    vec4 val0 = flrSampleGradBindless(linearRepeatSampler, param, param_1, param_2, param_3);
    vec2 param_4 = _inputUV + flowUV.zw;
    uint param_5 = _inputImageID;
    vec2 param_6 = uvDXDY.xy;
    vec2 param_7 = uvDXDY.zw;
    vec4 val1 = flrSampleGradBindless(linearRepeatSampler, param_4, param_5, param_6, param_7);
    return mix(val0, val1, vec4(flowLayerBlendFactor));
}

vec4 sampleDecalTextureGrad(uint textureIdx, vec2 uv, vec4 uvDXDY)
{
    vec2 param = uv;
    uint param_1 = textureIdx;
    vec2 param_2 = uvDXDY.xy;
    vec2 param_3 = uvDXDY.zw;
    return flrSampleGradBindless(linearRepeatSampler, param, param_1, param_2, param_3);
}

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

vec3 computeInteriorMappingRayIntersection(vec2 uv, vec3 posWS, vec3 camPosWS, vec3 tangent, vec3 binormal, vec3 normal, vec2 interiorTiling, vec2 interiorOffset, uint cubeFaceID)
{
    vec2 f = fract((uv + interiorOffset) * interiorTiling);
    vec3 rayPos = vec3((f * vec2(2.0)) - vec2(1.0), 1.0);
    rayPos = ((tangent * rayPos.x) + (binormal * rayPos.y)) + (normal * rayPos.z);
    vec3 rayPosection = posWS - camPosWS;
    vec3 id = vec3(1.0) / rayPosection;
    vec3 k = abs(id) - (rayPos * id);
    float kMin = min(min(k.x, k.y), k.z);
    rayPos += (rayPosection * kMin);
    vec3 _1058;
    if (cubeFaceID == 1u)
    {
        _1058 = vec3(-rayPos.x, rayPos.y, -rayPos.z);
    }
    else
    {
        vec3 _1073;
        if (cubeFaceID == 2u)
        {
            _1073 = vec3(rayPos.z, rayPos.y, -rayPos.x);
        }
        else
        {
            vec3 _1087;
            if (cubeFaceID == 3u)
            {
                _1087 = vec3(-rayPos.z, rayPos.y, rayPos.x);
            }
            else
            {
                _1087 = rayPos;
            }
            _1073 = _1087;
        }
        _1058 = _1073;
    }
    rayPos = _1058;
    return rayPos;
}

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

vec3 reorientNormal(vec3 u, vec3 t, vec3 s)
{
    vec4 q = vec4(cross(s, t), dot(s, t) + 1.0) / vec4(sqrt(2.0 * (dot(s, t) + 1.0)));
    return ((u * ((q.w * q.w) - dot(q.xyz, q.xyz))) + ((q.xyz * 2.0) * dot(q.xyz, u))) + (cross(q.xyz, u) * (2.0 * q.w));
}

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

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

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

void blendDecalDefault(inout LightingData d, DecalData dd, MaterialData decalMaterialData, inout DecalDataComputed ddComputed, inout float decalBlendFactor)
{
    uint decalMaterialFeatureBits = decalMaterialData.paramIntData0.x;
    uint decalMaskImageID = dd.decalIntParams0.w;
    uint albedoImageID = decalMaterialData.paramImgIDs0.x;
    uint normalImageID = decalMaterialData.paramImgIDs0.y;
    uint parametersImageID = decalMaterialData.paramImgIDs0.z;
    float normalScale = decalMaterialData.paramFloatData4.x;
    vec4 normalDecalSpace = dd.viewMatrix * vec4(d.NVtx, 0.0);
    vec2 ParamUVScale = decalMaterialData.paramFloatData2.xy;
    vec2 ParamUVOffset = decalMaterialData.paramFloatData2.zw;
    vec4 decalUVdxdy = ddComputed.decalUVdxdy * ParamUVScale.xxyy;
    vec4 decalTextureMask;
    vec4 albedo;
    vec4 normal;
    vec4 parameters;
    if ((ddComputed.decalFeatures & 16u) > 0u)
    {
        vec3 _2917 = pow(abs(normalDecalSpace.xyz), vec3(dd.decalParams0.w, dd.decalParams0.w, dd.decalParams0.w));
        vec4 weights;
        weights = vec4(_2917.x, _2917.y, _2917.z, weights.w);
        weights.w = 1.0 / ((weights.x + weights.y) + weights.z);
        vec3 triplanarPos = (ddComputed.decalPos.xyz * 0.5) + vec3(0.5);
        uint param = decalMaskImageID;
        vec3 param_1 = triplanarPos;
        vec4 param_2 = dd.decalMaskUVScaleOffset;
        vec4 param_3 = weights;
        decalTextureMask = triplanar(param, param_1, param_2, param_3);
        uint param_4 = albedoImageID;
        vec3 param_5 = triplanarPos;
        vec4 param_6 = dd.decalUVScaleOffset;
        vec4 param_7 = weights;
        albedo = triplanar(param_4, param_5, param_6, param_7);
        uint param_8 = normalImageID;
        vec3 param_9 = triplanarPos;
        vec4 param_10 = dd.decalUVScaleOffset;
        vec4 param_11 = weights;
        normal = triplanar(param_8, param_9, param_10, param_11);
        uint param_12 = parametersImageID;
        vec3 param_13 = triplanarPos;
        vec4 param_14 = dd.decalUVScaleOffset;
        vec4 param_15 = weights;
        parameters = triplanar(param_12, param_13, param_14, param_15);
    }
    else
    {
        if ((ddComputed.decalFeatures & 8u) > 0u)
        {
            vec3 wrapPos = ddComputed.decalPos.xyz;
            vec2 _2997 = (wrapPos.xy * 0.5) + vec2(0.5);
            wrapPos = vec3(_2997.x, _2997.y, wrapPos.z);
            float angle = dot(d.NVtx, dd.decalNormal.xyz);
            float _3009;
            if (angle > 0.0)
            {
                _3009 = -wrapPos.z;
            }
            else
            {
                _3009 = wrapPos.z;
            }
            wrapPos.z = _3009;
            ddComputed.decalUV = wrapPos.xy + (normalDecalSpace.xy * wrapPos.z);
        }
        float uvOffsetAnimFactor = 0.0;
        if ((decalMaterialFeatureBits & 8u) > 0u)
        {
            uvOffsetAnimFactor = d.time;
        }
        vec2 baseUV = (((ddComputed.decalUV * dd.decalUVScaleOffset.xy) * ParamUVScale) + dd.decalUVScaleOffset.zw) + (ParamUVOffset * uvOffsetAnimFactor);
        vec2 decalMaskUV = (ddComputed.decalUV * dd.decalMaskUVScaleOffset.xy) + dd.decalMaskUVScaleOffset.zw;
        if ((decalMaterialFeatureBits & 16u) > 0u)
        {
            float ParamFlowSpeed = decalMaterialData.paramFloatData5.z;
            float ParamFlowStrength = decalMaterialData.paramFloatData5.w;
            uint flowImageID = decalMaterialData.paramImgIDs1.z;
            uint param_16 = decalMaskImageID;
            vec2 param_17 = decalMaskUV;
            decalTextureMask = sampleDecalTexture(param_16, param_17);
            uint param_18 = flowImageID;
            vec2 param_19 = baseUV;
            float param_20 = dd.decalParams1.w;
            float param_21 = ParamFlowSpeed;
            float param_22 = ParamFlowStrength;
            vec4 param_23 = decalUVdxdy;
            vec4 flowData = computeFlowDataGradient(param_18, param_19, param_20, param_21, param_22, param_23);
            uint param_24 = albedoImageID;
            vec2 param_25 = baseUV;
            vec4 param_26 = flowData;
            vec4 param_27 = decalUVdxdy;
            albedo = computeFlowmapColorGradient(param_24, param_25, param_26, param_27);
            uint param_28 = normalImageID;
            vec2 param_29 = baseUV;
            vec4 param_30 = flowData;
            vec4 param_31 = decalUVdxdy;
            normal = computeFlowmapColorGradient(param_28, param_29, param_30, param_31);
            uint param_32 = parametersImageID;
            vec2 param_33 = baseUV;
            vec4 param_34 = flowData;
            vec4 param_35 = decalUVdxdy;
            parameters = computeFlowmapColorGradient(param_32, param_33, param_34, param_35);
        }
        else
        {
            uint param_36 = decalMaskImageID;
            vec2 param_37 = decalMaskUV;
            vec4 param_38 = decalUVdxdy;
            decalTextureMask = sampleDecalTextureGrad(param_36, param_37, param_38);
            uint param_39 = albedoImageID;
            vec2 param_40 = baseUV;
            vec4 param_41 = decalUVdxdy;
            albedo = sampleDecalTextureGrad(param_39, param_40, param_41);
            uint param_42 = normalImageID;
            vec2 param_43 = baseUV;
            vec4 param_44 = decalUVdxdy;
            normal = sampleDecalTextureGrad(param_42, param_43, param_44);
            uint param_45 = parametersImageID;
            vec2 param_46 = baseUV;
            vec4 param_47 = decalUVdxdy;
            parameters = sampleDecalTextureGrad(param_45, param_46, param_47);
        }
    }
    vec3 N = mix(d.NVtx, -dd.decalNormal.xyz, vec3(clamp(dd.decalParams2.y, 0.0, 1.0)));
    vec3 T = -dd.decalTangent.xyz;
    vec3 B = cross(N, T);
    if (dd.decalParams2.x > 0.0)
    {
        decalBlendFactor *= mix(1.0, decalTextureMask[ddComputed.decalMaskChannelIdx], dd.decalParams2.x);
    }
    else
    {
        decalBlendFactor *= step(clamp(-dd.decalParams2.x, 0.0, 1.0) + 0.001000000047497451305389404296875, decalTextureMask[ddComputed.decalMaskChannelIdx]);
    }
    vec4 param_48 = normal;
    vec3 _3205 = decodeNormalMap(param_48);
    normal = vec4(_3205.x, _3205.y, _3205.z, normal.w);
    vec2 _3211 = normal.xy * normalScale;
    normal = vec4(_3211.x, _3211.y, normal.z, normal.w);
    vec3 parameterScale = decalMaterialData.paramFloatData1.xyz;
    parameters.x = clamp((parameters.x * clamp(parameterScale.x, 0.0, 1.0)) + clamp(parameterScale.x - 1.0, 0.0, 1.0), 0.0, 1.0);
    parameters.y = clamp((parameters.y * clamp(parameterScale.y, 0.0, 1.0)) + clamp(parameterScale.y - 1.0, 0.0, 1.0), 0.0, 1.0);
    parameters.z = 1.0 - clamp((1.0 - parameters.z) * parameterScale.z, 0.0, 1.0);
    vec3 decalNormal = normalize(((T * normal.x) + (B * normal.y)) + (N * normal.z));
    if ((decalMaterialFeatureBits & 512u) > 0u)
    {
        vec2 interiorTiling = decalMaterialData.paramFloatData9.xy;
        vec2 interiorOffset = decalMaterialData.paramFloatData9.zw;
        uint cubeFaceID = decalMaterialData.paramIntData0.w;
        vec2 param_49 = ddComputed.decalUV;
        vec3 param_50 = d.posWS;
        vec3 param_51 = d.cameraPosWS;
        vec3 param_52 = T;
        vec3 param_53 = B;
        vec3 param_54 = normalDecalSpace.xyz;
        vec2 param_55 = interiorTiling;
        vec2 param_56 = interiorOffset;
        uint param_57 = cubeFaceID;
        vec3 rayDir = computeInteriorMappingRayIntersection(param_49, param_50, param_51, param_52, param_53, param_54, param_55, param_56, param_57);
        float refractionMipIdx = parameters.x * 3.0;
        uint interiorCubeImageID = decalMaterialData.paramImgIDs2.y;
        vec3 param_58 = rayDir;
        float param_59 = refractionMipIdx;
        uint param_60 = interiorCubeImageID;
        vec3 interiorColor = flrSampleLevelBindlessCube(linearRepeatSampler, param_58, param_59, param_60).xyz;
        vec3 _3333 = mix(interiorColor, albedo.xyz, vec3(albedo.w * 1.0));
        albedo = vec4(_3333.x, _3333.y, _3333.z, albedo.w);
        albedo.w = 1.0;
    }
    decalBlendFactor *= albedo.w;
    if (!((ddComputed.decalFeatures & 1u) > 0u))
    {
        vec3 param_61 = d.N;
        vec3 param_62 = decalNormal;
        vec3 param_63 = d.NVtx;
        decalNormal = reorientNormal(param_61, param_62, param_63);
    }
    uint param_64 = dd.decalIntParams0.y;
    vec4 decalTint = decodeARGB8uint(param_64);
    vec3 _3366 = albedo.xyz * decalTint.xyz;
    albedo = vec4(_3366.x, _3366.y, _3366.z, albedo.w);
    uint colorCorrectionMaskImageID = decalMaterialData.paramImgIDs2.x;
    uint param_65 = colorCorrectionMaskImageID;
    vec2 param_66 = ddComputed.decalUV;
    vec4 param_67 = decalUVdxdy;
    float correctionMask = sampleDecalTextureGrad(param_65, param_66, param_67).x;
    vec3 param_68 = albedo.xyz;
    float lum = getLuminance(param_68);
    vec3 correctedAlbedo = vec3(lum) + ((albedo.xyz - vec3(lum)) * decalMaterialData.paramFloatData0.z);
    uint param_69 = floatBitsToUint(decalMaterialData.paramFloatData0.x);
    vec3 param_70 = decodeARGB8uint(param_69).xyz;
    correctedAlbedo = (correctedAlbedo * gammaToLinear(param_70)) * decalMaterialData.paramFloatData0.y;
    vec3 _3417 = mix(albedo.xyz, correctedAlbedo, vec3(correctionMask));
    albedo = vec4(_3417.x, _3417.y, _3417.z, albedo.w);
    vec3 decalOpacity = clamp(vec3(decalBlendFactor) * dd.decalOpacityParams.yzw, vec3(0.0), vec3(1.0));
    d.baseColor = mix(d.baseColor, albedo.xyz, vec3(decalOpacity.x));
    d.roughness = mix(d.roughness, parameters.x, decalOpacity.z);
    d.metalness = mix(d.metalness, parameters.y, clamp(decalOpacity.z * dd.decalParams2.z, 0.0, 1.0));
    d.occlusion = mix(d.occlusion, parameters.z, decalOpacity.z);
    d.N = mix(d.N, decalNormal, vec3(decalOpacity.y));
}

void blendDecalEmissive(inout LightingData d, DecalData dd, MaterialData decalMaterialData, DecalDataComputed ddComputed, float decalBlendFactor)
{
    uint decalMaterialFeatureBits = decalMaterialData.paramIntData0.x;
    uint decalMaskImageID = dd.decalIntParams0.w;
    uint emissiveImageID = decalMaterialData.paramImgIDs0.x;
    uint emissiveMaskImageID = decalMaterialData.paramImgIDs0.y;
    uint flowImageID = decalMaterialData.paramImgIDs0.z;
    vec4 emissive = vec4(0.0);
    vec2 ParamUVOffset = decalMaterialData.paramFloatData0.xy;
    vec2 ParamUVScale = decalMaterialData.paramFloatData0.zw;
    vec4 decalUVdxdy = ddComputed.decalUVdxdy * ParamUVScale.xxyy;
    vec2 baseUV = (((ddComputed.decalUV * dd.decalUVScaleOffset.xy) * ParamUVScale) + dd.decalUVScaleOffset.zw) + ParamUVOffset;
    vec2 decalMaskUV = (ddComputed.decalUV * dd.decalMaskUVScaleOffset.xy) + dd.decalMaskUVScaleOffset.zw;
    if ((decalMaterialFeatureBits & 2u) > 0u)
    {
        float ParamFlowSpeed = decalMaterialData.paramFloatData2.z;
        float ParamFlowStrength = decalMaterialData.paramFloatData2.w;
        uint param = flowImageID;
        vec2 param_1 = baseUV;
        float param_2 = dd.decalParams1.w;
        float param_3 = ParamFlowSpeed;
        float param_4 = ParamFlowStrength;
        vec4 param_5 = decalUVdxdy;
        vec4 flowData = computeFlowDataGradient(param, param_1, param_2, param_3, param_4, param_5);
        uint param_6 = emissiveImageID;
        vec2 param_7 = baseUV;
        vec4 param_8 = flowData;
        vec4 param_9 = decalUVdxdy;
        emissive = computeFlowmapColorGradient(param_6, param_7, param_8, param_9);
    }
    else
    {
        uint param_10 = emissiveImageID;
        vec2 param_11 = baseUV;
        vec4 param_12 = decalUVdxdy;
        emissive = sampleDecalTextureGrad(param_10, param_11, param_12);
    }
    uint param_13 = decalMaskImageID;
    vec2 param_14 = decalMaskUV;
    vec4 param_15 = decalUVdxdy;
    vec4 decalTextureMask = sampleDecalTextureGrad(param_13, param_14, param_15);
    uint param_16 = emissiveMaskImageID;
    vec2 param_17 = baseUV;
    vec4 param_18 = decalUVdxdy;
    vec4 emissiveMask = sampleDecalTextureGrad(param_16, param_17, param_18);
    uint param_19 = dd.decalIntParams0.y;
    vec4 decalTint = decodeARGB8uint(param_19);
    vec3 ParamEmissiveColor = decalMaterialData.paramFloatData1.xyz;
    float ParamEmissiveStrength = decalMaterialData.paramFloatData2.x * dd.decalOpacityParams.x;
    vec3 _3616 = (((emissive.xyz * emissiveMask.xyz) * decalTint.xyz) * ParamEmissiveColor) * ParamEmissiveStrength;
    emissive = vec4(_3616.x, _3616.y, _3616.z, emissive.w);
    d.emissive += (((emissive.xyz * emissive.w) * decalBlendFactor) * decalTextureMask[ddComputed.decalMaskChannelIdx]);
}

void renderSingleDecal(inout LightingData d, DecalData dd, MaterialData decalMaterialData)
{
    LightingData param = d;
    DecalData param_1 = dd;
    DecalDataComputed param_2;
    updateDecalDataComputed(param, param_1, param_2);
    DecalDataComputed ddComputed = param_2;
    LightingData param_3 = d;
    DecalData param_4 = dd;
    DecalDataComputed param_5 = ddComputed;
    float decalBlendFactor = computeDecalBlendFactor(param_3, param_4, param_5);
    if (decalBlendFactor <= 0.0)
    {
        return;
    }
    uint decalMaterialTypeIdx = decalMaterialData.paramIntData0.y;
    if (decalMaterialTypeIdx <= 1u)
    {
        LightingData param_6 = d;
        DecalData param_7 = dd;
        MaterialData param_8 = decalMaterialData;
        DecalDataComputed param_9 = ddComputed;
        float param_10 = decalBlendFactor;
        blendDecalDefault(param_6, param_7, param_8, param_9, param_10);
        d = param_6;
        ddComputed = param_9;
    }
    else
    {
        if (decalMaterialTypeIdx == 5u)
        {
            LightingData param_11 = d;
            DecalData param_12 = dd;
            MaterialData param_13 = decalMaterialData;
            DecalDataComputed param_14 = ddComputed;
            float param_15 = decalBlendFactor;
            blendDecalEmissive(param_11, param_12, param_13, param_14, param_15);
            d = param_11;
        }
        else
        {
            d.baseColor = vec3(1.0, 0.0, 0.0);
        }
    }
}

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

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 _4969 = all(lessThanEqual(posProbe, vec3(1.0)));
        bool _4975;
        if (_4969)
        {
            _4975 = all(greaterThanEqual(posProbe, vec3(-1.0)));
        }
        else
        {
            _4975 = _4969;
        }
        if (_4975)
        {
            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 _1300 = posLS.xyz / posLS.www;
    posLS = vec4(_1300.x, _1300.y, _1300.z, posLS.w);
    vec2 _1307 = (posLS.xy * 0.5) + vec2(0.5);
    posLS = vec4(_1307.x, _1307.y, posLS.z, posLS.w);
    return posLS;
}

uint findBestFittingSplit(vec3 posWS, inout vec4 posLS)
{
    for (uint i = 0u; i < uint(_3942.shadowParameters0.x); i++)
    {
        vec3 param = posWS;
        mat4 param_1 = _3942.pssmViewProjMatrices[i];
        posLS = calcPosLS(param, param_1);
        bool _3959 = all(lessThanEqual(posLS.xyz, vec3(1.0)));
        bool _3966;
        if (_3959)
        {
            _3966 = all(greaterThanEqual(posLS.xyz, vec3(0.0)));
        }
        else
        {
            _3966 = _3959;
        }
        if (_3966)
        {
            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 _1332 = vec4(vec3(uv, float(shadowMapIdx)), depth);
    return texture(shadowBufferTex_1, vec4(_1332.xyz, _1332.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 _4150 = findBestFittingSplit(param, param_1);
    vec4 posLS = param_1;
    uint shadowMapIdx = _4150;
    if (shadowMapIdx != 4294967295u)
    {
        vec3 param_2 = posWS;
        vec3 param_3 = normalVtx;
        vec3 param_4 = L;
        mat4 param_5 = _3942.pssmViewProjMatrices[shadowMapIdx];
        float param_6 = 10.0 + ((10.0 * float(shadowMapIdx)) * 1.0);
        vec2 _4172 = calcBiasedShadowUV(param_2, param_3, param_4, param_5, param_6);
        posLS = vec4(_4172.x, _4172.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 _4187 = calcFading(param_9);
        float fadeSplits = _4187;
        uint nextShadowMapIdx = shadowMapIdx + 1u;
        if (nextShadowMapIdx < uint(_3942.shadowParameters0.x))
        {
            vec3 param_10 = posWS;
            mat4 param_11 = _3942.pssmViewProjMatrices[nextShadowMapIdx];
            vec4 tempPosLS = calcPosLS(param_10, param_11);
            vec3 param_12 = posWS;
            vec3 param_13 = normalVtx;
            vec3 param_14 = L;
            mat4 param_15 = _3942.pssmViewProjMatrices[nextShadowMapIdx];
            float param_16 = 10.0 + ((10.0 * float(shadowMapIdx)) * 1.0);
            vec2 _4222 = calcBiasedShadowUV(param_12, param_13, param_14, param_15, param_16);
            tempPosLS = vec4(_4222.x, _4222.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(_3942.shadowParameters0.x) - 1u))
            {
                vec3 param_19 = posWS;
                mat4 param_20 = _3942.pssmViewProjMatrices[shadowMapIdx];
                vec4 posLSLastSplit = calcPosLS(param_19, param_20);
                vec3 param_21 = posLSLastSplit.xyz;
                float _4256 = calcFading(param_21);
                float fadeGlobal = _4256;
                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 = _3942.dirLightProjectorParams.x;
    if (projImageId != 4294967295u)
    {
        vec3 posLS = (_3942.dirLightProjectorViewProjMatrix * vec4(posWS, 1.0)).xyw;
        vec2 _4045 = posLS.xy / vec2(posLS.z);
        posLS = vec3(_4045.x, _4045.y, posLS.z);
        vec2 _4054 = posLS.xy * _3942.dirLightProjectorTransform.xy;
        posLS = vec3(_4054.x, _4054.y, posLS.z);
        vec2 _4069 = posLS.xy + ((_3942.dirLightProjectorTransform.zw * _3942.frameParameters0.x) * _3942.dirLightProjectorTransform.xy);
        posLS = vec3(_4069.x, _4069.y, posLS.z);
        vec2 _4076 = (posLS.xy * 0.5) + vec2(0.5);
        posLS = vec3(_4076.x, _4076.y, posLS.z);
        float projectorFactor = uintBitsToFloat(_3942.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 _3998 = calcDistanceFieldShadowing(param, param_1, param_2, param_3, param_4, param_5, param_6);
    uint totalSteps = param_6;
    return _3998;
}

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 _1656;
    if (DdR < discD)
    {
        _1656 = normalize((d.L * discD) + (normalize(S) * discR));
    }
    else
    {
        _1656 = d.R;
    }
    d.L = _1656;
}

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 _2063 = (d.materialData.paramIntData0.x & 4u) > 0u;
    bool _2069;
    if (_2063)
    {
        _2069 = d.translucency > 0.0;
    }
    else
    {
        _2069 = _2063;
    }
    if (_2069)
    {
        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 = _3942.localLightViewProjMatrices[localShadowBufferIdx];
        vec3 posLS = calcPosLS(param, param_1).xyz;
        vec3 param_2 = posWS;
        vec3 param_3 = shadowBiasNormal;
        vec3 param_4 = L;
        mat4 param_5 = _3942.localLightViewProjMatrices[localShadowBufferIdx];
        float param_6 = 2.0;
        vec2 _4309 = calcBiasedShadowUV(param_2, param_3, param_4, param_5, param_6);
        posLS = vec3(_4309.x, _4309.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 _4349 = ld.lightTypeAndFlags.y + (floatBitsToUint(_3942.frameParameters0.w) * 128u);
        ExtendedLightData eld;
        eld.boxInverseWorldMatrix = _4341._extendedLightBuffer[_4349].boxInverseWorldMatrix;
        eld.viewProjectionMatrix = _4341._extendedLightBuffer[_4349].viewProjectionMatrix;
        eld.params0 = _4341._extendedLightBuffer[_4349].params0;
        eld.projectorTransform = _4341._extendedLightBuffer[_4349].projectorTransform;
        vec3 posLS_1 = (eld.viewProjectionMatrix * vec4(posWS, 1.0)).xyw;
        vec2 _4377 = posLS_1.xy / vec2(posLS_1.z);
        posLS_1 = vec3(_4377.x, _4377.y, posLS_1.z);
        vec2 _4385 = posLS_1.xy * eld.projectorTransform.xy;
        posLS_1 = vec3(_4385.x, _4385.y, posLS_1.z);
        vec2 _4400 = posLS_1.xy + ((eld.projectorTransform.zw * _3942.frameParameters0.x) * eld.projectorTransform.xy);
        posLS_1 = vec3(_4400.x, _4400.y, posLS_1.z);
        vec2 _4407 = (posLS_1.xy * 0.5) + vec2(0.5);
        posLS_1 = vec3(_4407.x, _4407.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) - (_3942.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 _4643;
                if (dot(h.xy, h.xy) < dot(h.zw, h.zw))
                {
                    _4643 = vec4(h.xy, hC.xy);
                }
                else
                {
                    _4643 = vec4(h.zw, hC.zw + vec2(9.729999542236328125));
                }
                vec4 hex = _4643;
                float hexRand = fract(sin(dot(hex.zw, vec2(141.1300048828125, 289.970001220703125))) * 43758.546875);
                float hexRandAnimated = (sin((hexRand * 6.28299999237060546875) + (_3942.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 _1955 = calcInverseSqrFalloff(param_4);
        radialFalloff = _1955;
    }
    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 _2426 = calculateAreaLightFalloff(param, param_1, param_2, param_3, param_4);
        d.NdL = param_2;
        attenuation = vec3(_2426);
    }
    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 _2581 = all(lessThanEqual(posBS, vec3(1.0)));
    bool _2588;
    if (_2581)
    {
        _2588 = all(greaterThanEqual(posBS, vec3(-1.0)));
    }
    else
    {
        _2588 = _2581;
    }
    if (_2588)
    {
        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 _4779 = calcLocalLightShadowAttenuation(param, param_1, param_2);
        factor *= _4779;
    }
    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 _4813 = renderCustomPointLight(param_7, param_8, param_9, param_10, param_11, param_12);
        outLighting0 = param_12;
        if (_4813)
        {
            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 _4891 = ld.lightTypeAndFlags.y + (floatBitsToUint(_3942.frameParameters0.w) * 128u);
                ExtendedLightData eld;
                eld.boxInverseWorldMatrix = _4341._extendedLightBuffer[_4891].boxInverseWorldMatrix;
                eld.viewProjectionMatrix = _4341._extendedLightBuffer[_4891].viewProjectionMatrix;
                eld.params0 = _4341._extendedLightBuffer[_4891].params0;
                eld.projectorTransform = _4341._extendedLightBuffer[_4891].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 = _3942.nearFar.xy;
    vec4 param_2 = _3942.nearFarWidthHeight;
    uvec3 clusterGridPos = calcGridPosForViewPos(param, param_1, param_2);
    uvec3 param_3 = clusterGridPos;
    uint clusterIdxNonUniform = calcClusterIndex(param_3);
    vec3 irrad = d.irradiance;
    float ao = min(d.occlusion, d.ambientOcclusion);
    float param_4 = ao;
    vec3 param_5 = d.baseColor;
    irrad *= calcAOMultiBounce(param_4, param_5);
    uint clusterIdx = clusterIdxNonUniform;
    uint decalCount = _5198._resourceIndexBuffer[(clusterIdx + 2u) + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] & 65535u;
    DecalData dd;
    MaterialData decalMaterialData;
    for (uint i = 0u; i < decalCount; i++)
    {
        uint decalIndex = _5198._resourceIndexBuffer[(((clusterIdx + (i * 3u)) + 3u) + 2u) + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] & 65535u;
        uint _5245 = decalIndex + (floatBitsToUint(_3942.frameParameters0.w) * 128u);
        dd.viewMatrix = _5239._decalBuffer[_5245].viewMatrix;
        dd.viewProjMatrix = _5239._decalBuffer[_5245].viewProjMatrix;
        dd.decalIntParams0 = _5239._decalBuffer[_5245].decalIntParams0;
        dd.decalOpacityParams = _5239._decalBuffer[_5245].decalOpacityParams;
        dd.decalUVScaleOffset = _5239._decalBuffer[_5245].decalUVScaleOffset;
        dd.decalMaskUVScaleOffset = _5239._decalBuffer[_5245].decalMaskUVScaleOffset;
        dd.decalParams0 = _5239._decalBuffer[_5245].decalParams0;
        dd.decalParams1 = _5239._decalBuffer[_5245].decalParams1;
        dd.decalParams2 = _5239._decalBuffer[_5245].decalParams2;
        dd.decalNormal = _5239._decalBuffer[_5245].decalNormal;
        dd.decalTangent = _5239._decalBuffer[_5245].decalTangent;
        decalMaterialData.paramIntData0 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramIntData0;
        decalMaterialData.paramFloatData0 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData0;
        decalMaterialData.paramFloatData1 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData1;
        decalMaterialData.paramFloatData2 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData2;
        decalMaterialData.paramFloatData3 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData3;
        decalMaterialData.paramFloatData4 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData4;
        decalMaterialData.paramFloatData5 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData5;
        decalMaterialData.paramFloatData6 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData6;
        decalMaterialData.paramFloatData7 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData7;
        decalMaterialData.paramFloatData8 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData8;
        decalMaterialData.paramFloatData9 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramFloatData9;
        decalMaterialData.paramImgIDs0 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramImgIDs0;
        decalMaterialData.paramImgIDs1 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramImgIDs1;
        decalMaterialData.paramImgIDs2 = _5276._materialDataBuffer[dd.decalIntParams0.z].paramImgIDs2;
        LightingData param_6 = d;
        DecalData param_7 = dd;
        MaterialData param_8 = decalMaterialData;
        renderSingleDecal(param_6, param_7, param_8);
        d = param_6;
    }
    d.baseColor = mix(vec3(0.5), d.baseColor, vec3(d.lightingWeights1.z));
    LightingData param_9 = d;
    initLightingDataFromGBuffer(param_9);
    d = param_9;
    LightingData param_10 = d;
    calculateLightingDataBase(param_10);
    d = param_10;
    irrad *= ((d.diffuseColor * 0.3183098733425140380859375) * _3942.lightingWeights0.z);
    vec3 specular = vec3(0.0);
    vec3 specularIrrad = vec3(0.0);
    float param_11 = d.roughness;
    float specMipIdx = roughnessToMipIdx(param_11);
    vec3 param_12 = d.specularColor;
    float param_13 = d.roughness;
    float param_14 = d.NdV;
    vec3 envBRDF = envBRDFApprox(param_12, param_13, param_14);
    float totalWeight = 0.0;
    uint clusterIdx_1 = clusterIdxNonUniform;
    uint specularProbeCount = (_5198._resourceIndexBuffer[(clusterIdx_1 + 1u) + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] >> uint(16)) & 65535u;
    SpecularProbeData sd;
    for (uint i_1 = 0u; i_1 < specularProbeCount; i_1++)
    {
        uint specularProbeIndex = (_5198._resourceIndexBuffer[(((clusterIdx_1 + (i_1 * 3u)) + 3u) + 1u) + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] >> uint(16)) & 65535u;
        uint _5413 = specularProbeIndex + (floatBitsToUint(_3942.frameParameters0.w) * 32u);
        sd.posAndRadiusWS = _5407._specularProbeBuffer[_5413].posAndRadiusWS;
        sd.worldMatrix = _5407._specularProbeBuffer[_5413].worldMatrix;
        sd.inverseWorldMatrix = _5407._specularProbeBuffer[_5413].inverseWorldMatrix;
        sd.imageIdAndFlags = _5407._specularProbeBuffer[_5413].imageIdAndFlags;
        sd.params0 = _5407._specularProbeBuffer[_5413].params0;
        sd.params1 = _5407._specularProbeBuffer[_5413].params1;
        SpecularProbeData param_15 = sd;
        vec3 param_16 = d.posWS;
        vec3 param_16a = d.posWSa;
        vec3 param_17 = d.cameraPosWS;
        vec3 param_18 = d.N;
        vec3 param_19 = d.R;
        float param_20 = specMipIdx;
        vec3 param_21 = envBRDF;
        vec3 param_22 = specular;
        vec3 param_23 = specularIrrad;
        float param_24 = totalWeight;
        calcLocalSpecular(param_15, param_16, param_16a, param_17, param_18, param_19, param_20, param_21, param_22, param_23, param_24);
        specular = param_22;
        specularIrrad = param_23;
        totalWeight = param_24;
    }
    if (totalWeight < 0.9900000095367431640625)
    {
        uint defaultSpecularId = 7u;
        defaultSpecularId++;
        vec3 param_25 = d.R;
        float param_26 = specMipIdx;
        uint param_27 = defaultSpecularId;
        vec3 specSample = flrSampleLevelBindlessCube(linearClampSampler, param_25, param_26, param_27).xyz;
        specular = mix(specSample * envBRDF, specular, vec3(totalWeight));
    }
    vec3 param_28 = d.specularColor;
    float param_29 = d.roughness;
    float param_30 = d.NdV;
    vec3 ssr = d.ssrSample.xyz * envBRDFApprox(param_28, param_29, param_30);
    specular = mix(specular, ssr, vec3(d.ssrSample.w));
    float specLum = dot(specularIrrad, vec3(1.0));
    float irradLum = dot(d.irradiance, vec3(1.0));
    float specFactor = irradLum / (specLum + 9.9999997473787516355514526367188e-05);
    specFactor = clamp(specFactor, 0.0, 1.0);
    specular *= specFactor;
    uint clusterIdx_2 = clusterIdxNonUniform;
    uint lightCount = (_5198._resourceIndexBuffer[(clusterIdx_2 + 2u) + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] >> uint(16)) & 65535u;
    LightData ld;
    vec3 _5650;
    vec3 _5656;
    for (uint i_2 = 0u; i_2 < lightCount; i_2++)
    {
        uint lightIndex = (_5198._resourceIndexBuffer[(((clusterIdx_2 + (i_2 * 3u)) + 3u) + 2u) + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] >> uint(16)) & 65535u;
        uint _5572 = lightIndex + (floatBitsToUint(_3942.frameParameters0.w) * 128u);
        ld.posAndRadiusWS = _5566._lightBuffer[_5572].posAndRadiusWS;
        ld.colorAndIntensity = _5566._lightBuffer[_5572].colorAndIntensity;
        ld.lightDirectionAndFalloffExp = _5566._lightBuffer[_5572].lightDirectionAndFalloffExp;
        ld.lightTangent = _5566._lightBuffer[_5572].lightTangent;
        ld.lightTypeAndFlags = _5566._lightBuffer[_5572].lightTypeAndFlags;
        ld.spotLightAngles = _5566._lightBuffer[_5572].spotLightAngles;
        ld.sphereAndShadowParams = _5566._lightBuffer[_5572].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_31 = ld;
        vec3 param_32 = lightDistVec;
        float falloff = calcExponentialFalloff(param_31, param_32);
        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_33 = _mod;
                vec3 param_34 = d.baseColor;
                _5656 = calcAOMultiBounce(param_33, param_34);
            }
            else
            {
                _5656 = _mod;
            }
            _5650 = _5656;
        }
        else
        {
            _5650 = vec3(1.0);
        }
        irrad *= _5650;
        specular *= mix(vec3(1.0), _mod, bvec3(applyToAll || (lightType == 4u)));
    }
    float param_35 = d.ambientOcclusion;
    float param_36 = d.NdV;
    float param_37 = d.roughness;
    specular *= calcSpecularOcclusionFromAo(param_35, param_36, param_37);
    specular *= _3942.lightingWeights0.w;
    outLighting0 = (irrad * 1.0) + (specular * 1.0);
    outLighting1 = (irrad * 0.0) + (specular * 0.0);
    if (_3942.dirLightColorAndIntens.w > 9.9999999392252902907785028219223e-09)
    {
        vec3 shadowBiasNormal = d.NVtx;
        float shadowFactor = _3942.dirLightDirWS.w;
        vec3 param_38 = d.posWS;
        vec3 param_39 = shadowBiasNormal;
        vec3 param_40 = _3942.dirLightDirWS.xyz;
        float param_41 = shadowFactor;
        float _5732 = calcDirShadowAttenuation(param_38, param_39, param_40, param_41);
        vec3 param_42 = d.posWS;
        vec3 dirLightAttenuation = vec3(_5732) * calcDirProjectorAttenuation(param_42);
        vec3 param_43 = _3942.dirLightDirWS.xyz;
        vec3 param_44 = d.NVtx;
        vec3 param_45 = d.posWS;
        float param_46 = 50000.0;
        dirLightAttenuation *= calcDistanceFieldShadowing(param_43, param_44, param_45, param_46);
        if (any(greaterThan(dirLightAttenuation, vec3(9.9999999392252902907785028219223e-09))))
        {
            LightingData param_47 = d;
            float param_48 = _3942.dirLightColorAndIntens.w;
            vec3 param_49 = _3942.dirLightColorAndIntens.xyz;
            vec3 param_50 = _3942.dirLightDirWS.xyz;
            vec3 param_51 = outLighting0;
            vec3 param_52 = outLighting1;
            vec4 param_53 = vec4(1.0, 1.0, 0.0, 0.0);
            vec3 param_54 = dirLightAttenuation;
            calcDirLightLighting(param_47, param_48, param_49, param_50, param_51, param_52, param_53, param_54);
            d = param_47;
            outLighting0 = param_51;
            outLighting1 = param_52;
        }
    }
    uint clusterIdx_3 = clusterIdxNonUniform;
    uint lightCount_1 = _5198._resourceIndexBuffer[clusterIdx_3 + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] & 65535u;
    LightData ld_1;
    for (uint i_3 = 0u; i_3 < lightCount_1; i_3++)
    {
        uint lightIndex_1 = _5198._resourceIndexBuffer[((clusterIdx_3 + (i_3 * 3u)) + 3u) + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] & 65535u;
        uint _5825 = lightIndex_1 + (floatBitsToUint(_3942.frameParameters0.w) * 128u);
        ld_1.posAndRadiusWS = _5566._lightBuffer[_5825].posAndRadiusWS;
        ld_1.colorAndIntensity = _5566._lightBuffer[_5825].colorAndIntensity;
        ld_1.lightDirectionAndFalloffExp = _5566._lightBuffer[_5825].lightDirectionAndFalloffExp;
        ld_1.lightTangent = _5566._lightBuffer[_5825].lightTangent;
        ld_1.lightTypeAndFlags = _5566._lightBuffer[_5825].lightTypeAndFlags;
        ld_1.spotLightAngles = _5566._lightBuffer[_5825].spotLightAngles;
        ld_1.sphereAndShadowParams = _5566._lightBuffer[_5825].sphereAndShadowParams;
        LightData param_55 = ld_1;
        LightingData param_56 = d;
        vec3 param_57 = outLighting0;
        vec3 param_58 = outLighting1;
        vec4 param_59 = vec4(1.0, 1.0, 0.0, 0.0);
        vec3 param_60 = vec3(1.0);
        calcLocalLightLighting(param_55, param_56, param_57, param_58, param_59, param_60);
        outLighting0 = param_57;
        outLighting1 = param_58;
    }
    
    outLighting0 += d.emissive;
    uint clusterIdx_4 = clusterIdxNonUniform;
    uint debugMode = floatBitsToUint(d.lightingWeights1.w);
    if (debugMode > 0u)
    {
        uint resourceOffset = debugMode - 1u;
        uint resourceCount = (_5198._resourceIndexBuffer[(clusterIdx_4 + (resourceOffset / 2u)) + (floatBitsToUint(_3942.frameParameters0.w) * 599040u)] >> uint(((resourceOffset % 2u) == 0u) ? 0 : 16)) & 65535u;
        if (resourceCount > 0u)
        {
            float param_61 = clamp(float(resourceCount) / 6.0, 0.0, 1.0);
            vec3 color = colormap(param_61).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 _5925;
    if (false == all(equal(outLighting0, outLighting0)))
    {
        _5925 = vec3(1.0, 0.0, 0.0);
    }
    else
    {
        _5925 = outLighting0;
    }
    outLighting0 = _5925;
    vec3 _5936;
    if (false == all(equal(outLighting1, outLighting1)))
    {
        _5936 = vec3(1.0, 0.0, 0.0);
    }
    else
    {
        _5936 = outLighting1;
    }
    outLighting1 = _5936;
}

void flrMain(FlrInput flrInput, inout FlrOutput flrOutput)
{
    vec2 sampleUv = flrInput.uv0;
    sampleUv *= _3942.dynamicResolutionParameters.xy;
    vec3 albedo = texture(albedoTex, sampleUv).xyz;
    albedo = clamp(albedo, vec3(0.0), vec3(65000.0));
    vec4 depthQuad0 = textureGather(depthBufferTex, sampleUv, 0);
    float depth = depthQuad0.w;
    vec4 materialBlendMask = texture(materialBlendMaskTex, sampleUv);
    float param = texture(motionVectorsTex, sampleUv).z;
    uint materialId = decodeMaterialId(param);
    if (depth == 0.0)
    {
        flrOutput.hdrColor = vec4(albedo, 1.0);
        return;
    }
    vec4 normals = texture(normalsTex, sampleUv);
    vec2 param_1 = normals.xy;
    vec3 normal = decodeNormal(param_1);
    vec2 param_2 = normals.zw;
    vec3 normalVtx = decodeNormal(param_2);
    vec3 normalVtxDdx = dFdx(normalVtx);
    vec3 normalVtxDdy = dFdy(normalVtx);
    float geomRoughnessFactor = min(pow(clamp(max(dot(normalVtxDdx, normalVtxDdx), dot(normalVtxDdy, normalVtxDdy)), 0.0, 1.0), 0.333000004291534423828125), 0.300000011920928955078125);
    vec4 parameter = texture(parameterTex, sampleUv);
    vec2 param_3 = flrInput.uv0;
    float param_4 = depth;
    mat4 param_5 = _3942.invViewProjMatrix;
    
    //Fix here.
    vec2 param_3a = param_3;
    param_3a.x -= vk3d_params.stereo.x * 0.5;
    vec3 posWSa = unproject(param_3a, param_4, param_5);
    param_3.x -= vk3d_params.stereo.x *(1-vk3d_params.stereo.y*depth*0.2)*0.5;
    vec3 posWS = unproject(param_3, param_4, param_5);
    
    vec2 param_6 = flrInput.uv0;
    float param_7 = depth;
    mat4 param_8 = _3942.invProjMatrix;
    
    //Fix here.
    vec2 param_6a = param_6;
    param_6a.x -= vk3d_params.stereo.x * 0.5;
    vec3 posVSa = unproject(param_6a, param_7, param_8);
    param_6.x -= vk3d_params.stereo.x *(1-vk3d_params.stereo.y*depth*0.2)*0.5;
    vec3 posVS = unproject(param_6, param_7, param_8);
    
    LightingDataDesc desc;
    desc.lightingWeights0 = _3942.lightingWeights0;
    desc.lightingWeights1 = _3942.lightingWeights1;
    desc.baseColor = albedo;
    desc.roughness = max(parameter.x, geomRoughnessFactor);
    desc.metalness = parameter.y;
    desc.occlusion = parameter.z;
    desc.translucency = parameter.w;
    desc.materialBlendMask = materialBlendMask;
    desc.materialId = materialId;
    uint _6082 = clamp(materialId, 0u, 4096u);
    desc.materialData.paramIntData0 = _5276._materialDataBuffer[_6082].paramIntData0;
    desc.materialData.paramFloatData0 = _5276._materialDataBuffer[_6082].paramFloatData0;
    desc.materialData.paramFloatData1 = _5276._materialDataBuffer[_6082].paramFloatData1;
    desc.materialData.paramFloatData2 = _5276._materialDataBuffer[_6082].paramFloatData2;
    desc.materialData.paramFloatData3 = _5276._materialDataBuffer[_6082].paramFloatData3;
    desc.materialData.paramFloatData4 = _5276._materialDataBuffer[_6082].paramFloatData4;
    desc.materialData.paramFloatData5 = _5276._materialDataBuffer[_6082].paramFloatData5;
    desc.materialData.paramFloatData6 = _5276._materialDataBuffer[_6082].paramFloatData6;
    desc.materialData.paramFloatData7 = _5276._materialDataBuffer[_6082].paramFloatData7;
    desc.materialData.paramFloatData8 = _5276._materialDataBuffer[_6082].paramFloatData8;
    desc.materialData.paramFloatData9 = _5276._materialDataBuffer[_6082].paramFloatData9;
    desc.materialData.paramImgIDs0 = _5276._materialDataBuffer[_6082].paramImgIDs0;
    desc.materialData.paramImgIDs1 = _5276._materialDataBuffer[_6082].paramImgIDs1;
    desc.materialData.paramImgIDs2 = _5276._materialDataBuffer[_6082].paramImgIDs2;
    desc.cameraPosWS = _3942.cameraPositionWS.xyz;
    desc.posWS = posWS;
    desc.posVS = posVS;
	if (vk3d_params.custom_params.x==1) {
        desc.posWSa = posWS;
        desc.posVSa = posVS;
    } else {
        desc.posWSa = posWSa;
        desc.posVSa = posVSa;
    }
    desc.N = normal;
    desc.NVtx = normalVtx;
    desc.ambientOcclusion = texture(ssaoTex, sampleUv).x;
    desc.emissive = vec3(0.0);
    desc.irradiance = vec3(0.0);
    bool _6137 = floatBitsToUint(_3942.frameParameters1.y) > 0u;
    bool _6145;
    if (_6137)
    {
        _6145 = (desc.materialData.paramIntData0.x & 256u) > 0u;
    }
    else
    {
        _6145 = _6137;
    }
    if (_6145)
    {
        desc.baseColor = vec3(0.0);
    }
    
    LightingData d;
    LightingData param_9 = d;
    LightingDataDesc param_10 = desc;
    initLightingData(param_9, param_10);
    d = param_9;
    desc = param_10;
    d.posWSneighborX = posWS + dFdx(posWS);
    d.posWSneighborY = posWS + dFdy(posWS);
    d.time = _3942.frameParameters0.x;
    vec4 depthQuad1 = textureGatherOffset(depthBufferTex, sampleUv, ivec2(-1), 0);
    vec4 dxy = vec4(depthQuad0.x, depthQuad0.z, depthQuad1.x, depthQuad1.z);
    bool useFirstMip = any(greaterThan(abs(vec4(depth) - dxy), vec4(9.9999997473787516355514526367188e-05)));
    d.depthFixup = useFirstMip ? 0.0 : 1.0;
    d.irradiance = textureLod(irradianceTex, sampleUv, 0.0).xyz;
    LightingData param_11 = d;
    vec3 param_12;
    vec3 param_13;
    calcLightingAll(param_11, param_12, param_13);
    d = param_11;
    vec3 outLighting0 = param_12;
    vec3 outLighting1 = param_13;
    flrOutput.hdrColor = vec4(outLighting0, 1.0);
    vec3 _6228 = flrOutput.hdrColor.xyz + max(vec3(0.0), albedo - vec3(1.0));
    flrOutput.hdrColor = vec4(_6228.x, _6228.y, _6228.z, flrOutput.hdrColor.w);
    vec3 _6236 = min(flrOutput.hdrColor.xyz, vec3(65000.0));
    flrOutput.hdrColor = vec4(_6236.x, _6236.y, _6236.z, flrOutput.hdrColor.w);
}

void main()
{
    FlrInput flrInput;
    flrInput.uv0 = inUV0;
    FlrInput param = flrInput;
    FlrOutput flrOutput;
    FlrOutput param_1 = flrOutput;
    flrMain(param, param_1);
    flrOutput = param_1;
    outHdrColor = flrOutput.hdrColor;
}







