rendermax: mainly organizing

added comments, non-enabled code for adaptive eyes,
develop
Warmist 2014-01-26 03:26:41 +02:00
parent 372f861010
commit b5b01ea02b
2 changed files with 36 additions and 9 deletions

@ -1179,6 +1179,7 @@ void lightThread::run()
{
while(!isDone)
{
//TODO: get area to process, and then process (by rounds): 1. occlusions, 2.sun, 3.lights(could be difficult, units/items etc...)
{//wait for occlusion (and lights) to be ready
tthread::lock_guard<tthread::mutex> guard(dispatch.occlusionMutex);
if(!dispatch.occlusionReady)
@ -1243,7 +1244,7 @@ rgbf lightThread::lightUpCell(rgbf power,int dx,int dy,int tx,int ty)
size_t tile=tx*h+ty;
int dsq=dx*dx+dy*dy;
float dt=1;
if(dsq == 1)
if(dsq == 1)//array lookup might be faster still
dt=1;
else if(dsq == 2)
dt = RootTwo;
@ -1263,10 +1264,10 @@ rgbf lightThread::lightUpCell(rgbf power,int dx,int dy,int tx,int ty)
}
if(ls.radius>0 && dsq>0)
{
if(power<=ls.power)
if(power<=ls.power) //quit early if hitting another (stronger) lightsource
return rgbf();
}
//float dt=sqrt(dsq);
rgbf oldCol=canvas[tile];
rgbf ncol=blendMax(power,oldCol);
canvas[tile]=ncol;
@ -1302,12 +1303,12 @@ void lightThread::doLight( int x,int y )
power=power*flicker;
}
rgbf surrounds;
lightUpCell( power, 0, 0,x, y);
lightUpCell( power, 0, 0,x, y); //light up the source itself
for(int i=-1;i<2;i++)
for(int j=-1;j<2;j++)
if(i!=0||j!=0)
surrounds += lightUpCell( power, i, j,x+i, y+j);
if(surrounds.dot(surrounds)>0.00001f)
surrounds += lightUpCell( power, i, j,x+i, y+j); //and this is wall hack (so that walls look nice)
if(surrounds.dot(surrounds)>0.00001f) //if we needed to light up the suroundings, then raycast
{
plotSquare(x,y,radius,
std::bind(&lightThread::doRay,this,power,x,y,_1,_2));

@ -44,6 +44,30 @@ namespace std
bool isInRect(const df::coord2d& pos,const DFHack::rect2d& rect);
struct renderer_light : public renderer_wrap {
private:
float light_adaptation;
rgbf adapt_to_light(const rgbf& light)
{
const float influence=0.0001;
const float max_adapt=1;
const float min_adapt=0;
float intensity=(light.r+light.g+light.b)/3.0;
light_adaptation=intensity*influence+light_adaptation*(1-influence);
float delta=light_adaptation-intensity;
rgbf ret;
ret.r=light.r-delta;
ret.g=light.g-delta;
ret.b=light.b-delta;
return ret;
//if light_adaptation/intensity~1 then draw 1,1,1 (i.e. totally adapted)
/*
1. adapted -> 1,1,1 (full bright everything okay) delta=0 multiplier=?
2. light adapted, real=dark -> darker delta>0 multiplier<1
3. dark adapted, real=light -> lighter delta<0 multiplier>1
*/
//if light_adaptation/intensity!=0 then draw
}
void colorizeTile(int x,int y)
{
const int tile = x*(df::global::gps->dimy) + y;
@ -51,8 +75,9 @@ private:
float *fg = p->fg + tile * 4 * 6;
float *bg = p->bg + tile * 4 * 6;
float *tex = p->tex + tile * 2 * 6;
rgbf light=lightGrid[tile];
for (int i = 0; i < 6; i++) {
rgbf light=lightGrid[tile];//for light adaptation: rgbf light=adapt_to_light(lightGrid[tile]);
for (int i = 0; i < 6; i++) { //oh how sse would do wonders here, or shaders...
*(fg++) *= light.r;
*(fg++) *= light.g;
*(fg++) *= light.b;
@ -73,10 +98,11 @@ private:
{
reinitLightGrid(df::global::gps->dimy,df::global::gps->dimx);
}
public:
tthread::fast_mutex dataMutex;
std::vector<rgbf> lightGrid;
renderer_light(renderer* parent):renderer_wrap(parent)
renderer_light(renderer* parent):renderer_wrap(parent),light_adaptation(1)
{
reinitLightGrid();
}