Skip to content

Commit 796e130

Browse files
committed
Nuke SHADER_3D_(DYNAMIC_STATIC) distinction
SHADER_3D_DYNAMIC and SHADER_3D_STATIC were two options for implicitly creating a shader from an image that lacks a text shader. Merge them into a single SHADER_3D. The only distinction between the two was using CGEN_IDENTITY vs. CGEN_IDENTITY_LIGHTING. This only makes a difference if r_overbrightQ3 is on. But even for emulating Quake 3 the code was wrong: it requested CGEN_IDENTITY_LIGHTING, which cancels overbright, for models. Models use the light grid which *should* receive the overbright factor. Actual ioq3 uses CGEN_LIGHTING_DIFFUSE, which we no longer have, for those models.
1 parent 0e4a305 commit 796e130

File tree

7 files changed

+19
-42
lines changed

7 files changed

+19
-42
lines changed

src/engine/renderer/tr_bsp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ static shader_t* ShaderForShaderNum( int shaderNum ) {
829829

830830
dshader_t* dsh = &s_worldData.shaders[shaderNum];
831831

832-
shader_t* shader = R_FindShader( dsh->shader, shaderType_t::SHADER_3D_STATIC, RSF_DEFAULT );
832+
shader_t* shader = R_FindShader( dsh->shader, shaderType_t::SHADER_3D, RSF_DEFAULT );
833833

834834
// If the shader had errors, just use default shader
835835
if ( shader->defaultShader ) {
@@ -3271,7 +3271,7 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump )
32713271
}
32723272

32733273
// get information from the shader for fog parameters
3274-
shader = R_FindShader( fogs->shader, shaderType_t::SHADER_3D_DYNAMIC, RSF_DEFAULT );
3274+
shader = R_FindShader( fogs->shader, shaderType_t::SHADER_3D, RSF_DEFAULT );
32753275

32763276
out->fogParms = shader->fogParms;
32773277

src/engine/renderer/tr_local.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,7 @@ enum class ssaoMode {
12081208
enum class shaderType_t
12091209
{
12101210
SHADER_2D, // surface material: shader is for 2D rendering (like GUI elements)
1211-
SHADER_3D_DYNAMIC, // surface material: shader is for cGen diffuseLighting lighting
1212-
SHADER_3D_STATIC, // surface material: pre-lit triangle models
1211+
SHADER_3D,
12131212
};
12141213

12151214
struct shader_t

src/engine/renderer/tr_model_iqm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ bool R_LoadIQModel( model_t *mod, const void *buffer, int filesize,
881881
}
882882

883883
surface->shader = R_FindShader( ( char* )IQMPtr(header, header->ofs_text + mesh->material),
884-
shaderType_t::SHADER_3D_DYNAMIC, RSF_DEFAULT );
884+
shaderType_t::SHADER_3D, RSF_DEFAULT );
885885
if( surface->shader->defaultShader )
886886
surface->shader = tr.defaultShader;
887887
surface->data = IQModel;

src/engine/renderer/tr_model_md3.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ bool R_LoadMD3( model_t *mod, int lod, const void *buffer, const char *modName )
187187

188188
// only consider the first shader
189189
md3Shader = ( md3Shader_t * )( ( byte * ) md3Surf + md3Surf->ofsShaders );
190-
surf->shader = R_FindShader( md3Shader->name, shaderType_t::SHADER_3D_DYNAMIC, RSF_DEFAULT );
190+
surf->shader = R_FindShader( md3Shader->name, shaderType_t::SHADER_3D, RSF_DEFAULT );
191191

192192
// swap all the triangles
193193
surf->numTriangles = md3Surf->numTriangles;

src/engine/renderer/tr_model_md5.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ bool R_LoadMD5( model_t *mod, const char *buffer, const char *modName )
317317
// lowercase the surface name so skin compares are faster
318318

319319
// register the shaders
320-
sh = R_FindShader( surf->shader, shaderType_t::SHADER_3D_DYNAMIC, RSF_DEFAULT );
320+
sh = R_FindShader( surf->shader, shaderType_t::SHADER_3D, RSF_DEFAULT );
321321

322322
if ( sh->defaultShader )
323323
{

src/engine/renderer/tr_shader.cpp

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5993,10 +5993,6 @@ shader_t *R_FindShaderByName( const char *name )
59935993
// see if the shader is already loaded
59945994
for ( sh = shaderHashTable[ hash ]; sh; sh = sh->next )
59955995
{
5996-
// NOTE: if there was no shader or image available with the name strippedName
5997-
// then a default shader is created with type == SHADER_3D_DYNAMIC, so we
5998-
// have to check all default shaders otherwise for every call to R_FindShader
5999-
// with that same strippedName a new default shader is created.
60005996
if ( Q_stricmp( sh->name, strippedName ) == 0 )
60015997
{
60025998
// match found
@@ -6022,19 +6018,14 @@ Will always return a valid shader, but it might be the
60226018
default shader if the real one can't be found.
60236019
60246020
In the interest of not requiring an explicit shader text entry to
6025-
be defined for every single image used in the game, three default
6026-
shader behaviors can be auto-created for any image:
6021+
be defined for every single image used in the game, two default
6022+
shader behaviors can be auto-created for any image that does not
6023+
have an explicit shader:
60276024
6028-
If type == SHADER_2D, then the image will be used
6029-
for 2D rendering unless an explicit shader is found
6025+
If type == SHADER_2D, then the image will default to using vertex colors.
60306026
6031-
If type == SHADER_3D_DYNAMIC, then the image will have
6032-
dynamic diffuse lighting applied to it, as appropriate for most
6033-
entity skin surfaces.
6034-
6035-
If type == SHADER_3D_STATIC, then the image will use
6036-
the vertex rgba modulate values, as appropriate for misc_model
6037-
pre-lit surfaces.
6027+
If type == SHADER_3D, then the renderer will choose appropriate precomputed
6028+
lighting: lightmap, (precomputed) vertex or light grid.
60386029
===============
60396030
*/
60406031
shader_t *R_FindShader( const char *name, shaderType_t type, int flags )
@@ -6059,7 +6050,7 @@ shader_t *R_FindShader( const char *name, shaderType_t type, int flags )
60596050
for ( sh = shaderHashTable[ hash ]; sh; sh = sh->next )
60606051
{
60616052
// NOTE: if there was no shader or image available with the name strippedName
6062-
// then a default shader is created with type == SHADER_3D_DYNAMIC, so we
6053+
// then a default shader is created with type == SHADER_3D, so we
60636054
// have to check all default shaders otherwise for every call to R_FindShader
60646055
// with that same strippedName a new default shader is created.
60656056
if ( ( sh->type == type || sh->defaultShader ) && !Q_stricmp( sh->name, strippedName ) )
@@ -6214,20 +6205,8 @@ shader_t *R_FindShader( const char *name, shaderType_t type, int flags )
62146205
break;
62156206
}
62166207

6217-
case shaderType_t::SHADER_3D_DYNAMIC:
6218-
{
6219-
// dynamic colors at vertexes
6220-
stages[ 0 ].type = stageType_t::ST_COLLAPSE_DIFFUSEMAP;
6221-
stages[ 0 ].bundle[ 0 ].image[ 0 ] = image;
6222-
stages[ 0 ].active = true;
6223-
stages[ 0 ].rgbGen = colorGen_t::CGEN_IDENTITY_LIGHTING;
6224-
stages[ 0 ].stateBits = implicitStateBits;
6225-
break;
6226-
}
6227-
6228-
case shaderType_t::SHADER_3D_STATIC:
6208+
case shaderType_t::SHADER_3D:
62296209
{
6230-
// explicit colors at vertexes
62316210
stages[ 0 ].type = stageType_t::ST_COLLAPSE_DIFFUSEMAP;
62326211
stages[ 0 ].bundle[ 0 ].image[ 0 ] = image;
62336212
stages[ 0 ].active = true;
@@ -6349,8 +6328,7 @@ class ListShadersCmd : public Cmd::StaticCmd
63496328
{
63506329
static const std::unordered_map<shaderType_t, std::string> shaderTypeName = {
63516330
{ shaderType_t::SHADER_2D, "2D" },
6352-
{ shaderType_t::SHADER_3D_DYNAMIC, "3D_DYNAMIC" },
6353-
{ shaderType_t::SHADER_3D_STATIC, "3D_STATIC" },
6331+
{ shaderType_t::SHADER_3D, "3D" },
63546332
};
63556333

63566334
static const std::unordered_map<shaderSort_t, std::string> shaderSortName = {
@@ -6822,7 +6800,7 @@ static void CreateInternalShaders()
68226800

68236801
Q_strncpyz( shader.name, "<default>", sizeof( shader.name ) );
68246802

6825-
shader.type = shaderType_t::SHADER_3D_DYNAMIC;
6803+
shader.type = shaderType_t::SHADER_3D;
68266804
shader.noFog = true;
68276805
shader.fogShader = nullptr;
68286806
stages[ 0 ].type = stageType_t::ST_DIFFUSEMAP;
@@ -6833,7 +6811,7 @@ static void CreateInternalShaders()
68336811

68346812
Q_strncpyz( shader.name, "<fogEqual>", sizeof( shader.name ) );
68356813

6836-
shader.type = shaderType_t::SHADER_3D_DYNAMIC;
6814+
shader.type = shaderType_t::SHADER_3D;
68376815
shader.sort = Util::ordinal( shaderSort_t::SS_FOG );
68386816
stages[0].type = stageType_t::ST_FOGMAP;
68396817
for ( int i = 0; i < 5; i++ ) {
@@ -6845,7 +6823,7 @@ static void CreateInternalShaders()
68456823

68466824
Q_strncpyz( shader.name, "<fogLE>", sizeof( shader.name ) );
68476825

6848-
shader.type = shaderType_t::SHADER_3D_DYNAMIC;
6826+
shader.type = shaderType_t::SHADER_3D;
68496827
shader.sort = Util::ordinal( shaderSort_t::SS_FOG );
68506828
stages[0].type = stageType_t::ST_FOGMAP;
68516829
for ( int i = 0; i < 5; i++ ) {

src/engine/renderer/tr_skin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ qhandle_t RE_RegisterSkin( const char *name )
261261
Q_strncpyz( surf->name, surfName, sizeof( surf->name ) );
262262

263263
// RB: bspSurface_t does not have ::hash yet
264-
surf->shader = R_FindShader( token, shaderType_t::SHADER_3D_DYNAMIC, RSF_DEFAULT );
264+
surf->shader = R_FindShader( token, shaderType_t::SHADER_3D, RSF_DEFAULT );
265265
skin->numSurfaces++;
266266
}
267267

0 commit comments

Comments
 (0)