Per-frame lights cleanup.

git-svn-id: https://svn.eduke32.com/eduke32@1304 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
plagman 2009-04-12 13:51:43 +00:00
parent 80670cac29
commit 567c0bdd86
3 changed files with 147 additions and 139 deletions

View file

@ -167,6 +167,9 @@ extern int32_t staticlightcount;
extern _prlight gamelights[PR_MAXLIGHTS]; extern _prlight gamelights[PR_MAXLIGHTS];
extern int32_t gamelightcount; extern int32_t gamelightcount;
extern _prlight framelights[PR_MAXLIGHTS];
extern int32_t framelightcount;
// RENDER TARGETS // RENDER TARGETS
typedef struct s_prrt { typedef struct s_prrt {
GLenum target; GLenum target;
@ -271,8 +274,6 @@ void polymer_rotatesprite(int32_t sx, int32_t sy, int32_t z, int1
void polymer_drawmaskwall(int32_t damaskwallcnt); void polymer_drawmaskwall(int32_t damaskwallcnt);
void polymer_drawsprite(int32_t snum); void polymer_drawsprite(int32_t snum);
void polymer_setanimatesprites(animatespritesptr animatesprites, int32_t x, int32_t y, int32_t a, int32_t smoothratio); void polymer_setanimatesprites(animatespritesptr animatesprites, int32_t x, int32_t y, int32_t a, int32_t smoothratio);
void polymer_resetlights(void);
void polymer_addlight(_prlight light);
# ifdef POLYMER_C # ifdef POLYMER_C
@ -318,6 +319,8 @@ static int32_t polymer_bindmaterial(_prmaterial material, char* lights, int
static void polymer_unbindmaterial(int32_t programbits); static void polymer_unbindmaterial(int32_t programbits);
static void polymer_compileprogram(int32_t programbits); static void polymer_compileprogram(int32_t programbits);
// LIGHTS // LIGHTS
static void polymer_resetlights(void);
static void polymer_addlight(_prlight light);
static int32_t polymer_planeinlight(_prplane* plane, _prlight* light); static int32_t polymer_planeinlight(_prplane* plane, _prlight* light);
static void polymer_culllight(char lightindex); static void polymer_culllight(char lightindex);
static void polymer_prepareshadows(void); static void polymer_prepareshadows(void);

View file

@ -137,6 +137,8 @@ int32_t staticlightcount;
_prlight gamelights[PR_MAXLIGHTS]; _prlight gamelights[PR_MAXLIGHTS];
int32_t gamelightcount; int32_t gamelightcount;
_prlight framelights[PR_MAXLIGHTS];
int32_t framelightcount;
GLfloat shadowBias[] = GLfloat shadowBias[] =
{ {
@ -700,6 +702,8 @@ void polymer_drawrooms(int32_t daposx, int32_t daposy, int32_t da
pos[1] = -(float)(daposz) / 16.0f; pos[1] = -(float)(daposz) / 16.0f;
pos[2] = -daposx; pos[2] = -daposx;
polymer_resetlights();
polymer_dostaticlights(); polymer_dostaticlights();
i = 0; i = 0;
@ -709,6 +713,13 @@ void polymer_drawrooms(int32_t daposx, int32_t daposy, int32_t da
i++; i++;
} }
i = 0;
while (i < framelightcount)
{
polymer_addlight(framelights[i]);
i++;
}
depth = 0; depth = 0;
polymer_prepareshadows(); polymer_prepareshadows();
@ -1043,95 +1054,6 @@ void polymer_setanimatesprites(animatespritesptr animatesprites,
asi.smoothratio = smoothratio; asi.smoothratio = smoothratio;
} }
void polymer_resetlights(void)
{
int32_t i;
_prsector *s;
_prwall *w;
i = 0;
while (i < numsectors)
{
s = prsectors[i];
s->floor.lightcount = 0;
s->ceil.lightcount = 0;
i++;
}
i = 0;
while (i < numwalls)
{
w = prwalls[i];
w->wall.lightcount = 0;
w->over.lightcount = 0;
w->mask.lightcount = 0;
i++;
}
lightcount = 0;
}
void polymer_addlight(_prlight light)
{
if (light.sector == -1)
return;
if (lightcount < PR_MAXLIGHTS)
{
prlights[lightcount] = light;
if (light.radius) {
float radius, ang, horizang, lightpos[3];
// hack to avoid lights beams perpendicular to walls
if ((light.horiz <= 100) && (light.horiz > 90))
light.horiz = 90;
if ((light.horiz > 100) && (light.horiz < 110))
light.horiz = 110;
lightpos[0] = light.y;
lightpos[1] = -light.z / 16.0f;
lightpos[2] = -light.x;
// calculate the spot light transformations and matrices
radius = (float)(light.radius) / (2048.0f / 360.0f);
ang = (float)(light.angle) / (2048.0f / 360.0f);
horizang = (float)(-getangle(128, light.horiz-100)) / (2048.0f / 360.0f);
bglMatrixMode(GL_PROJECTION);
bglPushMatrix();
bglLoadIdentity();
bgluPerspective(radius * 2, 1, 0.1f, light.range / 1000.0f);
bglGetFloatv(GL_PROJECTION_MATRIX, prlights[lightcount].proj);
bglPopMatrix();
bglMatrixMode(GL_MODELVIEW);
bglPushMatrix();
bglLoadIdentity();
bglRotatef(horizang, 1.0f, 0.0f, 0.0f);
bglRotatef(ang, 0.0f, 1.0f, 0.0f);
bglScalef(1.0f / 1000.0f, 1.0f / 1000.0f, 1.0f / 1000.0f);
bglTranslatef(-lightpos[0], -lightpos[1], -lightpos[2]);
bglGetFloatv(GL_MODELVIEW_MATRIX, prlights[lightcount].transform);
bglPopMatrix();
polymer_extractfrustum(prlights[lightcount].transform, prlights[lightcount].proj, prlights[lightcount].frustum);
prlights[lightcount].rtindex = -1;
}
prlights[lightcount].isinview = 0;
polymer_culllight(lightcount);
lightcount++;
}
}
// CORE // CORE
static void polymer_displayrooms(int16_t dacursectnum) static void polymer_displayrooms(int16_t dacursectnum)
{ {
@ -3782,6 +3704,95 @@ static void polymer_compileprogram(int32_t programbits)
} }
// LIGHTS // LIGHTS
static void polymer_resetlights(void)
{
int32_t i;
_prsector *s;
_prwall *w;
i = 0;
while (i < numsectors)
{
s = prsectors[i];
s->floor.lightcount = 0;
s->ceil.lightcount = 0;
i++;
}
i = 0;
while (i < numwalls)
{
w = prwalls[i];
w->wall.lightcount = 0;
w->over.lightcount = 0;
w->mask.lightcount = 0;
i++;
}
lightcount = 0;
}
static void polymer_addlight(_prlight light)
{
if (light.sector == -1)
return;
if (lightcount < PR_MAXLIGHTS)
{
prlights[lightcount] = light;
if (light.radius) {
float radius, ang, horizang, lightpos[3];
// hack to avoid lights beams perpendicular to walls
if ((light.horiz <= 100) && (light.horiz > 90))
light.horiz = 90;
if ((light.horiz > 100) && (light.horiz < 110))
light.horiz = 110;
lightpos[0] = light.y;
lightpos[1] = -light.z / 16.0f;
lightpos[2] = -light.x;
// calculate the spot light transformations and matrices
radius = (float)(light.radius) / (2048.0f / 360.0f);
ang = (float)(light.angle) / (2048.0f / 360.0f);
horizang = (float)(-getangle(128, light.horiz-100)) / (2048.0f / 360.0f);
bglMatrixMode(GL_PROJECTION);
bglPushMatrix();
bglLoadIdentity();
bgluPerspective(radius * 2, 1, 0.1f, light.range / 1000.0f);
bglGetFloatv(GL_PROJECTION_MATRIX, prlights[lightcount].proj);
bglPopMatrix();
bglMatrixMode(GL_MODELVIEW);
bglPushMatrix();
bglLoadIdentity();
bglRotatef(horizang, 1.0f, 0.0f, 0.0f);
bglRotatef(ang, 0.0f, 1.0f, 0.0f);
bglScalef(1.0f / 1000.0f, 1.0f / 1000.0f, 1.0f / 1000.0f);
bglTranslatef(-lightpos[0], -lightpos[1], -lightpos[2]);
bglGetFloatv(GL_MODELVIEW_MATRIX, prlights[lightcount].transform);
bglPopMatrix();
polymer_extractfrustum(prlights[lightcount].transform, prlights[lightcount].proj, prlights[lightcount].frustum);
prlights[lightcount].rtindex = -1;
}
prlights[lightcount].isinview = 0;
polymer_culllight(lightcount);
lightcount++;
}
}
static int32_t polymer_planeinlight(_prplane* plane, _prlight* light) static int32_t polymer_planeinlight(_prplane* plane, _prlight* light)
{ {
float lightpos[3]; float lightpos[3];

View file

@ -4530,13 +4530,13 @@ void G_DrawRooms(int32_t snum,int32_t smoothratio)
} }
#ifdef POLYMER #ifdef POLYMER
if (getrendermode() == 4) if (getrendermode() == 4) {
polymer_setanimatesprites(G_DoSpriteAnimations, ud.camerax,ud.cameray,ud.cameraang,smoothratio); polymer_setanimatesprites(G_DoSpriteAnimations, ud.camerax,ud.cameray,ud.cameraang,smoothratio);
}
#endif #endif
drawrooms(ud.camerax,ud.cameray,ud.cameraz,ud.cameraang,ud.camerahoriz,ud.camerasect); drawrooms(ud.camerax,ud.cameray,ud.cameraz,ud.cameraang,ud.camerahoriz,ud.camerasect);
#ifdef POLYMER #ifdef POLYMER
if (getrendermode() == 4) framelightcount = 0;
polymer_resetlights();
#endif #endif
G_DoSpriteAnimations(ud.camerax,ud.cameray,ud.cameraang,smoothratio); G_DoSpriteAnimations(ud.camerax,ud.cameray,ud.cameraang,smoothratio);
drawmasks(); drawmasks();
@ -6646,9 +6646,6 @@ void G_DoSpriteAnimations(int32_t x,int32_t y,int32_t a,int32_t smoothratio)
intptr_t l, t1,t3,t4; intptr_t l, t1,t3,t4;
spritetype *s,*t; spritetype *s,*t;
int32_t switchpic; int32_t switchpic;
#ifdef POLYMER
_prlight light;
#endif
if (!spritesortcnt) return; if (!spritesortcnt) return;
@ -7372,37 +7369,36 @@ PALONLY:
case FLOORFLAME__STATIC: case FLOORFLAME__STATIC:
#ifdef POLYMER #ifdef POLYMER
light.radius = 0; framelights[framelightcount].radius = 0;
light.sector = t->sectnum; framelights[framelightcount].sector = t->sectnum;
light.x = t->x; framelights[framelightcount].x = t->x;
light.y = t->y; framelights[framelightcount].y = t->y;
light.z = t->z; framelights[framelightcount].z = t->z;
light.range = tilesizx[t->picnum]*tilesizy[t->picnum]; framelights[framelightcount].range = tilesizx[t->picnum]*tilesizy[t->picnum];
light.range -= rand()%((light.range>>3)+1); framelights[framelightcount].range -= rand()%((framelights[framelightcount].range>>3)+1);
light.color[0] = 255; framelights[framelightcount].color[0] = 255;
light.color[1] = 80; framelights[framelightcount].color[1] = 80;
light.color[2] = 0; framelights[framelightcount].color[2] = 0;
if ((DynamicTileMap[s->picnum] == ATOMICHEALTH__STATIC) || if ((DynamicTileMap[s->picnum] == ATOMICHEALTH__STATIC) ||
(DynamicTileMap[s->picnum] == FREEZEBLAST__STATIC)) (DynamicTileMap[s->picnum] == FREEZEBLAST__STATIC))
{ {
light.color[0] = 0; framelights[framelightcount].color[0] = 0;
light.color[1] = 0; framelights[framelightcount].color[1] = 0;
light.color[2] = 255; framelights[framelightcount].color[2] = 255;
} }
if ((DynamicTileMap[s->picnum] == SHRINKSPARK__STATIC) || if ((DynamicTileMap[s->picnum] == SHRINKSPARK__STATIC) ||
(DynamicTileMap[s->picnum] == SHRINKEREXPLOSION__STATIC)) (DynamicTileMap[s->picnum] == SHRINKEREXPLOSION__STATIC))
{ {
light.color[0] = 0; framelights[framelightcount].color[0] = 0;
light.color[1] = 255; framelights[framelightcount].color[1] = 255;
light.color[2] = 0; framelights[framelightcount].color[2] = 0;
} }
if (getrendermode() >= 4) framelightcount++;
polymer_addlight(light);
#endif #endif
if (t->picnum == EXPLOSION2) if (t->picnum == EXPLOSION2)
{ {
@ -7420,44 +7416,42 @@ PALONLY:
t->z = sector[t->sectnum].floorz; t->z = sector[t->sectnum].floorz;
t->shade = -127; t->shade = -127;
#ifdef POLYMER #ifdef POLYMER
light.radius = 0; framelights[framelightcount].radius = 0;
light.sector = t->sectnum; framelights[framelightcount].sector = t->sectnum;
light.x = t->x; framelights[framelightcount].x = t->x;
light.y = t->y; framelights[framelightcount].y = t->y;
light.z = t->z; framelights[framelightcount].z = t->z;
light.range = tilesizx[t->picnum]*tilesizy[t->picnum]; framelights[framelightcount].range = tilesizx[t->picnum]*tilesizy[t->picnum];
light.range -= rand()%((light.range>>3)+1); framelights[framelightcount].range -= rand()%((framelights[framelightcount].range>>3)+1);
light.color[0] = 255; framelights[framelightcount].color[0] = 255;
light.color[1] = 80; framelights[framelightcount].color[1] = 80;
light.color[2] = 0; framelights[framelightcount].color[2] = 0;
if (getrendermode() >= 4) framelightcount++;
polymer_addlight(light);
#endif #endif
break; break;
case COOLEXPLOSION1__STATIC: case COOLEXPLOSION1__STATIC:
t->shade = -127; t->shade = -127;
t->picnum += (s->shade>>1); t->picnum += (s->shade>>1);
#ifdef POLYMER #ifdef POLYMER
light.radius = 0; framelights[framelightcount].radius = 0;
light.sector = t->sectnum; framelights[framelightcount].sector = t->sectnum;
light.x = t->x; framelights[framelightcount].x = t->x;
light.y = t->y; framelights[framelightcount].y = t->y;
light.z = t->z; framelights[framelightcount].z = t->z;
light.range = tilesizx[t->picnum]*tilesizy[t->picnum]; framelights[framelightcount].range = tilesizx[t->picnum]*tilesizy[t->picnum];
light.range -= rand()%((light.range>>3)+1); framelights[framelightcount].range -= rand()%((framelights[framelightcount].range>>3)+1);
light.color[0] = 128; framelights[framelightcount].color[0] = 128;
light.color[1] = 0; framelights[framelightcount].color[1] = 0;
light.color[2] = 255; framelights[framelightcount].color[2] = 255;
if (getrendermode() >= 4) framelightcount++;
polymer_addlight(light);
#endif #endif
break; break;
case PLAYERONWATER__STATIC: case PLAYERONWATER__STATIC: