<commit_before>#pragma once

#pragma include "Includes/Configuration.inc.glsl"
#pragma include "Includes/Structures/Material.struct.glsl"
#pragma include "Includes/BRDF.inc.glsl"
#pragma include "Includes/IESLighting.inc.glsl"



float get_pointlight_attenuation(float radius, float dist) {

    // return step(d, r);

    // https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/
    // Inverse falloff
    float attenuation = 1.0 / (1.0 + 2*dist/radius + (dist*dist)/(radius*radius)); 


    // Cut light transition starting at 80% because the curve is exponential and never really gets 0
    // float cutoff = r * 0.7;
    // attenuation *= 1.0 - saturate((d / cutoff) - 1.0) * (0.7 / 0.3);

    float linear = 1.0 - saturate(dist / radius);

    return linear;

    return max(0.0, attenuation * linear);
} 

// @TODO: Make this method faster
vec3 applyLight(Material m, vec3 v, vec3 l, vec3 light_color, float attenuation, float shadow, vec4 directional_occlusion, int ies_profile) {


    // Debugging: Fast rendering path
    #if 0
        // return max(0, dot(m.normal, l)) * lightColor * attenuation * m.diffuse;
    #endif

    // Compute ies profile<commit_msg>Correct attenuation formula<commit_after>#pragma once

#pragma include "Includes/Configuration.inc.glsl"
#pragma include "Includes/Structures/Material.struct.glsl"
#pragma include "Includes/BRDF.inc.glsl"
#pragma include "Includes/IESLighting.inc.glsl"



float get_pointlight_attenuation(float radius, float dist) {

    // return step(d, r);

    // https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/
    // Inverse falloff
    // float attenuation = 1.0 / (1.0 + 2*dist/radius + (dist*dist)/(radius*radius)); 

    float d_by_r = dist / radius + 1;
    float attenuation = 1 / (d_by_r * d_by_r);

    // Cut light transition starting at 80% because the curve is exponential and never really gets 0
    // float cutoff = r * 0.7;
    // attenuation *= 1.0 - saturate((d / cutoff) - 1.0) * (0.7 / 0.3);

    float linear = 1.0 - saturate(dist / radius);

    return linear;

    return max(0.0, attenuation * linear);
} 

// @TODO: Make this method faster
vec3 applyLight(Material m, vec3 v, vec3 l, vec3 light_color, float attenuation, float shadow, vec4 directional_occlusion, int ies_profile) {


    // Debugging: Fast rendering path
    #if 0
        // return max(0, dot(m.normal, l)) * lightColor * attenuation * m.diffuse;
    #endif

    // Compute ies profile
{'fraction_non_alphanumeric': 0.12712550607287448, 'fraction_numerical': 0.03076923076923077, 'mean_word_length': 3.132107023411371, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '6695190', 'n_tokens_mistral': 904, 'n_tokens_neox': 783, 'n_words': 227}