<commit_before>#ifndef BLINNPHONGMATERIAL_GLSL
#define BLINNPHONGMATERIAL_GLSL
const float Pi = 3.141592653589793;

struct BlinnPhongTextures
{
    int hasKd;
    int hasKs;
    int hasNs;
    int hasNormal;
    int hasAlpha;

    sampler2D kd;
    sampler2D ks;
    sampler2D ns;
    sampler2D normal;
    sampler2D alpha;
};

struct Material
{
    vec4 kd;
    vec4 ks;

    float ns;
    float alpha;

    BlinnPhongTextures tex;
};

vec3 getKd(Material material, vec2 texCoord)
{
    if (material.tex.hasKd == 1)
    {
        return vec3(texture(material.tex.kd, texCoord));
    }

    return material.kd.xyz;
}

vec3 getKs(Material material, vec2 texCoord)
{
    if (material.tex.hasKs == 1)
    {
        return vec3(texture(material.tex.ks, texCoord));
    }

    return material.ks.xyz;
}

float getNs(Material material, vec2 texCoord)
{
    float ns = material.ns;
    if (material.tex.hasNs == 1)
    {
        ns = texture(material.tex.ns, texCoord).r;
    }

    return max(ns, 0.001);
}

vec3 getNormal(Material material, vec2 texCoord, vec3 N, vec3 T, vec3 B)
{
    if (material.tex.hasNormal == 1) {
        mat3 tbn;

        tbn[0]  = T;
        tbn[1]  = B;
        tbn[2]  = N;
<commit_msg>Phong to Blinn-Phong specular parameters conversion<commit_after>#ifndef BLINNPHONGMATERIAL_GLSL
#define BLINNPHONGMATERIAL_GLSL
// Blinn-Phong specular and exponent :
// As this shader is built on Blinn-Phong NDF, that approximate Cook-Torrance,
// Specular parameters from the asset must be converted so that specular highlight look the same than with
// standard Phong BRDF (divided both Ks and Ns by Pi looks good).
// See http://www.thetenthplanet.de/archives/255 for intuitions
const float Pi = 3.141592653589793;

struct BlinnPhongTextures
{
    int hasKd;
    int hasKs;
    int hasNs;
    int hasNormal;
    int hasAlpha;

    sampler2D kd;
    sampler2D ks;
    sampler2D ns;
    sampler2D normal;
    sampler2D alpha;
};

struct Material
{
    vec4 kd;
    vec4 ks;

    float ns;
    float alpha;

    BlinnPhongTextures tex;
};

vec3 getKd(Material material, vec2 texCoord)
{
    if (material.tex.hasKd == 1)
    {
        return vec3(texture(material.tex.kd, texCoord));
    }

    return material.kd.xyz;
}

vec3 getKs(Material material, vec2 texCoord)
{
    if (material.tex.hasKs == 1)
    {
        return vec3(texture(material.tex.ks, texCoord));
    }

    return material.ks.xyz / Pi; // Phong specular to blinn-phong exponent
}

float getNs(Material material, vec2 texCoord)
{
    float ns = material.ns;
    if (material.tex.hasNs == 1)
    {
        ns = texture(material.tex.ns, texCoord).r;
    }

    return max(ns, 0.001)/Pi; // Phong exponent to blinn-phong exponent
}

vec3 getNormal(Material material, vec2 texCoord, vec3 N, vec3 T, vec3 B)
{
    if (material.tex.hasNormal == 1) {
        mat3 tbn;

        tbn[0]  = T;
        tbn[1]  = B;
        tbn[2]  = N;

{'fraction_non_alphanumeric': 0.10361445783132531, 'fraction_numerical': 0.033390705679862305, 'mean_word_length': 2.6645649432534677, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '5623362', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1071, 'n_words': 278}