From b39cb4f095c0071da7734b06ea4c50ec312888ce Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 1 Mar 2018 13:01:26 +0100 Subject: [PATCH] - fixed translucemt sorting for particles. At least on any semi-modern hardware. On old legacy hardware which lacks some important features this will still glitch. --- src/gl/scene/gl_drawinfo.cpp | 41 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/gl/scene/gl_drawinfo.cpp b/src/gl/scene/gl_drawinfo.cpp index 84da70596..2e2d5d1aa 100644 --- a/src/gl/scene/gl_drawinfo.cpp +++ b/src/gl/scene/gl_drawinfo.cpp @@ -358,47 +358,51 @@ void GLDrawList::SortWallIntoPlane(SortNode * head,SortNode * sort) // // //========================================================================== -void GLDrawList::SortSpriteIntoPlane(SortNode * head,SortNode * sort) +void GLDrawList::SortSpriteIntoPlane(SortNode * head, SortNode * sort) { - GLFlat * fh=&flats[drawitems[head->itemindex].index]; - GLSprite * ss=&sprites[drawitems[sort->itemindex].index]; + GLFlat * fh = &flats[drawitems[head->itemindex].index]; + GLSprite * ss = &sprites[drawitems[sort->itemindex].index]; bool ceiling = fh->z > r_viewpoint.Pos.Z; - if ((ss->z1>fh->z && ss->z2z) || ss->modelframe) + auto hiz = ss->z1 > ss->z2 ? ss->z1 : ss->z2; + auto loz = ss->z1 < ss->z2 ? ss->z1 : ss->z2; + + if ((hiz > fh->z && loz < fh->z) || ss->modelframe) { // We have to split this sprite - GLSprite s=*ss; + GLSprite s = *ss; AddSprite(&s); // add a copy to avoid reallocation issues. - - // Splitting is done in the shader with clip planes, if available + + // Splitting is done in the shader with clip planes, if available. + // The fallback here only really works for non-y-billboarded sprites. if (gl.flags & RFL_NO_CLIP_PLANES) { GLSprite * ss1; - ss1=&sprites[sprites.Size()-1]; - ss=&sprites[drawitems[sort->itemindex].index]; // may have been reallocated! - float newtexv=ss->vt + ((ss->vb-ss->vt)/(ss->z2-ss->z1))*(fh->z-ss->z1); + ss1 = &sprites[sprites.Size() - 1]; + ss = &sprites[drawitems[sort->itemindex].index]; // may have been reallocated! + float newtexv = ss->vt + ((ss->vb - ss->vt) / (ss->z2 - ss->z1))*(fh->z - ss->z1); if (!ceiling) { - ss->z1=ss1->z2=fh->z; - ss->vt=ss1->vb=newtexv; + ss->z1 = ss1->z2 = fh->z; + ss->vt = ss1->vb = newtexv; } else { - ss1->z1=ss->z2=fh->z; - ss1->vt=ss->vb=newtexv; + ss1->z1 = ss->z2 = fh->z; + ss1->vt = ss->vb = newtexv; } } - SortNode * sort2=SortNodes.GetNew(); - memset(sort2,0,sizeof(SortNode)); - sort2->itemindex=drawitems.Size()-1; + SortNode * sort2 = SortNodes.GetNew(); + memset(sort2, 0, sizeof(SortNode)); + sort2->itemindex = drawitems.Size() - 1; head->AddToLeft(sort); head->AddToRight(sort2); } - else if ((ss->z2z && !ceiling) || (ss->z1>fh->z && ceiling)) // completely on the left side + else if ((hiz < fh->z && !ceiling) || (loz > fh->z && ceiling)) // completely on the left side { head->AddToLeft(sort); } @@ -406,7 +410,6 @@ void GLDrawList::SortSpriteIntoPlane(SortNode * head,SortNode * sort) { head->AddToRight(sort); } - }