Code changed:
In file worldlight.cpp:
replace function:
Pay attention at "isoccluded" function. disableraytable was added to fix "FOV shadow" bug.
I think this feature will put mapping in a new "light":).
In file worldlight.cpp:
replace function:
[SELECT ALL] Code:
void lightray(float bx, float by, const persistent_entity &light, float fade = 1, bool flicker = false) // done in realtime, needs to be fast
{
disableraytable();
float lx = light.x+(flicker ? (rnd(21)-10)*0.1f : 0);
float ly = light.y+(flicker ? (rnd(21)-10)*0.1f : 0);
float dx = bx-lx;
float dy = by-ly;
float dist = (float)sqrt(dx*dx+dy*dy);
if(dist<1.0f) return;
int reach = light.attr1;
int steps = (int)(reach*reach*1.6f/dist); // can change this for speedup/quality?
const int PRECBITS = 12;
const float PRECF = 4096.0f;
int x = (int)(lx*PRECF);
int y = (int)(ly*PRECF);
int fadescale = (int)(fade*PRECF);
int l = light.attr2*fadescale;
int stepx = (int)(dx/(float)steps*PRECF);
int stepy = (int)(dy/(float)steps*PRECF);
int stepl = (int)(l/(float)steps); // incorrect: light will fade quicker if near edge of the world
if(maxtmus)
{
l /= lightscale;
stepl /= lightscale;
if(light.attr3 || light.attr4) // coloured light version, special case because most lights are white
{
if(flicker)
{
int dimness = rnd((((255<<PRECBITS)-(int(light.attr2)+int(light.attr3)+int(light.attr4))*fadescale/3)>>(PRECBITS+4))+1);
x += stepx*dimness;
y += stepy*dimness;
}
if(OUTBORD(x>>PRECBITS, y>>PRECBITS)) return;
int g = light.attr3*fadescale;
int stepg = (int)(g/(float)steps);
int b = light.attr4*fadescale;
int stepb = (int)(b/(float)steps);
g /= lightscale;
stepg /= lightscale;
b /= lightscale;
stepb /= lightscale;
loopi(steps)
{
sqr *s = S(x>>PRECBITS, y>>PRECBITS);
s->r = min((l>>PRECBITS)+s->r, 255);
s->g = min((g>>PRECBITS)+s->g, 255);
s->b = min((b>>PRECBITS)+s->b, 255);
if(SOLID(s)) return;
if(isoccluded(light.x, light.y, x>>PRECBITS, y>>PRECBITS, 1)) return;
x += stepx;
y += stepy;
l -= stepl;
g -= stepg;
b -= stepb;
stepl -= 25;
stepg -= 25;
stepb -= 25;
}
}
else // white light, special optimized version
{
if(flicker)
{
int dimness = rnd((((255<<PRECBITS)-(light.attr2*fadescale))>>(PRECBITS+4))+1);
x += stepx*dimness;
y += stepy*dimness;
}
if(OUTBORD(x>>PRECBITS, y>>PRECBITS)) return;
if(hdr.ambient > 0xFF) loopi(steps)
{
sqr *s = S(x>>PRECBITS, y>>PRECBITS);
s->r = min((l>>PRECBITS)+s->r, 255);
s->g = min((l>>PRECBITS)+s->g, 255);
s->b = min((l>>PRECBITS)+s->b, 255);
if(SOLID(s)) return;
if(isoccluded(light.x, light.y, x>>PRECBITS, y>>PRECBITS, 1)) return;
x += stepx;
y += stepy;
l -= stepl;
stepl -= 25;
}
else loopi(steps)
{
sqr *s = S(x>>PRECBITS, y>>PRECBITS);
s->r = s->g = s->b = min((l>>PRECBITS)+s->r, 255);
if(SOLID(s)) return;
if(isoccluded(light.x, light.y, x>>PRECBITS, y>>PRECBITS, 1)) return;
x += stepx;
y += stepy;
l -= stepl;
stepl -= 25;
}
}
}
else // the old (white) light code, here for the few people with old video cards that don't support overbright
{
loopi(steps)
{
sqr *s = S(x>>PRECBITS, y>>PRECBITS);
int light = l>>PRECBITS;
if(light>s->r) s->r = s->g = s->b = (uchar)light;
if(SOLID(s)) return;
//if(isoccluded(light.x, light.y, x>>PRECBITS, y>>PRECBITS, 1)) return;
x += stepx;
y += stepy;
l -= stepl;
}
}
}
Pay attention at "isoccluded" function. disableraytable was added to fix "FOV shadow" bug.
I think this feature will put mapping in a new "light":).