Skip to content

Commit

Permalink
[rend2] Get rid of alphatest and glow shader permutations
Browse files Browse the repository at this point in the history
Those are handled via uniforms now. Less shaders to compile speeds up load times, having to switch less between glsl shaders speeds up ingame performance. Alphatest cases only commented out for now, will put these behind a cvar later, as some gpus might require to know if a discard can happen or not.

[rend2] Fix sky glowing when last rendered surface had a glow stage
  • Loading branch information
SomaZ committed May 3, 2024
1 parent b86845c commit 97e902a
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 78 deletions.
3 changes: 2 additions & 1 deletion code/rd-rend2/tr_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ static void RE_Blit(float fX0, float fY0, float fX1, float fY1, float fX2, float
GL_Cull(CT_TWO_SIDED);
GL_BindToTMU(pImage, TB_COLORMAP);

shaderProgram_t *shaderProgram = atest ? &tr.genericShader[GENERICDEF_USE_ALPHA_TEST] : &tr.genericShader[0];
//shaderProgram_t *shaderProgram = atest ? &tr.genericShader[GENERICDEF_USE_ALPHA_TEST] : &tr.genericShader[0];
shaderProgram_t *shaderProgram = &tr.genericShader[0];
GLSL_BindProgram(shaderProgram);

RB_BindUniformBlock(tr.staticUbo, UNIFORM_BLOCK_CAMERA, tr.camera2DUboOffset);
Expand Down
9 changes: 3 additions & 6 deletions shared/rd-rend2/glsl/generic.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,8 @@ uniform sampler2D u_DiffuseMap;
uniform int u_AlphaTestType;
#endif
uniform int u_FogIndex;
// x = glow out, y = deluxe, z = screen shadow, w = cube
uniform vec4 u_EnableTextures;

in vec2 var_DiffuseTex;
in vec4 var_Color;
Expand Down Expand Up @@ -599,10 +601,5 @@ void main()
#endif

out_Color = vec4(color.rgb * var_Color.rgb, color.a);

#if defined(USE_GLOW_BUFFER)
out_Glow = out_Color;
#else
out_Glow = vec4(0.0);
#endif
out_Glow = mix(vec4(0.0, 0.0, 0.0, out_Color.a), out_Color, u_EnableTextures.x);
}
11 changes: 2 additions & 9 deletions shared/rd-rend2/glsl/lightall.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,8 @@ uniform samplerCube u_CubeMap;
uniform sampler2D u_EnvBrdfMap;
#endif

#if defined(USE_NORMALMAP) || defined(USE_DELUXEMAP) || defined(USE_SPECULARMAP) || defined(USE_CUBEMAP)
// y = deluxe, w = cube
// x = glow out, y = deluxe, z = screen shadow, w = cube
uniform vec4 u_EnableTextures;
#endif

uniform vec4 u_NormalScale;
uniform vec4 u_SpecularScale;
Expand Down Expand Up @@ -1195,10 +1193,5 @@ void main()
#endif

out_Color.a = diffuse.a;

#if defined(USE_GLOW_BUFFER)
out_Glow = out_Color;
#else
out_Glow = vec4(0.0, 0.0, 0.0, out_Color.a);
#endif
out_Glow = mix(vec4(0.0, 0.0, 0.0, out_Color.a), out_Color, u_EnableTextures.x);
}
6 changes: 3 additions & 3 deletions shared/rd-rend2/glsl/surface_sprites.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ uniform int u_FogIndex;
uniform vec4 u_FogColorMask;
#endif

#if defined(ALPHA_TEST)
#if defined(USE_ALPHA_TEST)
uniform int u_AlphaTestType;
#endif

Expand Down Expand Up @@ -223,7 +223,7 @@ float CalcFog(in vec3 viewOrigin, in vec3 position, in Fog fog)

void main()
{
#if defined(ALPHA_TEST)
#if defined(USE_ALPHA_TEST)
float alphaTestValue = 0.5;
if (u_AlphaTestType == ALPHA_TEST_GT0)
{
Expand Down Expand Up @@ -256,7 +256,7 @@ void main()
}
#endif

#if defined(ALPHA_TEST)
#if defined(USE_ALPHA_TEST)
if (u_AlphaTestType == ALPHA_TEST_GT0)
{
if (out_Color.a == 0.0)
Expand Down
40 changes: 21 additions & 19 deletions shared/rd-rend2/tr_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ static size_t GLSL_GetShaderHeader(
ALPHA_TEST_GE128,
ALPHA_TEST_GE192));

Q_strcat(dest, size, "#define USE_ALPHA_TEST\n");

Q_strcat(dest, size,
va("#define MAX_G2_BONES %i\n",
MAX_G2_BONES));
Expand Down Expand Up @@ -1474,11 +1476,11 @@ static int GLSL_LoadGPUProgramGeneric(
if (i & GENERICDEF_USE_RGBAGEN)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_RGBAGEN\n");

if (i & GENERICDEF_USE_GLOW_BUFFER)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_GLOW_BUFFER\n");
/*if (i & GENERICDEF_USE_GLOW_BUFFER)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_GLOW_BUFFER\n");*/

if (i & GENERICDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");
/*if (i & GENERICDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");*/

if (!GLSL_LoadGPUShader(builder, &tr.genericShader[i], "generic", attribs, NO_XFB_VARS,
extradefines, *programDesc))
Expand Down Expand Up @@ -1540,8 +1542,8 @@ static int GLSL_LoadGPUProgramFogPass(
if (i & FOGDEF_USE_FALLBACK_GLOBAL_FOG)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_FALLBACK_GLOBAL_FOG\n");

if (i & FOGDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");
/*if (i & FOGDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");*/

if (!GLSL_LoadGPUShader(builder, &tr.fogShader[i], "fogpass", attribs, NO_XFB_VARS,
extradefines, *programDesc))
Expand All @@ -1552,7 +1554,7 @@ static int GLSL_LoadGPUProgramFogPass(
GLSL_InitUniforms(&tr.fogShader[i]);

qglUseProgram(tr.fogShader[i].program);
if (i & FOGDEF_USE_ALPHA_TEST)
//if (i & FOGDEF_USE_ALPHA_TEST)
GLSL_SetUniformInt(&tr.fogShader[i], UNIFORM_DIFFUSEMAP, 0);
qglUseProgram(0);

Expand Down Expand Up @@ -1603,8 +1605,8 @@ static int GLSL_LoadGPUProgramRefraction(
if (i & REFRACTIONDEF_USE_RGBAGEN)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_RGBAGEN\n");

if (i & REFRACTIONDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");
/*if (i & REFRACTIONDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");*/

if (i & REFRACTIONDEF_USE_SRGB_TRANSFORM)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_LINEAR_LIGHT\n");
Expand Down Expand Up @@ -1769,11 +1771,11 @@ static int GLSL_LoadGPUProgramLightAll(
attribs |= ATTR_BONE_INDEXES | ATTR_BONE_WEIGHTS;
}

if (i & LIGHTDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");
/*if (i & LIGHTDEF_USE_ALPHA_TEST)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_ALPHA_TEST\n");*/

if (i & LIGHTDEF_USE_GLOW_BUFFER)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_GLOW_BUFFER\n");
/*if (i & LIGHTDEF_USE_GLOW_BUFFER)
Q_strcat(extradefines, sizeof(extradefines), "#define USE_GLOW_BUFFER\n");*/

if (!GLSL_LoadGPUShader(builder, &tr.lightallShader[i], "lightall", attribs, NO_XFB_VARS,
extradefines, *programDesc))
Expand Down Expand Up @@ -2238,9 +2240,9 @@ static int GLSL_LoadGPUProgramSurfaceSprites(
Q_strcat(extradefines, sizeof(extradefines),
"#define USE_FOG\n");

if ( i & SSDEF_ALPHA_TEST )
/*if ( i & SSDEF_ALPHA_TEST )
Q_strcat(extradefines, sizeof(extradefines),
"#define ALPHA_TEST\n");
"#define USE_ALPHA_TEST\n");*/

if (i & SSDEF_ADDITIVE)
Q_strcat(extradefines, sizeof(extradefines),
Expand Down Expand Up @@ -2584,8 +2586,8 @@ shaderProgram_t *GLSL_GetGenericShaderProgram(int stage)
shaderStage_t *pStage = tess.xstages[stage];
int shaderAttribs = 0;

if ( pStage->alphaTestType != ALPHA_TEST_NONE )
shaderAttribs |= GENERICDEF_USE_ALPHA_TEST;
/*if ( pStage->alphaTestType != ALPHA_TEST_NONE )
shaderAttribs |= GENERICDEF_USE_ALPHA_TEST;*/

if (backEnd.currentEntity->e.renderfx & (RF_DISINTEGRATE1 | RF_DISINTEGRATE2))
shaderAttribs |= GENERICDEF_USE_RGBAGEN;
Expand Down Expand Up @@ -2642,10 +2644,10 @@ shaderProgram_t *GLSL_GetGenericShaderProgram(int stage)
shaderAttribs |= GENERICDEF_USE_TCGEN_AND_TCMOD;
}

if (pStage->glow)
/*if (pStage->glow)
{
shaderAttribs |= GENERICDEF_USE_GLOW_BUFFER;
}
}*/

return &tr.genericShader[shaderAttribs];
}
46 changes: 23 additions & 23 deletions shared/rd-rend2/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1188,13 +1188,13 @@ enum
GENERICDEF_USE_FOG = 0x0004,
GENERICDEF_USE_RGBAGEN = 0x0008,
GENERICDEF_USE_SKELETAL_ANIMATION = 0x0010,
GENERICDEF_USE_GLOW_BUFFER = 0x0020,
GENERICDEF_USE_ALPHA_TEST = 0x0040,
// GENERICDEF_USE_GLOW_BUFFER = 0x0020,
// GENERICDEF_USE_ALPHA_TEST = 0x0040,
#ifdef REND2_SP_MD3
GENERICDEF_USE_VERTEX_ANIMATION = 0x0080,
GENERICDEF_ALL = 0x00FF,
#else
GENERICDEF_ALL = 0x007F,
GENERICDEF_ALL = 0x001F,
#endif // REND2_SP

GENERICDEF_COUNT = GENERICDEF_ALL + 1,
Expand All @@ -1204,13 +1204,13 @@ enum
{
FOGDEF_USE_DEFORM_VERTEXES = 0x0001,
FOGDEF_USE_SKELETAL_ANIMATION = 0x0002,
FOGDEF_USE_ALPHA_TEST = 0x0004,
FOGDEF_USE_FALLBACK_GLOBAL_FOG = 0x0008,
//FOGDEF_USE_ALPHA_TEST = 0x0004,
FOGDEF_USE_FALLBACK_GLOBAL_FOG = 0x0004,
#ifdef REND2_SP_MD3
FOGDEF_USE_VERTEX_ANIMATION = 0x0010,
FOGDEF_ALL = 0x001F,
#else
FOGDEF_ALL = 0x000F,
FOGDEF_ALL = 0x0007,
#endif // REND2_SP

FOGDEF_COUNT = FOGDEF_ALL + 1,
Expand All @@ -1222,13 +1222,13 @@ enum
REFRACTIONDEF_USE_TCGEN_AND_TCMOD = 0x0002,
REFRACTIONDEF_USE_RGBAGEN = 0x0004,
REFRACTIONDEF_USE_SKELETAL_ANIMATION = 0x0008,
REFRACTIONDEF_USE_ALPHA_TEST = 0x0010,
REFRACTIONDEF_USE_SRGB_TRANSFORM = 0x0020,
//REFRACTIONDEF_USE_ALPHA_TEST = 0x0010,
REFRACTIONDEF_USE_SRGB_TRANSFORM = 0x0010,
#ifdef REND2_SP_MD3
REFRACTIONDEF_USE_VERTEX_ANIMATION = 0x0040,
REFRACTIONDEF_ALL = 0x007F,
#else
REFRACTIONDEF_ALL = 0x003F,
REFRACTIONDEF_ALL = 0x001F,
#endif // REND2_SP

REFRACTIONDEF_COUNT = REFRACTIONDEF_ALL + 1,
Expand All @@ -1243,10 +1243,10 @@ enum
LIGHTDEF_USE_PARALLAXMAP = 0x0008,
// LIGHTDEF_USE_SHADOWMAP = 0x0010,
LIGHTDEF_USE_SKELETAL_ANIMATION = 0x0010,
LIGHTDEF_USE_GLOW_BUFFER = 0x0020,
LIGHTDEF_USE_ALPHA_TEST = 0x0040,
LIGHTDEF_USE_CLOTH_BRDF = 0x0080,
LIGHTDEF_USE_SPEC_GLOSS = 0x0100,
//LIGHTDEF_USE_GLOW_BUFFER = 0x0020,
//LIGHTDEF_USE_ALPHA_TEST = 0x0040,
LIGHTDEF_USE_CLOTH_BRDF = 0x0020,
LIGHTDEF_USE_SPEC_GLOSS = 0x0040,

LIGHTDEF_LIGHTTYPE_MASK = LIGHTDEF_USE_LIGHTMAP |
LIGHTDEF_USE_LIGHT_VECTOR |
Expand All @@ -1256,7 +1256,7 @@ enum
LIGHTDEF_USE_VERTEX_ANIMATION = 0x0200,
LIGHTDEF_ALL = 0x03FF,
#else
LIGHTDEF_ALL = 0x01FF,
LIGHTDEF_ALL = 0x007F,
#endif // REND2_SP

LIGHTDEF_COUNT = LIGHTDEF_ALL + 1
Expand All @@ -1265,15 +1265,15 @@ enum
enum
{
SSDEF_FACE_CAMERA = 0x01,
SSDEF_ALPHA_TEST = 0x02,
SSDEF_FACE_UP = 0x04,
SSDEF_FX_SPRITE = 0x08,
SSDEF_USE_FOG = 0x10,
SSDEF_FOG_MODULATE = 0x20,
SSDEF_ADDITIVE = 0x40,
SSDEF_FLATTENED = 0x80,

SSDEF_ALL = 0xFF,
//SSDEF_ALPHA_TEST = 0x02,
SSDEF_FACE_UP = 0x02,
SSDEF_FX_SPRITE = 0x04,
SSDEF_USE_FOG = 0x08,
SSDEF_FOG_MODULATE = 0x10,
SSDEF_ADDITIVE = 0x20,
SSDEF_FLATTENED = 0x40,

SSDEF_ALL = 0x7F,
SSDEF_COUNT = SSDEF_ALL + 1
};

Expand Down
Loading

0 comments on commit 97e902a

Please sign in to comment.