Skip to content

Commit bd91b46

Browse files
committed
tr_shader: add the linearColorMap, linearSpecularMap and linearRgbGen keywords and raw variants
- lienarColorMap, linearSpecularMap and linearRgbGen expects tr.worldLinearizeTexture. They are meant to be used in assets targeting the linear pipeline only. - rawColorMap, rawSpecularMap and rawRgbGen does the same, but there is no colorspace meaning. They are meant to be used when porting legacy assets that may be used in the naive pipeline to be rendered as they were before for historical purposes, while being ported the hacky way for the linear pipeline.
1 parent 90441c4 commit bd91b46

File tree

4 files changed

+68
-9
lines changed

4 files changed

+68
-9
lines changed

src/engine/renderer/tr_init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
12871287
}
12881288

12891289
static float convertFloatFromSRGB_NOP( float f ) { return f; }
1290-
static Color::Color convertColorFromSRGB_NOP( Color::Color c ) { return c; }
1290+
Color::Color convertColorFromSRGB_NOP( Color::Color c ) { return c; }
12911291

12921292
/*
12931293
===============

src/engine/renderer/tr_local.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,11 @@ enum
979979
ALL = BIT( 3 )
980980
};
981981

982+
using floatProcessor_t = float(*)(float);
983+
using colorProcessor_t = Color::Color(*)(Color::Color);
984+
985+
Color::Color convertColorFromSRGB_NOP( Color::Color c );
986+
982987
struct shaderStage_t
983988
{
984989
stageType_t type;
@@ -998,6 +1003,8 @@ enum
9981003
stageShaderBinder_t shaderBinder;
9991004
stageMaterialProcessor_t materialProcessor;
10001005

1006+
colorProcessor_t convertColorFromSRGB;
1007+
10011008
textureBundle_t bundle[ MAX_TEXTURE_BUNDLES ];
10021009

10031010
expression_t ifExp;
@@ -1021,6 +1028,7 @@ enum
10211028
Color::Color32Bit constantColor; // for CGEN_CONST and AGEN_CONST
10221029

10231030
uint32_t stateBits; // GLS_xxxx mask
1031+
uint8_t colorspaceBits; // LINEAR_xxxx mask
10241032

10251033
bool isCubeMap;
10261034

@@ -1272,6 +1280,12 @@ enum
12721280
GLS_DEFAULT = GLS_DEPTHMASK_TRUE
12731281
};
12741282

1283+
enum {
1284+
LINEAR_RGBGEN = ( 1 << 0 ),
1285+
LINEAR_COLORMAP = ( 1 << 1 ),
1286+
LINEAR_SPECULARMAP = ( 1 << 2 ),
1287+
};
1288+
12751289
// *INDENT-ON*
12761290
struct ShaderProgramDescriptor;
12771291

@@ -2397,9 +2411,6 @@ enum
23972411
int h;
23982412
};
23992413

2400-
using floatProcessor_t = float(*)(float);
2401-
using colorProcessor_t = Color::Color(*)(Color::Color);
2402-
24032414
/*
24042415
** trGlobals_t
24052416
**

src/engine/renderer/tr_shade.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17231723
{
17241724
tess.svars.color = pStage->constantColor;
17251725
tess.svars.color.Clamp();
1726-
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
1726+
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
17271727
break;
17281728
}
17291729

@@ -1733,7 +1733,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17331733
{
17341734
tess.svars.color = backEnd.currentEntity->e.shaderRGBA;
17351735
tess.svars.color.Clamp();
1736-
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
1736+
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
17371737
}
17381738
else
17391739
{
@@ -1749,7 +1749,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17491749
{
17501750
tess.svars.color = backEnd.currentEntity->e.shaderRGBA;
17511751
tess.svars.color.Clamp();
1752-
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
1752+
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
17531753
}
17541754
else
17551755
{
@@ -1782,7 +1782,7 @@ void Tess_ComputeColor( shaderStage_t *pStage )
17821782

17831783
tess.svars.color = Color::White * glow;
17841784
tess.svars.color.Clamp();
1785-
tess.svars.color = tr.convertColorFromSRGB( tess.svars.color );
1785+
tess.svars.color = pStage->convertColorFromSRGB( tess.svars.color );
17861786
break;
17871787
}
17881788

src/engine/renderer/tr_shader.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,16 +1491,23 @@ static bool LoadMap( shaderStage_t *stage, const char *buffer, stageType_t type,
14911491
to use any shader in UI, so we better take care of more than ST_COLORMAP. */
14921492
if ( ! ( shader.registerFlags & RSF_2D ) )
14931493
{
1494+
stage->convertColorFromSRGB = stage->colorspaceBits & LINEAR_RGBGEN ?
1495+
convertColorFromSRGB_NOP : stage->convertColorFromSRGB;
1496+
14941497
switch ( type )
14951498
{
14961499
case stageType_t::ST_COLORMAP:
14971500
case stageType_t::ST_DIFFUSEMAP:
1501+
imageParams.bits |= stage->colorspaceBits & LINEAR_COLORMAP ? 0 : IF_SRGB;
1502+
break;
14981503
case stageType_t::ST_GLOWMAP:
14991504
case stageType_t::ST_REFLECTIONMAP:
15001505
case stageType_t::ST_SKYBOXMAP:
1501-
case stageType_t::ST_SPECULARMAP:
15021506
imageParams.bits |= IF_SRGB;
15031507
break;
1508+
case stageType_t::ST_SPECULARMAP:
1509+
imageParams.bits |= stage->colorspaceBits & LINEAR_SPECULARMAP ? 0 : IF_SRGB;
1510+
break;
15041511
default:
15051512
break;
15061513
}
@@ -2095,6 +2102,8 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
20952102
bool loadMap = false;
20962103
bool loadAnimMap = false;
20972104

2105+
stage->convertColorFromSRGB = convertColorFromSRGB_NOP;
2106+
20982107
memset( delayedStageTextures, 0, sizeof( delayedStageTextures ) );
20992108
memset( delayedAnimationTextures, 0, sizeof( delayedAnimationTextures ) );
21002109

@@ -2641,6 +2650,45 @@ static bool ParseStage( shaderStage_t *stage, const char **text )
26412650
depthMaskBits = 0;
26422651
}
26432652
}
2653+
else if ( !Q_stricmp( token, "rawRgbGen" ) )
2654+
{
2655+
stage->colorspaceBits |= LINEAR_RGBGEN;
2656+
}
2657+
else if ( !Q_stricmp( token, "linearRgbGen" ) )
2658+
{
2659+
if ( !tr.worldLinearizeTexture )
2660+
{
2661+
Log::Warn("Usage of linearRgbGen in naive pipeline, assuming rawRgbGen");
2662+
}
2663+
2664+
stage->colorspaceBits |= LINEAR_RGBGEN;
2665+
}
2666+
else if ( !Q_stricmp( token, "rawColorMap" ) )
2667+
{
2668+
stage->colorspaceBits |= LINEAR_COLORMAP;
2669+
}
2670+
else if ( !Q_stricmp( token, "linearColorMap" ) )
2671+
{
2672+
if ( !tr.worldLinearizeTexture )
2673+
{
2674+
Log::Warn("Usage of linearColorMap in naive pipeline, assuming rawColorMap");
2675+
}
2676+
2677+
stage->colorspaceBits |= LINEAR_COLORMAP;
2678+
}
2679+
else if ( !Q_stricmp( token, "rawSpecularMap" ) )
2680+
{
2681+
stage->colorspaceBits |= LINEAR_SPECULARMAP;
2682+
}
2683+
else if ( !Q_stricmp( token, "linearSpecularMap" ) )
2684+
{
2685+
if ( !tr.worldLinearizeTexture )
2686+
{
2687+
Log::Warn("Usage of linearSpecularMap in naive pipeline, assuming rawSpecularMap");
2688+
}
2689+
2690+
stage->colorspaceBits |= LINEAR_SPECULARMAP;
2691+
}
26442692
// stage <type>
26452693
else if ( !Q_stricmp( token, "stage" ) )
26462694
{

0 commit comments

Comments
 (0)