<commit_before>#pragma warning(disable:3571)

float GetDiffuseDir(float3 normal, float3 lightDir)
{
    return saturate(dot(normal, lightDir));
}

float GetDiffusePointOrSpot(float3 normal, float3 lightVec, out float3 lightDir)
{
    float lightDist = length(lightVec);
    lightDir = lightVec / lightDist;
    return saturate(dot(normal, lightDir)) * tex1D(sLightRampMap, lightDist).r;
}

float GetDiffuseDirVolumetric()
{
    return 1.0;
}

float GetDiffusePointOrSpotVolumetric(float3 lightVec)
{
    float lightDist = length(lightVec);
    return tex1D(sLightRampMap, lightDist).r;
}

float GetSpecular(float3 normal, float3 eyeVec, float3 lightDir, float specularPower)
{
    float3 halfVec = normalize(normalize(eyeVec) + lightDir);
    return pow(dot(normal, halfVec), specularPower);
}

float3 GetAmbient(float zonePos)
{
    return cAmbientStartColor + zonePos * cAmbientEndColor;
}

float GetIntensity(float3 color)
{
    return dot(color, float3(0.333, 0.333, 0.333));
}

#ifdef NUMVERTEXLIGHTS
float GetVertexLight(int index, float3 worldPos, float3 normal)
{
    float3 lightDir = cVertexLights[index * 3 + 1].xyz;
    float3 lightPos = cVertexLights[index * 3 + 2].xyz;
    float invRange = cVertexLights[index * 3].w;
    float cutoff = cVertexLights[index * 3 + 1].w;
    float invCutoff = cVertexLights[index * 3 + 2].w;

    #ifndef BILLBOARD
        // Directional light
        if (invRange == 0.0)
        {
            float NdotL = max(dot(normal, lightDir), 0.0);
            return NdotL;
        }
        // Point/spot light
        else
        {
            float3 lightVec = (lightPos - worldPos) * invRange;
            float lightDist = length(lightVec);
            float3 localDir = lightVec / lightDist;
            float NdotL = max(dot(normal, localDir), 0.0);
            float atten = saturate(1.0 - lightDist * lightDist);
            float spotEffect = dot(localDir, lightDir);
            float spotAtten = saturate((spotEffect - cutoff) * invCutoff);
            return NdotL * atten * spotAtten;
        }
    #else
        // Directional light
        if (invRange == 0.0)
            return 1.0;
        // Point/spot light
        else
        {
            float3 lightVec = (lightPos - worldPos) * invRange;
            float lightDist = length(lightVec);
            float3 localDir = lightVec / lightDist;
            float atten = saturate(1.0 - lightDist * lightDist);
            float spotEffect = dot(localDir, lightDir);
            float spotAtten = saturate((spotEffect - cutoff) * invCutoff);
            return atten * spotAtten;
        }
    #endif
}
#endif

#ifdef SHADOW
float GetShadow(float4 shadowPos)
{
    // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed
    #ifndef LQSHADOW
        // Take four samples and average them
        #ifndef POINTLIGHT
            float2 offsets = cShadowMapInvSize * shadowPos.w;
        #else
            float2 offsets = cShadowMapInvSize;
        #endif
        float4 inLight = float4(
            tex2Dproj(sShadowMap, shadowPos).r,
            tex2Dproj(sShadowMap, float4(shadowPos.x + offsets.x, shadowPos.yzw)).r,
            tex2Dproj(sShadowMap, float4(shadowPos.x, shadowPos.y + offsets.y, shadowPos.zw)).r,
            tex2Dproj(sShadowMap, float4(shadowPos.xy + offsets.xy, shadowPos.zw)).r
        );
        #ifdef HWSHADOW
            return cShadowIntensity.y + dot(inLight, cShadowIntensity.x);
        #else
            #ifndef POINTLIGHT
                return cShadowIntensity.y + dot(inLight * shadowPos.w > shadowPos.z, cShadowIntensity.x);
            #else
                return cShadowIntensity.y + dot(inLight > shadowPos.z, cShadowIntensity.x);
            #endif
        #endif
    #else
        // Take one sample
        float inLight = tex2Dproj(sShadowMap, shadowPos).r;
        #ifdef HWSHADOW
            return cShadowIntensity.y + cShadowIntensity.x * inLight;
        #else
            #ifndef POINTLIGHT
                return cShadowIntensity.y + cShadowIntensity.x * (inLight * shadowPos.w > shadowPos.z);
            #else
                return cShadowIntensity.y + cShadowIntensity.x * (inLight > shadowPos.z);
            #endif
        #endif
    #endif
}

float GetCubeShadow(float3 lightVec)
{
    float3 axis = texCUBE(sFaceSelectCubeMap, lightVec).rgb;
    float depth = abs(dot(lightVec, axis));

    // Expand the maximum component of the light vector to get full 0.0 - 1.0 UV range from the cube map,
    // and to avoid sampling across faces. Some GPU's filter across faces, while others do not, and in this
    // case filtering across faces is wrong
    const float factor = 1.0 / 256.0;
    lightVec += factor * axis * lightVec;

    // Read the 2D UV coordinates, adjust according to shadow map size and add face offset
    float4 indirectPos = texCUBE(sIndirectionCubeMap, lightVec);
    indirectPos.xy *= cShadowCubeAdjust.xy;
    indirectPos.xy += float2(cShadowCubeAdjust.z + indirectPos.z * 0.5, cShadowCubeAdjust.w + indirectPos.w);

    float4 shadowPos = float4(indirectPos.xy, cShadowDepthFade.x + cShadowDepthFade.y / depth, 1.0);
    return GetShadow(shadowPos);
}

float GetShadowFade(float depth)<commit_msg>Fixed SM2 shader compile failure.<commit_after>#pragma warning(disable:3571)

float GetDiffuseDir(float3 normal, float3 lightDir)
{
    return saturate(dot(normal, lightDir));
}

float GetDiffusePointOrSpot(float3 normal, float3 lightVec, out float3 lightDir)
{
    float lightDist = length(lightVec);
    lightDir = lightVec / lightDist;
    return saturate(dot(normal, lightDir)) * tex1D(sLightRampMap, lightDist).r;
}

float GetDiffuseDirVolumetric()
{
    return 1.0;
}

float GetDiffusePointOrSpotVolumetric(float3 lightVec)
{
    float lightDist = length(lightVec);
    return tex1D(sLightRampMap, lightDist).r;
}

float GetSpecular(float3 normal, float3 eyeVec, float3 lightDir, float specularPower)
{
    float3 halfVec = normalize(normalize(eyeVec) + lightDir);
    return pow(dot(normal, halfVec), specularPower);
}

float3 GetAmbient(float zonePos)
{
    return cAmbientStartColor + zonePos * cAmbientEndColor;
}

float GetIntensity(float3 color)
{
    return dot(color, float3(0.333, 0.333, 0.333));
}

#ifdef NUMVERTEXLIGHTS
float GetVertexLight(int index, float3 worldPos, float3 normal)
{
    float3 lightDir = cVertexLights[index * 3 + 1].xyz;
    float3 lightPos = cVertexLights[index * 3 + 2].xyz;
    float invRange = cVertexLights[index * 3].w;
    float cutoff = cVertexLights[index * 3 + 1].w;
    float invCutoff = cVertexLights[index * 3 + 2].w;

    #ifndef BILLBOARD
        // Directional light
        if (invRange == 0.0)
        {
            float NdotL = max(dot(normal, lightDir), 0.0);
            return NdotL;
        }
        // Point/spot light
        else
        {
            float3 lightVec = (lightPos - worldPos) * invRange;
            float lightDist = length(lightVec);
            float3 localDir = lightVec / lightDist;
            float NdotL = max(dot(normal, localDir), 0.0);
            float atten = saturate(1.0 - lightDist * lightDist);
            float spotEffect = dot(localDir, lightDir);
            float spotAtten = saturate((spotEffect - cutoff) * invCutoff);
            return NdotL * atten * spotAtten;
        }
    #else
        // Directional light
        if (invRange == 0.0)
            return 1.0;
        // Point/spot light
        else
        {
            float3 lightVec = (lightPos - worldPos) * invRange;
            float lightDist = length(lightVec);
            float3 localDir = lightVec / lightDist;
            float atten = saturate(1.0 - lightDist * lightDist);
            float spotEffect = dot(localDir, lightDir);
            float spotAtten = saturate((spotEffect - cutoff) * invCutoff);
            return atten * spotAtten;
        }
    #endif
}
#endif

#ifdef SHADOW
float GetShadow(float4 shadowPos)
{
    // Note: in case of sampling a point light cube shadow, we optimize out the w divide as it has already been performed
    #ifndef LQSHADOW
        // Take four samples and average them
        #ifndef POINTLIGHT
            float2 offsets = cShadowMapInvSize * shadowPos.w;
        #else
            float2 offsets = cShadowMapInvSize;
        #endif
        float4 inLight = float4(
            tex2Dproj(sShadowMap, shadowPos).r,
            tex2Dproj(sShadowMap, float4(shadowPos.x + offsets.x, shadowPos.yzw)).r,
            tex2Dproj(sShadowMap, float4(shadowPos.x, shadowPos.y + offsets.y, shadowPos.zw)).r,
            tex2Dproj(sShadowMap, float4(shadowPos.xy + offsets.xy, shadowPos.zw)).r
        );
        #ifdef HWSHADOW
            return cShadowIntensity.y + dot(inLight, cShadowIntensity.x);
        #else
            #ifndef POINTLIGHT
                return cShadowIntensity.y + dot(inLight * shadowPos.w > shadowPos.z, cShadowIntensity.x);
            #else
                return cShadowIntensity.y + dot(inLight > shadowPos.z, cShadowIntensity.x);
            #endif
        #endif
    #else
        // Take one sample
        float inLight = tex2Dproj(sShadowMap, shadowPos).r;
        #ifdef HWSHADOW
            return cShadowIntensity.y + cShadowIntensity.x * inLight;
        #else
            #ifndef POINTLIGHT
                return cShadowIntensity.y + cShadowIntensity.x * (inLight * shadowPos.w > shadowPos.z);
            #else
                return cShadowIntensity.y + cShadowIntensity.x * (inLight > shadowPos.z);
            #endif
        #endif
    #endif
}

float GetCubeShadow(float3 lightVec)
{
    float3 axis = texCUBE(sFaceSelectCubeMap, lightVec).rgb;
    float depth = abs(dot(lightVec, axis));

    // Expand the maximum component of the light vector to get full 0.0 - 1.0 UV range from the cube map,
    // and to avoid sampling across faces. Some GPU's filter across faces, while others do not, and in this
    // case filtering across faces is wrong
    // Note: when doing also alpha masking on SM2, the texture sampling becomes too complex, so there is no
    // choice but to skip it
    #if defined(SM3) || !defined(ALPHAMASK)
    const float factor = 1.0 / 256.0;
    lightVec += factor * axis * lightVec;
    #endif

    // Read the 2D UV coordinates, adjust according to shadow map size and add face offset
    float4 indirectPos = texCUBE(sIndirectionCubeMap, lightVec);
    indirectPos.xy *= cShadowCubeAdjust.xy;
    indirectPos.xy += float2(cShadowCubeAdjust.z + indirectPos.z * 0.5, cShadowCubeAdjust.w + indirectPos.w);

    float4 shadowPos = float4(indirectPos.xy, cShadowDepthFade.x + cShadowDepthFade.y / depth, 1.0);
    return GetShadow(shadowPos);
}

float GetShadowFade(float depth)
{'fraction_non_alphanumeric': 0.09380250140003733, 'fraction_numerical': 0.01857382863543028, 'mean_word_length': 2.5246710526315788, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4425153', 'n_tokens_mistral': 3461, 'n_tokens_neox': 3277, 'n_words': 874}