#include "core.fsh"
#include "pbr.fsh"
#include "commonInput.fsh"
#include "light.fsh"
in highp vec3 P_f;
layout(location = 0) out vec4 fragColor;

#ifndef COM_BASE_TEX
in mediump vec4 COLOR0_f;
#endif

uniform float iblIntensity;

void main()
{
    PBRInfo info;
#ifndef COM_BASE_TEX
    info.albedo = COLOR0_f;
#else
    info.albedo = getBaseCol();
#endif
    vec2 metalRough = getMetaRough();
    info.metallic = metalRough.x;
    info.roughness = metalRough.y;
    info.emissive = vec3(0.0);
    
    info.dirN = getNormal();
    info.dirV = normalize(_WorldEye - P_f);
    vec3 dirR = reflect(-info.dirV, info.dirN);
  
    info.iSpec = IBL_Reflect(dirR, info.roughness) * iblIntensity;
    
#ifdef DI_IRRADIANCE_ENABLE
    info.iDiff = IBL_Irradiance(info.dirN) * iblIntensity;
#else
    info.iDiff = EnvCol;
#endif
    
    float alpha;
    vec3 color = BRDF_PBS(info, alpha);
    
    fragColor = vec4(LinearToSRGB(color), alpha);
}
