Skip to content

Commit

Permalink
Add r_actorshadows
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Jun 10, 2020
1 parent 62138c6 commit 03600c2
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 46 deletions.
4 changes: 4 additions & 0 deletions src/rendering/swrenderer/r_renderthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ namespace swrenderer
short clipbot[MAXWIDTH];
short cliptop[MAXWIDTH];

// Copy of the VisibleSprite buffers for the flat sprite pass
short clipbotcopy[MAXWIDTH];
short cliptopcopy[MAXWIDTH];

SWPixelFormatDrawers *Drawers(RenderViewport *viewport);

// Make sure texture can accessed safely
Expand Down
12 changes: 11 additions & 1 deletion src/rendering/swrenderer/scene/r_opaque_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
EXTERN_CVAR(Bool, r_fullbrightignoresectorcolor);
EXTERN_CVAR(Bool, r_drawvoxels);
EXTERN_CVAR(Bool, r_debug_disable_vis_filter);
EXTERN_CVAR(Bool, r_actorshadows);
extern uint32_t r_renderercaps;

double model_distance_cull = 1e16;
Expand Down Expand Up @@ -964,7 +965,16 @@ namespace swrenderer
}
else
{
RenderSprite::Project(Thread, thing, sprite.pos, sprite.tex, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, thinglightlevel, foggy, thingColormap);
RenderSprite::Project(Thread, thing, sprite.pos, sprite.tex, sprite.spriteScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, thinglightlevel, foggy, thingColormap, false);

if (r_actorshadows)
{
DVector2 shadowScale = sprite.spriteScale;
shadowScale.Y *= (thing->Scale.Y * 0.1);
DVector3 shadowPos = sprite.pos;
shadowPos.Z = thing->floorz;
RenderSprite::Project(Thread, thing, shadowPos, sprite.tex, shadowScale, sprite.renderflags, fakeside, fakefloor, fakeceiling, sec, thinglightlevel, foggy, thingColormap, true);
}
}
}
}
Expand Down
27 changes: 24 additions & 3 deletions src/rendering/swrenderer/scene/r_translucent_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ EXTERN_CVAR(Bool, r_drawvoxels)
EXTERN_CVAR(Bool, r_blendmethod)

CVAR(Bool, r_fullbrightignoresectorcolor, true, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);
CVAR(Bool, r_actorshadows, false, CVAR_ARCHIVE | CVAR_GLOBALCONFIG);

namespace swrenderer
{
Expand Down Expand Up @@ -135,15 +136,35 @@ namespace swrenderer
{
RenderPortal *renderportal = Thread->Portal.get();
DrawSegmentList *drawseglist = Thread->DrawSegments.get();

auto &sortedSprites = Thread->SpriteList->SortedSprites;
for (int i = sortedSprites.Size(); i > 0; i--)
int count = sortedSprites.Size();

if (r_actorshadows)
{
memcpy(Thread->clipbotcopy, Thread->clipbot, sizeof(short) * viewwidth);
memcpy(Thread->cliptopcopy, Thread->cliptop, sizeof(short) * viewwidth);
for (int i = count; i > 0; i--)
{
VisibleSprite* sprite = sortedSprites[i - 1];

if (sprite->IsCurrentPortalUniq(renderportal->CurrentPortalUniq))
{
if (sprite->FlatPass)
sprite->Render(Thread, clip3DFloor);
}
}
memcpy(Thread->clipbot, Thread->clipbotcopy, sizeof(short) * viewwidth);
memcpy(Thread->cliptop, Thread->cliptopcopy, sizeof(short) * viewwidth);
}

for (int i = count; i > 0; i--)
{
VisibleSprite *sprite = sortedSprites[i - 1];

if (sprite->IsCurrentPortalUniq(renderportal->CurrentPortalUniq))
{
sprite->Render(Thread, clip3DFloor);
if (!sprite->FlatPass)
sprite->Render(Thread, clip3DFloor);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/rendering/swrenderer/things/r_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ EXTERN_CVAR(Int, gl_texture_hqresize_targets)

namespace swrenderer
{
void RenderSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FSoftwareTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int lightlevel, bool foggy, FDynamicColormap *basecolormap)
void RenderSprite::Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FSoftwareTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int lightlevel, bool foggy, FDynamicColormap *basecolormap, bool shadowsprite)
{
auto viewport = thread->Viewport.get();

Expand Down Expand Up @@ -247,6 +247,14 @@ namespace swrenderer

vis->Light.SetColormap(thread, wallc.sz1, lightlevel, foggy, basecolormap, fullbright, invertcolormap, fadeToBlack, false, false);

if (shadowsprite)
{
vis->RenderStyle = LegacyRenderStyles[STYLE_TranslucentStencil];
vis->FillColor = 0;
vis->Alpha *= 0.5f;
vis->FlatPass = true;
}

thread->SpriteList->Push(vis);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rendering/swrenderer/things/r_sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace swrenderer
class RenderSprite : public VisibleSprite
{
public:
static void Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FSoftwareTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int lightlevel, bool foggy, FDynamicColormap *basecolormap);
static void Project(RenderThread *thread, AActor *thing, const DVector3 &pos, FSoftwareTexture *tex, const DVector2 &spriteScale, int renderflags, WaterFakeSide fakeside, F3DFloor *fakefloor, F3DFloor *fakeceiling, sector_t *current_sector, int lightlevel, bool foggy, FDynamicColormap *basecolormap, bool shadowsprite);

protected:
void Render(RenderThread *thread, short *cliptop, short *clipbottom, int minZ, int maxZ, Fake3DTranslucent clip3DFloor) override;
Expand Down
86 changes: 46 additions & 40 deletions src/rendering/swrenderer/things/r_visiblesprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,22 @@ namespace swrenderer
{
if (IsModel())
{
// Draw segments behind model
DrawSegmentList *segmentlist = thread->DrawSegments.get();
RenderPortal *renderportal = thread->Portal.get();
for (unsigned int index = 0; index != segmentlist->TranslucentSegmentsCount(); index++)
if (!FlatPass)
{
DrawSegment *ds = segmentlist->TranslucentSegment(index);
if (ds->drawsegclip.SubsectorDepth >= SubsectorDepth && ds->drawsegclip.CurrentPortalUniq == renderportal->CurrentPortalUniq)
// Draw segments behind model
DrawSegmentList* segmentlist = thread->DrawSegments.get();
RenderPortal* renderportal = thread->Portal.get();
for (unsigned int index = 0; index != segmentlist->TranslucentSegmentsCount(); index++)
{
int r1 = MAX<int>(ds->x1, 0);
int r2 = MIN<int>(ds->x2, viewwidth - 1);
DrawSegment* ds = segmentlist->TranslucentSegment(index);
if (ds->drawsegclip.SubsectorDepth >= SubsectorDepth && ds->drawsegclip.CurrentPortalUniq == renderportal->CurrentPortalUniq)
{
int r1 = MAX<int>(ds->x1, 0);
int r2 = MIN<int>(ds->x2, viewwidth - 1);

RenderDrawSegment renderer(thread);
renderer.Render(ds, r1, r2, clip3DFloor);
RenderDrawSegment renderer(thread);
renderer.Render(ds, r1, r2, clip3DFloor);
}
}
}

Expand Down Expand Up @@ -315,48 +318,51 @@ namespace swrenderer
RenderPortal *renderportal = thread->Portal.get();

// Render draw segments behind sprite
if (r_modelscene)
if (!FlatPass)
{
int subsectordepth = spr->SubsectorDepth;
for (unsigned int index = 0; index != segmentlist->TranslucentSegmentsCount(); index++)
if (r_modelscene)
{
DrawSegment *ds = segmentlist->TranslucentSegment(index);
if (ds->drawsegclip.SubsectorDepth >= subsectordepth && ds->drawsegclip.CurrentPortalUniq == renderportal->CurrentPortalUniq)
int subsectordepth = spr->SubsectorDepth;
for (unsigned int index = 0; index != segmentlist->TranslucentSegmentsCount(); index++)
{
int r1 = MAX<int>(ds->x1, 0);
int r2 = MIN<int>(ds->x2, viewwidth - 1);
DrawSegment* ds = segmentlist->TranslucentSegment(index);
if (ds->drawsegclip.SubsectorDepth >= subsectordepth && ds->drawsegclip.CurrentPortalUniq == renderportal->CurrentPortalUniq)
{
int r1 = MAX<int>(ds->x1, 0);
int r2 = MIN<int>(ds->x2, viewwidth - 1);

RenderDrawSegment renderer(thread);
renderer.Render(ds, r1, r2, clip3DFloor);
RenderDrawSegment renderer(thread);
renderer.Render(ds, r1, r2, clip3DFloor);
}
}
}
}
else
{
for (unsigned int index = 0; index != segmentlist->TranslucentSegmentsCount(); index++)
else
{
DrawSegment *ds = segmentlist->TranslucentSegment(index);

if (ds->x1 >= x2 || ds->x2 <= x1)
for (unsigned int index = 0; index != segmentlist->TranslucentSegmentsCount(); index++)
{
continue;
}
DrawSegment* ds = segmentlist->TranslucentSegment(index);

float neardepth = MIN(ds->WallC.sz1, ds->WallC.sz2);
float fardepth = MAX(ds->WallC.sz1, ds->WallC.sz2);
if (ds->x1 >= x2 || ds->x2 <= x1)
{
continue;
}

// Check if sprite is in front of draw seg:
if ((!spr->IsWallSprite() && neardepth > spr->depth) || ((spr->IsWallSprite() || fardepth > spr->depth) &&
(spr->gpos.Y - ds->curline->v1->fY()) * (ds->curline->v2->fX() - ds->curline->v1->fX()) -
(spr->gpos.X - ds->curline->v1->fX()) * (ds->curline->v2->fY() - ds->curline->v1->fY()) <= 0))
{
if (ds->drawsegclip.CurrentPortalUniq == renderportal->CurrentPortalUniq)
float neardepth = MIN(ds->WallC.sz1, ds->WallC.sz2);
float fardepth = MAX(ds->WallC.sz1, ds->WallC.sz2);

// Check if sprite is in front of draw seg:
if ((!spr->IsWallSprite() && neardepth > spr->depth) || ((spr->IsWallSprite() || fardepth > spr->depth) &&
(spr->gpos.Y - ds->curline->v1->fY()) * (ds->curline->v2->fX() - ds->curline->v1->fX()) -
(spr->gpos.X - ds->curline->v1->fX()) * (ds->curline->v2->fY() - ds->curline->v1->fY()) <= 0))
{
int r1 = MAX<int>(ds->x1, x1);
int r2 = MIN<int>(ds->x2, x2);
if (ds->drawsegclip.CurrentPortalUniq == renderportal->CurrentPortalUniq)
{
int r1 = MAX<int>(ds->x1, x1);
int r2 = MIN<int>(ds->x2, x2);

RenderDrawSegment renderer(thread);
renderer.Render(ds, r1, r2, clip3DFloor);
RenderDrawSegment renderer(thread);
renderer.Render(ds, r1, r2, clip3DFloor);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/rendering/swrenderer/things/r_visiblesprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace swrenderer
float SortDist() const { return idepth; }

int SubsectorDepth;
bool FlatPass = false;

protected:
virtual bool IsParticle() const { return false; }
Expand Down

0 comments on commit 03600c2

Please sign in to comment.