#include "ai.h"

AI_SHADER_NODE_EXPORT_METHODS(apMotionVector);

enum apMotionVectorParams
{
	p_mode,
	p_input,
	p_opacity,
	p_normalize,
};
const char *ModeNames[] =
	{
		"RevisionFX ReelSmart Motion Blur (RSMB)",
		"RevisionFX SmoothKit",
		NULL};
const char *NormalizeSizeNames[] =
	{
		"16",
		"32",
		"64",
		"128",
		"256",
		"512",
		"1024",
		"2048",
		"4096",
		NULL};

struct ShaderData
{
	int mode;
	int normalize;
	float frame;
	float shutter_start;
	float shutter_end;
};

node_parameters
{
	AiParameterEnum("mode", 0, ModeNames);
	AiParameterEnum("normalize", 0, NormalizeSizeNames);
}

node_initialize
{
	ShaderData *data = (ShaderData *)AiMalloc(sizeof(ShaderData));
	AiNodeSetLocalData(node, data);
}

node_update
{
	ShaderData *data = (ShaderData *)AiNodeGetLocalData(node);
	data->mode = AiNodeGetInt(node, "mode");
	data->normalize = AiNodeGetInt(node, "normalize");
	AtNode *option = AiUniverseGetOptions();
	data->frame = AiNodeGetFlt(node, "frame");
	AtNode *camera = AiUniverseGetCamera();
	data->shutter_start = AiNodeGetFlt(camera, "shutter_start");
	data->shutter_end = AiNodeGetFlt(camera, "shutter_end");
}

node_finish
{
	ShaderData *data = (ShaderData *)AiNodeGetLocalData(node);
	AiFree(data);
}

shader_evaluate
{
	ShaderData *data = (ShaderData *)AiNodeGetLocalData(node);
	float frame_start = sg->time + data->shutter_start;
	AtVector2 mv = AiShaderGlobalsGetPixelMotionVector(sg, frame_start, sg->time);
	// TODO
}