From cff72fb07251851928253da9943b69130edb7015 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 24 Nov 2016 08:23:50 +0100 Subject: [PATCH] Add stencil value to decal, particle, plane, port, sky, sprite, wall and wallsprite classes --- src/r_poly_decal.cpp | 10 +++++----- src/r_poly_decal.h | 4 ++-- src/r_poly_particle.cpp | 6 +++--- src/r_poly_particle.h | 2 +- src/r_poly_plane.cpp | 22 +++++++++++----------- src/r_poly_plane.h | 6 +++--- src/r_poly_portal.cpp | 12 ++++++------ src/r_poly_sky.cpp | 2 +- src/r_poly_sprite.cpp | 6 +++--- src/r_poly_sprite.h | 2 +- src/r_poly_wall.cpp | 10 +++++----- src/r_poly_wall.h | 5 +++-- src/r_poly_wallsprite.cpp | 6 +++--- src/r_poly_wallsprite.h | 2 +- 14 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/r_poly_decal.cpp b/src/r_poly_decal.cpp index 206eb9862..ded64a095 100644 --- a/src/r_poly_decal.cpp +++ b/src/r_poly_decal.cpp @@ -29,7 +29,7 @@ #include "r_poly.h" #include "a_sharedglobal.h" -void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const seg_t *line, uint32_t subsectorDepth) +void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue) { if (line->linedef == nullptr && line->sidedef == nullptr) return; @@ -37,11 +37,11 @@ void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const seg_t for (DBaseDecal *decal = line->sidedef->AttachedDecals; decal != nullptr; decal = decal->WallNext) { RenderPolyDecal render; - render.Render(worldToClip, decal, line, subsectorDepth); + render.Render(worldToClip, decal, line, subsectorDepth, stencilValue); } } -void RenderPolyDecal::Render(const TriMatrix &worldToClip, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth) +void RenderPolyDecal::Render(const TriMatrix &worldToClip, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue) { if (decal->RenderFlags & RF_INVISIBLE || !viewactive || !decal->PicNum.isValid()) return; @@ -163,8 +163,8 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, DBaseDecal *decal, co args.vcount = 4; args.mode = TriangleDrawMode::Fan; args.ccw = true; - args.stenciltestvalue = 0; - args.stencilwritevalue = 1; + args.stenciltestvalue = stencilValue; + args.stencilwritevalue = stencilValue; //mode = R_SetPatchStyle (decal->RenderStyle, (float)decal->Alpha, decal->Translation, decal->AlphaColor); PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, TriBlendMode::Shaded); } diff --git a/src/r_poly_decal.h b/src/r_poly_decal.h index 61087a773..c836a0cd7 100644 --- a/src/r_poly_decal.h +++ b/src/r_poly_decal.h @@ -27,8 +27,8 @@ class RenderPolyDecal { public: - static void RenderWallDecals(const TriMatrix &worldToClip, const seg_t *line, uint32_t subsectorDepth); + static void RenderWallDecals(const TriMatrix &worldToClip, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue); private: - void Render(const TriMatrix &worldToClip, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth); + void Render(const TriMatrix &worldToClip, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue); }; diff --git a/src/r_poly_particle.cpp b/src/r_poly_particle.cpp index 9b1dbaf1c..e69803e1e 100644 --- a/src/r_poly_particle.cpp +++ b/src/r_poly_particle.cpp @@ -28,7 +28,7 @@ #include "r_poly_particle.h" #include "r_poly.h" -void RenderPolyParticle::Render(const TriMatrix &worldToClip, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth) +void RenderPolyParticle::Render(const TriMatrix &worldToClip, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue) { DVector3 pos = particle->Pos; double psize = particle->size / 8.0; @@ -102,8 +102,8 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, particle_t *partic args.vcount = 4; args.mode = TriangleDrawMode::Fan; args.ccw = true; - args.stenciltestvalue = 0; - args.stencilwritevalue = 1; + args.stenciltestvalue = stencilValue; + args.stencilwritevalue = stencilValue; args.SetColormap(sub->sector->ColorMap); PolyTriangleDrawer::draw(args, TriDrawVariant::FillSubsector, TriBlendMode::AlphaBlend); } diff --git a/src/r_poly_particle.h b/src/r_poly_particle.h index f4218a310..3fbb2d2ab 100644 --- a/src/r_poly_particle.h +++ b/src/r_poly_particle.h @@ -28,5 +28,5 @@ class RenderPolyParticle { public: - void Render(const TriMatrix &worldToClip, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth); + void Render(const TriMatrix &worldToClip, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue); }; diff --git a/src/r_poly_plane.cpp b/src/r_poly_plane.cpp index e68487e17..68a56c69b 100644 --- a/src/r_poly_plane.cpp +++ b/src/r_poly_plane.cpp @@ -32,7 +32,7 @@ EXTERN_CVAR(Int, r_3dfloors) -void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, double skyCeilingHeight, double skyFloorHeight) +void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight) { RenderPolyPlane plane; @@ -58,7 +58,7 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, subsector_t *su double fakeHeight = fakeFloor->top.plane->ZatPoint(frontsector->centerspot); if (fakeHeight < ViewPos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) { - plane.Render3DFloor(worldToClip, sub, subsectorDepth, false, fakeFloor); + plane.Render3DFloor(worldToClip, sub, subsectorDepth, stencilValue, false, fakeFloor); } } @@ -79,16 +79,16 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, subsector_t *su double fakeHeight = fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot); if (fakeHeight > ViewPos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) { - plane.Render3DFloor(worldToClip, sub, subsectorDepth, true, fakeFloor); + plane.Render3DFloor(worldToClip, sub, subsectorDepth, stencilValue, true, fakeFloor); } } } - plane.Render(worldToClip, sub, subsectorDepth, true, skyCeilingHeight); - plane.Render(worldToClip, sub, subsectorDepth, false, skyFloorHeight); + plane.Render(worldToClip, sub, subsectorDepth, stencilValue, true, skyCeilingHeight); + plane.Render(worldToClip, sub, subsectorDepth, stencilValue, false, skyFloorHeight); } -void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, bool ceiling, F3DFloor *fakeFloor) +void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, F3DFloor *fakeFloor) { FTextureID picnum = ceiling ? *fakeFloor->bottom.texture : *fakeFloor->top.texture; FTexture *tex = TexMan(picnum); @@ -138,15 +138,15 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, subsector_t *s args.vcount = sub->numlines; args.mode = TriangleDrawMode::Fan; args.ccw = true; - args.stenciltestvalue = 0; - args.stencilwritevalue = 1; + args.stenciltestvalue = stencilValue; + args.stencilwritevalue = stencilValue + 1; args.SetTexture(tex); args.SetColormap(sub->sector->ColorMap); PolyTriangleDrawer::draw(args, TriDrawVariant::DrawNormal, TriBlendMode::Copy); PolyTriangleDrawer::draw(args, TriDrawVariant::Stencil, TriBlendMode::Copy); } -void RenderPolyPlane::Render(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, bool ceiling, double skyHeight) +void RenderPolyPlane::Render(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight) { sector_t *fakesector = sub->sector->heightsec; if (fakesector && (fakesector == sub->sector || (fakesector->MoreFlags & SECF_IGNOREHEIGHTSEC) == SECF_IGNOREHEIGHTSEC)) @@ -231,8 +231,8 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, subsector_t *sub, uin args.vcount = sub->numlines; args.mode = TriangleDrawMode::Fan; args.ccw = ccw; - args.stenciltestvalue = 0; - args.stencilwritevalue = 1; + args.stenciltestvalue = stencilValue; + args.stencilwritevalue = stencilValue + 1; args.SetColormap(frontsector->ColorMap); if (!isSky) diff --git a/src/r_poly_plane.h b/src/r_poly_plane.h index fa786ead9..d36bb70dc 100644 --- a/src/r_poly_plane.h +++ b/src/r_poly_plane.h @@ -27,10 +27,10 @@ class RenderPolyPlane { public: - static void RenderPlanes(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, double skyCeilingHeight, double skyFloorHeight); + static void RenderPlanes(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight); private: - void Render3DFloor(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, bool ceiling, F3DFloor *fakefloor); - void Render(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, bool ceiling, double skyHeight); + void Render3DFloor(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, F3DFloor *fakefloor); + void Render(const TriMatrix &worldToClip, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight); TriVertex PlaneVertex(vertex_t *v1, double height); }; diff --git a/src/r_poly_portal.cpp b/src/r_poly_portal.cpp index 79468032b..6b37d6424 100644 --- a/src/r_poly_portal.cpp +++ b/src/r_poly_portal.cpp @@ -80,7 +80,7 @@ void RenderPolyPortal::RenderSubsector(subsector_t *sub) if (sub->sector->CenterFloor() != sub->sector->CenterCeiling()) { - RenderPolyPlane::RenderPlanes(WorldToClip, sub, subsectorDepth, Cull.MaxCeilingHeight, Cull.MinFloorHeight); + RenderPolyPlane::RenderPlanes(WorldToClip, sub, subsectorDepth, StencilValue, Cull.MaxCeilingHeight, Cull.MinFloorHeight); FSectorPortal *ceilingPortal = frontsector->ValidatePortal(sector_t::ceiling); FSectorPortal *floorPortal = frontsector->ValidatePortal(sector_t::floor); @@ -167,12 +167,12 @@ void RenderPolyPortal::RenderLine(subsector_t *sub, seg_t *line, sector_t *front if (!(fakeFloor->flags & FF_EXISTS)) continue; if (!(fakeFloor->flags & FF_RENDERPLANES)) continue; if (!fakeFloor->model) continue; - RenderPolyWall::Render3DFloorLine(WorldToClip, line, frontsector, subsectorDepth, fakeFloor, SubsectorTranslucentWalls); + RenderPolyWall::Render3DFloorLine(WorldToClip, line, frontsector, subsectorDepth, StencilValue, fakeFloor, SubsectorTranslucentWalls); } } // Render wall, and update culling info if its an occlusion blocker - if (RenderPolyWall::RenderLine(WorldToClip, line, frontsector, subsectorDepth, SubsectorTranslucentWalls)) + if (RenderPolyWall::RenderLine(WorldToClip, line, frontsector, subsectorDepth, StencilValue, SubsectorTranslucentWalls)) { if (hasSegmentRange) Cull.MarkSegmentCulled(sx1, sx2); @@ -190,7 +190,7 @@ void RenderPolyPortal::RenderTranslucent() if (obj.particle) { RenderPolyParticle spr; - spr.Render(WorldToClip, obj.particle, obj.sub, obj.subsectorDepth); + spr.Render(WorldToClip, obj.particle, obj.sub, obj.subsectorDepth, StencilValue + 1); } else if (!obj.thing) { @@ -199,12 +199,12 @@ void RenderPolyPortal::RenderTranslucent() else if ((obj.thing->renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE) { RenderPolyWallSprite wallspr; - wallspr.Render(WorldToClip, obj.thing, obj.sub, obj.subsectorDepth); + wallspr.Render(WorldToClip, obj.thing, obj.sub, obj.subsectorDepth, StencilValue + 1); } else { RenderPolySprite spr; - spr.Render(WorldToClip, obj.thing, obj.sub, obj.subsectorDepth); + spr.Render(WorldToClip, obj.thing, obj.sub, obj.subsectorDepth, StencilValue + 1); } } } diff --git a/src/r_poly_sky.cpp b/src/r_poly_sky.cpp index 6fc817041..ad8d4b861 100644 --- a/src/r_poly_sky.cpp +++ b/src/r_poly_sky.cpp @@ -61,7 +61,7 @@ void PolySkyDome::Render(const TriMatrix &worldToClip) args.uniforms = uniforms; args.objectToClip = &objectToClip; args.stenciltestvalue = 255; - args.stencilwritevalue = 1; + args.stencilwritevalue = 255; args.SetTexture(frontskytex); args.SetColormap(&NormalLight); diff --git a/src/r_poly_sprite.cpp b/src/r_poly_sprite.cpp index 453ab2d00..0bacd6eb2 100644 --- a/src/r_poly_sprite.cpp +++ b/src/r_poly_sprite.cpp @@ -31,7 +31,7 @@ EXTERN_CVAR(Float, transsouls) EXTERN_CVAR(Int, r_drawfuzz) -void RenderPolySprite::Render(const TriMatrix &worldToClip, AActor *thing, subsector_t *sub, uint32_t subsectorDepth) +void RenderPolySprite::Render(const TriMatrix &worldToClip, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue) { if (IsThingCulled(thing)) return; @@ -134,8 +134,8 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, AActor *thing, subse args.vcount = 4; args.mode = TriangleDrawMode::Fan; args.ccw = true; - args.stenciltestvalue = 0; - args.stencilwritevalue = 1; + args.stenciltestvalue = stencilValue; + args.stencilwritevalue = stencilValue; args.SetTexture(tex, thing->Translation); args.SetColormap(sub->sector->ColorMap); diff --git a/src/r_poly_sprite.h b/src/r_poly_sprite.h index 085d9b570..e23d0d09d 100644 --- a/src/r_poly_sprite.h +++ b/src/r_poly_sprite.h @@ -27,7 +27,7 @@ class RenderPolySprite { public: - void Render(const TriMatrix &worldToClip, AActor *thing, subsector_t *sub, uint32_t subsectorDepth); + void Render(const TriMatrix &worldToClip, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue); static bool IsThingCulled(AActor *thing); static FTexture *GetSpriteTexture(AActor *thing, /*out*/ bool &flipX); diff --git a/src/r_poly_wall.cpp b/src/r_poly_wall.cpp index a4dd62e4b..f49908965 100644 --- a/src/r_poly_wall.cpp +++ b/src/r_poly_wall.cpp @@ -30,7 +30,7 @@ #include "r_poly.h" #include "r_sky.h" // for skyflatnum -bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, std::vector &translucentWallsOutput) +bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, std::vector &translucentWallsOutput) { RenderPolyWall wall; wall.LineSeg = line; @@ -120,7 +120,7 @@ bool RenderPolyWall::RenderLine(const TriMatrix &worldToClip, seg_t *line, secto return false; } -void RenderPolyWall::Render3DFloorLine(const TriMatrix &worldToClip, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, F3DFloor *fakeFloor, std::vector &translucentWallsOutput) +void RenderPolyWall::Render3DFloorLine(const TriMatrix &worldToClip, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, F3DFloor *fakeFloor, std::vector &translucentWallsOutput) { double frontceilz1 = fakeFloor->top.plane->ZatPoint(line->v1); double frontfloorz1 = fakeFloor->bottom.plane->ZatPoint(line->v1); @@ -211,8 +211,8 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip) args.vcount = 4; args.mode = TriangleDrawMode::Fan; args.ccw = true; - args.stenciltestvalue = 0; - args.stencilwritevalue = 1; + args.stenciltestvalue = StencilValue; + args.stencilwritevalue = StencilValue + 1; args.SetTexture(tex); args.SetColormap(Line->frontsector->ColorMap); @@ -231,7 +231,7 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip) PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, TriBlendMode::Add); } - RenderPolyDecal::RenderWallDecals(worldToClip, LineSeg, SubsectorDepth); + RenderPolyDecal::RenderWallDecals(worldToClip, LineSeg, SubsectorDepth, StencilValue); } void RenderPolyWall::ClampHeight(TriVertex &v1, TriVertex &v2) diff --git a/src/r_poly_wall.h b/src/r_poly_wall.h index d89731911..3d2f89f84 100644 --- a/src/r_poly_wall.h +++ b/src/r_poly_wall.h @@ -29,8 +29,8 @@ class PolyTranslucentObject; class RenderPolyWall { public: - static bool RenderLine(const TriMatrix &worldToClip, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, std::vector &translucentWallsOutput); - static void Render3DFloorLine(const TriMatrix &worldToClip, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, F3DFloor *fakeFloor, std::vector &translucentWallsOutput); + static bool RenderLine(const TriMatrix &worldToClip, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, std::vector &translucentWallsOutput); + static void Render3DFloorLine(const TriMatrix &worldToClip, seg_t *line, sector_t *frontsector, uint32_t subsectorDepth, uint32_t stencilValue, F3DFloor *fakeFloor, std::vector &translucentWallsOutput); void SetCoords(const DVector2 &v1, const DVector2 &v2, double ceil1, double floor1, double ceil2, double floor2); void Render(const TriMatrix &worldToClip); @@ -52,6 +52,7 @@ public: FSWColormap *Colormap = nullptr; bool Masked = false; uint32_t SubsectorDepth = 0; + uint32_t StencilValue = 0; private: void ClampHeight(TriVertex &v1, TriVertex &v2); diff --git a/src/r_poly_wallsprite.cpp b/src/r_poly_wallsprite.cpp index 6ed009c33..553235957 100644 --- a/src/r_poly_wallsprite.cpp +++ b/src/r_poly_wallsprite.cpp @@ -28,7 +28,7 @@ #include "r_poly_wallsprite.h" #include "r_poly.h" -void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, AActor *thing, subsector_t *sub, uint32_t subsectorDepth) +void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue) { if (RenderPolySprite::IsThingCulled(thing)) return; @@ -118,8 +118,8 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, AActor *thing, s args.vcount = 4; args.mode = TriangleDrawMode::Fan; args.ccw = true; - args.stenciltestvalue = 0; - args.stencilwritevalue = 1; + args.stenciltestvalue = stencilValue; + args.stencilwritevalue = stencilValue; args.SetTexture(tex); args.SetColormap(sub->sector->ColorMap); PolyTriangleDrawer::draw(args, TriDrawVariant::DrawSubsector, TriBlendMode::AlphaBlend); diff --git a/src/r_poly_wallsprite.h b/src/r_poly_wallsprite.h index 66a92b033..2942d6994 100644 --- a/src/r_poly_wallsprite.h +++ b/src/r_poly_wallsprite.h @@ -27,5 +27,5 @@ class RenderPolyWallSprite { public: - void Render(const TriMatrix &worldToClip, AActor *thing, subsector_t *sub, uint32_t subsectorDepth); + void Render(const TriMatrix &worldToClip, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue); };