- 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 = 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 // scissor test doesn't use the current viewport for the coordinates, so use real screen coordinates
int btm = (SCREENHEIGHT - screen->GetHeight()) / 2; int btm = (SCREENHEIGHT - screen->GetHeight()) / 2;

View file

@ -71,7 +71,7 @@ void GLWall::DrawDecal(DBaseDecal *decal)
line_t * line=seg->linedef; line_t * line=seg->linedef;
side_t * side=seg->sidedef; side_t * side=seg->sidedef;
int i; int i;
fixed_t zpos; float zpos;
int light; int light;
int rel; int rel;
float a; float a;
@ -129,33 +129,33 @@ void GLWall::DrawDecal(DBaseDecal *decal)
if (type!=RENDERWALL_TOP) return; if (type!=RENDERWALL_TOP) return;
if (line->flags & ML_DONTPEGTOP) if (line->flags & ML_DONTPEGTOP)
{ {
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling); zpos = decal->Z + frontsector->GetPlaneTexZF(sector_t::ceiling);
} }
else else
{ {
zpos = decal->Z + seg->backsector->GetPlaneTexZ(sector_t::ceiling); zpos = decal->Z + seg->backsector->GetPlaneTexZF(sector_t::ceiling);
} }
break; break;
case RF_RELLOWER: case RF_RELLOWER:
if (type!=RENDERWALL_BOTTOM) return; if (type!=RENDERWALL_BOTTOM) return;
if (line->flags & ML_DONTPEGBOTTOM) if (line->flags & ML_DONTPEGBOTTOM)
{ {
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::ceiling); zpos = decal->Z + frontsector->GetPlaneTexZF(sector_t::ceiling);
} }
else else
{ {
zpos = decal->Z + seg->backsector->GetPlaneTexZ(sector_t::floor); zpos = decal->Z + seg->backsector->GetPlaneTexZF(sector_t::floor);
} }
break; break;
case RF_RELMID: case RF_RELMID:
if (type==RENDERWALL_TOP || type==RENDERWALL_BOTTOM) return; if (type==RENDERWALL_TOP || type==RENDERWALL_BOTTOM) return;
if (line->flags & ML_DONTPEGBOTTOM) if (line->flags & ML_DONTPEGBOTTOM)
{ {
zpos = decal->Z + frontsector->GetPlaneTexZ(sector_t::floor); zpos = decal->Z + frontsector->GetPlaneTexZF(sector_t::floor);
} }
else 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 // now clip the decal to the actual polygon
float decalwidth = tex->TextureWidth() * FIXED2FLOAT(decal->ScaleX); float decalwidth = tex->TextureWidth() * decal->ScaleX;
float decalheight= tex->TextureHeight() * FIXED2FLOAT(decal->ScaleY); float decalheight= tex->TextureHeight() * decal->ScaleY;
float decallefto = tex->GetLeftOffset() * FIXED2FLOAT(decal->ScaleX); float decallefto = tex->GetLeftOffset() * decal->ScaleX;
float decaltopo = tex->GetTopOffset() * FIXED2FLOAT(decal->ScaleY); float decaltopo = tex->GetTopOffset() * decal->ScaleY;
float leftedge = glseg.fracleft * side->TexelLength; float leftedge = glseg.fracleft * side->TexelLength;
float linelength = glseg.fracright * side->TexelLength - leftedge; float linelength = glseg.fracright * side->TexelLength - leftedge;
// texel index of the decal's left edge // 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 left,right;
float lefttex,righttex; float lefttex,righttex;
@ -232,14 +232,14 @@ void GLWall::DrawDecal(DBaseDecal *decal)
dv[3].x=dv[2].x=glseg.x1+vx*right; dv[3].x=dv[2].x=glseg.x1+vx*right;
dv[3].y=dv[2].y=glseg.y1+vy*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[0].z=dv[3].z = dv[1].z - decalheight;
dv[1].v=dv[2].v = tex->GetVT(); dv[1].v=dv[2].v = tex->GetVT();
dv[1].u=dv[0].u = tex->GetU(lefttex / FIXED2FLOAT(decal->ScaleX)); dv[1].u=dv[0].u = tex->GetU(lefttex / decal->ScaleX);
dv[3].u=dv[2].u = tex->GetU(righttex / FIXED2FLOAT(decal->ScaleX)); dv[3].u=dv[2].u = tex->GetU(righttex / decal->ScaleX);
dv[0].v=dv[3].v = tex->GetVB(); 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) if (gl_lights && GLRenderer->mLightCount && !gl_fixedcolormap && gl_light_sprites)
{ {
// Note: This should be replaced with proper shader based lighting. // Note: This should be replaced with proper shader based lighting.
fixed_t x, y; double x, y;
decal->GetXY(seg->sidedef, x, y); decal->GetXY(seg->sidedef, x, y);
gl_SetDynSpriteLight(NULL, x, y, zpos, sub); 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; ADynamicLight *light;
float frac, lr, lg, lb; 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) && if (!(light->flags2&MF2_DORMANT) &&
(!(light->flags4&MF4_DONTLIGHTSELF) || light->target != self)) (!(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; radius = light->GetRadius() * gl_lights_size;
if (dist < radius) if (dist < radius)
@ -117,10 +138,10 @@ void gl_SetDynSpriteLight(AActor *thing, particle_t *particle)
{ {
if (thing != NULL) 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) 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 // 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); void gl_SetDynSpriteLight(AActor *actor, particle_t *particle);
#endif #endif

View file

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