layout (triangles, fractional_odd_spacing, ccw) in;

#include "/lib/settings.glsl"

in DATA {
	#if !defined ENTITIES && !defined HAND && defined SHADER_GRASS && !defined BLOCKENTITIES
		vec4 grassSideCheck;
		vec3 centerPosition;
	#endif

	vec4 color;

	#if defined IRIS_FEATURE_FADE_VARIABLE && VANILLA_CHUNK_FADING > 0 && !defined HAND
		float chunkFade;
	#endif

	vec4 lmtexcoord;
	vec3 normalMat;

	#if defined POM && (defined WORLD && !defined ENTITIES && !defined HAND || defined COLORWHEEL)
		vec4 texcoordam; // .st for add, .pq for mul
		vec2 texcoord;
	#endif

	#ifdef MC_NORMAL_MAP
		vec4 tangent;
	#endif

	flat int blockID;
	vec3 worldPosAbs;
} data_in[];

out DATA {
	#if !defined ENTITIES && !defined HAND && defined SHADER_GRASS && !defined BLOCKENTITIES
		vec4 grassSideCheck;
		vec3 centerPosition;
	#endif

	vec4 color;

	#if defined IRIS_FEATURE_FADE_VARIABLE && VANILLA_CHUNK_FADING > 0 && !defined HAND
		float chunkFade;
	#endif

	vec4 lmtexcoord;
	vec3 normalMat;

	#if defined POM && (defined WORLD && !defined ENTITIES && !defined HAND || defined COLORWHEEL)
		vec4 texcoordam; // .st for add, .pq for mul
		vec2 texcoord;
	#endif

	#ifdef MC_NORMAL_MAP
		vec4 tangent;
	#endif

	flat int blockID;
	vec3 worldPosAbs;
} data_out;


#define calcTessellation(u, v, w) (gl_TessCoord.x * u + gl_TessCoord.y * v + gl_TessCoord.z * w)

void main() {

    gl_Position = calcTessellation(gl_in[0].gl_Position, gl_in[1].gl_Position, gl_in[2].gl_Position);

    data_out.color = calcTessellation(data_in[0].color, data_in[1].color, data_in[2].color);
    data_out.lmtexcoord = calcTessellation(data_in[0].lmtexcoord, data_in[1].lmtexcoord, data_in[2].lmtexcoord);
    data_out.normalMat = calcTessellation(data_in[0].normalMat, data_in[1].normalMat, data_in[2].normalMat);

    #if defined POM && (defined WORLD && !defined ENTITIES && !defined HAND || defined COLORWHEEL)
        data_out.texcoordam = calcTessellation(data_in[0].texcoordam, data_in[1].texcoordam, data_in[2].texcoordam);
        data_out.texcoord = calcTessellation(data_in[0].texcoord, data_in[1].texcoord, data_in[2].texcoord);
    #endif

	#if defined IRIS_FEATURE_FADE_VARIABLE && VANILLA_CHUNK_FADING > 0 && !defined HAND
		data_out.chunkFade = calcTessellation(data_in[0].chunkFade, data_in[1].chunkFade, data_in[2].chunkFade);
	#endif

    #ifdef MC_NORMAL_MAP
        data_out.tangent = calcTessellation(data_in[0].tangent, data_in[1].tangent, data_in[2].tangent);
    #endif

    data_out.blockID = data_in[0].blockID;
    data_out.worldPosAbs = calcTessellation(data_in[0].worldPosAbs, data_in[1].worldPosAbs, data_in[2].worldPosAbs);

    #if !defined ENTITIES && !defined HAND && defined SHADER_GRASS && !defined BLOCKENTITIES && defined WORLD
        data_out.grassSideCheck = data_in[0].grassSideCheck;
        data_out.centerPosition = data_in[0].centerPosition;
    #endif

}