

#include "/lib/taa/res_params.glsl"
varying vec4 lmtexcoord;
varying vec4 color;
varying vec3 normalMat;

uniform sampler2D texture;
#ifdef LEAVES
flat varying float translucent;
#endif
flat varying float emissive;

#include "/lib/projections.glsl"
#include "/lib/uniforms.glsl"

// faster and actually more precise than pow 2.2
vec3 toLinear(vec3 sRGB)
{
    return sRGB * (sRGB * (sRGB * 0.305306011 + 0.682171111) + 0.012522878);
}

#if defined ENTITY && defined NO_ENTITY_TAA

/* RENDERTARGETS: 0,11,12,3 */
#else
/* RENDERTARGETS: 0,11,12 */

#endif

void main()
{

    vec4 albedo = texture(texture, lmtexcoord.xy, 0);
    albedo.rgb = toLinear(albedo.rgb * color.rgb);
#ifdef LEAVES
    gl_FragData[2].r = translucent; // Materials
#endif
    gl_FragData[0] = albedo;                                                                 // Albedo
    gl_FragData[1].rgba = vec4(encodeNormal(normalMat), encodeVec2(lmtexcoord.zw), color.a); // normals
    gl_FragData[2].g = emissive;
#ifdef ENTITY
#ifdef NO_ENTITY_TAA


    gl_FragData[3].g = 1 ; // Materials

#endif
#endif
}
