- use hardware clipping to apply 3D lights to sprites. This solves all the problems with properly lighting models and billboarded sprites.

- add some restrictions for the checks that exclude sprites which are too close to the camera. Most importantly, for clipping the first frame of a projectile, do not solely clip against the projectile's speed but use the player's radius as a limiting factor to avoid too large distances.
This commit is contained in:
Christoph Oelckers 2016-02-01 18:14:00 +01:00
parent 1ad310e69b
commit 2c55dcca27
2 changed files with 139 additions and 162 deletions

View file

@ -217,12 +217,48 @@ void GLSprite::Draw(int pass)
if (gltexture) gl_RenderState.SetMaterial(gltexture, CLAMP_XY, translation, OverrideShader, !!(RenderStyle.Flags & STYLEF_RedIsAlpha)); if (gltexture) gl_RenderState.SetMaterial(gltexture, CLAMP_XY, translation, OverrideShader, !!(RenderStyle.Flags & STYLEF_RedIsAlpha));
else if (!modelframe) gl_RenderState.EnableTexture(false); else if (!modelframe) gl_RenderState.EnableTexture(false);
//gl_SetColor(lightlevel, rel, Colormap, trans);
unsigned int iter;
if (lightlist)
{
iter = lightlist->Size();
gl_RenderState.EnableSplit(true);
glEnable(GL_CLIP_DISTANCE3);
glEnable(GL_CLIP_DISTANCE4);
}
else
{
iter = 1;
}
for (unsigned i = 0; i < iter; i++)
{
if (lightlist)
{
// set up the light slice
static secplane_t bottommost = { 0, 0, FRACUNIT, 32767<<FRACBITS, FRACUNIT };
static secplane_t topmost = { 0, 0, FRACUNIT, -(32767<<FRACBITS), FRACUNIT };
secplane_t *topplane = i == 0 ? &topmost : &(*lightlist)[i].plane;
secplane_t *lowplane = i == (*lightlist).Size() - 1 ? &bottommost : &(*lightlist)[i + 1].plane;
int thisll = (*lightlist)[i].caster != NULL ? gl_ClampLight(*(*lightlist)[i].p_lightlevel) : lightlevel;
FColormap thiscm;
thiscm.FadeColor = Colormap.FadeColor;
thiscm.CopyFrom3DLight(&(*lightlist)[i]);
gl_SetColor(thisll, rel, thiscm, trans);
gl_RenderState.SetSplitPlanes(*topplane, *lowplane);
}
if (!modelframe) if (!modelframe)
{ {
// [BB] Billboard stuff // [BB] Billboard stuff
const bool drawWithXYBillboard = ((particle && gl_billboard_particles) || (!(actor && actor->renderflags & RF_FORCEYBILLBOARD) const bool drawWithXYBillboard = ((particle && gl_billboard_particles) || (!(actor && actor->renderflags & RF_FORCEYBILLBOARD)
//&& GLRenderer->mViewActor != NULL //&& GLRenderer->mViewActor != NULL
&& (gl_billboard_mode == 1 || (actor && actor->renderflags & RF_FORCEXYBILLBOARD)))); && (gl_billboard_mode == 1 || (actor && actor->renderflags & RF_FORCEXYBILLBOARD))));
gl_RenderState.Apply(); gl_RenderState.Apply();
Vector v1; Vector v1;
@ -252,6 +288,7 @@ void GLSprite::Draw(int pass)
} }
else else
{ {
v1 = Vector(x1, z1, y1); v1 = Vector(x1, z1, y1);
v2 = Vector(x2, z1, y2); v2 = Vector(x2, z1, y2);
v3 = Vector(x1, z2, y1); v3 = Vector(x1, z2, y1);
@ -287,6 +324,14 @@ void GLSprite::Draw(int pass)
{ {
gl_RenderModel(this); gl_RenderModel(this);
} }
}
if (lightlist)
{
glDisable(GL_CLIP_DISTANCE3);
glDisable(GL_CLIP_DISTANCE4);
gl_RenderState.EnableSplit(false);
}
if (pass==GLPASS_TRANSLUCENT) if (pass==GLPASS_TRANSLUCENT)
{ {
@ -322,87 +367,6 @@ inline void GLSprite::PutSprite(bool translucent)
gl_drawinfo->drawlists[list].AddSprite(this); gl_drawinfo->drawlists[list].AddSprite(this);
} }
//==========================================================================
//
//
//
//==========================================================================
void GLSprite::SplitSprite(sector_t * frontsector, bool translucent)
{
GLSprite copySprite;
fixed_t lightbottom;
float maplightbottom;
unsigned int i;
bool put=false;
TArray<lightlist_t> & lightlist=frontsector->e->XFloor.lightlist;
for(i=0;i<lightlist.Size();i++)
{
// Particles don't go through here so we can safely assume that actor is not NULL
if (i<lightlist.Size()-1) lightbottom=lightlist[i+1].plane.ZatPoint(actor);
else lightbottom=frontsector->floorplane.ZatPoint(actor);
maplightbottom=FIXED2FLOAT(lightbottom);
if (maplightbottom<z2) maplightbottom=z2;
if (maplightbottom<z1)
{
copySprite=*this;
copySprite.lightlevel = gl_ClampLight(*lightlist[i].p_lightlevel);
copySprite.Colormap.CopyFrom3DLight(&lightlist[i]);
if (glset.nocoloredspritelighting)
{
int v = (copySprite.Colormap.LightColor.r + copySprite.Colormap.LightColor.g + copySprite.Colormap.LightColor.b )/3;
copySprite.Colormap.LightColor.r=
copySprite.Colormap.LightColor.g=
copySprite.Colormap.LightColor.b=(255+v+v)/3;
}
z1=copySprite.z2=maplightbottom;
vt=copySprite.vb=copySprite.vt+
(maplightbottom-copySprite.z1)*(copySprite.vb-copySprite.vt)/(z2-copySprite.z1);
copySprite.PutSprite(translucent);
put=true;
}
}
}
void GLSprite::SetSpriteColor(sector_t *sector, fixed_t center_y)
{
fixed_t lightbottom;
float maplightbottom;
unsigned int i;
TArray<lightlist_t> & lightlist=actor->Sector->e->XFloor.lightlist;
for(i=0;i<lightlist.Size();i++)
{
// Particles don't go through here so we can safely assume that actor is not NULL
if (i<lightlist.Size()-1) lightbottom=lightlist[i+1].plane.ZatPoint(actor);
else lightbottom=sector->floorplane.ZatPoint(actor);
//maplighttop=FIXED2FLOAT(lightlist[i].height);
maplightbottom=FIXED2FLOAT(lightbottom);
if (maplightbottom<z2) maplightbottom=z2;
if (maplightbottom<center_y)
{
lightlevel=*lightlist[i].p_lightlevel;
Colormap.CopyFrom3DLight(&lightlist[i]);
if (glset.nocoloredspritelighting)
{
int v = (Colormap.LightColor.r + Colormap.LightColor.g + Colormap.LightColor.b )/3;
Colormap.LightColor.r=
Colormap.LightColor.g=
Colormap.LightColor.b=(255+v+v)/3;
}
return;
}
}
}
//========================================================================== //==========================================================================
// //
// //
@ -542,6 +506,8 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
// Too close to the camera. This doesn't look good if it is a sprite. // Too close to the camera. This doesn't look good if it is a sprite.
if (P_AproxDistance(thingpos.x-viewx, thingpos.y-viewy)<2*FRACUNIT) if (P_AproxDistance(thingpos.x-viewx, thingpos.y-viewy)<2*FRACUNIT)
{
if (viewz >= thingpos.z - 2 * FRACUNIT && viewz <= thingpos.z + thing->height + 2 * FRACUNIT)
{ {
// exclude vertically moving objects from this check. // exclude vertically moving objects from this check.
if (!(thing->velx == 0 && thing->vely == 0 && thing->velz != 0)) if (!(thing->velx == 0 && thing->vely == 0 && thing->velz != 0))
@ -552,12 +518,15 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
} }
} }
} }
}
// don't draw first frame of a player missile // don't draw first frame of a player missile
if (thing->flags&MF_MISSILE && thing->target==GLRenderer->mViewActor && GLRenderer->mViewActor != NULL) if (thing->flags&MF_MISSILE && !(thing->flags7 & MF7_FLYCHEAT) && thing->target==GLRenderer->mViewActor && GLRenderer->mViewActor != NULL)
{ {
if (P_AproxDistance(thingpos.x-viewx, thingpos.y-viewy) < thing->Speed ) return; fixed_t clipdist = clamp(thing->Speed, thing->target->radius, thing->target->radius*2);
if (P_AproxDistance(thingpos.x-viewx, thingpos.y-viewy) < clipdist) return;
} }
thing->flags7 |= MF7_FLYCHEAT; // do this only once for the very first frame, but not if it gets into range again.
if (GLRenderer->mCurrentPortal) if (GLRenderer->mCurrentPortal)
{ {
@ -831,19 +800,23 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
&& (gl_billboard_mode == 1 || actor->renderflags & RF_FORCEXYBILLBOARD ) ); && (gl_billboard_mode == 1 || actor->renderflags & RF_FORCEXYBILLBOARD ) );
if (drawWithXYBillboard || modelframe) // no light splitting when:
// 1. no lightlist
// 2. any fixed colormap
// 3. any bright object
// 4. any with render style shadow (which doesn't use the sector light)
// 5. anything with render style reverse subtract (light effect is not what would be desired here)
if (thing->Sector->e->XFloor.lightlist.Size() != 0 && gl_fixedcolormap == CM_DEFAULT && !fullbright &&
RenderStyle.BlendOp != STYLEOP_Shadow && RenderStyle.BlendOp != STYLEOP_RevSub)
{ {
if (!gl_fixedcolormap && !fullbright) SetSpriteColor(actor->Sector, thingpos.y + (actor->height>>1)); lightlist = &thing->Sector->e->XFloor.lightlist;
PutSprite(hw_styleflags != STYLEHW_Solid);
}
else if (thing->Sector->e->XFloor.lightlist.Size()==0 || gl_fixedcolormap || fullbright)
{
PutSprite(hw_styleflags != STYLEHW_Solid);
} }
else else
{ {
SplitSprite(thing->Sector, hw_styleflags != STYLEHW_Solid); lightlist = NULL;
} }
PutSprite(hw_styleflags != STYLEHW_Solid);
rendered_sprites++; rendered_sprites++;
} }
@ -965,6 +938,11 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
if (gl_particles_style != 2 && trans>=1.0f-FLT_EPSILON) hw_styleflags = STYLEHW_Solid; if (gl_particles_style != 2 && trans>=1.0f-FLT_EPSILON) hw_styleflags = STYLEHW_Solid;
else hw_styleflags = STYLEHW_NoAlphaTest; else hw_styleflags = STYLEHW_NoAlphaTest;
if (sector->e->XFloor.lightlist.Size() != 0 && gl_fixedcolormap == CM_DEFAULT && !fullbright)
lightlist = &sector->e->XFloor.lightlist;
else
lightlist = NULL;
PutSprite(hw_styleflags != STYLEHW_Solid); PutSprite(hw_styleflags != STYLEHW_Solid);
rendered_sprites++; rendered_sprites++;
} }

View file

@ -333,8 +333,8 @@ public:
float trans; float trans;
AActor * actor; AActor * actor;
particle_t * particle; particle_t * particle;
TArray<lightlist_t> *lightlist;
void SplitSprite(sector_t * frontsector, bool translucent);
void SetLowerParam(); void SetLowerParam();
void PerformSpriteClipAdjustment(AActor *thing, fixed_t thingx, fixed_t thingy, float spriteheight); void PerformSpriteClipAdjustment(AActor *thing, fixed_t thingx, fixed_t thingy, float spriteheight);
@ -345,7 +345,6 @@ public:
void Process(AActor* thing,sector_t * sector); void Process(AActor* thing,sector_t * sector);
void ProcessParticle (particle_t *particle, sector_t *sector);//, int shade, int fakeside) void ProcessParticle (particle_t *particle, sector_t *sector);//, int shade, int fakeside)
void SetThingColor(PalEntry); void SetThingColor(PalEntry);
void SetSpriteColor(sector_t *sector, fixed_t y);
// Lines start-end and fdiv must intersect. // Lines start-end and fdiv must intersect.
double CalcIntersectionVertex(GLWall * w2); double CalcIntersectionVertex(GLWall * w2);