precision highp float;
precision highp int;
precision highp sampler2D;
precision highp sampler2DArray;

in vec4 vertPosition;
in mat4 vertModelMatrix;

flat out mat4 invModelMatrix;
flat out vec3 decalDirection;
flat out float normal_angle_cutoff;
flat out float angle_fade_start;
flat out float alpha_scale;

layout (std140) uniform decalGlobalData {
	mat4 viewMatrix;
	mat4 projMatrix;
	mat4 invViewMatrix;
	mat4 invProjMatrix;

	vec2 viewportSize;
};

layout (std140) uniform decalInfoData {
	int diffuse_index;
	int glow_index;
	int normal_index;
	int diffuse_blend_mode;

	int glow_blend_mode;
};

void main() {
    normal_angle_cutoff = vertModelMatrix[0][3];
    angle_fade_start = vertModelMatrix[1][3];
    alpha_scale = vertModelMatrix[2][3];

    mat4 modelMatrix = vertModelMatrix;
    modelMatrix[0][3] = 0.0;
    modelMatrix[1][3] = 0.0;
    modelMatrix[2][3] = 0.0;

    invModelMatrix = inverse(modelMatrix);
    decalDirection = mat3(viewMatrix) * modelMatrix[2].xyz;
	gl_Position = projMatrix * viewMatrix * modelMatrix * vertPosition;
}
