
float computePhaseFactor(float x, float g)
{
    float gg = g * g;
    return (gg * -0.25 + 0.25) * pow(-2.0 * (g * x) + (gg + 1.0), -1.5) / PI;
}

float shadowFunc_no_shadow(float diffuseSun, float sssAmount, vec3 p3, vec2 lightmap, float ao, vec3 fragpos)
{
    ivec2 texCoords = ivec2(gl_FragCoord.xy);

    vec4 basicTex = texelFetch(colortex2, texCoords, 0);
    vec2 lightmap2 = decodeVec2(basicTex.b);

    float angleFactor = dot(normalize(p3), lightPos);

    float phaseG1 = computePhaseFactor(angleFactor, 0.5) * 0.5;
    float phaseG2 = computePhaseFactor(angleFactor, 0.1) * 0.5;
    float phaseG3 = computePhaseFactor(angleFactor, 0.6);

    float maxPhase = max(phaseG1, phaseG2);
    float scaledPhase = maxPhase * PI;

    float phaseFactor = clamp(scaledPhase, 0.0, 1.0);
    phaseFactor = max(phaseFactor, diffuseSun);

    float shading = pow(lightmap.y, 8) * lightmap.y;
    // shading = min(rayTraceShadow2(diffuseSun, worldToView(lightPos), fragpos, noise_standard(gl_FragCoord.xy)), shading);

    diffuseSun *= shading;

    diffuseSun = mix(diffuseSun * (1.0 - sssAmount), phaseFactor, sssAmount) * lightmap.y * (1.0 - 0.9 * rainStrength);

    return diffuseSun * ao;
}
