- Replace subsector gbuffer in softpoly with a zbuffer

This commit is contained in:
Magnus Norddahl 2017-08-12 15:16:31 +02:00
parent 4483d665d4
commit bf38fd57b0
21 changed files with 222 additions and 166 deletions

View file

@ -38,13 +38,13 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
PolySubsectorGBuffer *PolySubsectorGBuffer::Instance() PolyZBuffer *PolyZBuffer::Instance()
{ {
static PolySubsectorGBuffer buffer; static PolyZBuffer buffer;
return &buffer; return &buffer;
} }
void PolySubsectorGBuffer::Resize(int newwidth, int newheight) void PolyZBuffer::Resize(int newwidth, int newheight)
{ {
width = newwidth; width = newwidth;
height = newheight; height = newheight;

View file

@ -26,21 +26,21 @@
struct TriVertex; struct TriVertex;
class PolySubsectorGBuffer class PolyZBuffer
{ {
public: public:
static PolySubsectorGBuffer *Instance(); static PolyZBuffer *Instance();
void Resize(int newwidth, int newheight); void Resize(int newwidth, int newheight);
int Width() const { return width; } int Width() const { return width; }
int Height() const { return height; } int Height() const { return height; }
int BlockWidth() const { return (width + 7) / 8; } int BlockWidth() const { return (width + 7) / 8; }
int BlockHeight() const { return (height + 7) / 8; } int BlockHeight() const { return (height + 7) / 8; }
uint32_t *Values() { return values.data(); } float *Values() { return values.data(); }
private: private:
int width; int width;
int height; int height;
std::vector<uint32_t> values; std::vector<float> values;
}; };
class PolyStencilBuffer class PolyStencilBuffer

View file

@ -53,12 +53,11 @@ public:
void SetTexture(FTexture *texture); void SetTexture(FTexture *texture);
void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false); void SetTexture(FTexture *texture, uint32_t translationID, bool forcePal = false);
void SetLight(FSWColormap *basecolormap, uint32_t lightlevel, double globVis, bool fixed); void SetLight(FSWColormap *basecolormap, uint32_t lightlevel, double globVis, bool fixed);
void SetSubsectorDepth(uint32_t subsectorDepth) { mSubsectorDepth = subsectorDepth; } void SetDepthTest(bool enable) { mDepthTest = enable; }
void SetSubsectorDepthTest(bool enable) { mSubsectorTest = enable; }
void SetStencilTestValue(uint8_t stencilTestValue) { mStencilTestValue = stencilTestValue; } void SetStencilTestValue(uint8_t stencilTestValue) { mStencilTestValue = stencilTestValue; }
void SetWriteColor(bool enable) { mWriteColor = enable; } void SetWriteColor(bool enable) { mWriteColor = enable; }
void SetWriteStencil(bool enable, uint8_t stencilWriteValue = 0) { mWriteStencil = enable; mStencilWriteValue = stencilWriteValue; } void SetWriteStencil(bool enable, uint8_t stencilWriteValue = 0) { mWriteStencil = enable; mStencilWriteValue = stencilWriteValue; }
void SetWriteSubsectorDepth(bool enable) { mWriteSubsector = enable; } void SetWriteDepth(bool enable) { mWriteDepth = enable; }
void SetFaceCullCCW(bool counterclockwise) { mFaceCullCCW = counterclockwise; } void SetFaceCullCCW(bool counterclockwise) { mFaceCullCCW = counterclockwise; }
void SetStyle(TriBlendMode blendmode, double srcalpha = 1.0, double destalpha = 1.0) { mBlendMode = blendmode; mSrcAlpha = (uint32_t)(srcalpha * 256.0 + 0.5); mDestAlpha = (uint32_t)(destalpha * 256.0 + 0.5); } void SetStyle(TriBlendMode blendmode, double srcalpha = 1.0, double destalpha = 1.0) { mBlendMode = blendmode; mSrcAlpha = (uint32_t)(srcalpha * 256.0 + 0.5); mDestAlpha = (uint32_t)(destalpha * 256.0 + 0.5); }
void SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *texture, bool fullbright); void SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FTexture *texture, bool fullbright);
@ -85,9 +84,8 @@ public:
uint8_t StencilTestValue() const { return mStencilTestValue; } uint8_t StencilTestValue() const { return mStencilTestValue; }
uint8_t StencilWriteValue() const { return mStencilWriteValue; } uint8_t StencilWriteValue() const { return mStencilWriteValue; }
bool SubsectorTest() const { return mSubsectorTest; } bool DepthTest() const { return mDepthTest; }
bool WriteSubsector() const { return mWriteSubsector; } bool WriteDepth() const { return mWriteDepth; }
uint32_t SubsectorDepth() const { return mSubsectorDepth; }
TriBlendMode BlendMode() const { return mBlendMode; } TriBlendMode BlendMode() const { return mBlendMode; }
uint32_t Color() const { return mColor; } uint32_t Color() const { return mColor; }
@ -117,10 +115,10 @@ private:
int mVertexCount = 0; int mVertexCount = 0;
PolyDrawMode mDrawMode = PolyDrawMode::Triangles; PolyDrawMode mDrawMode = PolyDrawMode::Triangles;
bool mFaceCullCCW = false; bool mFaceCullCCW = false;
bool mSubsectorTest = false; bool mDepthTest = false;
bool mWriteStencil = true; bool mWriteStencil = true;
bool mWriteColor = true; bool mWriteColor = true;
bool mWriteSubsector = true; bool mWriteDepth = true;
const uint8_t *mTexturePixels = nullptr; const uint8_t *mTexturePixels = nullptr;
int mTextureWidth = 0; int mTextureWidth = 0;
int mTextureHeight = 0; int mTextureHeight = 0;
@ -131,7 +129,6 @@ private:
float mClipPlane[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; float mClipPlane[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
TriBlendMode mBlendMode = TriBlendMode::FillOpaque; TriBlendMode mBlendMode = TriBlendMode::FillOpaque;
uint32_t mLight = 0; uint32_t mLight = 0;
uint32_t mSubsectorDepth = 0;
uint32_t mColor = 0; uint32_t mColor = 0;
uint32_t mSrcAlpha = 0; uint32_t mSrcAlpha = 0;
uint32_t mDestAlpha = 0; uint32_t mDestAlpha = 0;

View file

@ -99,7 +99,7 @@ void PolyTriangleDrawer::draw_arrays(const PolyDrawArgs &drawargs, WorkerThreadD
args.stencilPitch = PolyStencilBuffer::Instance()->BlockWidth(); args.stencilPitch = PolyStencilBuffer::Instance()->BlockWidth();
args.stencilValues = PolyStencilBuffer::Instance()->Values(); args.stencilValues = PolyStencilBuffer::Instance()->Values();
args.stencilMasks = PolyStencilBuffer::Instance()->Masks(); args.stencilMasks = PolyStencilBuffer::Instance()->Masks();
args.subsectorGBuffer = PolySubsectorGBuffer::Instance()->Values(); args.zbuffer = PolyZBuffer::Instance()->Values();
bool ccw = drawargs.FaceCullCCW(); bool ccw = drawargs.FaceCullCCW();
const TriVertex *vinput = drawargs.Vertices(); const TriVertex *vinput = drawargs.Vertices();

View file

@ -76,10 +76,9 @@ private:
int clipright; int clipright;
int clipbottom; int clipbottom;
// Subsector buffer // Depth buffer
uint32_t * RESTRICT subsectorGBuffer; float * RESTRICT zbuffer;
uint32_t subsectorDepth; int32_t zbufferPitch;
int32_t subsectorPitch;
// Triangle bounding block // Triangle bounding block
int minx, miny; int minx, miny;
@ -113,10 +112,10 @@ private:
void CoverageTest(); void CoverageTest();
void StencilEqualTest(); void StencilEqualTest();
void StencilGreaterEqualTest(); void StencilGreaterEqualTest();
void SubsectorTest(); void DepthTest(const TriDrawTriangleArgs *args);
void ClipTest(); void ClipTest();
void StencilWrite(); void StencilWrite();
void SubsectorWrite(); void DepthWrite(const TriDrawTriangleArgs *args);
}; };
TriangleBlock::TriangleBlock(const TriDrawTriangleArgs *args) TriangleBlock::TriangleBlock(const TriDrawTriangleArgs *args)
@ -134,9 +133,8 @@ TriangleBlock::TriangleBlock(const TriDrawTriangleArgs *args)
stencilTestValue = args->uniforms->StencilTestValue(); stencilTestValue = args->uniforms->StencilTestValue();
stencilWriteValue = args->uniforms->StencilWriteValue(); stencilWriteValue = args->uniforms->StencilWriteValue();
subsectorGBuffer = args->subsectorGBuffer; zbuffer = args->zbuffer;
subsectorDepth = args->uniforms->SubsectorDepth(); zbufferPitch = args->stencilPitch;
subsectorPitch = args->stencilPitch;
// 28.4 fixed-point coordinates // 28.4 fixed-point coordinates
#ifdef NO_SSE #ifdef NO_SSE
@ -235,10 +233,10 @@ void TriangleBlock::Loop(const TriDrawTriangleArgs *args, WorkerThreadData *thre
int core_skip = (num_cores - ((miny / q) - core) % num_cores) % num_cores; int core_skip = (num_cores - ((miny / q) - core) % num_cores) % num_cores;
int start_miny = miny + core_skip * q; int start_miny = miny + core_skip * q;
bool subsectorTest = args->uniforms->SubsectorTest(); bool depthTest = args->uniforms->DepthTest();
bool writeColor = args->uniforms->WriteColor(); bool writeColor = args->uniforms->WriteColor();
bool writeStencil = args->uniforms->WriteStencil(); bool writeStencil = args->uniforms->WriteStencil();
bool writeSubsector = args->uniforms->WriteSubsector(); bool writeDepth = args->uniforms->WriteDepth();
int bmode = (int)args->uniforms->BlendMode(); int bmode = (int)args->uniforms->BlendMode();
auto drawFunc = args->destBgra ? ScreenTriangle::TriDrawers32[bmode] : ScreenTriangle::TriDrawers8[bmode]; auto drawFunc = args->destBgra ? ScreenTriangle::TriDrawers32[bmode] : ScreenTriangle::TriDrawers8[bmode];
@ -259,8 +257,8 @@ void TriangleBlock::Loop(const TriDrawTriangleArgs *args, WorkerThreadData *thre
if (Mask0 == 0 && Mask1 == 0) if (Mask0 == 0 && Mask1 == 0)
continue; continue;
// To do: make the stencil test use its own flag for comparison mode instead of abusing the subsector test.. // To do: make the stencil test use its own flag for comparison mode instead of abusing the depth test..
if (!subsectorTest) if (!depthTest)
{ {
StencilEqualTest(); StencilEqualTest();
if (Mask0 == 0 && Mask1 == 0) if (Mask0 == 0 && Mask1 == 0)
@ -272,7 +270,7 @@ void TriangleBlock::Loop(const TriDrawTriangleArgs *args, WorkerThreadData *thre
if (Mask0 == 0 && Mask1 == 0) if (Mask0 == 0 && Mask1 == 0)
continue; continue;
SubsectorTest(); DepthTest(args);
if (Mask0 == 0 && Mask1 == 0) if (Mask0 == 0 && Mask1 == 0)
continue; continue;
} }
@ -281,34 +279,54 @@ void TriangleBlock::Loop(const TriDrawTriangleArgs *args, WorkerThreadData *thre
drawFunc(X, Y, Mask0, Mask1, args); drawFunc(X, Y, Mask0, Mask1, args);
if (writeStencil) if (writeStencil)
StencilWrite(); StencilWrite();
if (writeSubsector) if (writeDepth)
SubsectorWrite(); DepthWrite(args);
} }
} }
} }
#ifdef NO_SSE #ifdef NO_SSE
void TriangleBlock::SubsectorTest() void TriangleBlock::DepthTest(const TriDrawTriangleArgs *args)
{ {
int block = (X >> 3) + (Y >> 3) * subsectorPitch; int block = (X >> 3) + (Y >> 3) * zbufferPitch;
uint32_t *subsector = subsectorGBuffer + block * 64; float *depth = zbuffer + block * 64;
const TriVertex &v1 = *args->v1;
float stepXW = args->gradientX.W;
float stepYW = args->gradientY.W;
float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y);
uint32_t mask0 = 0; uint32_t mask0 = 0;
uint32_t mask1 = 0; uint32_t mask1 = 0;
for (int i = 0; i < 32; i++) for (int iy = 0; iy < 4; iy++)
{ {
bool covered = *subsector >= subsectorDepth; float posXW = posYW;
mask0 <<= 1; for (int ix = 0; ix < 8; ix++)
mask0 |= (uint32_t)covered; {
subsector++; bool covered = *depth <= posXW;
mask0 <<= 1;
mask0 |= (uint32_t)covered;
depth++;
posXW += stepXW;
}
posYW += stepYW;
} }
for (int i = 0; i < 32; i++)
for (int iy = 0; iy < 4; iy++)
{ {
bool covered = *subsector >= subsectorDepth; float posXW = posYW;
mask1 <<= 1; for (int ix = 0; ix < 8; ix++)
mask1 |= (uint32_t)covered; {
subsector++; bool covered = *depth <= posXW;
mask1 <<= 1;
mask1 |= (uint32_t)covered;
depth++;
posXW += stepXW;
}
posYW += stepYW;
} }
Mask0 = Mask0 & mask0; Mask0 = Mask0 & mask0;
@ -317,26 +335,50 @@ void TriangleBlock::SubsectorTest()
#else #else
void TriangleBlock::SubsectorTest() void TriangleBlock::DepthTest(const TriDrawTriangleArgs *args)
{ {
int block = (X >> 3) + (Y >> 3) * subsectorPitch; int block = (X >> 3) + (Y >> 3) * zbufferPitch;
uint32_t *subsector = subsectorGBuffer + block * 64; float *depth = zbuffer + block * 64;
const TriVertex &v1 = *args->v1;
float stepXW = args->gradientX.W;
float stepYW = args->gradientY.W;
float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y);
__m128 mposYW = _mm_setr_ps(posYW, posYW + stepXW, posYW + stepXW + stepXW, posYW + stepXW + stepXW + stepXW);
__m128 mstepXW = _mm_set1_ps(stepXW * 4.0f);
__m128 mstepYW = _mm_set1_ps(stepYW);
uint32_t mask0 = 0; uint32_t mask0 = 0;
uint32_t mask1 = 0; uint32_t mask1 = 0;
__m128i msubsectorDepth = _mm_set1_epi32(subsectorDepth);
__m128i mnotxor = _mm_set1_epi32(0xffffffff);
for (int iy = 0; iy < 8; iy++) for (int iy = 0; iy < 4; iy++)
{ {
mask0 <<= 4; __m128 mposXW = mposYW;
mask0 |= _mm_movemask_ps(_mm_castsi128_ps(_mm_shuffle_epi32(_mm_xor_si128(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)subsector), msubsectorDepth), mnotxor), _MM_SHUFFLE(0, 1, 2, 3)))); for (int ix = 0; ix < 2; ix++)
subsector += 4; {
__m128 covered = _mm_cmplt_ps(_mm_loadu_ps(depth), mposXW);
mask0 <<= 4;
mask0 |= _mm_movemask_ps(_mm_shuffle_ps(covered, covered, _MM_SHUFFLE(0, 1, 2, 3)));
depth += 4;
mposXW = _mm_add_ps(mposXW, mstepXW);
}
mposYW = _mm_add_ps(mposYW, mstepYW);
} }
for (int iy = 0; iy < 8; iy++)
for (int iy = 0; iy < 4; iy++)
{ {
mask1 <<= 4; __m128 mposXW = mposYW;
mask1 |= _mm_movemask_ps(_mm_castsi128_ps(_mm_shuffle_epi32(_mm_xor_si128(_mm_cmplt_epi32(_mm_loadu_si128((const __m128i *)subsector), msubsectorDepth), mnotxor), _MM_SHUFFLE(0, 1, 2, 3)))); for (int ix = 0; ix < 2; ix++)
subsector += 4; {
__m128 covered = _mm_cmplt_ps(_mm_loadu_ps(depth), mposXW);
mask1 <<= 4;
mask1 |= _mm_movemask_ps(_mm_shuffle_ps(covered, covered, _MM_SHUFFLE(0, 1, 2, 3)));
depth += 4;
mposXW = _mm_add_ps(mposXW, mstepXW);
}
mposYW = _mm_add_ps(mposYW, mstepYW);
} }
Mask0 = Mask0 & mask0; Mask0 = Mask0 & mask0;
@ -798,65 +840,91 @@ void TriangleBlock::StencilWrite()
#ifdef NO_SSE #ifdef NO_SSE
void TriangleBlock::SubsectorWrite() void TriangleBlock::DepthWrite(const TriDrawTriangleArgs *args)
{ {
int block = (X >> 3) + (Y >> 3) * subsectorPitch; int block = (X >> 3) + (Y >> 3) * zbufferPitch;
uint32_t *subsector = subsectorGBuffer + block * 64; float *depth = zbuffer + block * 64;
const TriVertex &v1 = *args->v1;
float stepXW = args->gradientX.W;
float stepYW = args->gradientY.W;
float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y);
if (Mask0 == 0xffffffff && Mask1 == 0xffffffff) if (Mask0 == 0xffffffff && Mask1 == 0xffffffff)
{ {
for (int i = 0; i < 64; i++) for (int iy = 0; iy < 8; iy++)
{ {
*(subsector++) = subsectorDepth; float posXW = posYW;
for (int ix = 0; ix < 8; ix++)
{
*(depth++) = posXW;
posXW += stepXW;
}
posYW += stepYW;
} }
} }
else else
{ {
uint32_t mask0 = Mask0; uint32_t mask0 = Mask0;
uint32_t mask1 = Mask1; uint32_t mask1 = Mask1;
for (int i = 0; i < 32; i++)
for (int iy = 0; iy < 4; iy++)
{ {
if (mask0 & (1 << 31)) float posXW = posYW;
*subsector = subsectorDepth; for (int ix = 0; ix < 8; ix++)
mask0 <<= 1; {
subsector++; if (mask0 & (1 << 31))
*depth = posXW;
posXW += stepXW;
mask0 <<= 1;
depth++;
}
posYW += stepYW;
} }
for (int i = 0; i < 32; i++)
for (int iy = 0; iy < 4; iy++)
{ {
if (mask1 & (1 << 31)) float posXW = posYW;
*subsector = subsectorDepth; for (int ix = 0; ix < 8; ix++)
mask1 <<= 1; {
subsector++; if (mask1 & (1 << 31))
*depth = posXW;
posXW += stepXW;
mask1 <<= 1;
depth++;
}
posYW += stepYW;
} }
} }
} }
#else #else
void TriangleBlock::SubsectorWrite() void TriangleBlock::DepthWrite(const TriDrawTriangleArgs *args)
{ {
int block = (X >> 3) + (Y >> 3) * subsectorPitch; int block = (X >> 3) + (Y >> 3) * zbufferPitch;
uint32_t *subsector = subsectorGBuffer + block * 64; float *depth = zbuffer + block * 64;
__m128i msubsectorDepth = _mm_set1_epi32(subsectorDepth);
const TriVertex &v1 = *args->v1;
float stepXW = args->gradientX.W;
float stepYW = args->gradientY.W;
float posYW = v1.w + stepXW * (X - v1.x) + stepYW * (Y - v1.y);
__m128 mposYW = _mm_setr_ps(posYW, posYW + stepXW, posYW + stepXW + stepXW, posYW + stepXW + stepXW + stepXW);
__m128 mstepXW = _mm_set1_ps(stepXW * 4.0f);
__m128 mstepYW = _mm_set1_ps(stepYW);
if (Mask0 == 0xffffffff && Mask1 == 0xffffffff) if (Mask0 == 0xffffffff && Mask1 == 0xffffffff)
{ {
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4; for (int iy = 0; iy < 8; iy++)
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4; {
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4; __m128 mposXW = mposYW;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4; _mm_storeu_ps(depth, mposXW); depth += 4; mposXW = _mm_add_ps(mposXW, mstepXW);
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4; _mm_storeu_ps(depth, mposXW); depth += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4; mposYW = _mm_add_ps(mposYW, mstepYW);
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4; }
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth); subsector += 4;
_mm_storeu_si128((__m128i*)subsector, msubsectorDepth);
} }
else else
{ {
@ -866,23 +934,21 @@ void TriangleBlock::SubsectorWrite()
__m128i mmask0 = _mm_set1_epi32(Mask0); __m128i mmask0 = _mm_set1_epi32(Mask0);
__m128i mmask1 = _mm_set1_epi32(Mask1); __m128i mmask1 = _mm_set1_epi32(Mask1);
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask0 = _mm_slli_epi32(mmask0, 4); subsector += 4; for (int iy = 0; iy < 4; iy++)
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask0 = _mm_slli_epi32(mmask0, 4); subsector += 4; {
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask0 = _mm_slli_epi32(mmask0, 4); subsector += 4; __m128 mposXW = mposYW;
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask0 = _mm_slli_epi32(mmask0, 4); subsector += 4; _mm_maskmoveu_si128(_mm_castps_si128(mposXW), _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)depth); mmask0 = _mm_slli_epi32(mmask0, 4); depth += 4; mposXW = _mm_add_ps(mposXW, mstepXW);
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask0 = _mm_slli_epi32(mmask0, 4); subsector += 4; _mm_maskmoveu_si128(_mm_castps_si128(mposXW), _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)depth); mmask0 = _mm_slli_epi32(mmask0, 4); depth += 4;
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask0 = _mm_slli_epi32(mmask0, 4); subsector += 4; mposYW = _mm_add_ps(mposYW, mstepYW);
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask0 = _mm_slli_epi32(mmask0, 4); subsector += 4; }
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask0, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); subsector += 4;
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask1 = _mm_slli_epi32(mmask1, 4); subsector += 4; for (int iy = 0; iy < 4; iy++)
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask1 = _mm_slli_epi32(mmask1, 4); subsector += 4; {
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask1 = _mm_slli_epi32(mmask1, 4); subsector += 4; __m128 mposXW = mposYW;
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask1 = _mm_slli_epi32(mmask1, 4); subsector += 4; _mm_maskmoveu_si128(_mm_castps_si128(mposXW), _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)depth); mmask1 = _mm_slli_epi32(mmask1, 4); depth += 4; mposXW = _mm_add_ps(mposXW, mstepXW);
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask1 = _mm_slli_epi32(mmask1, 4); subsector += 4; _mm_maskmoveu_si128(_mm_castps_si128(mposXW), _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)depth); mmask1 = _mm_slli_epi32(mmask1, 4); depth += 4;
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask1 = _mm_slli_epi32(mmask1, 4); subsector += 4; mposYW = _mm_add_ps(mposYW, mstepYW);
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); mmask1 = _mm_slli_epi32(mmask1, 4); subsector += 4; }
_mm_maskmoveu_si128(msubsectorDepth, _mm_xor_si128(_mm_cmpeq_epi32(_mm_and_si128(mmask1, topfour), _mm_setzero_si128()), mxormask), (char*)subsector); subsector += 4;
} }
} }

View file

@ -60,7 +60,7 @@ struct TriDrawTriangleArgs
uint8_t *stencilValues; uint8_t *stencilValues;
uint32_t *stencilMasks; uint32_t *stencilMasks;
int32_t stencilPitch; int32_t stencilPitch;
uint32_t *subsectorGBuffer; float *zbuffer;
const PolyDrawArgs *uniforms; const PolyDrawArgs *uniforms;
bool destBgra; bool destBgra;
ScreenTriangleStepVariables gradientX; ScreenTriangleStepVariables gradientX;

View file

@ -159,7 +159,7 @@ void PolyRenderer::ClearBuffers()
{ {
FrameMemory.Clear(); FrameMemory.Clear();
PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0); PolyStencilBuffer::Instance()->Clear(RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0);
PolySubsectorGBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight()); PolyZBuffer::Instance()->Resize(RenderTarget->GetPitch(), RenderTarget->GetHeight());
NextStencilValue = 0; NextStencilValue = 0;
} }

View file

@ -31,7 +31,7 @@
#include "a_sharedglobal.h" #include "a_sharedglobal.h"
#include "swrenderer/scene/r_scene.h" #include "swrenderer/scene/r_scene.h"
void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue) void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, const seg_t *line, uint32_t stencilValue)
{ {
if (line->linedef == nullptr && line->sidedef == nullptr) if (line->linedef == nullptr && line->sidedef == nullptr)
return; return;
@ -39,11 +39,11 @@ void RenderPolyDecal::RenderWallDecals(const TriMatrix &worldToClip, const PolyC
for (DBaseDecal *decal = line->sidedef->AttachedDecals; decal != nullptr; decal = decal->WallNext) for (DBaseDecal *decal = line->sidedef->AttachedDecals; decal != nullptr; decal = decal->WallNext)
{ {
RenderPolyDecal render; RenderPolyDecal render;
render.Render(worldToClip, clipPlane, decal, line, subsectorDepth, stencilValue); render.Render(worldToClip, clipPlane, decal, line, stencilValue);
} }
} }
void RenderPolyDecal::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue) void RenderPolyDecal::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, DBaseDecal *decal, const seg_t *line, uint32_t stencilValue)
{ {
if (decal->RenderFlags & RF_INVISIBLE || !viewactive || !decal->PicNum.isValid()) if (decal->RenderFlags & RF_INVISIBLE || !viewactive || !decal->PicNum.isValid())
return; return;
@ -62,6 +62,10 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const PolyClipPlane &
DVector2 decal_pos = { dcx, dcy }; DVector2 decal_pos = { dcx, dcy };
DVector2 angvec = (line->v2->fPos() - line->v1->fPos()).Unit(); DVector2 angvec = (line->v2->fPos() - line->v1->fPos()).Unit();
DVector2 normal = { angvec.Y, -angvec.X };
decal_pos += normal;
DVector2 decal_left = decal_pos - edge_left * angvec; DVector2 decal_left = decal_pos - edge_left * angvec;
DVector2 decal_right = decal_pos + edge_right * angvec; DVector2 decal_right = decal_pos + edge_right * angvec;
@ -139,7 +143,6 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const PolyClipPlane &
PolyDrawArgs args; PolyDrawArgs args;
args.SetLight(GetColorTable(front->Colormap), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), fullbrightSprite); args.SetLight(GetColorTable(front->Colormap), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), fullbrightSprite);
args.SetSubsectorDepth(subsectorDepth);
args.SetColor(0xff000000 | decal->AlphaColor, decal->AlphaColor >> 24); args.SetColor(0xff000000 | decal->AlphaColor, decal->AlphaColor >> 24);
args.SetStyle(decal->RenderStyle, decal->Alpha, decal->AlphaColor, decal->Translation, tex, false); args.SetStyle(decal->RenderStyle, decal->Alpha, decal->AlphaColor, decal->Translation, tex, false);
args.SetTransform(&worldToClip); args.SetTransform(&worldToClip);
@ -147,8 +150,8 @@ void RenderPolyDecal::Render(const TriMatrix &worldToClip, const PolyClipPlane &
args.SetStencilTestValue(stencilValue); args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(true, stencilValue); args.SetWriteStencil(true, stencilValue);
args.SetClipPlane(clipPlane); args.SetClipPlane(clipPlane);
args.SetSubsectorDepthTest(true); args.SetDepthTest(true);
args.SetWriteStencil(false); args.SetWriteStencil(false);
args.SetWriteSubsectorDepth(false); args.SetWriteDepth(false);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
} }

View file

@ -27,8 +27,8 @@
class RenderPolyDecal class RenderPolyDecal
{ {
public: public:
static void RenderWallDecals(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue); static void RenderWallDecals(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, const seg_t *line, uint32_t stencilValue);
private: private:
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, DBaseDecal *decal, const seg_t *line, uint32_t subsectorDepth, uint32_t stencilValue); void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, DBaseDecal *decal, const seg_t *line, uint32_t stencilValue);
}; };

View file

@ -31,7 +31,7 @@
EXTERN_CVAR(Int, gl_particles_style) EXTERN_CVAR(Int, gl_particles_style)
void RenderPolyParticle::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue) void RenderPolyParticle::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, particle_t *particle, subsector_t *sub, uint32_t stencilValue)
{ {
DVector3 pos = particle->Pos; DVector3 pos = particle->Pos;
double psize = particle->size / 8.0; double psize = particle->size / 8.0;
@ -75,15 +75,14 @@ void RenderPolyParticle::Render(const TriMatrix &worldToClip, const PolyClipPlan
PolyDrawArgs args; PolyDrawArgs args;
args.SetLight(GetColorTable(sub->sector->Colormap), lightlevel, PolyRenderer::Instance()->Light.ParticleGlobVis(foggy), fullbrightSprite); args.SetLight(GetColorTable(sub->sector->Colormap), lightlevel, PolyRenderer::Instance()->Light.ParticleGlobVis(foggy), fullbrightSprite);
args.SetSubsectorDepth(subsectorDepth); args.SetDepthTest(true);
args.SetSubsectorDepthTest(true);
args.SetColor(particle->color | 0xff000000, particle->color >> 24); args.SetColor(particle->color | 0xff000000, particle->color >> 24);
args.SetStyle(TriBlendMode::Shaded, particle->alpha, 1.0 - particle->alpha); args.SetStyle(TriBlendMode::Shaded, particle->alpha, 1.0 - particle->alpha);
args.SetTransform(&worldToClip); args.SetTransform(&worldToClip);
args.SetFaceCullCCW(true); args.SetFaceCullCCW(true);
args.SetStencilTestValue(stencilValue); args.SetStencilTestValue(stencilValue);
args.SetWriteStencil(false); args.SetWriteStencil(false);
args.SetWriteSubsectorDepth(false); args.SetWriteDepth(false);
args.SetClipPlane(clipPlane); args.SetClipPlane(clipPlane);
args.SetTexture(GetParticleTexture(), ParticleTextureSize, ParticleTextureSize); args.SetTexture(GetParticleTexture(), ParticleTextureSize, ParticleTextureSize);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);

View file

@ -28,7 +28,7 @@
class RenderPolyParticle class RenderPolyParticle
{ {
public: public:
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, particle_t *particle, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue); void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, particle_t *particle, subsector_t *sub, uint32_t stencilValue);
private: private:
static uint8_t *GetParticleTexture(); static uint8_t *GetParticleTexture();

View file

@ -33,7 +33,7 @@
EXTERN_CVAR(Int, r_3dfloors) EXTERN_CVAR(Int, r_3dfloors)
void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t ceilingSubsectorDepth, uint32_t floorSubsectorDepth, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals) void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals)
{ {
RenderPolyPlane plane; RenderPolyPlane plane;
@ -61,7 +61,7 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const PolyClipP
double fakeHeight = fakeFloor->top.plane->ZatPoint(frontsector->centerspot); double fakeHeight = fakeFloor->top.plane->ZatPoint(frontsector->centerspot);
if (fakeHeight < viewpoint.Pos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot)) if (fakeHeight < viewpoint.Pos.Z && fakeHeight > frontsector->floorplane.ZatPoint(frontsector->centerspot))
{ {
plane.Render3DFloor(worldToClip, clipPlane, sub, floorSubsectorDepth, stencilValue, false, fakeFloor); plane.Render3DFloor(worldToClip, clipPlane, sub, stencilValue, false, fakeFloor);
} }
} }
@ -82,16 +82,16 @@ void RenderPolyPlane::RenderPlanes(const TriMatrix &worldToClip, const PolyClipP
double fakeHeight = fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot); double fakeHeight = fakeFloor->bottom.plane->ZatPoint(frontsector->centerspot);
if (fakeHeight > viewpoint.Pos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot)) if (fakeHeight > viewpoint.Pos.Z && fakeHeight < frontsector->ceilingplane.ZatPoint(frontsector->centerspot))
{ {
plane.Render3DFloor(worldToClip, clipPlane, sub, ceilingSubsectorDepth, stencilValue, true, fakeFloor); plane.Render3DFloor(worldToClip, clipPlane, sub, stencilValue, true, fakeFloor);
} }
} }
} }
plane.Render(worldToClip, clipPlane, cull, sub, ceilingSubsectorDepth, stencilValue, true, skyCeilingHeight, sectorPortals); plane.Render(worldToClip, clipPlane, cull, sub, stencilValue, true, skyCeilingHeight, sectorPortals);
plane.Render(worldToClip, clipPlane, cull, sub, floorSubsectorDepth, stencilValue, false, skyFloorHeight, sectorPortals); plane.Render(worldToClip, clipPlane, cull, sub, stencilValue, false, skyFloorHeight, sectorPortals);
} }
void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, F3DFloor *fakeFloor) void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t stencilValue, bool ceiling, F3DFloor *fakeFloor)
{ {
FTextureID picnum = ceiling ? *fakeFloor->bottom.texture : *fakeFloor->top.texture; FTextureID picnum = ceiling ? *fakeFloor->bottom.texture : *fakeFloor->top.texture;
FTexture *tex = TexMan(picnum); FTexture *tex = TexMan(picnum);
@ -131,7 +131,6 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const PolyClip
PolyDrawArgs args; PolyDrawArgs args;
args.SetLight(GetColorTable(sub->sector->Colormap), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), false); args.SetLight(GetColorTable(sub->sector->Colormap), lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), false);
args.SetSubsectorDepth(subsectorDepth);
args.SetTransform(&worldToClip); args.SetTransform(&worldToClip);
args.SetStyle(TriBlendMode::TextureOpaque); args.SetStyle(TriBlendMode::TextureOpaque);
args.SetFaceCullCCW(true); args.SetFaceCullCCW(true);
@ -142,7 +141,7 @@ void RenderPolyPlane::Render3DFloor(const TriMatrix &worldToClip, const PolyClip
args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan); args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan);
} }
void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals) void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals)
{ {
const auto &viewpoint = PolyRenderer::Instance()->Viewpoint; const auto &viewpoint = PolyRenderer::Instance()->Viewpoint;
bool foggy = false; bool foggy = false;
@ -302,7 +301,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
PolyDrawArgs args; PolyDrawArgs args;
args.SetLight(GetColorTable(frontsector->Colormap, frontsector->SpecialColors[ceiling]), frontsector->lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), false); args.SetLight(GetColorTable(frontsector->Colormap, frontsector->SpecialColors[ceiling]), frontsector->lightlevel, PolyRenderer::Instance()->Light.WallGlobVis(foggy), false);
args.SetSubsectorDepth(isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth); //args.SetSubsectorDepth(isSky ? RenderPolyScene::SkySubsectorDepth : subsectorDepth);
args.SetTransform(&worldToClip); args.SetTransform(&worldToClip);
args.SetFaceCullCCW(ccw); args.SetFaceCullCCW(ccw);
args.SetStencilTestValue(stencilValue); args.SetStencilTestValue(stencilValue);
@ -320,7 +319,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
if (portal) if (portal)
{ {
args.SetWriteStencil(true, polyportal->StencilValue); args.SetWriteStencil(true, polyportal->StencilValue);
polyportal->Shape.push_back({ vertices, (int)sub->numlines, ccw, subsectorDepth }); polyportal->Shape.push_back({ vertices, (int)sub->numlines, ccw });
} }
else else
{ {
@ -328,7 +327,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
} }
args.SetWriteColor(false); args.SetWriteColor(false);
args.SetWriteSubsectorDepth(false); args.SetWriteDepth(false);
args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan); args.DrawArray(vertices, sub->numlines, PolyDrawMode::TriangleFan);
for (uint32_t i = 0; i < sub->numlines; i++) for (uint32_t i = 0; i < sub->numlines; i++)
@ -397,7 +396,7 @@ void RenderPolyPlane::Render(const TriMatrix &worldToClip, const PolyClipPlane &
if (portal) if (portal)
{ {
polyportal->Shape.push_back({ wallvert, 4, ccw, subsectorDepth }); polyportal->Shape.push_back({ wallvert, 4, ccw });
} }
} }
} }

View file

@ -30,7 +30,7 @@ class PolyCull;
class RenderPolyPlane class RenderPolyPlane
{ {
public: public:
static void RenderPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t ceilingSubsectorDepth, uint32_t floorSubsectorDepth, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals); static void RenderPlanes(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t stencilValue, double skyCeilingHeight, double skyFloorHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals);
private: private:
struct UVTransform struct UVTransform
@ -47,7 +47,7 @@ private:
float xOffs, yOffs; float xOffs, yOffs;
}; };
void Render3DFloor(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, F3DFloor *fakefloor); void Render3DFloor(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, subsector_t *sub, uint32_t stencilValue, bool ceiling, F3DFloor *fakefloor);
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals); void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, PolyCull &cull, subsector_t *sub, uint32_t stencilValue, bool ceiling, double skyHeight, std::vector<std::unique_ptr<PolyDrawSectorPortal>> &sectorPortals);
TriVertex PlaneVertex(vertex_t *v1, double height, const UVTransform &transform); TriVertex PlaneVertex(vertex_t *v1, double height, const UVTransform &transform);
}; };

View file

@ -26,11 +26,10 @@
struct PolyPortalVertexRange struct PolyPortalVertexRange
{ {
PolyPortalVertexRange(const TriVertex *vertices, int count, bool ccw, uint32_t subsectorDepth) : Vertices(vertices), Count(count), Ccw(ccw), SubsectorDepth(subsectorDepth) { } PolyPortalVertexRange(const TriVertex *vertices, int count, bool ccw) : Vertices(vertices), Count(count), Ccw(ccw) { }
const TriVertex *Vertices; const TriVertex *Vertices;
int Count; int Count;
bool Ccw; bool Ccw;
uint32_t SubsectorDepth;
}; };
class PolyPortalSegment class PolyPortalSegment

View file

@ -179,7 +179,7 @@ void RenderPolyScene::RenderSubsector(subsector_t *sub, uint32_t ceilingSubsecto
if (sub->sector->CenterFloor() != sub->sector->CenterCeiling()) if (sub->sector->CenterFloor() != sub->sector->CenterCeiling())
{ {
RenderPolyPlane::RenderPlanes(WorldToClip, PortalPlane, Cull, sub, ceilingSubsectorDepth, floorSubsectorDepth, StencilValue, Cull.MaxCeilingHeight, Cull.MinFloorHeight, SectorPortals); RenderPolyPlane::RenderPlanes(WorldToClip, PortalPlane, Cull, sub, StencilValue, Cull.MaxCeilingHeight, Cull.MinFloorHeight, SectorPortals);
} }
if (mainBSP) if (mainBSP)
@ -384,7 +384,6 @@ void RenderPolyScene::RenderPortals(int portalDepth)
for (const auto &verts : portal->Shape) for (const auto &verts : portal->Shape)
{ {
args.SetFaceCullCCW(verts.Ccw); args.SetFaceCullCCW(verts.Ccw);
args.SetSubsectorDepth(verts.SubsectorDepth);
args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan); args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan);
} }
} }
@ -396,7 +395,6 @@ void RenderPolyScene::RenderPortals(int portalDepth)
for (const auto &verts : portal->Shape) for (const auto &verts : portal->Shape)
{ {
args.SetFaceCullCCW(verts.Ccw); args.SetFaceCullCCW(verts.Ccw);
args.SetSubsectorDepth(verts.SubsectorDepth);
args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan); args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan);
} }
} }
@ -420,7 +418,6 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
for (const auto &verts : portal->Shape) for (const auto &verts : portal->Shape)
{ {
args.SetFaceCullCCW(verts.Ccw); args.SetFaceCullCCW(verts.Ccw);
args.SetSubsectorDepth(verts.SubsectorDepth);
args.SetWriteColor(false); args.SetWriteColor(false);
args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan); args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan);
} }
@ -439,7 +436,6 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
for (const auto &verts : portal->Shape) for (const auto &verts : portal->Shape)
{ {
args.SetFaceCullCCW(verts.Ccw); args.SetFaceCullCCW(verts.Ccw);
args.SetSubsectorDepth(verts.SubsectorDepth);
args.SetWriteColor(false); args.SetWriteColor(false);
args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan); args.DrawArray(verts.Vertices, verts.Count, PolyDrawMode::TriangleFan);
} }
@ -467,7 +463,7 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
if (obj->particle) if (obj->particle)
{ {
RenderPolyParticle spr; RenderPolyParticle spr;
spr.Render(WorldToClip, PortalPlane, obj->particle, obj->sub, obj->subsectorDepth, StencilValue + 1); spr.Render(WorldToClip, PortalPlane, obj->particle, obj->sub, StencilValue + 1);
} }
else if (!obj->thing) else if (!obj->thing)
{ {
@ -476,12 +472,12 @@ void RenderPolyScene::RenderTranslucent(int portalDepth)
else if ((obj->thing->renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE) else if ((obj->thing->renderflags & RF_SPRITETYPEMASK) == RF_WALLSPRITE)
{ {
RenderPolyWallSprite wallspr; RenderPolyWallSprite wallspr;
wallspr.Render(WorldToClip, PortalPlane, obj->thing, obj->sub, obj->subsectorDepth, StencilValue + 1); wallspr.Render(WorldToClip, PortalPlane, obj->thing, obj->sub, StencilValue + 1);
} }
else else
{ {
RenderPolySprite spr; RenderPolySprite spr;
spr.Render(WorldToClip, PortalPlane, obj->thing, obj->sub, obj->subsectorDepth, StencilValue + 1, obj->SpriteLeft, obj->SpriteRight); spr.Render(WorldToClip, PortalPlane, obj->thing, obj->sub, StencilValue + 1, obj->SpriteLeft, obj->SpriteRight);
} }
} }
} }

View file

@ -83,7 +83,6 @@ void PolySkyDome::Render(const TriMatrix &worldToClip)
PolyDrawArgs args; PolyDrawArgs args;
args.SetLight(&NormalLight, 255, PolyRenderer::Instance()->Light.WallGlobVis(false), true); args.SetLight(&NormalLight, 255, PolyRenderer::Instance()->Light.WallGlobVis(false), true);
args.SetSubsectorDepth(RenderPolyScene::SkySubsectorDepth);
args.SetTransform(&objectToClip); args.SetTransform(&objectToClip);
args.SetStencilTestValue(255); args.SetStencilTestValue(255);
args.SetWriteStencil(true, 1); args.SetWriteStencil(true, 1);

View file

@ -67,7 +67,7 @@ bool RenderPolySprite::GetLine(AActor *thing, DVector2 &left, DVector2 &right)
return true; return true;
} }
void RenderPolySprite::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2) void RenderPolySprite::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t stencilValue, float t1, float t2)
{ {
DVector2 line[2]; DVector2 line[2];
if (!GetLine(thing, line[0], line[1])) if (!GetLine(thing, line[0], line[1]))
@ -142,7 +142,6 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const PolyClipPlane
PolyDrawArgs args; PolyDrawArgs args;
args.SetLight(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite); args.SetLight(GetColorTable(sub->sector->Colormap, sub->sector->SpecialColors[sector_t::sprites], true), lightlevel, PolyRenderer::Instance()->Light.SpriteGlobVis(foggy), fullbrightSprite);
args.SetSubsectorDepth(subsectorDepth);
args.SetTransform(&worldToClip); args.SetTransform(&worldToClip);
args.SetFaceCullCCW(true); args.SetFaceCullCCW(true);
args.SetStencilTestValue(stencilValue); args.SetStencilTestValue(stencilValue);
@ -152,8 +151,8 @@ void RenderPolySprite::Render(const TriMatrix &worldToClip, const PolyClipPlane
args.SetStyle(LegacyRenderStyles[STYLE_Normal], 1.0f, thing->fillcolor, thing->Translation, tex, fullbrightSprite); args.SetStyle(LegacyRenderStyles[STYLE_Normal], 1.0f, thing->fillcolor, thing->Translation, tex, fullbrightSprite);
else else
args.SetStyle(thing->RenderStyle, thing->Alpha, thing->fillcolor, thing->Translation, tex, fullbrightSprite); args.SetStyle(thing->RenderStyle, thing->Alpha, thing->fillcolor, thing->Translation, tex, fullbrightSprite);
args.SetSubsectorDepthTest(true); args.SetDepthTest(true);
args.SetWriteSubsectorDepth(false); args.SetWriteDepth(false);
args.SetWriteStencil(false); args.SetWriteStencil(false);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
} }

View file

@ -27,7 +27,7 @@
class RenderPolySprite class RenderPolySprite
{ {
public: public:
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue, float t1, float t2); void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t stencilValue, float t1, float t2);
static bool GetLine(AActor *thing, DVector2 &left, DVector2 &right); static bool GetLine(AActor *thing, DVector2 &left, DVector2 &right);
static bool IsThingCulled(AActor *thing); static bool IsThingCulled(AActor *thing);

View file

@ -270,7 +270,6 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &c
PolyDrawArgs args; PolyDrawArgs args;
args.SetLight(GetColorTable(Line->frontsector->Colormap, Line->frontsector->SpecialColors[sector_t::walltop]), GetLightLevel(), PolyRenderer::Instance()->Light.WallGlobVis(foggy), false); args.SetLight(GetColorTable(Line->frontsector->Colormap, Line->frontsector->SpecialColors[sector_t::walltop]), GetLightLevel(), PolyRenderer::Instance()->Light.WallGlobVis(foggy), false);
args.SetSubsectorDepth(SubsectorDepth);
args.SetTransform(&worldToClip); args.SetTransform(&worldToClip);
args.SetFaceCullCCW(true); args.SetFaceCullCCW(true);
args.SetStencilTestValue(StencilValue); args.SetStencilTestValue(StencilValue);
@ -283,9 +282,9 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &c
{ {
args.SetWriteStencil(true, Polyportal->StencilValue); args.SetWriteStencil(true, Polyportal->StencilValue);
args.SetWriteColor(false); args.SetWriteColor(false);
args.SetWriteSubsectorDepth(false); args.SetWriteDepth(false);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
Polyportal->Shape.push_back({ vertices, 4, true, SubsectorDepth }); Polyportal->Shape.push_back({ vertices, 4, true });
} }
else if (!Masked) else if (!Masked)
{ {
@ -298,13 +297,13 @@ void RenderPolyWall::Render(const TriMatrix &worldToClip, const PolyClipPlane &c
double srcalpha = MIN(Line->alpha, 1.0); double srcalpha = MIN(Line->alpha, 1.0);
double destalpha = addtrans ? 1.0 : 1.0 - srcalpha; double destalpha = addtrans ? 1.0 : 1.0 - srcalpha;
args.SetStyle(TriBlendMode::TextureAdd, srcalpha, destalpha); args.SetStyle(TriBlendMode::TextureAdd, srcalpha, destalpha);
args.SetSubsectorDepthTest(true); args.SetDepthTest(true);
args.SetWriteSubsectorDepth(true); args.SetWriteDepth(true);
args.SetWriteStencil(false); args.SetWriteStencil(false);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);
} }
RenderPolyDecal::RenderWallDecals(worldToClip, clipPlane, LineSeg, SubsectorDepth, StencilValue); RenderPolyDecal::RenderWallDecals(worldToClip, clipPlane, LineSeg, StencilValue);
} }
void RenderPolyWall::ClampHeight(TriVertex &v1, TriVertex &v2) void RenderPolyWall::ClampHeight(TriVertex &v1, TriVertex &v2)

View file

@ -29,7 +29,7 @@
#include "polyrenderer/poly_renderer.h" #include "polyrenderer/poly_renderer.h"
#include "polyrenderer/scene/poly_light.h" #include "polyrenderer/scene/poly_light.h"
void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue) void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t stencilValue)
{ {
if (RenderPolySprite::IsThingCulled(thing)) if (RenderPolySprite::IsThingCulled(thing))
return; return;
@ -106,8 +106,8 @@ void RenderPolyWallSprite::Render(const TriMatrix &worldToClip, const PolyClipPl
args.SetStencilTestValue(stencilValue); args.SetStencilTestValue(stencilValue);
args.SetTexture(tex); args.SetTexture(tex);
args.SetClipPlane(clipPlane); args.SetClipPlane(clipPlane);
args.SetSubsectorDepthTest(true); args.SetDepthTest(true);
args.SetWriteSubsectorDepth(false); args.SetWriteDepth(false);
args.SetWriteStencil(false); args.SetWriteStencil(false);
args.SetStyle(TriBlendMode::TextureMasked); args.SetStyle(TriBlendMode::TextureMasked);
args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan); args.DrawArray(vertices, 4, PolyDrawMode::TriangleFan);

View file

@ -27,5 +27,5 @@
class RenderPolyWallSprite class RenderPolyWallSprite
{ {
public: public:
void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t subsectorDepth, uint32_t stencilValue); void Render(const TriMatrix &worldToClip, const PolyClipPlane &clipPlane, AActor *thing, subsector_t *sub, uint32_t stencilValue);
}; };