- clip sprites to linked sector portal planes.

This is the first part of properly handling those transitions.
This commit is contained in:
Christoph Oelckers 2016-04-18 16:27:04 +02:00
parent 990f5a79b4
commit 741f054601
2 changed files with 36 additions and 28 deletions

View file

@ -107,6 +107,8 @@ void gl_SetRenderStyle(FRenderStyle style, bool drawopaque, bool allowcolorblend
CVAR(Bool, gl_nolayer, false, 0) CVAR(Bool, gl_nolayer, false, 0)
static const float LARGE_VALUE = 1e19f;
//========================================================================== //==========================================================================
// //
// //
@ -218,30 +220,25 @@ void GLSprite::Draw(int pass)
//gl_SetColor(lightlevel, rel, Colormap, trans); //gl_SetColor(lightlevel, rel, Colormap, trans);
unsigned int iter; unsigned int iter = lightlist? lightlist->Size() : 1;
bool clipping = false;
if (lightlist) if (lightlist || topclip != LARGE_VALUE || bottomclip != -LARGE_VALUE)
{ {
iter = lightlist->Size(); clipping = true;
gl_RenderState.EnableSplit(true); gl_RenderState.EnableSplit(true);
glEnable(GL_CLIP_DISTANCE3); glEnable(GL_CLIP_DISTANCE3);
glEnable(GL_CLIP_DISTANCE4); glEnable(GL_CLIP_DISTANCE4);
} }
else
{
iter = 1;
}
secplane_t bottomp = { { 0, 0, -1. }, bottomclip };
secplane_t topp = { { 0, 0, -1. }, topclip };
for (unsigned i = 0; i < iter; i++) for (unsigned i = 0; i < iter; i++)
{ {
if (lightlist) if (lightlist)
{ {
// set up the light slice // set up the light slice
static secplane_t bottommost = { {0, 0, 1.}, FLT_MAX }; secplane_t *topplane = i == 0 ? &topp : &(*lightlist)[i].plane;
static secplane_t topmost = { { 0, 0, 1. }, -FLT_MAX }; secplane_t *lowplane = i == (*lightlist).Size() - 1 ? &bottomp : &(*lightlist)[i + 1].plane;
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; int thisll = (*lightlist)[i].caster != NULL ? gl_ClampLight(*(*lightlist)[i].p_lightlevel) : lightlevel;
FColormap thiscm; FColormap thiscm;
@ -255,6 +252,10 @@ void GLSprite::Draw(int pass)
gl_SetColor(thisll, rel, thiscm, trans); gl_SetColor(thisll, rel, thiscm, trans);
gl_RenderState.SetSplitPlanes(*topplane, *lowplane); gl_RenderState.SetSplitPlanes(*topplane, *lowplane);
} }
else if (clipping)
{
gl_RenderState.SetSplitPlanes(topp, bottomp);
}
if (!modelframe) if (!modelframe)
{ {
@ -330,7 +331,7 @@ void GLSprite::Draw(int pass)
} }
} }
if (lightlist) if (clipping)
{ {
glDisable(GL_CLIP_DISTANCE3); glDisable(GL_CLIP_DISTANCE3);
glDisable(GL_CLIP_DISTANCE4); glDisable(GL_CLIP_DISTANCE4);
@ -476,12 +477,12 @@ void GLSprite::PerformSpriteClipAdjustment(AActor *thing, const DVector2 &thingp
// //
//========================================================================== //==========================================================================
void GLSprite::Process(AActor* thing,sector_t * sector) void GLSprite::Process(AActor* thing, sector_t * sector, bool thruportal)
{ {
sector_t rs; sector_t rs;
sector_t * rendersector; sector_t * rendersector;
// don't draw the thing that's used as camera (for viewshifts during quakes!) // don't draw the thing that's used as camera (for viewshifts during quakes!)
if (thing==GLRenderer->mViewActor || (thing == players[consoleplayer].camera && !r_showviewer)) return; if (thing == GLRenderer->mViewActor || (thing == players[consoleplayer].camera && !r_showviewer)) return;
// Don't waste time projecting sprites that are definitely not visible. // Don't waste time projecting sprites that are definitely not visible.
if (thing == NULL || thing->sprite == 0 || !thing->IsVisibleToPlayer()) if (thing == NULL || thing->sprite == 0 || !thing->IsVisibleToPlayer())
@ -496,14 +497,14 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
P_CheckPlayerSprite(thing, spritenum, sprscale); P_CheckPlayerSprite(thing, spritenum, sprscale);
} }
if (thing->renderflags & RF_INVISIBLE || !thing->RenderStyle.IsVisible(thing->Alpha)) if (thing->renderflags & RF_INVISIBLE || !thing->RenderStyle.IsVisible(thing->Alpha))
{ {
if (!(thing->flags & MF_STEALTH) || !gl_fixedcolormap || !gl_enhanced_nightvision) if (!(thing->flags & MF_STEALTH) || !gl_fixedcolormap || !gl_enhanced_nightvision)
return; return;
} }
// If this thing is in a map section that's not in view it can't possibly be visible // If this thing is in a map section that's not in view it can't possibly be visible
if (!(currentmapsection[thing->subsector->mapsection>>3] & (1 << (thing->subsector->mapsection & 7)))) return; if (!(currentmapsection[thing->subsector->mapsection >> 3] & (1 << (thing->subsector->mapsection & 7)))) return;
// [RH] Interpolate the sprite's position to make it look smooth // [RH] Interpolate the sprite's position to make it look smooth
DVector3 thingpos = thing->InterpolatedPosition(r_TicFracF); DVector3 thingpos = thing->InterpolatedPosition(r_TicFracF);
@ -527,10 +528,10 @@ 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) if (thing->flags&MF_MISSILE)
{ {
if (!(thing->flags7 & MF7_FLYCHEAT) && thing->target==GLRenderer->mViewActor && GLRenderer->mViewActor != NULL) if (!(thing->flags7 & MF7_FLYCHEAT) && thing->target == GLRenderer->mViewActor && GLRenderer->mViewActor != NULL)
{ {
double clipdist = clamp(thing->Speed, thing->target->radius, thing->target->radius*2); double clipdist = clamp(thing->Speed, thing->target->radius, thing->target->radius * 2);
if ((thingpos-ViewPos).LengthSquared() < clipdist * clipdist) return; if ((thingpos - ViewPos).LengthSquared() < clipdist * clipdist) return;
} }
thing->flags7 |= MF7_FLYCHEAT; // do this only once for the very first frame, but not if it gets into range again. thing->flags7 |= MF7_FLYCHEAT; // do this only once for the very first frame, but not if it gets into range again.
} }
@ -541,18 +542,20 @@ void GLSprite::Process(AActor* thing,sector_t * sector)
if (clipres == GLPortal::PClip_InFront) return; if (clipres == GLPortal::PClip_InFront) return;
} }
player_t *player=&players[consoleplayer]; player_t *player = &players[consoleplayer];
FloatRect r; FloatRect r;
if (sector->sectornum!=thing->Sector->sectornum) if (sector->sectornum != thing->Sector->sectornum && !thruportal)
{ {
rendersector=gl_FakeFlat(thing->Sector, &rs, false); rendersector = gl_FakeFlat(thing->Sector, &rs, false);
} }
else else
{ {
rendersector=sector; rendersector = sector;
} }
topclip = rendersector->PortalBlocksMovement(sector_t::ceiling) ? LARGE_VALUE : rendersector->SkyBoxes[sector_t::ceiling]->specialf1;
bottomclip = rendersector->PortalBlocksMovement(sector_t::floor) ? -LARGE_VALUE : rendersector->SkyBoxes[sector_t::floor]->specialf1;
x = thingpos.X; x = thingpos.X;
z = thingpos.Z - thing->Floorclip; z = thingpos.Z - thing->Floorclip;
@ -892,6 +895,8 @@ void GLSprite::ProcessParticle (particle_t *particle, sector_t *sector)//, int s
modelframe=NULL; modelframe=NULL;
gltexture=NULL; gltexture=NULL;
topclip = LARGE_VALUE;
bottomclip = -LARGE_VALUE;
// [BB] Load the texture for round or smooth particles // [BB] Load the texture for round or smooth particles
if (gl_particles_style) if (gl_particles_style)

View file

@ -334,6 +334,9 @@ public:
int index; int index;
int depth; int depth;
float topclip;
float bottomclip;
float x,y,z; // needed for sorting! float x,y,z; // needed for sorting!
float ul,ur; float ul,ur;
@ -354,7 +357,7 @@ public:
void Draw(int pass); void Draw(int pass);
void PutSprite(bool translucent); void PutSprite(bool translucent);
void Process(AActor* thing,sector_t * sector); void Process(AActor* thing,sector_t * sector, bool thruportal = false);
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);