Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "tparamuiconcept.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class BaseRaylitFx : public TStandardRasterFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
	TPointParamP m_p;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_z;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_intensity;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_decay;
Toshihiro Shimizu 890ddd
	TDoubleParamP m_smoothness;
Toshihiro Shimizu 890ddd
	TBoolParamP m_includeInput;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	BaseRaylitFx()
Toshihiro Shimizu 890ddd
		: m_p(TPointD(0, 0)), m_z(300.0), m_intensity(60), m_decay(1.0), m_smoothness(100), m_includeInput(false)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		m_p->getX()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
		m_p->getY()->setMeasureName("fxLength");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		bindParam(this, "p", m_p);
Toshihiro Shimizu 890ddd
		bindParam(this, "z", m_z);
Toshihiro Shimizu 890ddd
		bindParam(this, "intensity", m_intensity);
Toshihiro Shimizu 890ddd
		bindParam(this, "decay", m_decay);
Toshihiro Shimizu 890ddd
		bindParam(this, "smoothness", m_smoothness);
Toshihiro Shimizu 890ddd
		bindParam(this, "includeInput", m_includeInput);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		addInputPort("Source", m_input);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	~BaseRaylitFx() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	bool canHandle(const TRenderSettings &info, double frame) { return false; }
Toshihiro Shimizu 890ddd
	int getMemoryRequirement(const TRectD &rect, double frame, const TRenderSettings &info);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doDryCompute(TRectD &rect, double frame, const TRenderSettings &info);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void getParamUIs(TParamUIConcept *&concepts, int &length)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		concepts = new TParamUIConcept[length = 1];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		concepts[0].m_type = TParamUIConcept::POINT;
Toshihiro Shimizu 890ddd
		concepts[0].m_label = "Center";
Toshihiro Shimizu 890ddd
		concepts[0].m_params.push_back(m_p);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
bool BaseRaylitFx::doGetBBox(double frame, TRectD &bBox, const TRenderSettings &info)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (m_input.isConnected()) {
Toshihiro Shimizu 890ddd
		bool ret = m_input->doGetBBox(frame, bBox, info);
Toshihiro Shimizu 890ddd
		if (ret)
Toshihiro Shimizu 890ddd
			bBox = TConsts::infiniteRectD;
Toshihiro Shimizu 890ddd
		return ret;
Toshihiro Shimizu 890ddd
	} else {
Toshihiro Shimizu 890ddd
		bBox = TRectD();
Toshihiro Shimizu 890ddd
		return false;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void BaseRaylitFx::doDryCompute(TRectD &rect,
Toshihiro Shimizu 890ddd
								double frame,
Toshihiro Shimizu 890ddd
								const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_input.isConnected())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD bboxIn;
Toshihiro Shimizu 890ddd
	m_input->getBBox(frame, bboxIn, ri);
Toshihiro Shimizu 890ddd
	if (bboxIn == TConsts::infiniteRectD)
Toshihiro Shimizu 890ddd
		bboxIn = rect;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 12c444
	TDimension sizeIn(std::max(tceil(bboxIn.getLx()), 1), std::max(tceil(bboxIn.getLy()), 1));
Toshihiro Shimizu 890ddd
	bboxIn = TRectD(bboxIn.getP00(), TDimensionD(sizeIn.lx, sizeIn.ly));
Toshihiro Shimizu 890ddd
	m_input->dryCompute(bboxIn, frame, ri);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//---------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
int BaseRaylitFx::getMemoryRequirement(const TRectD &rect, double frame, const TRenderSettings &info)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	TRectD bboxIn;
Toshihiro Shimizu 890ddd
	m_input->getBBox(frame, bboxIn, info);
Toshihiro Shimizu 890ddd
	if (bboxIn == TConsts::infiniteRectD)
Toshihiro Shimizu 890ddd
		return -1;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (bboxIn.isEmpty())
Toshihiro Shimizu 890ddd
		return 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	return TRasterFx::memorySize(bboxIn, info.m_bpp);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class RaylitFx : public BaseRaylitFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(RaylitFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
protected:
Toshihiro Shimizu 890ddd
	TPixelParamP m_color;
Toshihiro Shimizu 890ddd
	TBoolParamP m_invert;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	RaylitFx()
Toshihiro Shimizu 890ddd
		: m_color(TPixel(255, 80, 0)), m_invert(false)
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		bindParam(this, "color", m_color);
Toshihiro Shimizu 890ddd
		bindParam(this, "invert", m_invert);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(RaylitFx, "raylitFx")
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void RaylitFx::doCompute(TTile &tileOut, double frame, const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_input.isConnected())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double scale = sqrt(fabs(ri.m_affine.det()));
Toshihiro Shimizu 890ddd
	int shrink = (ri.m_shrinkX + ri.m_shrinkY) / 2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD p(ri.m_affine * m_p->getValue(frame));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD rectIn(tileOut.m_pos, TDimensionD(tileOut.getRaster()->getLx(), tileOut.getRaster()->getLy()));
Toshihiro Shimizu 890ddd
	TRectD bboxIn;
Toshihiro Shimizu 890ddd
	m_input->getBBox(frame, bboxIn, ri);
Toshihiro Shimizu 890ddd
	if (bboxIn == TConsts::infiniteRectD)
Toshihiro Shimizu 890ddd
		bboxIn = rectIn;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!bboxIn.isEmpty()) {
Toshihiro Shimizu 890ddd
		TPoint posIn, posOut;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTile tileIn;
Shinya Kitaoka 12c444
		TDimension sizeIn(std::max(tceil(bboxIn.getLx()), 1), std::max(tceil(bboxIn.getLy()), 1));
Toshihiro Shimizu 890ddd
		m_input->allocateAndCompute(tileIn, bboxIn.getP00(), sizeIn,
Toshihiro Shimizu 890ddd
									tileOut.getRaster(), frame, ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRop::RaylitParams params;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		params.m_scale = scale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.x = params.m_lightOriginDst.x = p.x;
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.y = params.m_lightOriginDst.y = p.y;
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.z = params.m_lightOriginDst.z = (int)m_z->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_color = m_color->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_intensity = m_intensity->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_decay = m_decay->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_smoothness = m_smoothness->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_invert = m_invert->getValue();
Toshihiro Shimizu 890ddd
		params.m_includeInput = m_includeInput->getValue();
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.x -= (int)tileIn.m_pos.x;
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.y -= (int)tileIn.m_pos.y;
Toshihiro Shimizu 890ddd
		params.m_lightOriginDst.x -= (int)tileOut.m_pos.x;
Toshihiro Shimizu 890ddd
		params.m_lightOriginDst.y -= (int)tileOut.m_pos.y;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRop::raylit(tileOut.getRaster(), tileIn.getRaster(), params);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//========================================================================================
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
class ColorRaylitFx : public BaseRaylitFx
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	FX_PLUGIN_DECLARATION(ColorRaylitFx)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Toshihiro Shimizu 890ddd
	ColorRaylitFx() : BaseRaylitFx() {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	void doCompute(TTile &tile, double frame, const TRenderSettings &);
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void ColorRaylitFx::doCompute(TTile &tileOut, double frame, const TRenderSettings &ri)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_input.isConnected())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	double scale = sqrt(fabs(ri.m_affine.det()));
Toshihiro Shimizu 890ddd
	int shrink = (ri.m_shrinkX + ri.m_shrinkY) / 2;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TPointD p(ri.m_affine * m_p->getValue(frame));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	TRectD rectIn(tileOut.m_pos, TDimensionD(tileOut.getRaster()->getLx(), tileOut.getRaster()->getLy()));
Toshihiro Shimizu 890ddd
	TRectD bboxIn;
Toshihiro Shimizu 890ddd
	m_input->getBBox(frame, bboxIn, ri);
Toshihiro Shimizu 890ddd
	if (bboxIn == TConsts::infiniteRectD)
Toshihiro Shimizu 890ddd
		bboxIn = rectIn;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!bboxIn.isEmpty()) {
Toshihiro Shimizu 890ddd
		TPoint posIn, posOut;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TTile tileIn;
Shinya Kitaoka 12c444
		TDimension sizeIn(std::max(tceil(bboxIn.getLx()), 1), std::max(tceil(bboxIn.getLy()), 1));
Toshihiro Shimizu 890ddd
		m_input->allocateAndCompute(tileIn, bboxIn.getP00(), sizeIn,
Toshihiro Shimizu 890ddd
									tileOut.getRaster(), frame, ri);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRop::RaylitParams params;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		params.m_scale = scale;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.x = params.m_lightOriginDst.x = p.x;
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.y = params.m_lightOriginDst.y = p.y;
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.z = params.m_lightOriginDst.z = (int)m_z->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_intensity = m_intensity->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_decay = m_decay->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_smoothness = m_smoothness->getValue(frame);
Toshihiro Shimizu 890ddd
		params.m_includeInput = m_includeInput->getValue();
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.x -= (int)tileIn.m_pos.x;
Toshihiro Shimizu 890ddd
		params.m_lightOriginSrc.y -= (int)tileIn.m_pos.y;
Toshihiro Shimizu 890ddd
		params.m_lightOriginDst.x -= (int)tileOut.m_pos.x;
Toshihiro Shimizu 890ddd
		params.m_lightOriginDst.y -= (int)tileOut.m_pos.y;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
		TRop::glassRaylit(tileOut.getRaster(), tileIn.getRaster(), params);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(ColorRaylitFx, "colorRaylitFx")