Skip to content

Commit

Permalink
- implement anamorphesis proof-of-concept
Browse files Browse the repository at this point in the history
  • Loading branch information
madame-rachelle committed Mar 15, 2024
1 parent df2359f commit 0468fda
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/rendering/hwrenderer/scene/hw_sprites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ CVAR(Bool, gl_usecolorblending, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
CVAR(Bool, gl_sprite_blend, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Int, gl_spriteclip, -1, CVAR_ARCHIVE)
CVAR(Bool, gl_spriteclipupdate, false, CVAR_ARCHIVE)
CVAR(Bool, r_debug_nolimitanamorphoses, false, 0)
CVAR(Float, r_spriteclipanamorphicminbias, 0.6, CVAR_ARCHIVE)
CVAR(Float, gl_sclipthreshold, 10.0, CVAR_ARCHIVE)
CVAR(Float, gl_sclipfactor, 1.8f, CVAR_ARCHIVE)
CVAR(Int, gl_particles_style, 2, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) // 0 = square, 1 = round, 2 = smooth
Expand Down Expand Up @@ -1068,6 +1070,56 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
depth = (float)((x - vp.Pos.X) * vp.TanCos + (y - vp.Pos.Y) * vp.TanSin);
if (isSpriteShadow) depth += 1.f/65536.f; // always sort shadows behind the sprite.

if (gl_spriteclip == -1 && (thing->renderflags & RF_SPRITETYPEMASK) == RF_FACESPRITE) // perform anamorphosis
{
float minbias = r_spriteclipanamorphicminbias;
minbias = clamp(minbias, 0.3f, 1.0f);

float btm = thing->Sector->floorplane.ZatPoint(thing) - thing->Floorclip;
float top = thing->Sector->ceilingplane.ZatPoint(thingpos);

float vbtm = thing->Sector->floorplane.ZatPoint(vp.Pos);
float vtop = thing->Sector->ceilingplane.ZatPoint(vp.Pos);

float vpx = vp.Pos.X;
float vpy = vp.Pos.Y;
float vpz = vp.Pos.Z;

float tpx = thingpos.X;
float tpy = thingpos.Y;
float tpz = thingpos.Z;

if (!(r_debug_nolimitanamorphoses))
{
// this should help prevent clipping through walls ...
float objradiusbias = 1.f - thing->radius / sqrt((vpx - tpx) * (vpx - tpx) + (vpy - tpy) * (vpy - tpy));
minbias = max(minbias, objradiusbias);
}

float bintersect, tintersect;
if (z2 < vpz && vbtm < vpz)
bintersect = min((btm - vpz) / (z2 - vpz), (vbtm - vpz) / (z2 - vpz));
else
bintersect = 1.0;

if (z1 > vpz && vtop > vpz)
tintersect = min((top - vpz) / (z1 - vpz), (vtop - vpz) / (z1 - vpz));
else
tintersect = 1.0;

if (thing->waterlevel >= 1 && thing->waterlevel <= 2)
bintersect = tintersect = 1.0f;

float spbias = clamp(min(bintersect, tintersect), minbias, 1.0f);
float vpbias = 1.0 - spbias;
x1 = x1 * spbias + vpx * vpbias;
y1 = y1 * spbias + vpy * vpbias;
z1 = z1 * spbias + vpz * vpbias;
x2 = x2 * spbias + vpx * vpbias;
y2 = y2 * spbias + vpy * vpbias;
z2 = z2 * spbias + vpz * vpbias;
}

// light calculation

bool enhancedvision = false;
Expand Down Expand Up @@ -1286,6 +1338,7 @@ void HWSprite::Process(HWDrawInfo *di, AActor* thing, sector_t * sector, area_t
{
lightlist = nullptr;
}

PutSprite(di, hw_styleflags != STYLEHW_Solid);
rendered_sprites++;
}
Expand Down
1 change: 1 addition & 0 deletions wadsrc/static/menudef.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,7 @@ OptionValue "SpriteclipModes"
1, "$OPTVAL_SMART"
2, "$OPTVAL_ALWAYS"
3, "$OPTVAL_SMARTER"
-1, "$OPTVAL_ANAMORPHIC"
}

OptionValue "EnhancedStealth"
Expand Down

0 comments on commit 0468fda

Please sign in to comment.