Skip to content

Commit

Permalink
[rend2] Sort sky draws to prevent popping
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SomaZ committed Feb 25, 2025
1 parent 0721f54 commit 8fe80d3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions shared/rd-rend2/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,7 @@ typedef struct {
backEndCounters_t pc;
trRefEntity_t *currentEntity;
qboolean skyRenderedThisView; // flag for drawing sun
byte skyNumber;

qboolean projection2D; // if qtrue, drawstretchpic doesn't need to change modes
float color2D[4];
Expand Down
6 changes: 5 additions & 1 deletion shared/rd-rend2/tr_shade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2056,7 +2056,11 @@ static void RB_IterateStagesGeneric( shaderCommands_t *input, const VertexArrays

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

uint32_t key = RB_CreateSortKey(item, stage, input->shader->sort);
uint32_t key;
if (input->shader->sort == SS_ENVIRONMENT)
key = RB_CreateSortKey(item, stage+8, input->shader->sort);
else
key = RB_CreateSortKey(item, stage, input->shader->sort);

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

Expand Down
4 changes: 3 additions & 1 deletion shared/rd-rend2/tr_sky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ static void DrawSkySide( struct image_s *image, const int mins[2], const int max
RB_FillDrawCommand(item.draw, GL_TRIANGLES, 1, &tess);
item.draw.params.indexed.numIndices -= tess.firstIndex;

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

RB_CommitInternalBufferData();
Expand Down Expand Up @@ -867,6 +868,7 @@ void RB_StageIteratorSky( void ) {

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


Expand Down

0 comments on commit 8fe80d3

Please sign in to comment.