Skip to content

Commit 8fe80d3

Browse files
committed
[rend2] Sort sky draws to prevent popping
When multiple skys are rendered per frame, they could pop randomly because of inconsitent sorting. Also makes sure sky stages are rendered after the actual sky image.
1 parent 0721f54 commit 8fe80d3

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

shared/rd-rend2/tr_local.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,6 +2479,7 @@ typedef struct {
24792479
backEndCounters_t pc;
24802480
trRefEntity_t *currentEntity;
24812481
qboolean skyRenderedThisView; // flag for drawing sun
2482+
byte skyNumber;
24822483

24832484
qboolean projection2D; // if qtrue, drawstretchpic doesn't need to change modes
24842485
float color2D[4];

shared/rd-rend2/tr_shade.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,11 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input, const VertexArrays
20562056

20572057
RB_FillDrawCommand(item.draw, GL_TRIANGLES, 1, input);
20582058

2059-
uint32_t key = RB_CreateSortKey(item, stage, input->shader->sort);
2059+
uint32_t key;
2060+
if (input->shader->sort == SS_ENVIRONMENT)
2061+
key = RB_CreateSortKey(item, stage+8, input->shader->sort);
2062+
else
2063+
key = RB_CreateSortKey(item, stage, input->shader->sort);
20602064

20612065
RB_AddDrawItem(backEndData->currentPass, key, item);
20622066

shared/rd-rend2/tr_sky.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
482482
RB_FillDrawCommand(item.draw, GL_TRIANGLES, 1, &tess);
483483
item.draw.params.indexed.numIndices -= tess.firstIndex;
484484

485-
uint32_t key = RB_CreateSortKey(item, 0, SS_ENVIRONMENT);
485+
int skyNumber = MAX(0, 7 - backEnd.skyNumber);
486+
uint32_t key = RB_CreateSortKey(item, skyNumber, SS_ENVIRONMENT);
486487
RB_AddDrawItem(backEndData->currentPass, key, item);
487488

488489
RB_CommitInternalBufferData();
@@ -867,6 +868,7 @@ void RB_StageIteratorSky( void ) {
867868

868869
// note that sky was drawn so we will draw a sun later
869870
backEnd.skyRenderedThisView = qtrue;
871+
backEnd.skyNumber++;
870872
}
871873

872874

0 commit comments

Comments
 (0)