mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-24 21:21:04 +00:00
Renderer floatification: Use floating point for visibility values
This commit is contained in:
parent
ded3f92452
commit
4416d88eb2
6 changed files with 50 additions and 53 deletions
|
@ -93,9 +93,9 @@ extern bool r_showviewer;
|
|||
|
||||
// PRIVATE DATA DECLARATIONS -----------------------------------------------
|
||||
|
||||
static float CurrentVisibility = 8.f;
|
||||
static fixed_t MaxVisForWall;
|
||||
static fixed_t MaxVisForFloor;
|
||||
static double CurrentVisibility = 8.f;
|
||||
static double MaxVisForWall;
|
||||
static double MaxVisForFloor;
|
||||
bool r_dontmaplines;
|
||||
|
||||
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
||||
|
@ -103,15 +103,14 @@ bool r_dontmaplines;
|
|||
CVAR (String, r_viewsize, "", CVAR_NOSET)
|
||||
CVAR (Bool, r_shadercolormaps, true, CVAR_ARCHIVE)
|
||||
|
||||
fixed_t r_BaseVisibility;
|
||||
fixed_t r_WallVisibility;
|
||||
fixed_t r_FloorVisibility;
|
||||
double r_BaseVisibility;
|
||||
double r_WallVisibility;
|
||||
double r_FloorVisibility;
|
||||
float r_TiltVisibility;
|
||||
fixed_t r_SpriteVisibility;
|
||||
fixed_t r_ParticleVisibility;
|
||||
fixed_t r_SkyVisibility;
|
||||
double r_SpriteVisibility;
|
||||
double r_ParticleVisibility;
|
||||
|
||||
fixed_t GlobVis;
|
||||
double GlobVis;
|
||||
fixed_t viewingrangerecip;
|
||||
double FocalLengthX;
|
||||
double FocalLengthY;
|
||||
|
@ -250,10 +249,10 @@ void R_InitTextureMapping ()
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void R_SetVisibility (float vis)
|
||||
void R_SetVisibility(double vis)
|
||||
{
|
||||
// Allow negative visibilities, just for novelty's sake
|
||||
vis = clamp (vis, -204.7f, 204.7f); // (205 and larger do not work in 5:4 aspect ratio)
|
||||
vis = clamp(vis, -204.7, 204.7); // (205 and larger do not work in 5:4 aspect ratio)
|
||||
|
||||
CurrentVisibility = vis;
|
||||
|
||||
|
@ -264,7 +263,7 @@ void R_SetVisibility (float vis)
|
|||
return;
|
||||
}
|
||||
|
||||
r_BaseVisibility = xs_RoundToInt(vis * 65536.f);
|
||||
r_BaseVisibility = vis;
|
||||
|
||||
// Prevent overflow on walls
|
||||
if (r_BaseVisibility < 0 && r_BaseVisibility < -MaxVisForWall)
|
||||
|
@ -274,8 +273,8 @@ void R_SetVisibility (float vis)
|
|||
else
|
||||
r_WallVisibility = r_BaseVisibility;
|
||||
|
||||
r_WallVisibility = FixedMul (FLOAT2FIXED(InvZtoScale * SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1] /
|
||||
(viewwidth*SCREENHEIGHT*3)), xs_ToInt(r_WallVisibility * FocalTangent));
|
||||
r_WallVisibility = (InvZtoScale * SCREENWIDTH*BaseRatioSizes[WidescreenRatio][1] /
|
||||
(viewwidth*SCREENHEIGHT*3)) * (r_WallVisibility * FocalTangent);
|
||||
|
||||
// Prevent overflow on floors/ceilings. Note that the calculation of
|
||||
// MaxVisForFloor means that planes less than two units from the player's
|
||||
|
@ -288,9 +287,9 @@ void R_SetVisibility (float vis)
|
|||
else
|
||||
r_FloorVisibility = r_BaseVisibility;
|
||||
|
||||
r_FloorVisibility = xs_ToInt(160.0 * r_FloorVisibility / FocalLengthY);
|
||||
r_FloorVisibility = 160.0 * r_FloorVisibility / FocalLengthY;
|
||||
|
||||
r_TiltVisibility = vis * (float)FocalTangent * (16.f * 320.f) / (float)viewwidth;
|
||||
r_TiltVisibility = float(vis * FocalTangent * (16.f * 320.f) / viewwidth);
|
||||
r_SpriteVisibility = r_WallVisibility;
|
||||
}
|
||||
|
||||
|
@ -300,7 +299,7 @@ void R_SetVisibility (float vis)
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
float R_GetVisibility ()
|
||||
double R_GetVisibility()
|
||||
{
|
||||
return CurrentVisibility;
|
||||
}
|
||||
|
@ -323,7 +322,7 @@ CCMD (r_visibility)
|
|||
}
|
||||
else if (!netgame)
|
||||
{
|
||||
R_SetVisibility ((float)atof (argv[1]));
|
||||
R_SetVisibility(atof(argv[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -396,13 +395,13 @@ void R_SWRSetWindow(int windowSize, int fullWidth, int fullHeight, int stHeight,
|
|||
|
||||
R_InitTextureMapping ();
|
||||
|
||||
MaxVisForWall = FLOAT2FIXED((InvZtoScale * (SCREENWIDTH*r_Yaspect) /
|
||||
(viewwidth*SCREENHEIGHT * FocalTangent)));
|
||||
MaxVisForWall = FixedDiv (0x7fff0000, MaxVisForWall);
|
||||
MaxVisForFloor = int(0x7fff0000 / (viewheight * FocalLengthY / 160));
|
||||
MaxVisForWall = (InvZtoScale * (SCREENWIDTH*r_Yaspect) /
|
||||
(viewwidth*SCREENHEIGHT * FocalTangent));
|
||||
MaxVisForWall = 32767.0 / MaxVisForWall;
|
||||
MaxVisForFloor = 32767.0 / (viewheight * FocalLengthY / 160);
|
||||
|
||||
// Reset r_*Visibility vars
|
||||
R_SetVisibility (R_GetVisibility ());
|
||||
R_SetVisibility(R_GetVisibility());
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
17
src/r_main.h
17
src/r_main.h
|
@ -82,17 +82,16 @@ extern bool r_dontmaplines;
|
|||
// Change R_CalcTiltedLighting() when this changes.
|
||||
#define GETPALOOKUP(vis,shade) (clamp<int> (((shade)-MIN(MAXLIGHTVIS,(vis)))>>FRACBITS, 0, NUMCOLORMAPS-1))
|
||||
|
||||
extern fixed_t GlobVis;
|
||||
extern double GlobVis;
|
||||
|
||||
void R_SetVisibility (float visibility);
|
||||
float R_GetVisibility ();
|
||||
void R_SetVisibility(double visibility);
|
||||
double R_GetVisibility();
|
||||
|
||||
extern fixed_t r_BaseVisibility;
|
||||
extern fixed_t r_WallVisibility;
|
||||
extern fixed_t r_FloorVisibility;
|
||||
extern double r_BaseVisibility;
|
||||
extern double r_WallVisibility;
|
||||
extern double r_FloorVisibility;
|
||||
extern float r_TiltVisibility;
|
||||
extern fixed_t r_SpriteVisibility;
|
||||
extern fixed_t r_SkyVisibility;
|
||||
extern double r_SpriteVisibility;
|
||||
|
||||
extern int r_actualextralight;
|
||||
extern bool foggy;
|
||||
|
@ -137,7 +136,7 @@ void R_MultiresInit (void);
|
|||
|
||||
|
||||
extern int stacked_extralight;
|
||||
extern float stacked_visibility;
|
||||
extern double stacked_visibility;
|
||||
extern DVector3 stacked_viewpos;
|
||||
extern DAngle stacked_angle;
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ visplane_t *ceilingplane;
|
|||
// you are changing them to draw a stacked sector. Otherwise, stacked sectors
|
||||
// won't draw in skyboxes properly.
|
||||
int stacked_extralight;
|
||||
float stacked_visibility;
|
||||
double stacked_visibility;
|
||||
DVector3 stacked_viewpos;
|
||||
DAngle stacked_angle;
|
||||
|
||||
|
@ -123,7 +123,7 @@ short ceilingclip[MAXWIDTH];
|
|||
// texture mapping
|
||||
//
|
||||
|
||||
static fixed_t planeheight;
|
||||
static double planeheight;
|
||||
|
||||
extern "C" {
|
||||
//
|
||||
|
@ -217,7 +217,7 @@ void R_MapPlane (int y, int x1)
|
|||
// [RH] Notice that I dumped the caching scheme used by Doom.
|
||||
// It did not offer any appreciable speedup.
|
||||
|
||||
distance = FixedMul (planeheight, yslope[y]);
|
||||
distance = xs_ToInt(planeheight * yslope[y]);
|
||||
|
||||
ds_xstep = FixedMul (distance, xstepscale);
|
||||
ds_ystep = FixedMul (distance, ystepscale);
|
||||
|
@ -228,7 +228,7 @@ void R_MapPlane (int y, int x1)
|
|||
{
|
||||
// Determine lighting based on the span's distance from the viewer.
|
||||
ds_colormap = basecolormap->Maps + (GETPALOOKUP (
|
||||
xs_ToInt(GlobVis * fabs(CenterY - y)), planeshade) << COLORMAPSHIFT);
|
||||
FLOAT2FIXED(GlobVis * fabs(CenterY - y)), planeshade) << COLORMAPSHIFT);
|
||||
}
|
||||
|
||||
#ifdef X86_ASM
|
||||
|
@ -1187,7 +1187,7 @@ void R_DrawPortals ()
|
|||
ptrdiff_t savedds_p = ds_p - drawsegs;
|
||||
ptrdiff_t savedlastopening = lastopening;
|
||||
size_t savedinteresting = FirstInterestingDrawseg;
|
||||
float savedvisibility = R_GetVisibility ();
|
||||
double savedvisibility = R_GetVisibility();
|
||||
AActor *savedcamera = camera;
|
||||
sector_t *savedsector = viewsector;
|
||||
|
||||
|
@ -1359,7 +1359,7 @@ void R_DrawPortals ()
|
|||
camera = savedcamera;
|
||||
viewsector = savedsector;
|
||||
ViewPos = savedpos;
|
||||
R_SetVisibility (savedvisibility);
|
||||
R_SetVisibility(savedvisibility);
|
||||
extralight = savedextralight;
|
||||
ViewAngle = savedangle;
|
||||
R_SetViewAngle ();
|
||||
|
@ -1559,9 +1559,9 @@ void R_DrawNormalPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
|||
basexfrac = FixedMul (xscale, finecosine[planeang]) + x*xstepscale;
|
||||
baseyfrac = FixedMul (yscale, -finesine[planeang]) + x*ystepscale;
|
||||
|
||||
planeheight = FLOAT2FIXED(fabs(pl->height.Zat0() - ViewPos.Z));
|
||||
planeheight = fabs(pl->height.Zat0() - ViewPos.Z);
|
||||
|
||||
GlobVis = FixedDiv (r_FloorVisibility, planeheight);
|
||||
GlobVis = r_FloorVisibility / planeheight;
|
||||
if (fixedlightlev >= 0)
|
||||
ds_colormap = basecolormap->Maps + fixedlightlev, plane_shade = false;
|
||||
else if (fixedcolormap)
|
||||
|
@ -1709,7 +1709,7 @@ void R_DrawTiltedPlane (visplane_t *pl, fixed_t alpha, bool additive, bool maske
|
|||
plane_sz[0] = -plane_sz[0];
|
||||
}
|
||||
|
||||
planelightfloat = (r_TiltVisibility * lxscale * lyscale) / (fabs(pl->height.ZatPoint(ViewPos)) / 65536.0);
|
||||
planelightfloat = (r_TiltVisibility * lxscale * lyscale) / fabs(pl->height.ZatPoint(ViewPos));
|
||||
|
||||
if (pl->height.fC() > 0)
|
||||
planelightfloat = -planelightfloat;
|
||||
|
|
|
@ -50,7 +50,7 @@ struct visplane_s
|
|||
// have stacked sectors inside a skybox. If the visplane is not for a
|
||||
// stack, then they are unused.
|
||||
int extralight;
|
||||
float visibility;
|
||||
double visibility;
|
||||
DVector3 viewpos;
|
||||
DAngle viewangle;
|
||||
fixed_t Alpha;
|
||||
|
|
|
@ -2312,8 +2312,8 @@ void R_NewWall (bool needlights)
|
|||
wallshade = LIGHT2SHADE(curline->sidedef->GetLightLevel(foggy, frontsector->lightlevel)
|
||||
+ r_actualextralight);
|
||||
GlobVis = r_WallVisibility;
|
||||
rw_lightleft = FLOAT2FIXED(FIXED2DBL(GlobVis) / WallC.sz1);
|
||||
rw_lightstep = (FLOAT2FIXED(FIXED2DBL(GlobVis) / WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1);
|
||||
rw_lightleft = FLOAT2FIXED(GlobVis / WallC.sz1);
|
||||
rw_lightstep = (FLOAT2FIXED(GlobVis / WallC.sz2) - rw_lightleft) / (WallC.sx2 - WallC.sx1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -533,8 +533,8 @@ void R_DrawWallSprite(vissprite_t *spr)
|
|||
|
||||
int shade = LIGHT2SHADE(spr->sector->lightlevel + r_actualextralight);
|
||||
GlobVis = r_WallVisibility;
|
||||
rw_lightleft = SafeDivScale12(GlobVis, xs_Fix<12>::ToFix(spr->wallc.sz1));
|
||||
rw_lightstep = (SafeDivScale12(GlobVis, xs_Fix<12>::ToFix(spr->wallc.sz2)) - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1);
|
||||
rw_lightleft = FLOAT2FIXED(GlobVis / spr->wallc.sz1);
|
||||
rw_lightstep = (FLOAT2FIXED(GlobVis / spr->wallc.sz2) - rw_lightleft) / (spr->wallc.sx2 - spr->wallc.sx1);
|
||||
rw_light = rw_lightleft + (x1 - spr->wallc.sx1) * rw_lightstep;
|
||||
if (fixedlightlev >= 0)
|
||||
dc_colormap = usecolormap->Maps + fixedlightlev;
|
||||
|
@ -1128,7 +1128,7 @@ void R_ProjectSprite (AActor *thing, int fakeside, F3DFloor *fakefloor, F3DFloor
|
|||
else
|
||||
{ // diminished light
|
||||
vis->ColormapNum = GETPALOOKUP(
|
||||
(fixed_t)(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade);
|
||||
FLOAT2FIXED(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade);
|
||||
vis->Style.colormap = mybasecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT);
|
||||
}
|
||||
}
|
||||
|
@ -1204,7 +1204,7 @@ static void R_ProjectWallSprite(AActor *thing, const DVector3 &pos, FTextureID p
|
|||
vis->bIsVoxel = false;
|
||||
vis->bWallSprite = true;
|
||||
vis->ColormapNum = GETPALOOKUP(
|
||||
(fixed_t)DivScale12 (r_SpriteVisibility, xs_Fix<20>::ToFix(MAX(tz, MINZ))), spriteshade);
|
||||
FLOAT2FIXED(r_SpriteVisibility / MAX(tz, MINZ)), spriteshade);
|
||||
vis->Style.colormap = basecolormap->Maps + (vis->ColormapNum << COLORMAPSHIFT);
|
||||
vis->wallc = wallc;
|
||||
}
|
||||
|
@ -2002,7 +2002,7 @@ void R_DrawSprite (vissprite_t *spr)
|
|||
{ // diminished light
|
||||
spriteshade = LIGHT2SHADE(sec->lightlevel + r_actualextralight);
|
||||
spr->Style.colormap = mybasecolormap->Maps + (GETPALOOKUP (
|
||||
(fixed_t)DivScale12 (r_SpriteVisibility, xs_Fix<20>::ToFix(MAX(MINZ, (double)spr->depth))), spriteshade) << COLORMAPSHIFT);
|
||||
FLOAT2FIXED(r_SpriteVisibility / MAX(MINZ, (double)spr->depth)), spriteshade) << COLORMAPSHIFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2558,9 +2558,8 @@ void R_ProjectParticle (particle_t *particle, const sector_t *sector, int shade,
|
|||
}
|
||||
else
|
||||
{
|
||||
// Using MulScale15 instead of 16 makes particles slightly more visible
|
||||
// than regular sprites.
|
||||
vis->ColormapNum = GETPALOOKUP(MulScale15 (FLOAT2FIXED(tiz), r_SpriteVisibility), shade);
|
||||
// Particles are slightly more visible than regular sprites.
|
||||
vis->ColormapNum = GETPALOOKUP(FLOAT2FIXED(tiz * r_SpriteVisibility * 0.5), shade);
|
||||
vis->Style.colormap = map + (vis->ColormapNum << COLORMAPSHIFT);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue