#include "ai.h"

AI_SHADER_NODE_EXPORT_METHODS(apZinkeBSDF)

enum apHairBSDFParams
{
	p_weight,
	p_opacity
};


struct ShaderData
{
};

node_parameters
{
	AiParameterRGB("weight", 0.0, 0.0, 0.0);
	AiParameterRGB("opacity", 1, 1, 1);
}

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

node_update
{
}

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

shader_evaluate
{
	ShaderData *data = (ShaderData *)AiNodeGetLocalData(node);
	AtRGB weight = AiShaderEvalParamRGB(p_weight);
	AtRGB opacity = AiShaderEvalParamRGB(p_opacity);
	AtBSDF *bsdf = AiZinkeBSDF(sg, weight, sg->dPdv);

	AtClosureList closures;
	closures.add(bsdf);
	closures.add(AiClosureTransparent(sg, 1.0 - opacity));
	sg->out.CLOSURE() = closures;
}

node_loader
{
	if (i > 0)
	return false;

	node->methods = apZinkeBSDF;
	node->output_type = AI_TYPE_CLOSURE;
	node->name = "apZinkeBSDF";
	node->node_type = AI_NODE_SHADER;
	strcpy(node->version, AI_VERSION);
	return true;
}
