|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "traster.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// Local namespace stuff
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
namespace {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename t=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
struct RaylitFuncTraits {
|
|
Shinya Kitaoka |
120a6e |
typedef void (*function_type)(T *, T *, int, int, int, int, const TRect &,
|
|
Shinya Kitaoka |
120a6e |
const TRect &, const TRop::RaylitParams &);
|
|
Toshihiro Shimizu |
890ddd |
};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename t=""></typename>
|
|
Shinya Kitaoka |
120a6e |
void performStandardRaylit(T *bufIn, T *bufOut, int dxIn, int dyIn, int dxOut,
|
|
Shinya Kitaoka |
120a6e |
int dyOut, const TRect &srcRect,
|
|
Shinya Kitaoka |
120a6e |
const TRect &dstRect,
|
|
Shinya Kitaoka |
120a6e |
const TRop::RaylitParams ¶ms) {
|
|
Shinya Kitaoka |
120a6e |
/* NOTATION: Diagram assuming octant 1
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/ |
|
|
Shinya Kitaoka |
120a6e |
/ |
|
|
Shinya Kitaoka |
120a6e |
/ - ray_final_y | octLy
|
|
Shinya Kitaoka |
120a6e |
/ 1 |
|
|
Shinya Kitaoka |
120a6e |
+---- |
|
|
Shinya Kitaoka |
120a6e |
_____ octLx
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
So, octLx and octLy are the octant's lx and ly; ray_final_y is the final height
|
|
Shinya Kitaoka |
120a6e |
of the ray we're tracing
|
|
Shinya Kitaoka |
120a6e |
*/
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Build colors-related variables
|
|
Shinya Kitaoka |
120a6e |
int max = T::maxChannelValue;
|
|
Shinya Kitaoka |
120a6e |
/*-- 透明部分の色 --*/
|
|
Shinya Kitaoka |
120a6e |
int transp_val = (params.m_invert) ? max : 0, opaque_val = max - transp_val;
|
|
Shinya Kitaoka |
120a6e |
int value, val_r, val_g, val_b, val_m;
|
|
Shinya Kitaoka |
120a6e |
double lightness, r_fac, g_fac, b_fac, m_fac;
|
|
Shinya Kitaoka |
120a6e |
/*-- 8bit/16bitの違いを吸収する係数 --*/
|
|
Shinya Kitaoka |
120a6e |
double factor = max / 255.0;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
255f14 |
// NOTE: These variable initializations are, well,
|
|
shun-iwasawa |
255f14 |
// heuristic at least. They were probably tested
|
|
shun-iwasawa |
255f14 |
// to be good, but didn't quite make any REAL sense.
|
|
Shinya Kitaoka |
120a6e |
// They could be done MUCH better, but changing them
|
|
shun-iwasawa |
255f14 |
// would alter the way raylit has been applied until now.
|
|
shun-iwasawa |
255f14 |
// Should be changed at some point, though...
|
|
shun-iwasawa |
255f14 |
|
|
shun-iwasawa |
255f14 |
double scale = params.m_scale;
|
|
shun-iwasawa |
255f14 |
double decay = log(params.m_decay / 100.0 + 1.0) + 1.0;
|
|
shun-iwasawa |
255f14 |
double intensity = 1e8 * log(params.m_intensity / 100.0 + 1.0) / scale;
|
|
shun-iwasawa |
255f14 |
double smoothness = log(params.m_smoothness * 5.0 / 100.0 + 1.0);
|
|
shun-iwasawa |
255f14 |
double radius = params.m_radius;
|
|
shun-iwasawa |
255f14 |
|
|
Shinya Kitaoka |
120a6e |
/*-- 1ステップ進んだ時、次のピクセルで光源が無かったときの光の弱まる割合 --*/
|
|
shun-iwasawa |
255f14 |
double neg_delta_p = smoothness * intensity;
|
|
Shinya Kitaoka |
120a6e |
/*-- 1ステップ進んだ時、次のピクセルで光源が有ったときの光の強まる割合 --*/
|
|
Shinya Kitaoka |
120a6e |
double quot_delta_p = intensity / max; //
|
|
shun-iwasawa |
255f14 |
|
|
Shinya Kitaoka |
120a6e |
/*--
|
|
Shinya Kitaoka |
120a6e |
* m_colorはRaylitFxのColor値。r_fac、g_fac、b_facは各チャンネルをPremultiplyした値
|
|
Shinya Kitaoka |
120a6e |
* --*/
|
|
Shinya Kitaoka |
120a6e |
m_fac = (params.m_color.m / 255.0);
|
|
Shinya Kitaoka |
120a6e |
r_fac = m_fac * (params.m_color.r / 255.0);
|
|
Shinya Kitaoka |
120a6e |
g_fac = m_fac * (params.m_color.g / 255.0);
|
|
Shinya Kitaoka |
120a6e |
b_fac = m_fac * (params.m_color.b / 255.0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Geometry-related variables
|
|
Shinya Kitaoka |
120a6e |
int x, y, ray_final_y;
|
|
Shinya Kitaoka |
120a6e |
int octLx = dstRect.x1 - dstRect.x0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double rayPosIncrementX = 1.0 / scale;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double sq_z = sq(params.m_lightOriginSrc.z); // We'll be making square
|
|
Shinya Kitaoka |
120a6e |
// distances from p, so square
|
|
Shinya Kitaoka |
120a6e |
// it once now
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Perform raylit
|
|
Shinya Kitaoka |
120a6e |
T *pixIn, *pixOut;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (ray_final_y = 0; ray_final_y < octLx; ++ray_final_y) {
|
|
Shinya Kitaoka |
120a6e |
// Initialize increment variables
|
|
Shinya Kitaoka |
120a6e |
lightness = 0.0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double rayPosIncrementY = rayPosIncrementX * (ray_final_y / (double)octLx);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Use an integer counter to know when y must increase. Will add ray_final_y
|
|
Shinya Kitaoka |
120a6e |
// as long as
|
|
Shinya Kitaoka |
120a6e |
// a multiple of octLx-1 is reached, then increase
|
|
Shinya Kitaoka |
120a6e |
int yIncrementCounter = 0, yIncrementThreshold = octLx - 1;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Trace a single ray of light
|
|
Shinya Kitaoka |
120a6e |
TPointD rayPos(rayPosIncrementX, rayPosIncrementY);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (x = dstRect.x0, y = dstRect.y0, pixIn = bufIn, pixOut = bufOut;
|
|
Shinya Kitaoka |
120a6e |
(x < dstRect.x1) && (y < dstRect.y1); ++x) {
|
|
Shinya Kitaoka |
120a6e |
bool insideSrc = (x >= srcRect.x0) && (x < srcRect.x1) &&
|
|
Shinya Kitaoka |
120a6e |
(y >= srcRect.y0) && (y < srcRect.y1);
|
|
Shinya Kitaoka |
120a6e |
if (insideSrc) {
|
|
Shinya Kitaoka |
120a6e |
// Add a light component depending on source's matte
|
|
Shinya Kitaoka |
120a6e |
if (pixIn->m == opaque_val)
|
|
Shinya Kitaoka |
120a6e |
lightness = std::max(
|
|
Shinya Kitaoka |
120a6e |
0.0, lightness - neg_delta_p); // No light source - ray fading
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
if (pixIn->m == transp_val)
|
|
Shinya Kitaoka |
120a6e |
lightness += intensity; // Full light source - ray enforcing
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
lightness = std::max(
|
|
Shinya Kitaoka |
120a6e |
0.0, lightness + // Half light source
|
|
Shinya Kitaoka |
120a6e |
(params.m_invert ? pixIn->m : (max - pixIn->m)) *
|
|
Shinya Kitaoka |
120a6e |
quot_delta_p); // matte-linear enforcing
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (params.m_includeInput) {
|
|
Shinya Kitaoka |
120a6e |
val_r = pixIn->r;
|
|
Shinya Kitaoka |
120a6e |
val_g = pixIn->g;
|
|
Shinya Kitaoka |
120a6e |
val_b = pixIn->b;
|
|
Shinya Kitaoka |
120a6e |
val_m = pixIn->m;
|
|
Shinya Kitaoka |
120a6e |
} else
|
|
Shinya Kitaoka |
120a6e |
val_r = val_g = val_b = val_m = 0;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
if (!params.m_invert)
|
|
Shinya Kitaoka |
120a6e |
lightness += intensity;
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
lightness = std::max(0.0, lightness - neg_delta_p);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
val_r = val_g = val_b = val_m = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool insideDst = (x >= 0) && (y >= 0);
|
|
Shinya Kitaoka |
120a6e |
if (insideDst) {
|
|
Shinya Kitaoka |
120a6e |
// Write the corresponding destination pixel
|
|
shun-iwasawa |
255f14 |
if (lightness > 0.0) {
|
|
shun-iwasawa |
255f14 |
if (radius == 0.0) {
|
|
shun-iwasawa |
255f14 |
value = (int)(factor * lightness /
|
|
shun-iwasawa |
255f14 |
(rayPos.x *
|
|
shun-iwasawa |
255f14 |
pow((double)(sq(rayPos.x) + sq(rayPos.y) + sq_z),
|
|
shun-iwasawa |
255f14 |
decay)) +
|
|
shun-iwasawa |
255f14 |
0.5); // * ^-d... 0.5 rounds
|
|
shun-iwasawa |
255f14 |
} else {
|
|
shun-iwasawa |
255f14 |
double ratio = std::max(0.001, 1.0 - radius / norm(rayPos));
|
|
shun-iwasawa |
255f14 |
value = (int)(factor * lightness /
|
|
shun-iwasawa |
255f14 |
(rayPos.x * ratio *
|
|
shun-iwasawa |
255f14 |
pow((double)(sq(rayPos.x * ratio) +
|
|
shun-iwasawa |
255f14 |
sq(rayPos.y * ratio) + sq_z),
|
|
shun-iwasawa |
255f14 |
decay)) +
|
|
shun-iwasawa |
255f14 |
0.5); // * ^-d... 0.5 rounds
|
|
shun-iwasawa |
255f14 |
}
|
|
shun-iwasawa |
255f14 |
} else
|
|
Shinya Kitaoka |
120a6e |
value = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// NOTE: pow() could be slow. If that is the case, it could be cached
|
|
Shinya Kitaoka |
120a6e |
// for the whole octant along the longest ray at integer positions,
|
|
Shinya Kitaoka |
120a6e |
// and then linearly interpolated between those... Have to profile this
|
|
Shinya Kitaoka |
120a6e |
// before resorting to that...
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
val_r += value * r_fac;
|
|
Shinya Kitaoka |
120a6e |
val_g += value * g_fac;
|
|
Shinya Kitaoka |
120a6e |
val_b += value * b_fac;
|
|
Shinya Kitaoka |
120a6e |
val_m += value * m_fac;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
pixOut->r = (val_r > max) ? max : val_r;
|
|
Shinya Kitaoka |
120a6e |
pixOut->g = (val_g > max) ? max : val_g;
|
|
Shinya Kitaoka |
120a6e |
pixOut->b = (val_b > max) ? max : val_b;
|
|
Shinya Kitaoka |
120a6e |
pixOut->m = (val_m > max) ? max : val_m;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Increment variables along the x-axis
|
|
Shinya Kitaoka |
120a6e |
pixIn += dxIn, pixOut += dxOut;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
rayPos.x += rayPosIncrementX, rayPos.y += rayPosIncrementY;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Increment variables along the y-axis
|
|
Shinya Kitaoka |
120a6e |
if ((yIncrementCounter += ray_final_y) >= yIncrementThreshold) {
|
|
Shinya Kitaoka |
120a6e |
++y, pixIn += dyIn, pixOut += dyOut;
|
|
Shinya Kitaoka |
120a6e |
yIncrementCounter -= yIncrementThreshold;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename t=""></typename>
|
|
Shinya Kitaoka |
120a6e |
void performColorRaylit(T *bufIn, T *bufOut, int dxIn, int dyIn, int dxOut,
|
|
Shinya Kitaoka |
120a6e |
int dyOut, const TRect &srcRect, const TRect &dstRect,
|
|
Shinya Kitaoka |
120a6e |
const TRop::RaylitParams ¶ms) {
|
|
Shinya Kitaoka |
120a6e |
// Build colors-related variables
|
|
Shinya Kitaoka |
120a6e |
int max = T::maxChannelValue;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int val_r, val_g, val_b, val_m;
|
|
Shinya Kitaoka |
120a6e |
double lightness_r, lightness_g, lightness_b;
|
|
Shinya Kitaoka |
120a6e |
double factor = max / 255.0;
|
|
Shinya Kitaoka |
120a6e |
|
|
shun-iwasawa |
255f14 |
// NOTE: These variable initializations are, well,
|
|
shun-iwasawa |
255f14 |
// heuristic at least. They were probably tested
|
|
shun-iwasawa |
255f14 |
// to be good, but didn't quite make any REAL sense.
|
|
Shinya Kitaoka |
120a6e |
// They could be done MUCH better, but changing them
|
|
shun-iwasawa |
255f14 |
// would alter the way raylit has been applied until now.
|
|
shun-iwasawa |
255f14 |
// Should be changed at some point, though...
|
|
shun-iwasawa |
255f14 |
|
|
shun-iwasawa |
255f14 |
double scale = params.m_scale;
|
|
shun-iwasawa |
255f14 |
double decay = log(params.m_decay / 100.0 + 1.0) + 1.0;
|
|
shun-iwasawa |
255f14 |
double intensity = 1e8 * log(params.m_intensity / 100.0 + 1.0) / scale;
|
|
shun-iwasawa |
255f14 |
double smoothness = log(params.m_smoothness * 5.0 / 100.0 + 1.0);
|
|
shun-iwasawa |
255f14 |
double radius = params.m_radius;
|
|
shun-iwasawa |
255f14 |
|
|
Shinya Kitaoka |
120a6e |
double neg_delta_p =
|
|
Shinya Kitaoka |
120a6e |
smoothness *
|
|
Shinya Kitaoka |
120a6e |
intensity; // would alter the way raylit has been applied until now.
|
|
Shinya Kitaoka |
120a6e |
double quot_delta_p = intensity / max; //
|
|
Shinya Kitaoka |
120a6e |
// Should be changed at some point, though...
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Geometry-related variables
|
|
Shinya Kitaoka |
120a6e |
int x, y, ray_final_y;
|
|
Shinya Kitaoka |
120a6e |
int octLx = dstRect.x1 - dstRect.x0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double rayPosIncrementX = 1.0 / scale;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double fac, sq_z = sq(params.m_lightOriginSrc.z); // We'll be making square
|
|
Shinya Kitaoka |
120a6e |
// distances from p, so
|
|
Shinya Kitaoka |
120a6e |
// square it once now
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Perform raylit
|
|
Shinya Kitaoka |
120a6e |
T *pixIn, *pixOut;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (ray_final_y = 0; ray_final_y < octLx; ++ray_final_y) {
|
|
Shinya Kitaoka |
120a6e |
// Initialize increment variables
|
|
Shinya Kitaoka |
120a6e |
lightness_r = lightness_g = lightness_b = 0.0;
|
|
Shinya Kitaoka |
120a6e |
int l, l_max;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
double rayPosIncrementY = rayPosIncrementX * (ray_final_y / (double)octLx);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Use an integer counter to know when y must increase. Will add ray_final_y
|
|
Shinya Kitaoka |
120a6e |
// as long as
|
|
Shinya Kitaoka |
120a6e |
// a multiple of octLx-1 is reached, then increase
|
|
Shinya Kitaoka |
120a6e |
int yIncrementCounter = 0, yIncrementThreshold = octLx - 1;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Trace a single ray of light
|
|
Shinya Kitaoka |
120a6e |
TPointD rayPos(rayPosIncrementX, rayPosIncrementY);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (x = dstRect.x0, y = dstRect.y0, pixIn = bufIn, pixOut = bufOut;
|
|
Shinya Kitaoka |
120a6e |
(x < dstRect.x1) && (y < dstRect.y1); ++x) {
|
|
Shinya Kitaoka |
120a6e |
bool insideSrc = (x >= srcRect.x0) && (x < srcRect.x1) &&
|
|
Shinya Kitaoka |
120a6e |
(y >= srcRect.y0) && (y < srcRect.y1);
|
|
Shinya Kitaoka |
120a6e |
if (insideSrc) {
|
|
Shinya Kitaoka |
120a6e |
val_r = pixIn->r;
|
|
Shinya Kitaoka |
120a6e |
val_g = pixIn->g;
|
|
Shinya Kitaoka |
120a6e |
val_b = pixIn->b;
|
|
Shinya Kitaoka |
120a6e |
val_m = pixIn->m;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
lightness_r = std::max(0.0, val_r ? lightness_r + val_r * quot_delta_p
|
|
Shinya Kitaoka |
120a6e |
: lightness_r - neg_delta_p);
|
|
Shinya Kitaoka |
120a6e |
lightness_g = std::max(0.0, val_g ? lightness_g + val_g * quot_delta_p
|
|
Shinya Kitaoka |
120a6e |
: lightness_g - neg_delta_p);
|
|
Shinya Kitaoka |
120a6e |
lightness_b = std::max(0.0, val_b ? lightness_b + val_b * quot_delta_p
|
|
Shinya Kitaoka |
120a6e |
: lightness_b - neg_delta_p);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (!params.m_includeInput) val_r = val_g = val_b = val_m = 0;
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
lightness_r = std::max(0.0, lightness_r - neg_delta_p);
|
|
Shinya Kitaoka |
120a6e |
lightness_g = std::max(0.0, lightness_g - neg_delta_p);
|
|
Shinya Kitaoka |
120a6e |
lightness_b = std::max(0.0, lightness_b - neg_delta_p);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
val_r = val_g = val_b = val_m = 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
bool insideDst = (x >= 0) && (y >= 0);
|
|
Shinya Kitaoka |
120a6e |
if (insideDst) {
|
|
Shinya Kitaoka |
120a6e |
// Write the corresponding destination pixel
|
|
shun-iwasawa |
255f14 |
if (radius == 0.0) {
|
|
shun-iwasawa |
255f14 |
fac = factor /
|
|
shun-iwasawa |
255f14 |
(rayPos.x *
|
|
shun-iwasawa |
255f14 |
pow((double)(sq(rayPos.x) + sq(rayPos.y) + sq_z), decay));
|
|
shun-iwasawa |
255f14 |
} else {
|
|
shun-iwasawa |
255f14 |
double ratio = std::max(0.001, 1.0 - radius / norm(rayPos));
|
|
shun-iwasawa |
255f14 |
fac =
|
|
shun-iwasawa |
255f14 |
factor /
|
|
shun-iwasawa |
255f14 |
(rayPos.x * ratio *
|
|
shun-iwasawa |
255f14 |
pow((double)(sq(rayPos.x * ratio) + sq(rayPos.y * ratio) + sq_z),
|
|
shun-iwasawa |
255f14 |
decay));
|
|
shun-iwasawa |
255f14 |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// NOTE: pow() could be slow. If that is the case, it could be cached
|
|
Shinya Kitaoka |
120a6e |
// for the whole octant along the longest ray at integer positions,
|
|
Shinya Kitaoka |
120a6e |
// and then linearly interpolated between those... Have to profile this
|
|
Shinya Kitaoka |
120a6e |
// before resorting to that...
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
val_r += l = (int)(fac * lightness_r + 0.5);
|
|
Shinya Kitaoka |
120a6e |
l_max = l;
|
|
Shinya Kitaoka |
120a6e |
val_g += l = (int)(fac * lightness_g + 0.5);
|
|
Shinya Kitaoka |
120a6e |
l_max = std::max(l, l_max);
|
|
Shinya Kitaoka |
120a6e |
val_b += l = (int)(fac * lightness_b + 0.5);
|
|
Shinya Kitaoka |
120a6e |
l_max = std::max(l, l_max);
|
|
Shinya Kitaoka |
120a6e |
val_m += l_max;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
pixOut->r = (val_r > max) ? max : val_r;
|
|
Shinya Kitaoka |
120a6e |
pixOut->g = (val_g > max) ? max : val_g;
|
|
Shinya Kitaoka |
120a6e |
pixOut->b = (val_b > max) ? max : val_b;
|
|
Shinya Kitaoka |
120a6e |
pixOut->m = (val_m > max) ? max : val_m;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Increment variables along the x-axis
|
|
Shinya Kitaoka |
120a6e |
pixIn += dxIn, pixOut += dxOut;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
rayPos.x += rayPosIncrementX, rayPos.y += rayPosIncrementY;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Increment variables along the y-axis
|
|
Shinya Kitaoka |
120a6e |
if ((yIncrementCounter += ray_final_y) >= yIncrementThreshold) {
|
|
Shinya Kitaoka |
120a6e |
++y, pixIn += dyIn, pixOut += dyOut;
|
|
Shinya Kitaoka |
120a6e |
yIncrementCounter -= yIncrementThreshold;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
/*-- ピザ状に8分割された領域の1つを計算する --*/
|
|
Toshihiro Shimizu |
890ddd |
template <typename t=""></typename>
|
|
Shinya Kitaoka |
120a6e |
void computeOctant(const TRasterPT<t> &src, const TRasterPT<t> &dst, int octant,</t></t>
|
|
Shinya Kitaoka |
120a6e |
const TRop::RaylitParams ¶ms,
|
|
Shinya Kitaoka |
120a6e |
typename RaylitFuncTraits<t>::function_type raylitFunc) {</t>
|
|
Shinya Kitaoka |
120a6e |
// Build octant geometry variables
|
|
Shinya Kitaoka |
120a6e |
int x0, x1, lxIn, lxOut, dxIn, dxOut;
|
|
Shinya Kitaoka |
120a6e |
int y0, y1, lyIn, lyOut, dyIn, dyOut;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
const T3DPoint &pIn = params.m_lightOriginSrc,
|
|
Shinya Kitaoka |
120a6e |
&pOut = params.m_lightOriginDst;
|
|
Shinya Kitaoka |
120a6e |
int srcWrap = src->getWrap(), dstWrap = dst->getWrap();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
T *bufIn = (T *)src->getRawData() + tfloor(pIn.y) * srcWrap + tfloor(pIn.x);
|
|
Shinya Kitaoka |
120a6e |
T *bufOut =
|
|
Shinya Kitaoka |
120a6e |
(T *)dst->getRawData() + tfloor(pOut.y) * dstWrap + tfloor(pOut.x);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
TRect srcRect(src->getBounds() +
|
|
Shinya Kitaoka |
120a6e |
TPoint(tround(pOut.x - pIn.x), tround(pOut.y - pIn.y)));
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
lxIn = src->getLx(), lxOut = dst->getLx();
|
|
Shinya Kitaoka |
120a6e |
lyIn = src->getLy(), lyOut = dst->getLy();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*-- 1ピクセルずつ進むときの移動値 --*/
|
|
Shinya Kitaoka |
120a6e |
// Vertical octant pairs
|
|
Shinya Kitaoka |
120a6e |
if (octant == 1 || octant == 8)
|
|
Shinya Kitaoka |
120a6e |
dxIn = 1, dxOut = 1, x0 = tfloor(pOut.x), x1 = lxOut;
|
|
Shinya Kitaoka |
120a6e |
if (octant == 2 || octant == 7)
|
|
Shinya Kitaoka |
120a6e |
dyIn = 1, dyOut = 1, y0 = tfloor(pOut.x), y1 = lxOut;
|
|
Shinya Kitaoka |
120a6e |
if (octant == 3 || octant == 6)
|
|
Shinya Kitaoka |
120a6e |
dyIn = -1, dyOut = -1, y0 = lxOut - tfloor(pOut.x) - 1, y1 = lxOut,
|
|
otakuto |
ed7dcd |
std::swap(srcRect.x0, srcRect.x1), srcRect.x0 = lxOut - srcRect.x0,
|
|
Shinya Kitaoka |
120a6e |
srcRect.x1 = lxOut - srcRect.x1;
|
|
Shinya Kitaoka |
120a6e |
if (octant == 4 || octant == 5)
|
|
Shinya Kitaoka |
120a6e |
dxIn = -1, dxOut = -1, x0 = lxOut - tfloor(pOut.x) - 1, x1 = lxOut,
|
|
otakuto |
ed7dcd |
std::swap(srcRect.x0, srcRect.x1), srcRect.x0 = lxOut - srcRect.x0,
|
|
Shinya Kitaoka |
120a6e |
srcRect.x1 = lxOut - srcRect.x1;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Horizontal octant pairs
|
|
Shinya Kitaoka |
120a6e |
if (octant == 2 || octant == 3)
|
|
Shinya Kitaoka |
120a6e |
dxIn = srcWrap, dxOut = dstWrap, x0 = tfloor(pOut.y), x1 = lyOut;
|
|
Shinya Kitaoka |
120a6e |
if (octant == 1 || octant == 4)
|
|
Shinya Kitaoka |
120a6e |
dyIn = srcWrap, dyOut = dstWrap, y0 = tfloor(pOut.y), y1 = lyOut;
|
|
Shinya Kitaoka |
120a6e |
if (octant == 5 || octant == 8)
|
|
Shinya Kitaoka |
120a6e |
dyIn = -srcWrap, dyOut = -dstWrap, y0 = lyOut - tfloor(pOut.y) - 1,
|
|
shun-iwasawa |
255f14 |
y1 = lyOut, std::swap(srcRect.y0, srcRect.y1),
|
|
shun-iwasawa |
255f14 |
srcRect.y0 = lyOut - srcRect.y0, srcRect.y1 = lyOut - srcRect.y1;
|
|
Shinya Kitaoka |
120a6e |
if (octant == 6 || octant == 7)
|
|
Shinya Kitaoka |
120a6e |
dxIn = -srcWrap, dxOut = -dstWrap, x0 = lyOut - tfloor(pOut.y) - 1,
|
|
shun-iwasawa |
255f14 |
x1 = lyOut, std::swap(srcRect.y0, srcRect.y1),
|
|
shun-iwasawa |
255f14 |
srcRect.y0 = lyOut - srcRect.y0, srcRect.y1 = lyOut - srcRect.y1;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
/*-- 縦向きのピザ領域を計算する場合は、90度回転してから --*/
|
|
Shinya Kitaoka |
120a6e |
// Swap x and y axis where necessary
|
|
Shinya Kitaoka |
120a6e |
if (octant == 2 || octant == 3 || octant == 6 || octant == 7) {
|
|
otakuto |
ed7dcd |
std::swap(lxIn, lyIn), std::swap(lxOut, lyOut);
|
|
otakuto |
ed7dcd |
std::swap(srcRect.x0, srcRect.y0), std::swap(srcRect.x1, srcRect.y1);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
int octLx = (x1 - x0), octLy = (y1 - y0);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
assert(octLx > 0 && octLy > 0);
|
|
Shinya Kitaoka |
120a6e |
if (octLx <= 0 && octLy <= 0) return;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
raylitFunc(bufIn, bufOut, dxIn, dyIn, dxOut, dyOut, srcRect,
|
|
Shinya Kitaoka |
120a6e |
TRect(x0, y0, x1, y1), params);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
OCTANTS:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
\ 3 | 2 /
|
|
Toshihiro Shimizu |
890ddd |
\ | /
|
|
Toshihiro Shimizu |
890ddd |
\ | /
|
|
Toshihiro Shimizu |
890ddd |
4 \|/ 1
|
|
Toshihiro Shimizu |
890ddd |
----+----
|
|
Toshihiro Shimizu |
890ddd |
5 /|\ 8
|
|
Toshihiro Shimizu |
890ddd |
/ | \
|
|
Toshihiro Shimizu |
890ddd |
/ | \
|
|
Toshihiro Shimizu |
890ddd |
/ 6 | 7 \
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename t=""></typename>
|
|
Shinya Kitaoka |
120a6e |
void doRaylit(const TRasterPT<t> &src, const TRasterPT<t> &dst,</t></t>
|
|
Shinya Kitaoka |
120a6e |
const TRop::RaylitParams ¶ms,
|
|
Shinya Kitaoka |
120a6e |
typename RaylitFuncTraits<t>::function_type raylitFunc) {</t>
|
|
Shinya Kitaoka |
120a6e |
int lxOut = dst->getLx(), lyOut = dst->getLy();
|
|
Shinya Kitaoka |
120a6e |
const T3DPoint &p = params.m_lightOriginDst;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
src->lock();
|
|
Shinya Kitaoka |
120a6e |
dst->lock();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Depending on the position of p, only some of the quadrants need to be built
|
|
Shinya Kitaoka |
120a6e |
if (p.y < lyOut) {
|
|
Shinya Kitaoka |
120a6e |
if (p.x < lxOut) {
|
|
Shinya Kitaoka |
120a6e |
// Compute the raylit fx on each octant independently
|
|
Shinya Kitaoka |
120a6e |
computeOctant(src, dst, 1, params, raylitFunc);
|
|
Shinya Kitaoka |
120a6e |
computeOctant(src, dst, 2, params, raylitFunc);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (p.x >= 0) {
|
|
Shinya Kitaoka |
120a6e |
computeOctant(src, dst, 3, params, raylitFunc);
|
|
Shinya Kitaoka |
120a6e |
computeOctant(src, dst, 4, params, raylitFunc);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (p.y >= 0) {
|
|
Shinya Kitaoka |
120a6e |
if (p.x >= 0) {
|
|
Shinya Kitaoka |
120a6e |
computeOctant(src, dst, 5, params, raylitFunc);
|
|
Shinya Kitaoka |
120a6e |
computeOctant(src, dst, 6, params, raylitFunc);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (p.x < lxOut) {
|
|
Shinya Kitaoka |
120a6e |
computeOctant(src, dst, 7, params, raylitFunc);
|
|
Shinya Kitaoka |
120a6e |
computeOctant(src, dst, 8, params, raylitFunc);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
dst->unlock();
|
|
Shinya Kitaoka |
120a6e |
src->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
} // namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
// TRop::raylit implementation
|
|
Toshihiro Shimizu |
890ddd |
//***********************************************************************************************
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::raylit(const TRasterP &dstRas, const TRasterP &srcRas,
|
|
Shinya Kitaoka |
120a6e |
const RaylitParams ¶ms) {
|
|
Shinya Kitaoka |
120a6e |
if ((TRaster32P)dstRas && (TRaster32P)srcRas)
|
|
Shinya Kitaoka |
120a6e |
doRaylit<tpixel32>(srcRas, dstRas, params,</tpixel32>
|
|
Shinya Kitaoka |
120a6e |
&performStandardRaylit<tpixel32>);</tpixel32>
|
|
Shinya Kitaoka |
120a6e |
else if ((TRaster64P)dstRas && (TRaster64P)srcRas)
|
|
Shinya Kitaoka |
120a6e |
doRaylit<tpixel64>(srcRas, dstRas, params,</tpixel64>
|
|
Shinya Kitaoka |
120a6e |
&performStandardRaylit<tpixel64>);</tpixel64>
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
throw TException("TRop::raylit unsupported pixel type");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//--------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
void TRop::glassRaylit(const TRasterP &dstRas, const TRasterP &srcRas,
|
|
Shinya Kitaoka |
120a6e |
const RaylitParams ¶ms) {
|
|
Shinya Kitaoka |
120a6e |
if ((TRaster32P)dstRas && (TRaster32P)srcRas)
|
|
Shinya Kitaoka |
120a6e |
doRaylit<tpixel32>(srcRas, dstRas, params, &performColorRaylit<tpixel32>);</tpixel32></tpixel32>
|
|
Shinya Kitaoka |
120a6e |
else if ((TRaster64P)dstRas && (TRaster64P)srcRas)
|
|
Shinya Kitaoka |
120a6e |
doRaylit<tpixel64>(srcRas, dstRas, params, &performColorRaylit<tpixel64>);</tpixel64></tpixel64>
|
|
Shinya Kitaoka |
120a6e |
else
|
|
Shinya Kitaoka |
120a6e |
throw TException("TRop::raylit unsupported pixel type");
|
|
Toshihiro Shimizu |
890ddd |
}
|