tahoma2d/toonz/sources/stdfx/raylitfx.cpp

253 lines
8 KiB
C++
Raw Normal View History

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