- adjustments to GL renderer for decal and alpha changes.

- handle portals in sprite lighting, but do not use the playsim's utility functions for efficiency.
This commit is contained in:
Christoph Oelckers 2016-03-22 23:19:21 +01:00
parent eee5143b26
commit eadecaf407
5 changed files with 47 additions and 26 deletions

View File

@ -375,7 +375,7 @@ void FGLRenderer::DrawTexture(FTexture *img, DCanvas::DrawParms &parms)
{
color = PalEntry(light, light, light);
}
color.a = Scale(parms.alpha, 255, FRACUNIT);
color.a = (BYTE)(parms.Alpha * 255);
// scissor test doesn't use the current viewport for the coordinates, so use real screen coordinates
int btm = (SCREENHEIGHT - screen->GetHeight()) / 2;

View File

@ -71,7 +71,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
line_t * line=seg->linedef;
side_t * side=seg->sidedef;
int i;
fixed_t zpos;
float zpos;
int light;
int rel;
float a;
@ -129,33 +129,33 @@ void GLWall::DrawDecal(DBaseDecal *decal)
if (type!=RENDERWALL_TOP) return;
if (line->flags & ML_DONTPEGTOP)
{
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling);
zpos = decal->Z + frontsector->GetPlaneTexZF(sector_t::ceiling);
}
else
{
zpos = decal->Z + seg->backsector->GetPlaneTexZ(sector_t::ceiling);
zpos = decal->Z + seg->backsector->GetPlaneTexZF(sector_t::ceiling);
}
break;
case RF_RELLOWER:
if (type!=RENDERWALL_BOTTOM) return;
if (line->flags & ML_DONTPEGBOTTOM)
{
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling);
zpos = decal->Z + frontsector->GetPlaneTexZF(sector_t::ceiling);
}
else
{
zpos = decal->Z + seg->backsector->GetPlaneTexZ(sector_t::floor);
zpos = decal->Z + seg->backsector->GetPlaneTexZF(sector_t::floor);
}
break;
case RF_RELMID:
if (type==RENDERWALL_TOP || type==RENDERWALL_BOTTOM) return;
if (line->flags & ML_DONTPEGBOTTOM)
{
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::floor);
zpos = decal->Z + frontsector->GetPlaneTexZF(sector_t::floor);
}
else
{
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling);
zpos = decal->Z + frontsector->GetPlaneTexZF(sector_t::ceiling);
}
}
@ -179,20 +179,20 @@ void GLWall::DrawDecal(DBaseDecal *decal)
a = FIXED2FLOAT(decal->Alpha);
a = decal->Alpha;
// now clip the decal to the actual polygon
float decalwidth = tex->TextureWidth() * FIXED2FLOAT(decal->ScaleX);
float decalheight= tex->TextureHeight() * FIXED2FLOAT(decal->ScaleY);
float decallefto = tex->GetLeftOffset() * FIXED2FLOAT(decal->ScaleX);
float decaltopo = tex->GetTopOffset() * FIXED2FLOAT(decal->ScaleY);
float decalwidth = tex->TextureWidth() * decal->ScaleX;
float decalheight= tex->TextureHeight() * decal->ScaleY;
float decallefto = tex->GetLeftOffset() * decal->ScaleX;
float decaltopo = tex->GetTopOffset() * decal->ScaleY;
float leftedge = glseg.fracleft * side->TexelLength;
float linelength = glseg.fracright * side->TexelLength - leftedge;
// texel index of the decal's left edge
float decalpixpos = (float)side->TexelLength * decal->LeftDistance / (1<<30) - (flipx? decalwidth-decallefto : decallefto) - leftedge;
float decalpixpos = (float)side->TexelLength * decal->LeftDistance - (flipx? decalwidth-decallefto : decallefto) - leftedge;
float left,right;
float lefttex,righttex;
@ -232,14 +232,14 @@ void GLWall::DrawDecal(DBaseDecal *decal)
dv[3].x=dv[2].x=glseg.x1+vx*right;
dv[3].y=dv[2].y=glseg.y1+vy*right;
zpos+= FRACUNIT*(flipy? decalheight-decaltopo : decaltopo);
zpos+= (flipy? decalheight-decaltopo : decaltopo);
dv[1].z=dv[2].z = FIXED2FLOAT(zpos);
dv[1].z=dv[2].z = zpos;
dv[0].z=dv[3].z = dv[1].z - decalheight;
dv[1].v=dv[2].v = tex->GetVT();
dv[1].u=dv[0].u = tex->GetU(lefttex / FIXED2FLOAT(decal->ScaleX));
dv[3].u=dv[2].u = tex->GetU(righttex / FIXED2FLOAT(decal->ScaleX));
dv[1].u=dv[0].u = tex->GetU(lefttex / decal->ScaleX);
dv[3].u=dv[2].u = tex->GetU(righttex / decal->ScaleX);
dv[0].v=dv[3].v = tex->GetVB();
@ -297,7 +297,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
if (gl_lights && GLRenderer->mLightCount && !gl_fixedcolormap && gl_light_sprites)
{
// Note: This should be replaced with proper shader based lighting.
fixed_t x, y;
double x, y;
decal->GetXY(seg->sidedef, x, y);
gl_SetDynSpriteLight(NULL, x, y, zpos, sub);
}

View File

@ -63,7 +63,7 @@
//
//==========================================================================
void gl_SetDynSpriteLight(AActor *self, fixed_t x, fixed_t y, fixed_t z, subsector_t * subsec)
void gl_SetDynSpriteLight(AActor *self, float x, float y, float z, subsector_t * subsec)
{
ADynamicLight *light;
float frac, lr, lg, lb;
@ -80,7 +80,28 @@ void gl_SetDynSpriteLight(AActor *self, fixed_t x, fixed_t y, fixed_t z, subsect
if (!(light->flags2&MF2_DORMANT) &&
(!(light->flags4&MF4_DONTLIGHTSELF) || light->target != self))
{
float dist = FVector3(FIXED2FLOAT(x - light->_f_X()), FIXED2FLOAT(y - light->_f_Y()), FIXED2FLOAT(z - light->_f_Z())).Length();
float dist;
// This is a performance critical section of code where we cannot afford to let the compiler decide whether to inline the function or not.
// This will do the calculations explicitly rather than calling one of AActor's utility functions.
if (Displacements.size > 0)
{
int fromgroup = light->Sector->PortalGroup;
int togroup = subsec->sector->PortalGroup;
if (fromgroup == togroup || fromgroup == 0 || togroup == 0) goto direct;
fixedvec2 offset = Displacements.getOffset(fromgroup, togroup);
dist = FVector3(x - light->X() - FIXED2FLOAT(offset.x), y - light->Y() - FIXED2FLOAT(offset.y), z - light->Z()).LengthSquared();
}
else
{
direct:
dist = FVector3(x - light->X(), y - light->Y(), z - light->Z()).LengthSquared();
}
// This is to avoid calling the software-implemented sqrt function which gets used by FVector3::Length().
// With fast math on in this module this call will be mapped to a machine instruction on most platforms.
dist = sqrtf(dist);
radius = light->GetRadius() * gl_lights_size;
if (dist < radius)
@ -117,10 +138,10 @@ void gl_SetDynSpriteLight(AActor *thing, particle_t *particle)
{
if (thing != NULL)
{
gl_SetDynSpriteLight(thing, thing->_f_X(), thing->_f_Y(), thing->_f_Z() + (thing->_f_height() >> 1), thing->subsector);
gl_SetDynSpriteLight(thing, thing->X(), thing->Y(), thing->Center(), thing->subsector);
}
else if (particle != NULL)
{
gl_SetDynSpriteLight(NULL, particle->x, particle->y, particle->z, particle->subsector);
gl_SetDynSpriteLight(NULL, FIXED2FLOAT(particle->x), FIXED2FLOAT(particle->y), FIXED2FLOAT(particle->z), particle->subsector);
}
}

View File

@ -363,7 +363,7 @@ inline float Dist2(float x1,float y1,float x2,float y2)
// Light + color
void gl_SetDynSpriteLight(AActor *self, fixed_t x, fixed_t y, fixed_t z, subsector_t *subsec);
void gl_SetDynSpriteLight(AActor *self, float x, float y, float z, subsector_t *subsec);
void gl_SetDynSpriteLight(AActor *actor, particle_t *particle);
#endif

View File

@ -300,7 +300,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
visstyle_t vis;
vis.RenderStyle=playermo->RenderStyle;
vis.alpha=playermo->Alpha;
vis.Alpha=playermo->Alpha;
vis.colormap = NULL;
if (playermo->Inventory)
{
@ -350,7 +350,7 @@ void FGLRenderer::DrawPlayerSprites(sector_t * viewsector, bool hudModelStep)
}
else if (trans == 0.f)
{
trans = FIXED2FLOAT(vis.alpha);
trans = vis.Alpha;
}
// now draw the different layers of the weapon