<commit_before>vec3 specularLight (
    vec4 position,
    vec3 normal,
    vec3 color,
    vec4 light_pos,
    float light_ambient,
    const bool backlight) {

    vec3 light_dir = normalize(position.xyz - light_pos.xyz); // from light point to vertex

    vec3 view_pos = vec3(0., 0., 500.);
    vec3 view_dir = normalize(position.xyz - view_pos.xyz);


    // color *= abs(max(float(backlight) * -1., dot(normal, -light_dir ))) + light_ambient;

	// color *= max(0., dot(normal, light_dir * -1.0)) + light_ambient;



    // vec3 viewDirection = normalize(vec3(v_inv * vec4(0.0, 0.0, 0.0, 1.0) - m * v_coord));
    // vec3 viewDirection = normalize(vec3(position * vec4(0.0, 0.0, 0.0, 1.0) * position));
    // vec3 lightDirection = normalize(light_pos.xyz);
    // vec3 normalDirection = normalize(normal);

    vec3 specularReflection;
    if (dot(normal, -light_dir) < 0.0) // light source on the wrong side?
    {
      specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
    }
    else
    {
        float attenuation = 1.0;
        float lightSpecularTerm = 1.0;
        float materialSpecularTerm = 10.0;
        float materialShininessTerm = 10.0;

        specularReflection = attenuation * vec3(lightSpecularTerm) * vec3(materialSpecularTerm) * 
            pow(max(0.0, dot(reflect(-light_dir, normal), view_dir)), materialShininessTerm);

        // specularReflection = attenuation * vec3(light0.specular) * vec3(mymaterial.specular) * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), mymaterial.shininess);
    }

    color *= abs(max(float(backlight) * -1., dot(normal, light_dir * -1.0))) + light_ambient + specularReflection;

    return color;
}

#pragma glslify: export(specularLight)<commit_msg>small cleanup/tweak on specular light shader<commit_after>vec3 specularLight (
    vec4 position,
    vec3 normal,
    vec3 color,
    vec4 light_pos,
    float light_ambient,
    const bool backlight) {

    vec3 light_dir = normalize(position.xyz - light_pos.xyz); // direction from the light to the model
    vec3 view_pos = vec3(0., 0., 500.); // approximate location of eye (TODO: make this configurable and calculated based on proper FOV/perspective calc)
    vec3 view_dir = normalize(position.xyz - view_pos.xyz); // direction from eye to model

    vec3 specularReflection;

    if (dot(normal, -light_dir) < 0.0) { // light source on the wrong side?
      specularReflection = vec3(0.0, 0.0, 0.0); // no specular reflection
    }
    else {
        // TODO: make configurable / part of material + light definitions
        float attenuation = 1.0;
        float lightSpecularTerm = 1.0;
        float materialSpecularTerm = 10.0;
        float materialShininessTerm = 10.0;

        specularReflection =
            attenuation *
            vec3(lightSpecularTerm) *
            vec3(materialSpecularTerm) *
            pow(max(0.0, dot(reflect(-light_dir, normal), view_dir)), materialShininessTerm);
    }

    // specularReflection *= vec3(1., 0., 0.); // test specular color (TODO: add support in light definition)

    float diffuse = abs(max(float(backlight) * -1., dot(normal, light_dir * -1.0)));

    // Diffuse + specular + ambient
    color *=
        diffuse +
        specularReflection +
        light_ambient;

    return color;
}

#pragma glslify: export(specularLight)
{'fraction_non_alphanumeric': 0.11997618338791306, 'fraction_numerical': 0.035427210479309315, 'mean_word_length': 2.870967741935484, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7480226', 'n_tokens_mistral': 1145, 'n_tokens_neox': 1055, 'n_words': 271}